Skip to content

Commit a587036

Browse files
authored
Rollup merge of #96589 - Badel2:source-callsite, r=michaelwoerister
Use source callsite in check_argument_types suggestion This makes the "remove extra arguement" suggestion valid when the function argument is a macro. Additionally, this may fix #96225, but the only way I can reproduce that issue is using the playground, so we will need to wait until after this is merged to ensure it's fixed.
2 parents 329a73d + 685f66b commit a587036

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
980980
);
981981
for (idx, arg) in matched_inputs.iter().enumerate() {
982982
let suggestion_text = if let Some(arg) = arg {
983-
let arg_span = provided_args[*arg].span;
983+
let arg_span = provided_args[*arg].span.source_callsite();
984984
let arg_text = source_map.span_to_snippet(arg_span).unwrap();
985985
arg_text
986986
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// run-rustfix
2+
// Check that the HELP suggestion is `l(vec![])` instead of `l($crate::vec::Vec::new())`
3+
fn l(_a: Vec<u8>) {}
4+
5+
fn main() {
6+
l(vec![])
7+
//~^ ERROR this function takes 1 argument but 2 arguments were supplied
8+
//~| HELP remove the extra argument
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// run-rustfix
2+
// Check that the HELP suggestion is `l(vec![])` instead of `l($crate::vec::Vec::new())`
3+
fn l(_a: Vec<u8>) {}
4+
5+
fn main() {
6+
l(vec![], vec![])
7+
//~^ ERROR this function takes 1 argument but 2 arguments were supplied
8+
//~| HELP remove the extra argument
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0061]: this function takes 1 argument but 2 arguments were supplied
2+
--> $DIR/remove-extra-argument.rs:6:5
3+
|
4+
LL | l(vec![], vec![])
5+
| ^ ------ argument unexpected
6+
|
7+
note: function defined here
8+
--> $DIR/remove-extra-argument.rs:3:4
9+
|
10+
LL | fn l(_a: Vec<u8>) {}
11+
| ^ -----------
12+
help: remove the extra argument
13+
|
14+
LL | l(vec![])
15+
|
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)