Skip to content

Commit 6a1c063

Browse files
committed
Auto merge of #52175 - fpoli:testsuite-callsite-span, r=petrochenkov
Match errors using the callsite of macro expansions Fix for issue #51848
2 parents 00204c2 + 8ec9d72 commit 6a1c063

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+137
-49
lines changed

src/test/ui/codemap_tests/bad-format-args.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
format!();
13-
format!("" 1);
14-
format!("", 1 1);
12+
format!(); //~ ERROR requires at least a format string argument
13+
format!("" 1); //~ ERROR expected token: `,`
14+
format!("", 1 1); //~ ERROR expected token: `,`
1515
}

src/test/ui/codemap_tests/bad-format-args.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
error: requires at least a format string argument
22
--> $DIR/bad-format-args.rs:12:5
33
|
4-
LL | format!();
4+
LL | format!(); //~ ERROR requires at least a format string argument
55
| ^^^^^^^^^^
66
|
77
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
88

99
error: expected token: `,`
1010
--> $DIR/bad-format-args.rs:13:5
1111
|
12-
LL | format!("" 1);
12+
LL | format!("" 1); //~ ERROR expected token: `,`
1313
| ^^^^^^^^^^^^^^
1414
|
1515
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1616

1717
error: expected token: `,`
1818
--> $DIR/bad-format-args.rs:14:5
1919
|
20-
LL | format!("", 1 1);
20+
LL | format!("", 1 1); //~ ERROR expected token: `,`
2121
| ^^^^^^^^^^^^^^^^^
2222
|
2323
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

src/test/ui/cross-crate-macro-backtrace/main.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: in format string
12-
1311
// aux-build:extern_macro_crate.rs
1412
#[macro_use(myprintln, myprint)]
1513
extern crate extern_macro_crate;
1614

1715
fn main() {
1816
myprintln!("{}");
17+
//~^ ERROR in format string
1918
}

src/test/ui/cross-crate-macro-backtrace/main.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: 1 positional argument in format string, but no arguments were given
2-
--> $DIR/main.rs:18:5
2+
--> $DIR/main.rs:16:5
33
|
44
LL | myprintln!("{}");
55
| ^^^^^^^^^^^^^^^^^

src/test/ui/cross-file-errors/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ mod underscore;
1313

1414
fn main() {
1515
underscore!();
16+
//~^ ERROR expected expression, found reserved identifier `_`
1617
}

src/test/ui/edition-keywords-2015-2018-expansion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
extern crate edition_kw_macro_2018;
1818

1919
mod one_async {
20-
produces_async! {} // ERROR expected identifier, found reserved keyword
20+
produces_async! {} //~ ERROR expected identifier, found reserved keyword
2121
}
2222
mod two_async {
2323
produces_async_raw! {} // OK

src/test/ui/edition-keywords-2015-2018-expansion.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
error: expected identifier, found reserved keyword `async`
22
--> $DIR/edition-keywords-2015-2018-expansion.rs:20:5
33
|
4-
LL | produces_async! {} // ERROR expected identifier, found reserved keyword
4+
LL | produces_async! {} //~ ERROR expected identifier, found reserved keyword
55
| ^^^^^^^^^^^^^^^^^^ expected identifier, found reserved keyword
66
|
77
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

src/test/ui/edition-keywords-2018-2018-expansion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
extern crate edition_kw_macro_2018;
1818

1919
mod one_async {
20-
produces_async! {} // ERROR expected identifier, found reserved keyword `async`
20+
produces_async! {} //~ ERROR expected identifier, found reserved keyword `async`
2121
}
2222
mod two_async {
2323
produces_async_raw! {} // OK

src/test/ui/edition-keywords-2018-2018-expansion.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
error: expected identifier, found reserved keyword `async`
22
--> $DIR/edition-keywords-2018-2018-expansion.rs:20:5
33
|
4-
LL | produces_async! {} // ERROR expected identifier, found reserved keyword `async`
4+
LL | produces_async! {} //~ ERROR expected identifier, found reserved keyword `async`
55
| ^^^^^^^^^^^^^^^^^^ expected identifier, found reserved keyword
66
|
77
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

src/test/ui/hygiene/intercrate.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212

1313
// aux-build:intercrate.rs
1414

15-
// error-pattern:type `fn() -> u32 {intercrate::foo::bar::f}` is private
16-
1715
#![feature(decl_macro)]
1816

1917
extern crate intercrate;
2018

2119
fn main() {
2220
assert_eq!(intercrate::foo::m!(), 1);
21+
//~^ ERROR type `fn() -> u32 {intercrate::foo::bar::f}` is private
2322
}

src/test/ui/hygiene/intercrate.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: type `fn() -> u32 {intercrate::foo::bar::f}` is private
2-
--> $DIR/intercrate.rs:22:16
2+
--> $DIR/intercrate.rs:20:16
33
|
44
LL | assert_eq!(intercrate::foo::m!(), 1);
55
| ^^^^^^^^^^^^^^^^^^^^^

src/test/ui/hygiene/local_inner_macros_disabled.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
// `local_inner_macros` has no effect if `feature(use_extern_macros)` is not enabled
1212

1313
// aux-build:local_inner_macros.rs
14-
// error-pattern: cannot find macro `helper2!` in this scope
1514

1615
#[macro_use(public_macro)]
1716
extern crate local_inner_macros;
1817

19-
public_macro!();
18+
public_macro!(); //~ ERROR cannot find macro `helper2!` in this scope
2019

2120
fn main() {}

src/test/ui/hygiene/local_inner_macros_disabled.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
error: cannot find macro `helper2!` in this scope
2-
--> $DIR/local_inner_macros_disabled.rs:19:1
2+
--> $DIR/local_inner_macros_disabled.rs:18:1
33
|
4-
LL | public_macro!();
4+
LL | public_macro!(); //~ ERROR cannot find macro `helper2!` in this scope
55
| ^^^^^^^^^^^^^^^^
66
|
77
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

src/test/ui/issue-13446.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111

1212
// Used to cause ICE
1313

14-
// error-pattern: mismatched types
15-
1614
static VEC: [u32; 256] = vec![];
15+
//~^ ERROR mismatched types
1716

1817
fn main() {}

src/test/ui/issue-13446.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0308]: mismatched types
2-
--> $DIR/issue-13446.rs:16:26
2+
--> $DIR/issue-13446.rs:14:26
33
|
44
LL | static VEC: [u32; 256] = vec![];
55
| ^^^^^^ expected array of 256 elements, found struct `std::vec::Vec`

src/test/ui/issue-16966.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern:type annotations needed
1211
fn main() {
13-
panic!(
14-
std::default::Default::default()
15-
);
12+
panic!(std::default::Default::default());
13+
//~^ ERROR type annotations needed
1614
}

src/test/ui/issue-16966.stderr

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/issue-16966.rs:13:5
2+
--> $DIR/issue-16966.rs:12:5
33
|
4-
LL | / panic!(
5-
LL | | std::default::Default::default()
6-
LL | | );
7-
| |______^ cannot infer type for `M`
4+
LL | panic!(std::default::Default::default());
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for `M`
86
|
97
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
108

src/test/ui/issue-32829.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// error-pattern: calls in statics are limited
12-
1311
static S : u64 = { { panic!("foo"); 0 } };
12+
//~^ ERROR calls in statics are limited
1413

1514
fn main() {
1615
println!("{:?}", S);

src/test/ui/issue-32829.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
2-
--> $DIR/issue-32829.rs:13:22
2+
--> $DIR/issue-32829.rs:11:22
33
|
44
LL | static S : u64 = { { panic!("foo"); 0 } };
55
| ^^^^^^^^^^^^^^

src/test/ui/issue-50577.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
fn main() {
1212
enum Foo {
1313
Drop = assert_eq!(1, 1)
14+
//~^ ERROR if may be missing an else clause
1415
}
1516
}

src/test/ui/issue-51848.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// In case of macro expansion, the errors should be matched using the deepest callsite in the
12+
// macro call stack whose span is in the current file
13+
14+
macro_rules! macro_with_error {
15+
( ) => {
16+
println!("{"); //~ ERROR invalid
17+
};
18+
}
19+
20+
fn foo() {
21+
22+
}
23+
24+
fn main() {
25+
macro_with_error!();
26+
//^ In case of a local macro we want the error to be matched in the macro definition, not here
27+
28+
println!("}"); //~ ERROR invalid
29+
//^ In case of an external macro we want the error to be matched here
30+
}

src/test/ui/issue-51848.stderr

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: invalid format string: expected `'}'` but string was terminated
2+
--> $DIR/issue-51848.rs:16:20
3+
|
4+
LL | println!("{"); //~ ERROR invalid
5+
| ^ expected `'}'` in format string
6+
...
7+
LL | macro_with_error!();
8+
| -------------------- in this macro invocation
9+
|
10+
= note: if you intended to print `{`, you can escape it using `{{`
11+
12+
error: invalid format string: unmatched `}` found
13+
--> $DIR/issue-51848.rs:28:15
14+
|
15+
LL | println!("}"); //~ ERROR invalid
16+
| ^ unmatched `}` in format string
17+
|
18+
= note: if you intended to print `}`, you can escape it using `}}`
19+
20+
error: aborting due to 2 previous errors
21+

src/test/ui/lifetimes/borrowck-let-suggestion.nll.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | let mut x = vec![1].iter();
55
| ^^^^^^^ - temporary value only lives until here
66
| |
77
| temporary value does not live long enough
8+
LL | //~^ ERROR borrowed value does not live long enough
89
LL | x.use_mut();
910
| - borrow later used here
1011
|

src/test/ui/lifetimes/borrowck-let-suggestion.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
fn f() {
1212
let mut x = vec![1].iter();
13+
//~^ ERROR borrowed value does not live long enough
1314
x.use_mut();
1415
}
1516

src/test/ui/lifetimes/borrowck-let-suggestion.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let mut x = vec![1].iter();
55
| ^^^^^^^ - temporary value dropped here while still borrowed
66
| |
77
| temporary value does not live long enough
8-
LL | x.use_mut();
8+
...
99
LL | }
1010
| - temporary value needs to live until here
1111
|

src/test/ui/reachable/expr_again.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ fn main() {
1616
let x = loop {
1717
continue;
1818
println!("hi");
19+
//~^ ERROR unreachable statement
1920
};
2021
}

src/test/ui/reachable/expr_block.rs

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ fn c() {
3333
let x = {
3434
return;
3535
println!("foo");
36+
//~^ ERROR unreachable statement
3637
22
3738
};
3839
}

src/test/ui/reachable/expr_if.rs

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ fn baz() {
3535
// As the next action to be taken after the if arms, we should
3636
// report the `println!` as unreachable:
3737
println!("But I am.");
38+
//~^ ERROR unreachable statement
3839
}
3940

4041
fn main() { }

src/test/ui/reachable/expr_loop.rs

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
fn a() {
1717
loop { return; }
1818
println!("I am dead.");
19+
//~^ ERROR unreachable statement
1920
}
2021

2122
fn b() {
@@ -28,6 +29,7 @@ fn b() {
2829
fn c() {
2930
loop { return; }
3031
println!("I am dead.");
32+
//~^ ERROR unreachable statement
3133
}
3234

3335
fn d() {
@@ -38,6 +40,7 @@ fn d() {
3840
fn e() {
3941
loop { 'middle: loop { loop { break 'middle; } } }
4042
println!("I am dead.");
43+
//~^ ERROR unreachable statement
4144
}
4245

4346
fn main() { }

src/test/ui/reachable/expr_loop.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ LL | #![deny(unreachable_code)]
1212
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1313

1414
error: unreachable statement
15-
--> $DIR/expr_loop.rs:30:5
15+
--> $DIR/expr_loop.rs:31:5
1616
|
1717
LL | println!("I am dead.");
1818
| ^^^^^^^^^^^^^^^^^^^^^^^
1919
|
2020
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
2121

2222
error: unreachable statement
23-
--> $DIR/expr_loop.rs:40:5
23+
--> $DIR/expr_loop.rs:42:5
2424
|
2525
LL | println!("I am dead.");
2626
| ^^^^^^^^^^^^^^^^^^^^^^^

src/test/ui/reachable/expr_match.rs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn a() {
2222
fn b() {
2323
match () { () => return }
2424
println!("I am dead");
25+
//~^ ERROR unreachable statement
2526
}
2627

2728
fn c() {
@@ -32,6 +33,7 @@ fn c() {
3233
fn d() {
3334
match () { () if false => return, () => return }
3435
println!("I am dead");
36+
//~^ ERROR unreachable statement
3537
}
3638

3739
fn e() {

src/test/ui/reachable/expr_match.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ LL | println!("I am dead");
1919
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
2020

2121
error: unreachable statement
22-
--> $DIR/expr_match.rs:34:5
22+
--> $DIR/expr_match.rs:35:5
2323
|
2424
LL | println!("I am dead");
2525
| ^^^^^^^^^^^^^^^^^^^^^^

src/test/ui/reachable/expr_while.rs

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
fn foo() {
1717
while {return} {
1818
println!("Hello, world!");
19+
//~^ ERROR unreachable
1920
}
2021
}
2122

@@ -30,8 +31,10 @@ fn baz() {
3031
// Here, we cite the `while` loop as dead.
3132
while {return} {
3233
println!("I am dead.");
34+
//~^ ERROR unreachable
3335
}
3436
println!("I am, too.");
37+
//~^ ERROR unreachable
3538
}
3639

3740
fn main() { }

0 commit comments

Comments
 (0)