Skip to content

Invalid suggestion for missing lifetime specifier #75040

Closed
@yvt

Description

@yvt

I tried this code:

trait Tr {
    const A: &u32;
}

I expected to see this happen: Compilation failure with reasonable diagnosis

Instead, this happened: The compiler suggested adding <'a> before trait, which is syntactically invalid.

error[E0106]: missing lifetime specifier
 --> src/lib.rs:2:14
  |
2 |     const A: &u32;
  |              ^ expected named lifetime parameter
  |
help: consider introducing a named lifetime parameter
  |
1 | <'a>trait Tr {
2 |     const A: &'a u32;
  |

error: aborting due to previous error

Meta

rustc --version --verbose:

rustc 1.46.0-nightly (0c03aee8b 2020-07-05)
binary: rustc
commit-hash: 0c03aee8b81185d65b5821518661c30ecdb42de5
commit-date: 2020-07-05
host: x86_64-apple-darwin
release: 1.46.0-nightly
LLVM version: 10.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