Skip to content

E0392 incorrectly claims generic parameter used in associated type bound is unused #105311

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
PatchMixolydic opened this issue Dec 5, 2022 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@PatchMixolydic
Copy link
Contributor

PatchMixolydic commented Dec 5, 2022

Given the following code (playground):

trait Trait<T> {
    type Type;
}

struct X<U, F: Trait<(), Type = U>>(F);
struct Y<T, U, F: Trait<T, Type = U>>(F);

The current output is:

error[E0392]: parameter `T` is never used
 --> src/lib.rs:6:10
  |
6 | struct Y<T, U, F: Trait<T, Type = U>>(F);
  |          ^ unused 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: usize` instead

error[E0392]: parameter `U` is never used
 --> src/lib.rs:6:13
  |
6 | struct Y<T, U, F: Trait<T, Type = U>>(F);
  |             ^ unused parameter
  |
  = help: consider removing `U`, referring to it in a field, or using a marker such as `PhantomData`
  = help: if you intended `U` to be a const parameter, use `const U: usize` instead

Note that there are no diagnostics for X. Indeed, removing Y causes the build to succeed.

The first instance of E0392 is allegedly correct according to #60214 and #53589. However, the second diagnostic claiming that U is unused seems to be incorrect. Otherwise, E0392 should also complain about X's U parameter.

Ideally, the output should look like:

error[E0392]: parameter `T` is never used
 --> src/lib.rs:6:10
  |
6 | struct Y<T, U, F: Trait<T, Type = U>>(F);
  |          ^ unused 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: usize` instead

@rustbot modify labels +A-traits +D-incorrect

@PatchMixolydic PatchMixolydic added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 5, 2022
@rustbot rustbot added A-trait-system Area: Trait system D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels Dec 5, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. 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

2 participants