rust-lang / rust-lang/rust

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

Open
#124,634 6 comments 0 reactions 1 assignee View on GitHub

@shrirambalaji is already working on this.

Since Sep 15, 2024.

A-diagnostics D-terse E-help-wanted E-needs-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

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.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.