-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Invoke attributes on the statement for statement items
- Loading branch information
Showing
11 changed files
with
574 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// aux-build:attr-stmt-expr.rs | ||
// aux-build:test-macros.rs | ||
// compile-flags: -Z span-debug | ||
// check-pass | ||
|
||
#![feature(proc_macro_hygiene)] | ||
#![feature(stmt_expr_attributes)] | ||
#![feature(rustc_attrs)] | ||
#![allow(dead_code)] | ||
|
||
#![no_std] // Don't load unnecessary hygiene information from std | ||
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 test_macros::print_attr; | ||
use std::println; | ||
|
||
fn print_str(string: &'static str) { | ||
// macros are handled a bit differently | ||
#[expect_print_expr] | ||
println!("{}", string) | ||
} | ||
|
||
macro_rules! make_stmt { | ||
($stmt:stmt) => { | ||
$stmt | ||
} | ||
} | ||
|
||
macro_rules! second_make_stmt { | ||
($stmt:stmt) => { | ||
make_stmt!($stmt); | ||
} | ||
} | ||
|
||
|
||
fn main() { | ||
make_stmt!(struct Foo {}); | ||
|
||
#[print_attr] | ||
#[expect_let] | ||
let string = "Hello, world!"; | ||
|
||
#[print_attr] | ||
#[expect_print_stmt] | ||
println!("{}", string); | ||
|
||
#[print_attr] | ||
second_make_stmt!(#[allow(dead_code)] struct Bar {}); | ||
|
||
#[print_attr] | ||
#[rustc_dummy] | ||
struct Other {}; | ||
|
||
#[expect_expr] | ||
print_str("string") | ||
} |
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,187 @@ | ||
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), | ||
}, | ||
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:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "let", | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "string", | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: '=', | ||
spacing: Alone, | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Literal { | ||
kind: Str, | ||
symbol: "Hello, world!", | ||
suffix: None, | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: ';', | ||
spacing: Alone, | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
] | ||
PRINT-ATTR INPUT (DISPLAY): #[expect_print_stmt] println ! ("{}", string) ; | ||
PRINT-ATTR INPUT (DEBUG): TokenStream [ | ||
Punct { | ||
ch: '#', | ||
spacing: Alone, | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Group { | ||
delimiter: Bracket, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "expect_print_stmt", | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
], | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "println", | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: '!', | ||
spacing: Alone, | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Group { | ||
delimiter: Parenthesis, | ||
stream: TokenStream [ | ||
Literal { | ||
kind: Str, | ||
symbol: "{}", | ||
suffix: None, | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: ',', | ||
spacing: Alone, | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "string", | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
], | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: ';', | ||
spacing: Alone, | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#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), | ||
}, | ||
Punct { | ||
ch: '!', | ||
spacing: Alone, | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Group { | ||
delimiter: Parenthesis, | ||
stream: TokenStream [ | ||
Punct { | ||
ch: '#', | ||
spacing: Alone, | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Group { | ||
delimiter: Bracket, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "allow", | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#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:1:1: 1:1 (#0), | ||
}, | ||
], | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "struct", | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "Bar", | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#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:1:1: 1:1 (#0), | ||
}, | ||
Punct { | ||
ch: ';', | ||
spacing: Alone, | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
] | ||
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct Other { } | ||
PRINT-ATTR INPUT (DEBUG): TokenStream [ | ||
Punct { | ||
ch: '#', | ||
spacing: Alone, | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#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:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "struct", | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Ident { | ||
ident: "Other", | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
Group { | ||
delimiter: Brace, | ||
stream: TokenStream [], | ||
span: $DIR/allowed-attr-stmt-expr.rs:1:1: 1:1 (#0), | ||
}, | ||
] |
Oops, something went wrong.