-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Simplify lifetime requirements for PySlice trait
#19687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
7fab4fa to
6dbb5b3
Compare
6dbb5b3 to
d7f8937
Compare
|
I think I wrote that code initially. Sorry that it caused problems. I vaguely remember seeing/thinking about those problems back then, but I don't have the full context anymore. Seems like two people are involved already, so I'll leave it up to you two to decide whichever solution you prefer. |
|
|
No preference here about which fix to take. Returning "stuff" instead of "references to stuff" feels like a simplicity win to me too, if we can get away with it. |
oconnor663
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as a lifetime fix, though maybe someone who knows this code better might have an opinion about the "slices of non-Copy types" question?
I think the only person who might have a strong opinion is @sharkdp as the original author of this trait, and he's left it up to us 😆 The only current users of the trait are |
* main: (39 commits) [ty] Initial test suite for `TypedDict` (#19686) [ty] Improve debuggability of protocol types (#19662) [ty] Simplify lifetime requirements for `PySlice` trait (#19687) [ty] Improve `isinstance()` truthiness analysis for generic types (#19668) [`refurb`] Make example error out-of-the-box (`FURB164`) (#19673) Fix link: unused_import.rs (#19648) [ty] Remove `Specialization::display` (full) (#19682) [ty] Remove `KnownModule::is_enum` (#19681) [ty] Support `__setitem__` and improve `__getitem__` related diagnostics (#19578) [ty] Sync vendored typeshed stubs (#19676) [`flake8-use-pathlib`] Expand `PTH201` to check all `PurePath` subclasses (#19440) [`refurb`] Make example error out-of-the-box (`FURB180`) (#19672) [`pyupgrade`] Prevent infinite loop with `I002` (`UP010`, `UP035`) (#19413) [ty] Improve the `Display` for generic `type[]` types (#19667) [ty] Refactor `TypeInferenceBuilder::infer_subscript_expression_types` (#19658) Fix tests on 32-bit architectures (#19652) [ty] Move `pandas-stubs` to bad.txt (#19659) [ty] Remove special casing for string-literal-in-tuple `__contains__` (#19642) Update pre-commit's `ruff` id (#19654) Update salsa (#19449) ...

Summary
I ran into some nightmarish borrow-check issues in #19669 that were hard to figure out. This PR fixes them -- but I'm splitting it out of #19669 because it seems like a nice simplification on its own merits (it simplifies all callsites of the
py_slicemethod), and helps reduce the diff to review for that PR.I had to enlist @oconnor663's help to understand the lifetime issues I was running into in #19669. Quoting his analysis:
@oconnor663 has an alternative patch at 36a8eda that also fixes these issues, and continues the behaviour on
mainwherebyPySliceis implemented for all[T](this PR changes this:PySliceis now only implemented for all[T]whereT: Copy). I weakly prefer my version here, because it simplifies all callsites of the trait method, and iterating over references toTypes feels a bit silly when we know they're allCopy. But I'm happy to go with Jack's solution too, if we'd prefer to continue implementing the trait for[T]whereT: !Copy!Test Plan
cargo build