- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
fn add_one(x: i32) -> i32 {
    x + 1
}
fn main() {
    add_one(no_such_local, 10);
}Current output
error[E0425]: cannot find value `no_such_local` in this scope
 --> src/main.rs:6:13
  |
6 |     add_one(no_such_local, 10);
  |             ^^^^^^^^^^^^^ not found in this scope
error[E0061]: this function takes 1 argument but 2 arguments were supplied
 --> src/main.rs:6:5
  |
6 |     add_one(no_such_local, 10);
  |     ^^^^^^^              ----
  |                          | |
  |                          | unexpected argument of type `{integer}`
  |                          help: remove the extra argument
  |
note: function defined here
 --> src/main.rs:1:4
  |
1 | fn add_one(x: i32) -> i32 {
  |    ^^^^^^^ ------
Some errors have detailed explanations: E0061, E0425.
For more information about an error, try `rustc --explain E0061`.
Desired output
error[E0425]: cannot find value `no_such_local` in this scope
 --> src/main.rs:6:13
  |
6 |     add_one(no_such_local, 10);
  |             ^^^^^^^^^^^^^ not found in this scope
error[E0061]: this function takes 1 argument but 2 arguments were supplied
 --> src/main.rs:6:5
  |
6 |     add_one(no_such_local, 10);
  |     ^^^^^^^ ---------------
  |             | |
  |             | unexpected argument
  |             help: remove the extra argument
  |
note: function defined here
 --> src/main.rs:1:4
  |
1 | fn add_one(x: i32) -> i32 {
  |    ^^^^^^^ ------
Some errors have detailed explanations: E0061, E0425.
For more information about an error, try `rustc --explain E0061`.
Rationale and extra context
It's surprising that rustc suggests removing an argument whose type matches the expected type, in favour of a value that doesn't exist.
I encountered this when editing a struct and its methods to remove a field, where self.foo(self.old_field, argument) incorrectly suggested removing argument when foo no longer took two arguments.
Other cases
No response
Rust Version
$ rustc --version --verbose
rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: aarch64-apple-darwin
release: 1.78.0
LLVM version: 18.1.2Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.