-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of RFC 2151, Raw Identifiers #48942
Changes from 5 commits
fad1648
7d5c29b
d2e7953
5c3d632
ce84a41
bfb94ac
57f9c4d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ pub mod rt { | |
|
||
impl ToTokens for ast::Ident { | ||
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> { | ||
vec![TokenTree::Token(DUMMY_SP, token::Ident(*self))] | ||
vec![TokenTree::Token(DUMMY_SP, Token::from_ast_ident(*self))] | ||
} | ||
} | ||
|
||
|
@@ -238,7 +238,8 @@ pub mod rt { | |
if i > 0 { | ||
inner.push(TokenTree::Token(self.span, token::Colon).into()); | ||
} | ||
inner.push(TokenTree::Token(self.span, token::Ident(segment.identifier)).into()); | ||
inner.push(TokenTree::Token(self.span, | ||
token::Ident(segment.identifier, false)).into()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the best guess here would be |
||
} | ||
inner.push(self.tokens.clone()); | ||
|
||
|
@@ -658,10 +659,10 @@ fn expr_mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P<ast::Expr> { | |
token::Literal(token::ByteStr(i), suf) => return mk_lit!("ByteStr", suf, i), | ||
token::Literal(token::ByteStrRaw(i, n), suf) => return mk_lit!("ByteStrRaw", suf, i, n), | ||
|
||
token::Ident(ident) => { | ||
token::Ident(ident, is_raw) => { | ||
return cx.expr_call(sp, | ||
mk_token_path(cx, sp, "Ident"), | ||
vec![mk_ident(cx, sp, ident)]); | ||
vec![mk_ident(cx, sp, ident), cx.expr_bool(sp, is_raw)]); | ||
} | ||
|
||
token::Lifetime(ident) => { | ||
|
@@ -720,7 +721,7 @@ fn expr_mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P<ast::Expr> { | |
|
||
fn statements_mk_tt(cx: &ExtCtxt, tt: &TokenTree, quoted: bool) -> Vec<ast::Stmt> { | ||
match *tt { | ||
TokenTree::Token(sp, token::Ident(ident)) if quoted => { | ||
TokenTree::Token(sp, token::Ident(ident, _)) if quoted => { | ||
// tt.extend($ident.to_tokens(ext_cx)) | ||
|
||
let e_to_toks = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,7 +200,7 @@ pub fn parse( | |
let span = match trees.next() { | ||
Some(tokenstream::TokenTree::Token(span, token::Colon)) => match trees.next() { | ||
Some(tokenstream::TokenTree::Token(end_sp, ref tok)) => match tok.ident() { | ||
Some(kind) => { | ||
Some((kind, _)) => { | ||
let span = end_sp.with_lo(start_sp.lo()); | ||
result.push(TokenTree::MetaVarDecl(span, ident, kind)); | ||
continue; | ||
|
@@ -289,14 +289,14 @@ where | |
// `tree` is followed by an `ident`. This could be `$meta_var` or the `$crate` special | ||
// metavariable that names the crate of the invokation. | ||
Some(tokenstream::TokenTree::Token(ident_span, ref token)) if token.is_ident() => { | ||
let ident = token.ident().unwrap(); | ||
let (ident, _) = token.ident().unwrap(); | ||
let span = ident_span.with_lo(span.lo()); | ||
if ident.name == keywords::Crate.name() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I think this will accept There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a test case for this as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently |
||
let ident = ast::Ident { | ||
name: keywords::DollarCrate.name(), | ||
..ident | ||
}; | ||
TokenTree::Token(span, token::Ident(ident)) | ||
TokenTree::Token(span, token::Ident(ident, false)) | ||
} else { | ||
TokenTree::MetaVar(span, ident) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,7 +169,7 @@ pub fn transcribe(cx: &ExtCtxt, | |
Ident { ctxt: ident.ctxt.apply_mark(cx.current_expansion.mark), ..ident }; | ||
sp = sp.with_ctxt(sp.ctxt().apply_mark(cx.current_expansion.mark)); | ||
result.push(TokenTree::Token(sp, token::Dollar).into()); | ||
result.push(TokenTree::Token(sp, token::Ident(ident)).into()); | ||
result.push(TokenTree::Token(sp, token::Ident(ident, false)).into()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
quoted::TokenTree::Delimited(mut span, delimited) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as https://github.com/rust-lang/rust/pull/48942/files#r175613878
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this in
from_ast_ident
, since it seems this is the best behavior in all these cases.