forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#127253 - chenyukang:yukang-fix-126246-fn-parameters-check, r=estebank Fix incorrect suggestion for extra argument with a type error Fixes rust-lang#126246 I tried to fix it in the `find_errors` of ArgMatrix, but seems it's hard to avoid breaking some other test cases. The root cause is we eliminate the first argument even with a type error at here: https://github.com/rust-lang/rust/blob/6292b2af620dbd771ebb687c3a93c69ba8f97268/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs#L664 So the left argument is always treated as extra one. But if there is already a type error, an error message will be generated firstly, which make this issue a trivial one.
- Loading branch information
Showing
3 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
tests/ui/argument-suggestions/suggest-better-removing-issue-126246.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
fn add_one(x: i32) -> i32 { | ||
x + 1 | ||
} | ||
|
||
fn add_two(x: i32, y: i32) -> i32 { | ||
x + y | ||
} | ||
|
||
fn main() { | ||
add_one(2, 2); //~ ERROR this function takes 1 argument but 2 arguments were supplied | ||
add_one(no_such_local, 10); //~ ERROR cannot find value `no_such_local` in this scope | ||
//~| ERROR this function takes 1 argument but 2 arguments were supplied | ||
add_one(10, no_such_local); //~ ERROR cannot find value `no_such_local` in this scope | ||
//~| ERROR this function takes 1 argument but 2 arguments were supplied | ||
add_two(10, no_such_local, 10); //~ ERROR cannot find value `no_such_local` in this scope | ||
//~| ERROR this function takes 2 arguments but 3 arguments were supplied | ||
add_two(no_such_local, 10, 10); //~ ERROR cannot find value `no_such_local` in this scope | ||
//~| ERROR this function takes 2 arguments but 3 arguments were supplied | ||
add_two(10, 10, no_such_local); //~ ERROR cannot find value `no_such_local` in this scope | ||
//~| ERROR this function takes 2 arguments but 3 arguments were supplied | ||
} |
124 changes: 124 additions & 0 deletions
124
tests/ui/argument-suggestions/suggest-better-removing-issue-126246.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
error[E0425]: cannot find value `no_such_local` in this scope | ||
--> $DIR/suggest-better-removing-issue-126246.rs:11:13 | ||
| | ||
LL | add_one(no_such_local, 10); | ||
| ^^^^^^^^^^^^^ not found in this scope | ||
|
||
error[E0425]: cannot find value `no_such_local` in this scope | ||
--> $DIR/suggest-better-removing-issue-126246.rs:13:17 | ||
| | ||
LL | add_one(10, no_such_local); | ||
| ^^^^^^^^^^^^^ not found in this scope | ||
|
||
error[E0425]: cannot find value `no_such_local` in this scope | ||
--> $DIR/suggest-better-removing-issue-126246.rs:15:17 | ||
| | ||
LL | add_two(10, no_such_local, 10); | ||
| ^^^^^^^^^^^^^ not found in this scope | ||
|
||
error[E0425]: cannot find value `no_such_local` in this scope | ||
--> $DIR/suggest-better-removing-issue-126246.rs:17:13 | ||
| | ||
LL | add_two(no_such_local, 10, 10); | ||
| ^^^^^^^^^^^^^ not found in this scope | ||
|
||
error[E0425]: cannot find value `no_such_local` in this scope | ||
--> $DIR/suggest-better-removing-issue-126246.rs:19:21 | ||
| | ||
LL | add_two(10, 10, no_such_local); | ||
| ^^^^^^^^^^^^^ not found in this scope | ||
|
||
error[E0061]: this function takes 1 argument but 2 arguments were supplied | ||
--> $DIR/suggest-better-removing-issue-126246.rs:10:5 | ||
| | ||
LL | add_one(2, 2); | ||
| ^^^^^^^ --- | ||
| | | | ||
| | unexpected argument of type `{integer}` | ||
| help: remove the extra argument | ||
| | ||
note: function defined here | ||
--> $DIR/suggest-better-removing-issue-126246.rs:1:4 | ||
| | ||
LL | fn add_one(x: i32) -> i32 { | ||
| ^^^^^^^ ------ | ||
|
||
error[E0061]: this function takes 1 argument but 2 arguments were supplied | ||
--> $DIR/suggest-better-removing-issue-126246.rs:11:5 | ||
| | ||
LL | add_one(no_such_local, 10); | ||
| ^^^^^^^ --------------- | ||
| | | ||
| unexpected argument | ||
| help: remove the extra argument | ||
| | ||
note: function defined here | ||
--> $DIR/suggest-better-removing-issue-126246.rs:1:4 | ||
| | ||
LL | fn add_one(x: i32) -> i32 { | ||
| ^^^^^^^ ------ | ||
|
||
error[E0061]: this function takes 1 argument but 2 arguments were supplied | ||
--> $DIR/suggest-better-removing-issue-126246.rs:13:5 | ||
| | ||
LL | add_one(10, no_such_local); | ||
| ^^^^^^^ --------------- | ||
| | | | ||
| | unexpected argument | ||
| help: remove the extra argument | ||
| | ||
note: function defined here | ||
--> $DIR/suggest-better-removing-issue-126246.rs:1:4 | ||
| | ||
LL | fn add_one(x: i32) -> i32 { | ||
| ^^^^^^^ ------ | ||
|
||
error[E0061]: this function takes 2 arguments but 3 arguments were supplied | ||
--> $DIR/suggest-better-removing-issue-126246.rs:15:5 | ||
| | ||
LL | add_two(10, no_such_local, 10); | ||
| ^^^^^^^ --------------- | ||
| | | | ||
| | unexpected argument | ||
| help: remove the extra argument | ||
| | ||
note: function defined here | ||
--> $DIR/suggest-better-removing-issue-126246.rs:5:4 | ||
| | ||
LL | fn add_two(x: i32, y: i32) -> i32 { | ||
| ^^^^^^^ ------ ------ | ||
|
||
error[E0061]: this function takes 2 arguments but 3 arguments were supplied | ||
--> $DIR/suggest-better-removing-issue-126246.rs:17:5 | ||
| | ||
LL | add_two(no_such_local, 10, 10); | ||
| ^^^^^^^ --------------- | ||
| | | ||
| unexpected argument | ||
| help: remove the extra argument | ||
| | ||
note: function defined here | ||
--> $DIR/suggest-better-removing-issue-126246.rs:5:4 | ||
| | ||
LL | fn add_two(x: i32, y: i32) -> i32 { | ||
| ^^^^^^^ ------ ------ | ||
|
||
error[E0061]: this function takes 2 arguments but 3 arguments were supplied | ||
--> $DIR/suggest-better-removing-issue-126246.rs:19:5 | ||
| | ||
LL | add_two(10, 10, no_such_local); | ||
| ^^^^^^^ --------------- | ||
| | | | ||
| | unexpected argument | ||
| help: remove the extra argument | ||
| | ||
note: function defined here | ||
--> $DIR/suggest-better-removing-issue-126246.rs:5:4 | ||
| | ||
LL | fn add_two(x: i32, y: i32) -> i32 { | ||
| ^^^^^^^ ------ ------ | ||
|
||
error: aborting due to 11 previous errors | ||
|
||
Some errors have detailed explanations: E0061, E0425. | ||
For more information about an error, try `rustc --explain E0061`. |