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

Invalid suggestion on missing lifetime in impl trait associated type #68904

Closed
unneon opened this issue Feb 6, 2020 · 1 comment
Closed

Invalid suggestion on missing lifetime in impl trait associated type #68904

unneon opened this issue Feb 6, 2020 · 1 comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@unneon
Copy link

unneon commented Feb 6, 2020

Trying to elide lifetimes in an associated type of an impl trait causes rustc to emit some suggestions that contain invalid Rust syntax.

I tried this code:

trait Traito {
	type Typeo;
}

fn f(_: impl Traito<Typeo=&()>) {
}

I expected to see this happen: an error is emitted, possibly with a suggestion of adding a generic lifetime parameter.

Instead, this happened: the suggestion contains invalid Rust syntax, where the lifetime appears as if the parameter type was the generic parameter list:

    Checking wibblywobbly v0.1.0 (/home/matcegla/wibblywobbly)
error[E0106]: missing lifetime specifier
 --> src/lib.rs:5:27
  |
5 | fn f(_: impl Traito<Typeo=&()>) {
  |                           ^ expected named lifetime parameter
  |
help: consider introducing a named lifetime parameter
  |
5 | fn f(_: 'lifetime, impl Traito<Typeo=&'lifetime ()>) {
  |         ^^^^^^^^^^                   ^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0106`.
error: could not compile `wibblywobbly`.

To learn more, run the command again with --verbose.

rustc --version --verbose:
rustc 1.43.0-nightly (58b8343 2020-02-05)
binary: rustc
commit-hash: 58b8343
commit-date: 2020-02-05
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0

@jonas-schievink jonas-schievink added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 6, 2020
@estebank
Copy link
Contributor

estebank commented Feb 6, 2020

This was fixed in #68583: https://github.com/rust-lang/rust/pull/68583/files#diff-d4a8232a0918ba144fa7f17e2d941851.

It was very recently merged so it should be visible in tomorrow's nightly, I think.

@estebank estebank closed this as completed Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants