You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
RPITIT is allowed to name any in-scope lifetime parameter, unlike inherent RPIT methods #112194
I noticed (while responding to this comment by @aliemjay) that there's an inconsistency in how we handle returning Self if it captures lifetimes. For both inherent methods and RPITIT, if you write -> impl Trait and then return self on an impl for a type that containing a lifetime, we give you an error:
structFoo<'a>(&'astr);// ERROR: hidden type for `impl Sized` captures lifetime that does not appear in boundsimpl<'a>Foo<'a>{fnfoo(self) -> implSized{self}}traitTrait<'a>{fnbar(self) -> implSized;}// ERROR: hidden type for `impl Sized` captures lifetime that does not appear in boundsimpl<'a>Trait<'a>for&'ai32{fnbar(self) -> implSized{self}}
However, if you write -> Self on an implementation of a trait method that's written with -> impl Trait, there is no error (though this would require #[refine] with RFC 3245):
First, this inconsistency is weird from a user perspective because it seems like the capture rules say what lifetimes your hidden type is allowed to reference, and such a property can only be strengthened by an implementation (by referencing fewer, or longer-lived, lifetimes than the trait allows), never weakened. But here, the implementation specifies it a concrete type which allows it to name additional lifetimes.
Given that, we should probably apply the same restriction to RPITIT for the sake of consistency and not allow it to name any lifetime parameters as we assume it can today (including through Self). Though this might create other issues I'm not thinking of.
Perhaps we should consider example (1.) from my previous comment to be a refinement since it references a function lifetime parameter that isn't mentioned by the opaque, and deny it.
What to do with self types is a bit more delicate, as you noted above, and I have no idea what the best choice is there.
Activity
Remove "Self" as a "type parameter" wrt scoping rules
compiler-errors commentedon Jun 26, 2023
This is even more problematic when considering you can capture early-bound lifetimes not named by the opaque:
but not late-bound ones1:
Footnotes
Which for technical reason we should never be able to capture, since we literally don't have a way of desugaring that as a GAT. ↩
compiler-errors commentedon Jun 26, 2023
Perhaps we should consider example (1.) from my previous comment to be a refinement since it references a function lifetime parameter that isn't mentioned by the opaque, and deny it.
What to do with self types is a bit more delicate, as you noted above, and I have no idea what the best choice is there.
Rollup merge of rust-lang#113182 - compiler-errors:rpit-stricter-capt…
Rollup merge of rust-lang#113182 - compiler-errors:rpit-stricter-capt…
Auto merge of rust-lang#114489 - compiler-errors:rpitit-capture-all, …