rust-lang / rust-lang/rust

need to show help for `adding an explicit lifetime bound`.

Open
#125,453 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
struct Foo<'a, K: 'a = i32>(&'static T, &'static K);
fn main() {}
Current output
error[E0412]: cannot find type `T` in this scope
  --> ./src/main.rs:43:38
   |
43 | struct Foo<'a, K: 'a = i32>(&'static T, &'static K);
   |                -                     ^
   |                |
   |                similarly named type parameter `K` defined here
   |
help: a type parameter with a similar name exists
   |
43 | struct Foo<'a, K: 'a = i32>(&'static K, &'static K);
   |                                      ~
help: you might be missing a type parameter
   |
43 | struct Foo<'a, K: 'a, T = i32>(&'static T, &'static K);
   |                     +++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0412`.
Desired output
error[E0412]: cannot find type `T` in this scope
  --> ./src/main.rs:43:38
   |
43 | struct Foo<'a, K: 'a = i32>(&'static T, &'static K);
   |                -                     ^
   |                |
   |                similarly named type parameter `K` defined here
   |
help: a type parameter with a similar name exists
   |
43 | struct Foo<'a, K: 'a = i32>(&'static K, &'static K);
   |                                      ~
help: you might be missing a type parameter
   |
43 | struct Foo<'a, K: 'a = i32, T: 'static>(&'static T, &'static K);
   |
help: consider adding an explicit lifetime bound
   |
43 | struct Foo<'a, K: 'a + 'static = i32>(&'static T, &'static K);
   |                      +++++++++

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0412`.
Rationale and extra context

No response

Other cases

No response

Rust Version
rustc 1.80.0-nightly (ef0027897 2024-05-12)
binary: rustc
commit-hash: ef0027897d2e9014766fb47dce9ddbb925d2f540
commit-date: 2024-05-12
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.4
Anything else?

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the E0412 diagnostic with the Rust snippet in ./src/main.rs using the reported rustc version, then trace the compiler diagnostic that produces the missing-type-parameter suggestions. Done means the output also includes the explicit lifetime-bound suggestion shown in the desired output, without losing the existing suggestions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.