rust-lang / rust-lang/rust

Confusing message for unused type parameter that is used, but not transitively used

Open
#161,365 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<T> {
    bar: Bar<T>,
}

struct Bar<T> {}
Current output
error[E0392]: type parameter `T` is never used
 --> src/lib.rs:1:12
  |
1 | struct Foo<T> {
  |            ^ unused type parameter
2 |     bar: Bar<T>,
  |              - `T` is named here, but is likely unused in the containing type
  |
  = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
  = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead

error[E0392]: type parameter `T` is never used
 --> src/lib.rs:5:12
  |
5 | struct Bar<T> {}
  |            ^ unused type parameter
  |
  = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
  = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead

For more information about this error, try `rustc --explain E0392`.
error: could not compile `playground` (lib) due to 2 previous errors
Desired output
error[E0392]: type parameter `T` is never used
 --> src/lib.rs:1:12
  |
1 | struct Foo<T> {
  |            ^ unused type parameter
2 |     bar: Bar<T>,
  |              - `T` is named here, but is also unused in `Bar`
  |
  = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
  = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead

error[E0392]: type parameter `T` is never used
 --> src/lib.rs:5:12
  |
5 | struct Bar<T> {}
  |            ^ unused type parameter
  |
  = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
  = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead

For more information about this error, try `rustc --explain E0392`.
error: could not compile `playground` (lib) due to 2 previous errors
Rationale and extra context

The phrasing "is named here, but is likely unused in the containing type" is confusing.

  1. What is the "containing type"? It seems like it should refer to Bar<T>, but then I would call that a "constituent type" of Foo<T> or something like that.
  2. Why does it say "likely"? The compiler can see the full source code, it should know whether that’s the case or not.
Other cases

Rust Version
the one on https://play.rust-lang.org/
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 error E0392 with the provided Foo and Bar snippet on the Rust playground, then trace the compiler diagnostic that emits the “likely unused in the containing type” wording. Done means the diagnostic clearly describes the transitive unused parameter relationship and preserves the intended output for both reported errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.