Skip to content

Commit bcd1fed

Browse files
committed
add UI test
1 parent c73bcf0 commit bcd1fed

File tree

4 files changed

+72
-3
lines changed

4 files changed

+72
-3
lines changed

src/librustc_errors/emitter.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,8 +795,11 @@ impl EmitterWriter {
795795
if spans_updated {
796796
children.push(SubDiagnostic {
797797
level: Level::Note,
798-
message: vec![("this error originates in a macro outside of the current crate (run with RUST_MACRO_BACKTRACE=1 for more info)"
799-
.to_string(), Style::NoStyle)],
798+
message: vec![
799+
(["this error originates in a macro outside of the current crate",
800+
"(run with RUST_MACRO_BACKTRACE=1 for more info)"].join(" "),
801+
Style::NoStyle),
802+
],
800803
span: MultiSpan::new(),
801804
render_span: None,
802805
});
@@ -1242,7 +1245,7 @@ impl EmitterWriter {
12421245
if let Some(ref cm) = self.cm {
12431246
for trace in sp.macro_backtrace().iter().rev() {
12441247
let line_offset = buffer.num_lines();
1245-
1248+
12461249
let mut diag_string =
12471250
format!("in this expansion of {}", trace.macro_decl_name);
12481251
if let Some(def_site_span) = trace.def_site_span {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2017 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+
// Test that the macro backtrace facility works (supporting file)
12+
13+
// a non-local macro
14+
#[macro_export]
15+
macro_rules! ping {
16+
() => {
17+
pong!();
18+
}
19+
}
20+

src/test/ui/macro_backtrace/main.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2017 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+
// Test that the macro backtrace facility works
12+
// aux-build:ping.rs
13+
// rustc-env:RUST_MACRO_BACKTRACE
14+
15+
#[macro_use] extern crate ping;
16+
17+
// a local macro
18+
macro_rules! pong {
19+
() => { syntax error };
20+
}
21+
22+
fn main() {
23+
pong!();
24+
ping!();
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `error`
2+
--> $DIR/main.rs:19:20
3+
|
4+
19 | () => { syntax error };
5+
| -^^^^^ unexpected token
6+
| |
7+
| expected one of 8 possible tokens here
8+
$DIR/main.rs:23:5: 23:13 note: in this expansion of pong! (defined in $DIR/main.rs)
9+
10+
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `error`
11+
--> $DIR/main.rs:19:20
12+
|
13+
19 | () => { syntax error };
14+
| -^^^^^ unexpected token
15+
| |
16+
| expected one of 8 possible tokens here
17+
$DIR/main.rs:24:5: 24:13 note: in this expansion of ping! (defined in <ping macros>)
18+
<ping macros>:1:11: 1:24 note: in this expansion of pong! (defined in $DIR/main.rs)
19+
20+
error: aborting due to 2 previous errors
21+

0 commit comments

Comments
 (0)