forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
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 rust-lang#75084 - Aaron1011:stabilize/ident-new-raw, …
…r=petrochenkov Stabilize Ident::new_raw Tracking issue: rust-lang#54723 This is a continuation of PR rust-lang#59002
- Loading branch information
Showing
4 changed files
with
66 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// force-host | ||
// no-prefer-dynamic | ||
|
||
#![crate_type = "proc-macro"] | ||
|
||
extern crate proc_macro; | ||
use proc_macro::{TokenStream, TokenTree, Ident, Punct, Spacing, Span}; | ||
|
||
#[proc_macro] | ||
pub fn make_struct(input: TokenStream) -> TokenStream { | ||
match input.into_iter().next().unwrap() { | ||
TokenTree::Ident(ident) => { | ||
vec![ | ||
TokenTree::Ident(Ident::new("struct", Span::call_site())), | ||
TokenTree::Ident(Ident::new_raw(&ident.to_string(), Span::call_site())), | ||
TokenTree::Punct(Punct::new(';', Spacing::Alone)) | ||
].into_iter().collect() | ||
} | ||
_ => panic!() | ||
} | ||
} | ||
|
||
#[proc_macro] | ||
pub fn make_bad_struct(input: TokenStream) -> TokenStream { | ||
match input.into_iter().next().unwrap() { | ||
TokenTree::Ident(ident) => { | ||
vec![ | ||
TokenTree::Ident(Ident::new_raw("struct", Span::call_site())), | ||
TokenTree::Ident(Ident::new(&ident.to_string(), Span::call_site())), | ||
TokenTree::Punct(Punct::new(';', Spacing::Alone)) | ||
].into_iter().collect() | ||
} | ||
_ => panic!() | ||
} | ||
} |
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,16 @@ | ||
// aux-build:raw-ident.rs | ||
|
||
#[macro_use] extern crate raw_ident; | ||
|
||
fn main() { | ||
make_struct!(fn); | ||
make_struct!(Foo); | ||
make_struct!(await); | ||
|
||
r#fn; | ||
r#Foo; | ||
Foo; | ||
r#await; | ||
|
||
make_bad_struct!(S); //~ ERROR expected one of | ||
} |
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: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `S` | ||
--> $DIR/raw-ident.rs:15:5 | ||
| | ||
LL | make_bad_struct!(S); | ||
| ^^^^^^^^^^^^^^^^^^^^ expected one of 8 possible tokens | ||
| | ||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: aborting due to previous error | ||
|