Skip to content

Incorrect suggestion when type annotation on turbofished enum is needed #100137

Closed

Description

Given the following code: https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=b9b341939839ec733bf081c5ddf86e5b

enum OhNo<T, U> {
  A(T),
  B(U),
  C,
}

fn uwu() {
    OhNo::C::<u32, _>;
}

The current output is:

Compiling playground v0.0.1 (/playground)
error[E0282]: type annotations needed
 --> src/lib.rs:8:5
  |
8 |     OhNo::C::<u32, _>;
  |     ^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `U` declared on the enum `OhNo`
  |
help: consider specifying the generic arguments
  |
8 |     OhNo::<u32, _>::C::<u32, _>;
  |         ++++++++++

For more information about this error, try `rustc --explain E0282`.
error: could not compile `playground` due to previous error

But applying this causes an error, saying that C doesn't allow type arguments.

This happens on nightly and beta, but not on stable. I'm assuming the "consider specifying the generic arguments" was added recently.

I don't think we need the help here, because the generic arguments are already specified.

@rustbot label +D-invalid-suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-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