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

On missing HRLT annotation, we sometimes provide a slightly incorrect suggestion #72404

Closed
estebank opened this issue May 20, 2020 · 0 comments · Fixed by #75372
Closed

On missing HRLT annotation, we sometimes provide a slightly incorrect suggestion #72404

estebank opened this issue May 20, 2020 · 0 comments · Fixed by #75372
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-enhancement Category: An issue proposing an enhancement or a PR with one. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

Given the following code:

struct X<'a>(&'a ());
struct S<'a>(&'a dyn Fn(&X) -> &X);

fn main() {
    let x = S(&|x| {
        println!("hi");
        x
    });
    x.0(&X(&()));
}

we currently give the following output

error[E0106]: missing lifetime specifier
 --> src/main.rs:2:32
  |
2 | struct S<'a>(&'a dyn Fn(&X) -> &X);
  |                         --     ^ expected named lifetime parameter
  |
  = help: this function's return type contains a borrowed value, but the signature does not say which one of argument 1's 2 lifetimes it is borrowed from
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'a` lifetime
  |
2 | struct S<'a>(&'a dyn for<'a> Fn(&'a X) -> &'a X);
  |                      ^^^^^^^    ^^^^^     ^^^
help: consider introducing a named lifetime parameter
  |
2 | struct S<'a, 'a>(&'a dyn Fn(&'a X) -> &'a X);
  |          ^^^                ^^^^^     ^^^

error[E0106]: missing lifetime specifier
 --> src/main.rs:2:33
  |
2 | struct S<'a>(&'a dyn Fn(&X) -> &X);
  |                         --      ^ expected named lifetime parameter
  |
  = help: this function's return type contains a borrowed value, but the signature does not say which one of argument 1's 2 lifetimes it is borrowed from
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'a` lifetime
  |
2 | struct S<'a>(&'a dyn for<'a> Fn(&'a X) -> &X<'a>);
  |                      ^^^^^^^    ^^^^^      ^^^^^
help: consider introducing a named lifetime parameter
  |
2 | struct S<'a, 'a>(&'a dyn Fn(&'a X) -> &X<'a>);
  |          ^^^                ^^^^^      ^^^^^

Beyond the verbosity, one of the suggestions offers struct S<'a, 'a>, which is not ideal.

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-papercut Diagnostics: An error or lint that needs small tweaks. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels May 20, 2020
@crlf0710 crlf0710 added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jun 11, 2020
@estebank estebank self-assigned this Aug 10, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Aug 13, 2020
Fix suggestion to use lifetime in type and in assoc const

_Do not merge until rust-lang#75363 has landed, as it has the test case for this._

* Account for associated types
* Associated `const`s can't have generics (fix rust-lang#74264)
* Do not suggest duplicate lifetimes and suggest `for<'a>` more (fix rust-lang#72404)
JohnTitor added a commit to JohnTitor/rust that referenced this issue Aug 13, 2020
Fix suggestion to use lifetime in type and in assoc const

_Do not merge until rust-lang#75363 has landed, as it has the test case for this._

* Account for associated types
* Associated `const`s can't have generics (fix rust-lang#74264)
* Do not suggest duplicate lifetimes and suggest `for<'a>` more (fix rust-lang#72404)
@bors bors closed this as completed in b9585fd Aug 13, 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-enhancement Category: An issue proposing an enhancement or a PR with one. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. D-papercut Diagnostics: An error or lint that needs small tweaks. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
2 participants