Open ehuss opened 2 months ago
Some notes:
Be concrete and short about what is happening.
All three parts of that diagnostic are necessary to explain the error without being inaccurate -- namely, we need to say that an inner opaque can't capture a higher ranked lifetime from an outer opaque. You can capture higher-ranked lifetimes (from the fn signature), just not ones from an outer opaque type.
I'm happy to make the error message more specific by rendering the names of the things involved here, but we also risk very large names coming from very large impl Trait
types.
I assume this is blocked on precise_capturing
Nah, I can implement the suggestion in a way that's gated on precise_capturing
. And precise_capturing
is necessarily landing before lifetime_capture_rules_2024
/the edition, so I'm not worried here.
Would also be nice if it also explained why this is an error. The real reason why this doesn't work is overly technical and probably not appreciable by the user.
We just need to say that this behavior is not supported in impl Trait
s today.
Add a link to the edition-guide chapter that explains capture rules
For the record, this is an error you can observe on master today (i.e. without lifetime_capture_rules_2024
) so we do need to be careful not to link someone an explanation that is not actually the reason why the error occurred. We should be able to detect whether the opaque captures the lifetime implicitly or explicitly, though.
(The E0657 docs could probably use an update at some point, especially after precise_capturing
happens)
I'm finding the error message for 2024 impl trait lifetime capture a little confusing. In the following example:
Produces the following output:
For someone that is not familiar with how impl trait capturing works, it seems confusing to understand why the compiler thinks that
impl Trait2
is trying to capture anything, since I'm not telling it to.I'm not entirely certain what would help here, but here are some suggestions:
impl Trait2 is capturing 'b
. Be concrete and short about what is happening.+ use<'a>
). I assume this is blocked onprecise_capturing
, and I'm not sure if there are intentions to do that. It would be nice if that explanation also explained to the user why that works ("explicitly capturing 'a indicates that theimpl Trait2
does not capture any other lifetimes").Version