Skip to content

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

Closed
@unneon

Description

@unneon

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions