-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #113999 - Centri3:macro-arm-expand, r=wesleywiser
Specify macro is invalid in certain contexts Adds a note when a macro is used where it really shouldn't be. Closes #113766
- Loading branch information
Showing
9 changed files
with
246 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// compile-flags: --crate-type=lib | ||
|
||
macro_rules! field { | ||
($name:ident:$type:ty) => { | ||
$name:$type | ||
}; | ||
} | ||
|
||
macro_rules! variant { | ||
($name:ident) => { | ||
$name | ||
} | ||
} | ||
|
||
struct Struct { | ||
field!(bar:u128), | ||
//~^ NOTE macros cannot expand to struct fields | ||
//~| ERROR unexpected token: `!` | ||
//~| NOTE unexpected token after this | ||
a: u32, | ||
b: u32, | ||
field!(recovers:()), //~ NOTE macros cannot expand to struct fields | ||
//~^ ERROR unexpected token: `!` | ||
//~^^ NOTE unexpected token after this | ||
} | ||
|
||
enum EnumVariant { | ||
variant!(whoops), | ||
//~^ NOTE macros cannot expand to enum variants | ||
//~| ERROR unexpected token: `!` | ||
//~| NOTE unexpected token after this | ||
U32, | ||
F64, | ||
variant!(recovers), | ||
//~^ NOTE macros cannot expand to enum variants | ||
//~| ERROR unexpected token: `!` | ||
//~| NOTE unexpected token after this | ||
Data { | ||
field!(x:u32), | ||
//~^ NOTE macros cannot expand to struct fields | ||
//~| ERROR unexpected token: `!` | ||
//~| NOTE unexpected token after this | ||
} | ||
} | ||
|
||
enum EnumVariantField { | ||
Named { | ||
field!(oopsies:()), | ||
//~^ NOTE macros cannot expand to struct fields | ||
//~| ERROR unexpected token: `!` | ||
//~| unexpected token after this | ||
field!(oopsies2:()), | ||
//~^ NOTE macros cannot expand to struct fields | ||
//~| ERROR unexpected token: `!` | ||
//~| unexpected token after this | ||
}, | ||
} | ||
|
||
union Union { | ||
A: u32, | ||
field!(oopsies:()), | ||
//~^ NOTE macros cannot expand to union fields | ||
//~| ERROR unexpected token: `!` | ||
//~| unexpected token after this | ||
B: u32, | ||
field!(recovers:()), | ||
//~^ NOTE macros cannot expand to union fields | ||
//~| ERROR unexpected token: `!` | ||
//~| unexpected token after this | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
error: unexpected token: `!` | ||
--> $DIR/macro-expand-to-field.rs:16:10 | ||
| | ||
LL | field!(bar:u128), | ||
| ^ unexpected token after this | ||
| | ||
= note: macros cannot expand to struct fields | ||
|
||
error: unexpected token: `!` | ||
--> $DIR/macro-expand-to-field.rs:22:10 | ||
| | ||
LL | field!(recovers:()), | ||
| ^ unexpected token after this | ||
| | ||
= note: macros cannot expand to struct fields | ||
|
||
error: unexpected token: `!` | ||
--> $DIR/macro-expand-to-field.rs:28:12 | ||
| | ||
LL | variant!(whoops), | ||
| ^ unexpected token after this | ||
| | ||
= note: macros cannot expand to enum variants | ||
|
||
error: unexpected token: `!` | ||
--> $DIR/macro-expand-to-field.rs:34:12 | ||
| | ||
LL | variant!(recovers), | ||
| ^ unexpected token after this | ||
| | ||
= note: macros cannot expand to enum variants | ||
|
||
error: unexpected token: `!` | ||
--> $DIR/macro-expand-to-field.rs:39:14 | ||
| | ||
LL | field!(x:u32), | ||
| ^ unexpected token after this | ||
| | ||
= note: macros cannot expand to struct fields | ||
|
||
error: unexpected token: `!` | ||
--> $DIR/macro-expand-to-field.rs:48:14 | ||
| | ||
LL | field!(oopsies:()), | ||
| ^ unexpected token after this | ||
| | ||
= note: macros cannot expand to struct fields | ||
|
||
error: unexpected token: `!` | ||
--> $DIR/macro-expand-to-field.rs:52:14 | ||
| | ||
LL | field!(oopsies2:()), | ||
| ^ unexpected token after this | ||
| | ||
= note: macros cannot expand to struct fields | ||
|
||
error: unexpected token: `!` | ||
--> $DIR/macro-expand-to-field.rs:61:10 | ||
| | ||
LL | field!(oopsies:()), | ||
| ^ unexpected token after this | ||
| | ||
= note: macros cannot expand to union fields | ||
|
||
error: unexpected token: `!` | ||
--> $DIR/macro-expand-to-field.rs:66:10 | ||
| | ||
LL | field!(recovers:()), | ||
| ^ unexpected token after this | ||
| | ||
= note: macros cannot expand to union fields | ||
|
||
error: aborting due to 9 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
macro_rules! arm { | ||
($pattern:pat => $block:block) => { | ||
$pattern => $block | ||
}; | ||
} | ||
|
||
fn main() { | ||
let x = Some(1); | ||
match x { | ||
Some(1) => {}, | ||
arm!(None => {}), | ||
//~^ NOTE macros cannot expand to match arms | ||
//~| ERROR unexpected `,` in pattern | ||
// doesn't recover | ||
Some(2) => {}, | ||
_ => {}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: unexpected `,` in pattern | ||
--> $DIR/macro-expand-to-match-arm.rs:11:25 | ||
| | ||
LL | arm!(None => {}), | ||
| ^ | ||
| | ||
= note: macros cannot expand to match arms | ||
|
||
error: aborting due to previous error | ||
|