proc_macro: Accept $crate
as an identifier if it comes from the compiler
This commit is contained in:
parent
8a8ef260be
commit
2bc67da378
3 changed files with 34 additions and 0 deletions
|
@ -150,6 +150,8 @@ impl FromInternal<(TokenStream, &'_ ParseSess, &'_ mut Vec<Self>)>
|
||||||
Question => op!('?'),
|
Question => op!('?'),
|
||||||
SingleQuote => op!('\''),
|
SingleQuote => op!('\''),
|
||||||
|
|
||||||
|
Ident(ident, false) if ident.name == keywords::DollarCrate.name() =>
|
||||||
|
tt!(Ident::dollar_crate()),
|
||||||
Ident(ident, is_raw) => tt!(Ident::new(ident.name, is_raw)),
|
Ident(ident, is_raw) => tt!(Ident::new(ident.name, is_raw)),
|
||||||
Lifetime(ident) => {
|
Lifetime(ident) => {
|
||||||
let ident = ident.without_first_quote();
|
let ident = ident.without_first_quote();
|
||||||
|
@ -359,6 +361,10 @@ impl Ident {
|
||||||
}
|
}
|
||||||
Ident { sym, is_raw, span }
|
Ident { sym, is_raw, span }
|
||||||
}
|
}
|
||||||
|
fn dollar_crate(span: Span) -> Ident {
|
||||||
|
// `$crate` is accepted as an ident only if it comes from the compiler.
|
||||||
|
Ident { sym: keywords::DollarCrate.name(), is_raw: false, span }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
|
// FIXME(eddyb) `Literal` should not expose internal `Debug` impls.
|
||||||
|
|
12
src/test/ui/proc-macro/auxiliary/dollar-crate.rs
Normal file
12
src/test/ui/proc-macro/auxiliary/dollar-crate.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// force-host
|
||||||
|
// no-prefer-dynamic
|
||||||
|
|
||||||
|
#![crate_type = "proc-macro"]
|
||||||
|
|
||||||
|
extern crate proc_macro;
|
||||||
|
use proc_macro::TokenStream;
|
||||||
|
|
||||||
|
#[proc_macro]
|
||||||
|
pub fn normalize(input: TokenStream) -> TokenStream {
|
||||||
|
input.into_iter().collect()
|
||||||
|
}
|
16
src/test/ui/proc-macro/dollar-crate.rs
Normal file
16
src/test/ui/proc-macro/dollar-crate.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
// compile-pass
|
||||||
|
// aux-build:dollar-crate.rs
|
||||||
|
|
||||||
|
extern crate dollar_crate;
|
||||||
|
|
||||||
|
type S = u8;
|
||||||
|
|
||||||
|
macro_rules! check { () => {
|
||||||
|
dollar_crate::normalize! {
|
||||||
|
type A = $crate::S;
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
|
||||||
|
check!();
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue