Skip to content

Commit 1322dbf

Browse files
committed
fixed macro in foreign crate
1 parent 7fc953a commit 1322dbf

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1546,7 +1546,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15461546
SuggestionText::Reorder => Some("reorder these arguments".to_string()),
15471547
SuggestionText::DidYouMean => Some("did you mean".to_string()),
15481548
};
1549-
if let Some(suggestion_text) = suggestion_text {
1549+
if let Some(suggestion_text) = suggestion_text
1550+
&& !full_call_span.in_external_macro(self.sess().source_map())
1551+
{
15501552
let source_map = self.sess().source_map();
15511553
let suggestion_span = if let Some(args_span) = error_span.trim_start(full_call_span) {
15521554
// Span of the braces, e.g. `(a, b, c)`.

tests/ui/not-enough-arguments.rs

+8
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@ fn bar(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32) {
1919
println!("{}", f);
2020
}
2121

22+
macro_rules! delegate_local {
23+
($method:ident) => {
24+
<Self>::$method(8)
25+
//~^ ERROR function takes 2 arguments but 1
26+
};
27+
}
28+
2229
struct Bar;
2330

2431
impl Bar {
2532
fn foo(a: u8, b: u8) {}
2633
fn bar() {
34+
delegate_local!(foo);
2735
delegate!(foo);
2836
//~^ ERROR function takes 2 arguments but 1
2937
}

tests/ui/not-enough-arguments.stderr

+24-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,38 @@
11
error[E0061]: this function takes 2 arguments but 1 argument was supplied
2-
--> $DIR/not-enough-arguments.rs:27:9
2+
--> $DIR/not-enough-arguments.rs:24:9
33
|
4-
LL | delegate!(foo);
5-
| ^^^^^^^^^^^^^^ argument #2 of type `u8` is missing
4+
LL | <Self>::$method(8)
5+
| ^^^^^^^^^^^^^^^--- argument #2 of type `u8` is missing
6+
...
7+
LL | delegate_local!(foo);
8+
| -------------------- in this macro invocation
69
|
710
note: associated function defined here
8-
--> $DIR/not-enough-arguments.rs:25:8
11+
--> $DIR/not-enough-arguments.rs:32:8
912
|
1013
LL | fn foo(a: u8, b: u8) {}
1114
| ^^^ -----
12-
= note: this error originates in the macro `delegate` (in Nightly builds, run with -Z macro-backtrace for more info)
15+
= note: this error originates in the macro `delegate_local` (in Nightly builds, run with -Z macro-backtrace for more info)
1316
help: provide the argument
14-
--> $DIR/auxiliary/delegate_macro.rs:4:26
1517
|
1618
LL | <Self>::$method(8, /* u8 */)
1719
| ++++++++++
1820

21+
error[E0061]: this function takes 2 arguments but 1 argument was supplied
22+
--> $DIR/not-enough-arguments.rs:35:9
23+
|
24+
LL | delegate!(foo);
25+
| ^^^^^^^^^^^^^^ argument #2 of type `u8` is missing
26+
|
27+
note: associated function defined here
28+
--> $DIR/not-enough-arguments.rs:32:8
29+
|
30+
LL | fn foo(a: u8, b: u8) {}
31+
| ^^^ -----
32+
= note: this error originates in the macro `delegate` (in Nightly builds, run with -Z macro-backtrace for more info)
33+
1934
error[E0061]: this function takes 4 arguments but 3 arguments were supplied
20-
--> $DIR/not-enough-arguments.rs:33:5
35+
--> $DIR/not-enough-arguments.rs:41:5
2136
|
2237
LL | foo(1, 2, 3);
2338
| ^^^--------- argument #4 of type `isize` is missing
@@ -33,7 +48,7 @@ LL | foo(1, 2, 3, /* isize */);
3348
| +++++++++++++
3449

3550
error[E0061]: this function takes 6 arguments but 3 arguments were supplied
36-
--> $DIR/not-enough-arguments.rs:35:5
51+
--> $DIR/not-enough-arguments.rs:43:5
3752
|
3853
LL | bar(1, 2, 3);
3954
| ^^^--------- three arguments of type `i32`, `i32`, and `i32` are missing
@@ -48,6 +63,6 @@ help: provide the arguments
4863
LL | bar(1, 2, 3, /* i32 */, /* i32 */, /* i32 */);
4964
| +++++++++++++++++++++++++++++++++
5065

51-
error: aborting due to 3 previous errors
66+
error: aborting due to 4 previous errors
5267

5368
For more information about this error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)