Account for type param in '_
constraint for returned trait suggestion
#73497
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
D-terse
Diagnostics: An error or lint that doesn't give enough information about the problem at hand.
P-low
Low priority
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Given
rust/src/test/ui/issues/issue-16922.rs
Lines 1 to 6 in f7a1f97
we currently output
rust/src/test/ui/issues/issue-16922.stderr
Lines 1 to 12 in f7a1f97
The suggestion is incomplete and will not result in compilable code. Because the lifetime is coming from an argument of type
T
, which is an unconstrained type parameter,T
itself will not have the needed lifetime and causes the'static
obligation that we're trying to reverse by suggesting'_
. The appropriate changes to the code would be eitherfn foo<'a, T: Any + 'a>(value: &'a T) -> Box<dyn Any + 'a>
orfn foo(value: &dyn Any) -> Box<dyn Any + '_>
, depending on whetherT
appears in any other argument or not.The text was updated successfully, but these errors were encountered: