Skip to content

Improve error output for "expected value, found type parameter" #124634

Open
@mhelsley

Description

Code

pub fn delayed_insert<'a, T, C: Clone + Component>
        (ecommands: &'a mut EntityCommands<'a>,
         delay: Duration, c: C)
        -> &'a mut EntityCommands<'a> {
    ecommands.insert(DelayedInsert<T, C>::new(delay, c))
}

Current output

error[E0423]: expected value, found type parameter `T`
  --> src/delay.rs:22:36
   |
18 | pub fn delayed_insert<'a, T, C: Clone + Component>
   |                           - found this type parameter
...
22 |     ecommands.insert(DelayedInsert<T, C>::new(delay, c))
   |                                    ^ help: a local variable with a similar name exists: `c`

Desired output

error[E0423]: expected value, found type parameter `T`
  --> src/delay.rs:22:36
   |
18 | pub fn delayed_insert<'a, T, C: Clone + Component>
   |                           - found this type parameter
...
22 |     ecommands.insert(DelayedInsert<T, C>::new(delay, c))
   |                                    ^ help: a local variable with a similar name exists: `c`
   |                                    ^ alternate help: Substituting ::< for < may fix this

Rationale and extra context

In some cases rustc correctly suggests that the turbofish syntax is required.

Here, however, it looks like user intent is ambiguous and the compiler expects a comparison operator (which expects a value on the right of the < operator) but the error help doesn't offer the "correct" suggestion. So it may be helpful to offer an aldditional suggestion whenever the output is "expected value, found type parameter": use turbofish syntax.

I suspect this shouldn't require gathering or printing any more information than the compiler already has at-hand in this context -- a static, alternative, suggestion is likely all that'd be needed.

Other cases

No response

Rust Version

rustc 1.77.2 (25ef9e3d8 2024-04-09)
binary: rustc
commit-hash: 25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04
commit-date: 2024-04-09
host: x86_64-unknown-linux-gnu
release: 1.77.2
LLVM version: 17.0.6

Anything else?

Might be as easy to close this issue as looking for that string in the rustc source and modifying an existing output string.

Activity

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-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.E-help-wantedCall for participation: Help is requested to fix this issue.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleT-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