-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Hint for missing lifetime bound on trait object is missing if type alias is used #103582
Comments
A similar issue occurs for fields of a struct, but that might be harder to fix. |
@rustbot claim |
…ckh726 Add hint for missing lifetime bound on trait object when type alias is used Fix issue rust-lang#103582. The problem: When a type alias is used to specify the return type of the method in a trait impl, the suggestion for fixing the problem of "missing lifetime bound on trait object" of the trait impl will not be created. The issue caused by the code which searches for the return trait objects when constructing the hint suggestion is not able to find the trait objects since they are specified in the type alias path instead of the return path of the trait impl. The solution: Trace the trait objects in the type alias path and provide them along with the alias span to generate the suggestion in case the type alias is used in return type of the method in the trait impl.
…ckh726 Add hint for missing lifetime bound on trait object when type alias is used Fix issue rust-lang#103582. The problem: When a type alias is used to specify the return type of the method in a trait impl, the suggestion for fixing the problem of "missing lifetime bound on trait object" of the trait impl will not be created. The issue caused by the code which searches for the return trait objects when constructing the hint suggestion is not able to find the trait objects since they are specified in the type alias path instead of the return path of the trait impl. The solution: Trace the trait objects in the type alias path and provide them along with the alias span to generate the suggestion in case the type alias is used in return type of the method in the trait impl.
…ckh726 Add hint for missing lifetime bound on trait object when type alias is used Fix issue rust-lang#103582. The problem: When a type alias is used to specify the return type of the method in a trait impl, the suggestion for fixing the problem of "missing lifetime bound on trait object" of the trait impl will not be created. The issue caused by the code which searches for the return trait objects when constructing the hint suggestion is not able to find the trait objects since they are specified in the type alias path instead of the return path of the trait impl. The solution: Trace the trait objects in the type alias path and provide them along with the alias span to generate the suggestion in case the type alias is used in return type of the method in the trait impl.
I've run into the same confusing error, but with a function call: fn create_confirmation_dialog<'a>() -> Option<MessageDialogLayer<'a>> {
Some(MessageDialogLayer::new(Color::LightRed, "Error", "Test", Box::new(MessageDialogActionMap::ok())))
} After searching for a while, I found it was because a pub fn new(..., actions: Box<dyn MessageDialogActions<'a>>) -> Self // error
pub fn new(..., actions: Box<dyn MessageDialogActions<'a> + 'a>) -> Self // correct This is the closest existing issue I found, is this a similar enough case or should I open a new issue? |
Re. the snippet from the issue description, ideally the compiler would suggest: - type BoxedGreeter = Box<dyn Greeter>;
+ type BoxedGreeter<'a> = Box<dyn Greeter + 'a>; This makes the snippet compile (unless the lint |
Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a0979812dc1acbc732481dd2d3185637
The current output is:
However, by removing the type alias: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=bfde1cf5c8a72349b117aa21bbd61c3d
The output looks like this, which is much more helpful:
Without the hint, this error isn't very helpful for beginners, as it doesn't do anything to explain why
'1
must outlive'static
. It would be helpful if a similar hint could be provided when a type alias is used.The text was updated successfully, but these errors were encountered: