Skip to content

Commit 612969e

Browse files
committed
In error messages, don't assume attributes are always proc macros
Now that `macro_rules` macros can define attribute rules, make sure error messages account for that.
1 parent bb113c0 commit 612969e

14 files changed

+43
-17
lines changed

compiler/rustc_errors/src/emitter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ pub trait Emitter {
417417
if !redundant_span || always_backtrace {
418418
let msg: Cow<'static, _> = match trace.kind {
419419
ExpnKind::Macro(MacroKind::Attr, _) => {
420-
"this procedural macro expansion".into()
420+
"this macro attribute expansion".into()
421421
}
422422
ExpnKind::Macro(MacroKind::Derive, _) => {
423423
"this derive macro expansion".into()

src/tools/miri/tests/fail/alloc/alloc_error_handler_custom.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ note: inside `_::__rg_oom`
1111
--> tests/fail/alloc/alloc_error_handler_custom.rs:LL:CC
1212
|
1313
LL | #[alloc_error_handler]
14-
| ---------------------- in this procedural macro expansion
14+
| ---------------------- in this macro attribute expansion
1515
LL | fn alloc_error_handler(layout: Layout) -> ! {
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717
= note: inside `alloc::alloc::handle_alloc_error::rt_error` at RUSTLIB/alloc/src/alloc.rs:LL:CC

tests/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/alloc-error-handler-bad-signature-1.rs:10:1
33
|
44
LL | #[alloc_error_handler]
5-
| ---------------------- in this procedural macro expansion
5+
| ---------------------- in this macro attribute expansion
66
LL | // fn oom(
77
LL | || info: &Layout,
88
LL | || ) -> ()
@@ -23,7 +23,7 @@ error[E0308]: mismatched types
2323
--> $DIR/alloc-error-handler-bad-signature-1.rs:10:1
2424
|
2525
LL | #[alloc_error_handler]
26-
| ---------------------- in this procedural macro expansion
26+
| ---------------------- in this macro attribute expansion
2727
LL | // fn oom(
2828
LL | || info: &Layout,
2929
LL | || ) -> ()

tests/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/alloc-error-handler-bad-signature-2.rs:10:1
33
|
44
LL | #[alloc_error_handler]
5-
| ---------------------- in this procedural macro expansion
5+
| ---------------------- in this macro attribute expansion
66
LL | // fn oom(
77
LL | || info: Layout,
88
LL | || ) {
@@ -31,7 +31,7 @@ error[E0308]: mismatched types
3131
--> $DIR/alloc-error-handler-bad-signature-2.rs:10:1
3232
|
3333
LL | #[alloc_error_handler]
34-
| ---------------------- in this procedural macro expansion
34+
| ---------------------- in this macro attribute expansion
3535
LL | // fn oom(
3636
LL | || info: Layout,
3737
LL | || ) {

tests/ui/alloc-error/alloc-error-handler-bad-signature-3.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0061]: this function takes 0 arguments but 1 argument was supplied
22
--> $DIR/alloc-error-handler-bad-signature-3.rs:10:1
33
|
44
LL | #[alloc_error_handler]
5-
| ---------------------- in this procedural macro expansion
5+
| ---------------------- in this macro attribute expansion
66
LL | fn oom() -> ! {
77
| _-^^^^^^^^^^^^
88
LL | | loop {}

tests/ui/allocator/not-an-allocator.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
22
--> $DIR/not-an-allocator.rs:2:11
33
|
44
LL | #[global_allocator]
5-
| ------------------- in this procedural macro expansion
5+
| ------------------- in this macro attribute expansion
66
LL | static A: usize = 0;
77
| ^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
88
|
@@ -12,7 +12,7 @@ error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
1212
--> $DIR/not-an-allocator.rs:2:11
1313
|
1414
LL | #[global_allocator]
15-
| ------------------- in this procedural macro expansion
15+
| ------------------- in this macro attribute expansion
1616
LL | static A: usize = 0;
1717
| ^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
1818
|
@@ -23,7 +23,7 @@ error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
2323
--> $DIR/not-an-allocator.rs:2:11
2424
|
2525
LL | #[global_allocator]
26-
| ------------------- in this procedural macro expansion
26+
| ------------------- in this macro attribute expansion
2727
LL | static A: usize = 0;
2828
| ^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
2929
|
@@ -34,7 +34,7 @@ error[E0277]: the trait bound `usize: GlobalAlloc` is not satisfied
3434
--> $DIR/not-an-allocator.rs:2:11
3535
|
3636
LL | #[global_allocator]
37-
| ------------------- in this procedural macro expansion
37+
| ------------------- in this macro attribute expansion
3838
LL | static A: usize = 0;
3939
| ^^^^^ the trait `GlobalAlloc` is not implemented for `usize`
4040
|

tests/ui/allocator/two-allocators.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: cannot define multiple global allocators
44
LL | static A: System = System;
55
| -------------------------- previous global allocator defined here
66
LL | #[global_allocator]
7-
| ------------------- in this procedural macro expansion
7+
| ------------------- in this macro attribute expansion
88
LL | static B: System = System;
99
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot define a new global allocator
1010

tests/ui/custom_test_frameworks/mismatch.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0277]: the trait bound `TestDescAndFn: Testable` is not satisfied
22
--> $DIR/mismatch.rs:9:1
33
|
44
LL | #[test]
5-
| ------- in this procedural macro expansion
5+
| ------- in this macro attribute expansion
66
LL | fn wrong_kind(){}
77
| ^^^^^^^^^^^^^^^^^ the trait `Testable` is not implemented for `TestDescAndFn`
88
|
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(macro_attr)]
2+
3+
macro_rules! local_attr {
4+
attr() { $($body:tt)* } => {
5+
compile_error!(concat!("local_attr: ", stringify!($($body)*)));
6+
};
7+
//~^^ ERROR: local_attr
8+
}
9+
10+
fn main() {
11+
#[local_attr]
12+
struct S;
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: local_attr: struct S;
2+
--> $DIR/macro-rules-attr-error.rs:5:9
3+
|
4+
LL | compile_error!(concat!("local_attr: ", stringify!($($body)*)));
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
...
7+
LL | #[local_attr]
8+
| ------------- in this macro attribute expansion
9+
|
10+
= note: this error originates in the attribute macro `local_attr` (in Nightly builds, run with -Z macro-backtrace for more info)
11+
12+
error: aborting due to 1 previous error
13+

0 commit comments

Comments
 (0)