Skip to content
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

"Consider adding an explicit lifetime bound" doesn't take into account existing bounds #65286

Closed
varkor opened this issue Oct 10, 2019 · 2 comments · Fixed by #69305
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@varkor
Copy link
Member

varkor commented Oct 10, 2019

trait X { fn foo(&self) {} }

fn p3<'a, 'b, T: 'b>(v: T) -> Box<dyn X + 'a> where T: X {
    Box::new(v)
}

produces:

error[E0309]: the parameter type `T` may not live long enough
 --> src/lib.rs:4:5
  |
3 | fn p3<'a, 'b, T: 'b>(v: T) -> Box<dyn X + 'a> where T: X {
  |               -- help: consider adding an explicit lifetime bound `T: 'a`...
4 |     Box::new(v)
  |     ^^^^^^^^^^^
  |

It should suggest T: 'a + 'b (or similar), ideally in the same format as E0599.

@varkor varkor added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-confusing Diagnostics: Confusing error or lint that should be reworked. labels Oct 10, 2019
@varkor
Copy link
Member Author

varkor commented Oct 10, 2019

Note that this problem is already present in the test suite:

LL | fn generic_in_child<'a, 'b, L: X<&'a Nested<M>>, M: 'b>() {
| ^ -- help: consider adding an explicit lifetime bound `M: 'a`...
| _____|

@estebank estebank added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. and removed D-confusing Diagnostics: Confusing error or lint that should be reworked. labels Oct 10, 2019
@estebank
Copy link
Contributor

We already supply a structured suggestion in this case that can be applied with VSCode. We don't display the whole suggested code to reduce duplication in the text and to fit the intended flow of the text "add lifetime bound..."/"...so that". Changing it should be easy to do, but do we want to?

@estebank estebank removed the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Feb 20, 2020
Centril added a commit to Centril/rust that referenced this issue Feb 20, 2020
Tweak binding lifetime suggestion text

We already have a structured suggestion, but the wording made it seem like that wasn't the case.

Fix rust-lang#65286. r? @varkor
@bors bors closed this as completed in c816430 Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants