diff options
| author | bors <bors@rust-lang.org> | 2020-11-28 07:48:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-11-28 07:48:56 +0000 |
| commit | 4ae328bef47dffcbf363e5ae873f419c06a5511d (patch) | |
| tree | a4638ba9c7a64bae7fa30ec681219ef1a00dc3d3 /src | |
| parent | f8e5209a21c698398a0f8c04af55e2ad6cbd113c (diff) | |
| parent | 92bfa05b07090be1b3bf32af0c8947a0f0b387e8 (diff) | |
| download | rust-4ae328bef47dffcbf363e5ae873f419c06a5511d.tar.gz rust-4ae328bef47dffcbf363e5ae873f419c06a5511d.zip | |
Auto merge of #78296 - Aaron1011:fix/stmt-tokens, r=petrochenkov
Properly handle attributes on statements
We now collect tokens for the underlying node wrapped by `StmtKind`
nstead of storing tokens directly in `Stmt`.
`LazyTokenStream` now supports capturing a trailing semicolon after it
is initially constructed. This allows us to avoid refactoring statement
parsing to wrap the parsing of the semicolon in `parse_tokens`.
Attributes on item statements
(e.g. `fn foo() { #[bar] struct MyStruct; }`) are now treated as
item attributes, not statement attributes, which is consistent with how
we handle attributes on other kinds of statements. The feature-gating
code is adjusted so that proc-macro attributes are still allowed on item
statements on stable.
Two built-in macros (`#[global_allocator]` and `#[test]`) needed to be
adjusted to support being passed `Annotatable::Stmt`.
Diffstat (limited to 'src')
21 files changed, 376 insertions, 119 deletions
diff --git a/src/test/ui/associated-type-bounds/dyn-impl-trait-type.rs b/src/test/ui/associated-type-bounds/dyn-impl-trait-type.rs index fd9e52a6ff2..a8d00803a53 100644 --- a/src/test/ui/associated-type-bounds/dyn-impl-trait-type.rs +++ b/src/test/ui/associated-type-bounds/dyn-impl-trait-type.rs @@ -30,7 +30,7 @@ fn def_et3() -> Et3 { impl Tr1 for A { type As1 = core::ops::Range<u8>; fn mk(&self) -> Self::As1 { 0..10 } - }; + } Box::new(A) } pub fn use_et3() { diff --git a/src/test/ui/associated-type-bounds/dyn-lcsit.rs b/src/test/ui/associated-type-bounds/dyn-lcsit.rs index c936fe0550a..b7869e22b4a 100644 --- a/src/test/ui/associated-type-bounds/dyn-lcsit.rs +++ b/src/test/ui/associated-type-bounds/dyn-lcsit.rs @@ -33,7 +33,7 @@ const cdef_et3: &dyn Tr1<As1: Clone + Iterator<Item: Add<u8, Output: Into<u8>>>> impl Tr1 for A { type As1 = core::ops::Range<u8>; fn mk(&self) -> Self::As1 { 0..10 } - }; + } &A }; pub fn use_et3() { diff --git a/src/test/ui/associated-type-bounds/dyn-rpit-and-let.rs b/src/test/ui/associated-type-bounds/dyn-rpit-and-let.rs index f22a6c44cb8..08f965452ef 100644 --- a/src/test/ui/associated-type-bounds/dyn-rpit-and-let.rs +++ b/src/test/ui/associated-type-bounds/dyn-rpit-and-let.rs @@ -35,7 +35,7 @@ fn def_et3() -> Box<dyn Tr1<As1: Clone + Iterator<Item: Add<u8, Output: Into<u8> impl Tr1 for A { type As1 = core::ops::Range<u8>; fn mk(&self) -> Self::As1 { 0..10 } - }; + } let x /* : Box<dyn Tr1<As1: Clone + Iterator<Item: Add<u8, Output: Into<u8>>>>> */ = Box::new(A); x diff --git a/src/test/ui/associated-type-bounds/lcsit.rs b/src/test/ui/associated-type-bounds/lcsit.rs index 497205f9f18..5364f25f89a 100644 --- a/src/test/ui/associated-type-bounds/lcsit.rs +++ b/src/test/ui/associated-type-bounds/lcsit.rs @@ -39,7 +39,7 @@ const cdef_et3: impl Tr1<As1: Clone + Iterator<Item: Add<u8, Output: Into<u8>>>> impl Tr1 for A { type As1 = core::ops::Range<u8>; fn mk(&self) -> Self::As1 { 0..10 } - }; + } let x: impl Tr1<As1: Clone + Iterator<Item: Add<u8, Output: Into<u8>>>> = A; x }; diff --git a/src/test/ui/associated-type-bounds/rpit.rs b/src/test/ui/associated-type-bounds/rpit.rs index 7b640d5a457..47cadf3310b 100644 --- a/src/test/ui/associated-type-bounds/rpit.rs +++ b/src/test/ui/associated-type-bounds/rpit.rs @@ -27,7 +27,7 @@ fn def_et3() -> impl Tr1<As1: Clone + Iterator<Item: Add<u8, Output: Into<u8>>>> impl Tr1 for A { type As1 = core::ops::Range<u8>; fn mk(self) -> Self::As1 { 0..10 } - }; + } A } diff --git a/src/test/ui/associated-type-bounds/trait-alias-impl-trait.rs b/src/test/ui/associated-type-bounds/trait-alias-impl-trait.rs index 9ee33e4149a..025540ce200 100644 --- a/src/test/ui/associated-type-bounds/trait-alias-impl-trait.rs +++ b/src/test/ui/associated-type-bounds/trait-alias-impl-trait.rs @@ -31,7 +31,7 @@ fn def_et3() -> Et3 { impl Tr1 for A { type As1 = core::ops::Range<u8>; fn mk(self) -> Self::As1 { 0..10 } - }; + } A } pub fn use_et3() { diff --git a/src/test/ui/const-generics/min_const_generics/macro.rs b/src/test/ui/const-generics/min_const_generics/macro.rs index 85ecce551d4..575fbd33572 100644 --- a/src/test/ui/const-generics/min_const_generics/macro.rs +++ b/src/test/ui/const-generics/min_const_generics/macro.rs @@ -15,14 +15,14 @@ impl<const N: usize> Marker<N> for Example<N> {} fn make_marker() -> impl Marker<{ #[macro_export] - macro_rules! const_macro { () => {{ 3 }} }; inline!() + macro_rules! const_macro { () => {{ 3 }} } inline!() }> { Example::<{ const_macro!() }> } fn from_marker(_: impl Marker<{ #[macro_export] - macro_rules! inline { () => {{ 3 }} }; inline!() + macro_rules! inline { () => {{ 3 }} } inline!() }>) {} fn main() { @@ -30,7 +30,7 @@ fn main() { #[macro_export] macro_rules! gimme_a_const { ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} - }; + } gimme_a_const!(run) }>; @@ -42,13 +42,13 @@ fn main() { let _ok: [u8; { #[macro_export] - macro_rules! const_two { () => {{ 2 }} }; + macro_rules! const_two { () => {{ 2 }} } const_two!() }]; let _ok = [0; { #[macro_export] - macro_rules! const_three { () => {{ 3 }} }; + macro_rules! const_three { () => {{ 3 }} } const_three!() }]; let _ok = [0; const_three!()]; diff --git a/src/test/ui/issues/issue-10767.rs b/src/test/ui/issues/issue-10767.rs index fa10f073b45..f40815fdbdb 100644 --- a/src/test/ui/issues/issue-10767.rs +++ b/src/test/ui/issues/issue-10767.rs @@ -5,6 +5,6 @@ pub fn main() { fn f() { - }; + } let _: Box<fn()> = box (f as fn()); } diff --git a/src/test/ui/issues/issue-2074.rs b/src/test/ui/issues/issue-2074.rs index bd5f015cca0..a6bea385804 100644 --- a/src/test/ui/issues/issue-2074.rs +++ b/src/test/ui/issues/issue-2074.rs @@ -5,11 +5,11 @@ pub fn main() { let one = || { - enum r { a }; + enum r { a } r::a as usize }; let two = || { - enum r { a }; + enum r { a } r::a as usize }; one(); two(); diff --git a/src/test/ui/lint/redundant-semicolon/item-stmt-semi.rs b/src/test/ui/lint/redundant-semicolon/item-stmt-semi.rs new file mode 100644 index 00000000000..4592bc31a39 --- /dev/null +++ b/src/test/ui/lint/redundant-semicolon/item-stmt-semi.rs @@ -0,0 +1,10 @@ +// check-pass +// This test should stop compiling +// we decide to enable this lint for item statements. + +#![deny(redundant_semicolons)] + +fn main() { + fn inner() {}; + struct Bar {}; +} diff --git a/src/test/ui/macros/macro-2.rs b/src/test/ui/macros/macro-2.rs index 4890c991dcd..a315981b6a6 100644 --- a/src/test/ui/macros/macro-2.rs +++ b/src/test/ui/macros/macro-2.rs @@ -3,7 +3,7 @@ pub fn main() { macro_rules! mylambda_tt { ($x:ident, $body:expr) => ({ - fn f($x: isize) -> isize { return $body; }; + fn f($x: isize) -> isize { return $body; } f }) } diff --git a/src/test/ui/macros/macro-path.rs b/src/test/ui/macros/macro-path.rs index be59d8d139b..6c011c897da 100644 --- a/src/test/ui/macros/macro-path.rs +++ b/src/test/ui/macros/macro-path.rs @@ -8,7 +8,7 @@ mod m { macro_rules! foo { ($p:path) => ({ - fn f() -> $p { 10 }; + fn f() -> $p { 10 } f() }) } diff --git a/src/test/ui/proc-macro/allowed-attr-stmt-expr.rs b/src/test/ui/proc-macro/allowed-attr-stmt-expr.rs index 03c10a43248..25243aeef3b 100644 --- a/src/test/ui/proc-macro/allowed-attr-stmt-expr.rs +++ b/src/test/ui/proc-macro/allowed-attr-stmt-expr.rs @@ -13,19 +13,28 @@ extern crate std; extern crate attr_stmt_expr; extern crate test_macros; -use attr_stmt_expr::{expect_let, expect_print_stmt, expect_expr, expect_print_expr}; +use attr_stmt_expr::{expect_let, expect_my_macro_stmt, expect_expr, expect_my_macro_expr}; use test_macros::print_attr; -use std::println; + +// We don't use `std::println` so that we avoid loading hygiene +// information from libstd, which would affect the SyntaxContext ids +macro_rules! my_macro { + ($($tt:tt)*) => { () } +} + fn print_str(string: &'static str) { // macros are handled a bit differently - #[expect_print_expr] - println!("{}", string) + #[expect_my_macro_expr] + my_macro!("{}", string) } macro_rules! make_stmt { ($stmt:stmt) => { - $stmt + #[print_attr] + #[rustc_dummy] + $stmt; // This semicolon is *not* passed to the macro, + // since `$stmt` is already a statement. } } @@ -35,6 +44,10 @@ macro_rules! second_make_stmt { } } +// The macro will see a semicolon here +#[print_attr] +struct ItemWithSemi; + fn main() { make_stmt!(struct Foo {}); @@ -44,8 +57,8 @@ fn main() { let string = "Hello, world!"; #[print_attr] - #[expect_print_stmt] - println!("{}", string); + #[expect_my_macro_stmt] + my_macro!("{}", string); #[print_attr] second_make_stmt!(#[allow(dead_code)] struct Bar {}); @@ -54,6 +67,12 @@ fn main() { #[rustc_dummy] struct Other {}; + // The macro also sees a semicolon, + // for consistency with the `ItemWithSemi` case above. + #[print_attr] + #[rustc_dummy] + struct NonBracedStruct; + #[expect_expr] print_str("string") } diff --git a/src/test/ui/proc-macro/allowed-attr-stmt-expr.stdout b/src/test/ui/proc-macro/allowed-attr-stmt-expr.stdout index 0c7ac4fb682..6cf864f3590 100644 --- a/src/test/ui/proc-macro/allowed-attr-stmt-expr.stdout +++ b/src/test/ui/proc-macro/allowed-attr-stmt-expr.stdout @@ -1,70 +1,117 @@ +PRINT-ATTR INPUT (DISPLAY): struct ItemWithSemi ; +PRINT-ATTR INPUT (DEBUG): TokenStream [ + Ident { + ident: "struct", + span: $DIR/allowed-attr-stmt-expr.rs:49:1: 49:7 (#0), + }, + Ident { + ident: "ItemWithSemi", + span: $DIR/allowed-attr-stmt-expr.rs:49:8: 49:20 (#0), + }, + Punct { + ch: ';', + spacing: Alone, + span: $DIR/allowed-attr-stmt-expr.rs:49:20: 49:21 (#0), + }, +] +PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Foo { } +PRINT-ATTR INPUT (DEBUG): TokenStream [ + Punct { + ch: '#', + spacing: Alone, + span: $DIR/allowed-attr-stmt-expr.rs:35:9: 35:10 (#11), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "rustc_dummy", + span: $DIR/allowed-attr-stmt-expr.rs:35:11: 35:22 (#11), + }, + ], + span: $DIR/allowed-attr-stmt-expr.rs:35:10: 35:23 (#11), + }, + Ident { + ident: "struct", + span: $DIR/allowed-attr-stmt-expr.rs:53:16: 53:22 (#0), + }, + Ident { + ident: "Foo", + span: $DIR/allowed-attr-stmt-expr.rs:53:23: 53:26 (#0), + }, + Group { + delimiter: Brace, + stream: TokenStream [], + span: $DIR/allowed-attr-stmt-expr.rs:53:27: 53:29 (#0), + }, +] PRINT-ATTR INPUT (DISPLAY): #[expect_let] let string = "Hello, world!" ; PRINT-ATTR INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Alone, - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:56:5: 56:6 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "expect_let", - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:56:7: 56:17 (#0), }, ], - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:56:6: 56:18 (#0), }, Ident { ident: "let", - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:57:5: 57:8 (#0), }, Ident { ident: "string", - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:57:9: 57:15 (#0), }, Punct { ch: '=', spacing: Alone, - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:57:16: 57:17 (#0), }, Literal { kind: Str, symbol: "Hello, world!", suffix: None, - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:57:18: 57:33 (#0), }, Punct { ch: ';', spacing: Alone, - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:57:33: 57:34 (#0), }, ] -PRINT-ATTR INPUT (DISPLAY): #[expect_print_stmt] println ! ("{}", string) ; +PRINT-ATTR INPUT (DISPLAY): #[expect_my_macro_stmt] my_macro ! ("{}", string) ; PRINT-ATTR INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Alone, - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:60:5: 60:6 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { - ident: "expect_print_stmt", - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + ident: "expect_my_macro_stmt", + span: $DIR/allowed-attr-stmt-expr.rs:60:7: 60:27 (#0), }, ], - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:60:6: 60:28 (#0), }, Ident { - ident: "println", - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + ident: "my_macro", + span: $DIR/allowed-attr-stmt-expr.rs:61:5: 61:13 (#0), }, Punct { ch: '!', spacing: Alone, - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:61:13: 61:14 (#0), }, Group { delimiter: Parenthesis, @@ -73,36 +120,36 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ kind: Str, symbol: "{}", suffix: None, - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:61:15: 61:19 (#0), }, Punct { ch: ',', spacing: Alone, - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:61:19: 61:20 (#0), }, Ident { ident: "string", - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:61:21: 61:27 (#0), }, ], - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:61:14: 61:28 (#0), }, Punct { ch: ';', spacing: Alone, - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:61:28: 61:29 (#0), }, ] PRINT-ATTR INPUT (DISPLAY): second_make_stmt ! (#[allow(dead_code)] struct Bar { }) ; PRINT-ATTR INPUT (DEBUG): TokenStream [ Ident { ident: "second_make_stmt", - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:64:5: 64:21 (#0), }, Punct { ch: '!', spacing: Alone, - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:64:21: 64:22 (#0), }, Group { delimiter: Parenthesis, @@ -110,48 +157,104 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Alone, - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:64:23: 64:24 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "allow", - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:64:25: 64:30 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "dead_code", - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:64:31: 64:40 (#0), }, ], - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:64:30: 64:41 (#0), }, ], - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:64:24: 64:42 (#0), }, Ident { ident: "struct", - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:64:43: 64:49 (#0), }, Ident { ident: "Bar", - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:64:50: 64:53 (#0), }, Group { delimiter: Brace, stream: TokenStream [], - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:64:54: 64:56 (#0), }, ], - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:64:22: 64:57 (#0), }, Punct { ch: ';', spacing: Alone, - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:64:57: 64:58 (#0), + }, +] +PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] #[allow(dead_code)] struct Bar { } +PRINT-ATTR INPUT (DEBUG): TokenStream [ + Punct { + ch: '#', + spacing: Alone, + span: $DIR/allowed-attr-stmt-expr.rs:35:9: 35:10 (#32), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "rustc_dummy", + span: $DIR/allowed-attr-stmt-expr.rs:35:11: 35:22 (#32), + }, + ], + span: $DIR/allowed-attr-stmt-expr.rs:35:10: 35:23 (#32), + }, + Punct { + ch: '#', + spacing: Alone, + span: $DIR/allowed-attr-stmt-expr.rs:64:23: 64:24 (#0), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "allow", + span: $DIR/allowed-attr-stmt-expr.rs:64:25: 64:30 (#0), + }, + Group { + delimiter: Parenthesis, + stream: TokenStream [ + Ident { + ident: "dead_code", + span: $DIR/allowed-attr-stmt-expr.rs:64:31: 64:40 (#0), + }, + ], + span: $DIR/allowed-attr-stmt-expr.rs:64:30: 64:41 (#0), + }, + ], + span: $DIR/allowed-attr-stmt-expr.rs:64:24: 64:42 (#0), + }, + Ident { + ident: "struct", + span: $DIR/allowed-attr-stmt-expr.rs:64:43: 64:49 (#0), + }, + Ident { + ident: "Bar", + span: $DIR/allowed-attr-stmt-expr.rs:64:50: 64:53 (#0), + }, + Group { + delimiter: Brace, + stream: TokenStream [], + span: $DIR/allowed-attr-stmt-expr.rs:64:54: 64:56 (#0), }, ] PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Other { } @@ -159,29 +262,60 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Alone, - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:67:5: 67:6 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "rustc_dummy", - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:67:7: 67:18 (#0), }, ], - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:67:6: 67:19 (#0), }, Ident { ident: "struct", - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:68:5: 68:11 (#0), }, Ident { ident: "Other", - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:68:12: 68:17 (#0), }, Group { delimiter: Brace, stream: TokenStream [], - span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/allowed-attr-stmt-expr.rs:68:18: 68:20 (#0), + }, +] +PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct NonBracedStruct ; +PRINT-ATTR INPUT (DEBUG): TokenStream [ + Punct { + ch: '#', + spacing: Alone, + span: $DIR/allowed-attr-stmt-expr.rs:73:5: 73:6 (#0), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "rustc_dummy", + span: $DIR/allowed-attr-stmt-expr.rs:73:7: 73:18 (#0), + }, + ], + span: $DIR/allowed-attr-stmt-expr.rs:73:6: 73:19 (#0), + }, + Ident { + ident: "struct", + span: $DIR/allowed-attr-stmt-expr.rs:74:5: 74:11 (#0), + }, + Ident { + ident: "NonBracedStruct", + span: $DIR/allowed-attr-stmt-expr.rs:74:12: 74:27 (#0), + }, + Punct { + ch: ';', + spacing: Alone, + span: $DIR/allowed-attr-stmt-expr.rs:74:27: 74:28 (#0), }, ] diff --git a/src/test/ui/proc-macro/attr-stmt-expr.rs b/src/test/ui/proc-macro/attr-stmt-expr.rs index ca1b163c986..0403684cda0 100644 --- a/src/test/ui/proc-macro/attr-stmt-expr.rs +++ b/src/test/ui/proc-macro/attr-stmt-expr.rs @@ -11,19 +11,26 @@ extern crate test_macros; extern crate attr_stmt_expr; use test_macros::print_attr; -use std::println; -use attr_stmt_expr::{expect_let, expect_print_stmt, expect_expr, expect_print_expr}; +use attr_stmt_expr::{expect_let, expect_my_macro_stmt, expect_expr, expect_my_macro_expr}; + +// We don't use `std::println` so that we avoid loading hygiene +// information from libstd, which would affect the SyntaxContext ids +macro_rules! my_macro { + ($($tt:tt)*) => { () } +} fn print_str(string: &'static str) { // macros are handled a bit differently - #[expect_print_expr] + #[expect_my_macro_expr] //~^ ERROR attributes on expressions are experimental //~| HELP add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable - println!("{}", string) + my_macro!("{}", string) } macro_rules! make_stmt { ($stmt:stmt) => { + #[print_attr] + #[rustc_dummy] $stmt } } @@ -42,8 +49,8 @@ fn main() { let string = "Hello, world!"; #[print_attr] - #[expect_print_stmt] - println!("{}", string); + #[expect_my_macro_stmt] + my_macro!("{}", string); #[print_attr] second_make_stmt!(#[allow(dead_code)] struct Bar {}); diff --git a/src/test/ui/proc-macro/attr-stmt-expr.stderr b/src/test/ui/proc-macro/attr-stmt-expr.stderr index 7bd60e8ee77..56178259d43 100644 --- a/src/test/ui/proc-macro/attr-stmt-expr.stderr +++ b/src/test/ui/proc-macro/attr-stmt-expr.stderr @@ -1,14 +1,14 @@ error[E0658]: attributes on expressions are experimental - --> $DIR/attr-stmt-expr.rs:19:5 + --> $DIR/attr-stmt-expr.rs:24:5 | -LL | #[expect_print_expr] - | ^^^^^^^^^^^^^^^^^^^^ +LL | #[expect_my_macro_expr] + | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable error[E0658]: attributes on expressions are experimental - --> $DIR/attr-stmt-expr.rs:55:5 + --> $DIR/attr-stmt-expr.rs:62:5 | LL | #[expect_expr] | ^^^^^^^^^^^^^^ diff --git a/src/test/ui/proc-macro/attr-stmt-expr.stdout b/src/test/ui/proc-macro/attr-stmt-expr.stdout index 5c1b586725b..f75309e6872 100644 --- a/src/test/ui/proc-macro/attr-stmt-expr.stdout +++ b/src/test/ui/proc-macro/attr-stmt-expr.stdout @@ -1,70 +1,101 @@ +PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Foo { } +PRINT-ATTR INPUT (DEBUG): TokenStream [ + Punct { + ch: '#', + spacing: Alone, + span: $DIR/attr-stmt-expr.rs:33:9: 33:10 (#8), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "rustc_dummy", + span: $DIR/attr-stmt-expr.rs:33:11: 33:22 (#8), + }, + ], + span: $DIR/attr-stmt-expr.rs:33:10: 33:23 (#8), + }, + Ident { + ident: "struct", + span: $DIR/attr-stmt-expr.rs:45:16: 45:22 (#0), + }, + Ident { + ident: "Foo", + span: $DIR/attr-stmt-expr.rs:45:23: 45:26 (#0), + }, + Group { + delimiter: Brace, + stream: TokenStream [], + span: $DIR/attr-stmt-expr.rs:45:27: 45:29 (#0), + }, +] PRINT-ATTR INPUT (DISPLAY): #[expect_let] let string = "Hello, world!" ; PRINT-ATTR INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Alone, - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:48:5: 48:6 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "expect_let", - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:48:7: 48:17 (#0), }, ], - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:48:6: 48:18 (#0), }, Ident { ident: "let", - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:49:5: 49:8 (#0), }, Ident { ident: "string", - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:49:9: 49:15 (#0), }, Punct { ch: '=', spacing: Alone, - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:49:16: 49:17 (#0), }, Literal { kind: Str, symbol: "Hello, world!", suffix: None, - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:49:18: 49:33 (#0), }, Punct { ch: ';', spacing: Alone, - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:49:33: 49:34 (#0), }, ] -PRINT-ATTR INPUT (DISPLAY): #[expect_print_stmt] println ! ("{}", string) ; +PRINT-ATTR INPUT (DISPLAY): #[expect_my_macro_stmt] my_macro ! ("{}", string) ; PRINT-ATTR INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Alone, - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:52:5: 52:6 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { - ident: "expect_print_stmt", - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + ident: "expect_my_macro_stmt", + span: $DIR/attr-stmt-expr.rs:52:7: 52:27 (#0), }, ], - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:52:6: 52:28 (#0), }, Ident { - ident: "println", - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + ident: "my_macro", + span: $DIR/attr-stmt-expr.rs:53:5: 53:13 (#0), }, Punct { ch: '!', spacing: Alone, - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:53:13: 53:14 (#0), }, Group { delimiter: Parenthesis, @@ -73,36 +104,36 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ kind: Str, symbol: "{}", suffix: None, - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:53:15: 53:19 (#0), }, Punct { ch: ',', spacing: Alone, - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:53:19: 53:20 (#0), }, Ident { ident: "string", - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:53:21: 53:27 (#0), }, ], - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:53:14: 53:28 (#0), }, Punct { ch: ';', spacing: Alone, - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:53:28: 53:29 (#0), }, ] PRINT-ATTR INPUT (DISPLAY): second_make_stmt ! (#[allow(dead_code)] struct Bar { }) ; PRINT-ATTR INPUT (DEBUG): TokenStream [ Ident { ident: "second_make_stmt", - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:56:5: 56:21 (#0), }, Punct { ch: '!', spacing: Alone, - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:56:21: 56:22 (#0), }, Group { delimiter: Parenthesis, @@ -110,48 +141,104 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Alone, - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:56:23: 56:24 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "allow", - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:56:25: 56:30 (#0), }, Group { delimiter: Parenthesis, stream: TokenStream [ Ident { ident: "dead_code", - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:56:31: 56:40 (#0), }, ], - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:56:30: 56:41 (#0), }, ], - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:56:24: 56:42 (#0), }, Ident { ident: "struct", - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:56:43: 56:49 (#0), }, Ident { ident: "Bar", - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:56:50: 56:53 (#0), }, Group { delimiter: Brace, stream: TokenStream [], - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:56:54: 56:56 (#0), }, ], - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:56:22: 56:57 (#0), }, Punct { ch: ';', spacing: Alone, - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:56:57: 56:58 (#0), + }, +] +PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] #[allow(dead_code)] struct Bar { } +PRINT-ATTR INPUT (DEBUG): TokenStream [ + Punct { + ch: '#', + spacing: Alone, + span: $DIR/attr-stmt-expr.rs:33:9: 33:10 (#29), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "rustc_dummy", + span: $DIR/attr-stmt-expr.rs:33:11: 33:22 (#29), + }, + ], + span: $DIR/attr-stmt-expr.rs:33:10: 33:23 (#29), + }, + Punct { + ch: '#', + spacing: Alone, + span: $DIR/attr-stmt-expr.rs:56:23: 56:24 (#0), + }, + Group { + delimiter: Bracket, + stream: TokenStream [ + Ident { + ident: "allow", + span: $DIR/attr-stmt-expr.rs:56:25: 56:30 (#0), + }, + Group { + delimiter: Parenthesis, + stream: TokenStream [ + Ident { + ident: "dead_code", + span: $DIR/attr-stmt-expr.rs:56:31: 56:40 (#0), + }, + ], + span: $DIR/attr-stmt-expr.rs:56:30: 56:41 (#0), + }, + ], + span: $DIR/attr-stmt-expr.rs:56:24: 56:42 (#0), + }, + Ident { + ident: "struct", + span: $DIR/attr-stmt-expr.rs:56:43: 56:49 (#0), + }, + Ident { + ident: "Bar", + span: $DIR/attr-stmt-expr.rs:56:50: 56:53 (#0), + }, + Group { + delimiter: Brace, + stream: TokenStream [], + span: $DIR/attr-stmt-expr.rs:56:54: 56:56 (#0), }, ] PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Other { } @@ -159,29 +246,29 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [ Punct { ch: '#', spacing: Alone, - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:59:5: 59:6 (#0), }, Group { delimiter: Bracket, stream: TokenStream [ Ident { ident: "rustc_dummy", - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:59:7: 59:18 (#0), }, ], - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:59:6: 59:19 (#0), }, Ident { ident: "struct", - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:60:5: 60:11 (#0), }, Ident { ident: "Other", - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:60:12: 60:17 (#0), }, Group { delimiter: Brace, stream: TokenStream [], - span: $DIR/attr-stmt-expr.rs:1:1: 1:1 (#0), + span: $DIR/attr-stmt-expr.rs:60:18: 60:20 (#0), }, ] diff --git a/src/test/ui/proc-macro/auxiliary/attr-stmt-expr.rs b/src/test/ui/proc-macro/auxiliary/attr-stmt-expr.rs index 213f999e9d0..19183c61651 100644 --- a/src/test/ui/proc-macro/auxiliary/attr-stmt-expr.rs +++ b/src/test/ui/proc-macro/auxiliary/attr-stmt-expr.rs @@ -15,9 +15,9 @@ pub fn expect_let(attr: TokenStream, item: TokenStream) -> TokenStream { } #[proc_macro_attribute] -pub fn expect_print_stmt(attr: TokenStream, item: TokenStream) -> TokenStream { +pub fn expect_my_macro_stmt(attr: TokenStream, item: TokenStream) -> TokenStream { assert!(attr.to_string().is_empty()); - assert_eq!(item.to_string(), "println ! (\"{}\", string) ;"); + assert_eq!(item.to_string(), "my_macro ! (\"{}\", string) ;"); item } @@ -29,9 +29,9 @@ pub fn expect_expr(attr: TokenStream, item: TokenStream) -> TokenStream { } #[proc_macro_attribute] -pub fn expect_print_expr(attr: TokenStream, item: TokenStream) -> TokenStream { +pub fn expect_my_macro_expr(attr: TokenStream, item: TokenStream) -> TokenStream { assert!(attr.to_string().is_empty()); - assert_eq!(item.to_string(), "println ! (\"{}\", string)"); + assert_eq!(item.to_string(), "my_macro ! (\"{}\", string)"); item } diff --git a/src/test/ui/structs-enums/nested-enum-same-names.rs b/src/test/ui/structs-enums/nested-enum-same-names.rs index dece3dcd54b..111b9ba9477 100644 --- a/src/test/ui/structs-enums/nested-enum-same-names.rs +++ b/src/test/ui/structs-enums/nested-enum-same-names.rs @@ -17,10 +17,10 @@ as it does not include the method name in the symbol name. pub struct Foo; impl Foo { pub fn foo() { - enum Panic { Common }; + enum Panic { Common } } pub fn bar() { - enum Panic { Common }; + enum Panic { Common } } } diff --git a/src/test/ui/try-is-identifier-edition2015.rs b/src/test/ui/try-is-identifier-edition2015.rs index dfb05599be6..90f56d5fa71 100644 --- a/src/test/ui/try-is-identifier-edition2015.rs +++ b/src/test/ui/try-is-identifier-edition2015.rs @@ -5,7 +5,7 @@ fn main() { let try = 2; - struct try { try: u32 }; + struct try { try: u32 } let try: try = try { try }; assert_eq!(try.try, 2); } diff --git a/src/test/ui/zero-sized/zero-size-type-destructors.rs b/src/test/ui/zero-sized/zero-size-type-destructors.rs index 98b5a439c82..fb87d8ea0ba 100644 --- a/src/test/ui/zero-sized/zero-size-type-destructors.rs +++ b/src/test/ui/zero-sized/zero-size-type-destructors.rs @@ -10,7 +10,7 @@ pub fn foo() { fn drop(&mut self) { unsafe { destructions -= 1 }; } - }; + } let _x = [Foo, Foo, Foo]; } |
