parent
6f681a8eb3
commit
ef5601b321
5 changed files with 50 additions and 56 deletions
|
@ -75,13 +75,12 @@ impl NestedMetaItem {
|
||||||
pub fn name_value_literal(&self) -> Option<(Symbol, &Lit)> {
|
pub fn name_value_literal(&self) -> Option<(Symbol, &Lit)> {
|
||||||
self.meta_item().and_then(|meta_item| {
|
self.meta_item().and_then(|meta_item| {
|
||||||
meta_item.meta_item_list().and_then(|meta_item_list| {
|
meta_item.meta_item_list().and_then(|meta_item_list| {
|
||||||
if meta_item_list.len() == 1 {
|
if meta_item_list.len() == 1
|
||||||
if let Some(ident) = meta_item.ident() {
|
&& let Some(ident) = meta_item.ident()
|
||||||
if let Some(lit) = meta_item_list[0].literal() {
|
&& let Some(lit) = meta_item_list[0].literal()
|
||||||
|
{
|
||||||
return Some((ident.name, lit));
|
return Some((ident.name, lit));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
None
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -12,11 +12,12 @@
|
||||||
#![feature(crate_visibility_modifier)]
|
#![feature(crate_visibility_modifier)]
|
||||||
#![feature(if_let_guard)]
|
#![feature(if_let_guard)]
|
||||||
#![feature(label_break_value)]
|
#![feature(label_break_value)]
|
||||||
#![feature(nll)]
|
#![feature(let_chains)]
|
||||||
#![feature(min_specialization)]
|
#![feature(min_specialization)]
|
||||||
#![recursion_limit = "256"]
|
#![feature(nll)]
|
||||||
#![feature(slice_internals)]
|
#![feature(slice_internals)]
|
||||||
#![feature(stmt_expr_attributes)]
|
#![feature(stmt_expr_attributes)]
|
||||||
|
#![recursion_limit = "256"]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rustc_macros;
|
extern crate rustc_macros;
|
||||||
|
|
|
@ -504,11 +504,9 @@ impl Token {
|
||||||
|
|
||||||
/// Returns `true` if the token is an interpolated path.
|
/// Returns `true` if the token is an interpolated path.
|
||||||
fn is_path(&self) -> bool {
|
fn is_path(&self) -> bool {
|
||||||
if let Interpolated(ref nt) = self.kind {
|
if let Interpolated(ref nt) = self.kind && let NtPath(..) = **nt {
|
||||||
if let NtPath(..) = **nt {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,22 +514,20 @@ impl Token {
|
||||||
/// That is, is this a pre-parsed expression dropped into the token stream
|
/// That is, is this a pre-parsed expression dropped into the token stream
|
||||||
/// (which happens while parsing the result of macro expansion)?
|
/// (which happens while parsing the result of macro expansion)?
|
||||||
pub fn is_whole_expr(&self) -> bool {
|
pub fn is_whole_expr(&self) -> bool {
|
||||||
if let Interpolated(ref nt) = self.kind {
|
if let Interpolated(ref nt) = self.kind
|
||||||
if let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtIdent(..) | NtBlock(_) = **nt {
|
&& let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtIdent(..) | NtBlock(_) = **nt
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is the token an interpolated block (`$b:block`)?
|
// Is the token an interpolated block (`$b:block`)?
|
||||||
pub fn is_whole_block(&self) -> bool {
|
pub fn is_whole_block(&self) -> bool {
|
||||||
if let Interpolated(ref nt) = self.kind {
|
if let Interpolated(ref nt) = self.kind && let NtBlock(..) = **nt {
|
||||||
if let NtBlock(..) = **nt {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -497,14 +497,15 @@ impl TokenStreamBuilder {
|
||||||
|
|
||||||
// If `self` is not empty and the last tree within the last stream is a
|
// If `self` is not empty and the last tree within the last stream is a
|
||||||
// token tree marked with `Joint`...
|
// token tree marked with `Joint`...
|
||||||
if let Some(TokenStream(ref mut last_stream_lrc)) = self.0.last_mut() {
|
if let Some(TokenStream(ref mut last_stream_lrc)) = self.0.last_mut()
|
||||||
if let Some((TokenTree::Token(last_token), Spacing::Joint)) = last_stream_lrc.last() {
|
&& let Some((TokenTree::Token(last_token), Spacing::Joint)) = last_stream_lrc.last()
|
||||||
// ...and `stream` is not empty and the first tree within it is
|
// ...and `stream` is not empty and the first tree within it is
|
||||||
// a token tree...
|
// a token tree...
|
||||||
let TokenStream(ref mut stream_lrc) = stream;
|
&& let TokenStream(ref mut stream_lrc) = stream
|
||||||
if let Some((TokenTree::Token(token), spacing)) = stream_lrc.first() {
|
&& let Some((TokenTree::Token(token), spacing)) = stream_lrc.first()
|
||||||
// ...and the two tokens can be glued together...
|
// ...and the two tokens can be glued together...
|
||||||
if let Some(glued_tok) = last_token.glue(&token) {
|
&& let Some(glued_tok) = last_token.glue(&token)
|
||||||
|
{
|
||||||
// ...then do so, by overwriting the last token
|
// ...then do so, by overwriting the last token
|
||||||
// tree in `self` and removing the first token tree
|
// tree in `self` and removing the first token tree
|
||||||
// from `stream`. This requires using `make_mut()`
|
// from `stream`. This requires using `make_mut()`
|
||||||
|
@ -531,9 +532,6 @@ impl TokenStreamBuilder {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.0.push(stream);
|
self.0.push(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -222,11 +222,11 @@ impl Lit {
|
||||||
}
|
}
|
||||||
token::Literal(lit) => lit,
|
token::Literal(lit) => lit,
|
||||||
token::Interpolated(ref nt) => {
|
token::Interpolated(ref nt) => {
|
||||||
if let token::NtExpr(expr) | token::NtLiteral(expr) = &**nt {
|
if let token::NtExpr(expr) | token::NtLiteral(expr) = &**nt
|
||||||
if let ast::ExprKind::Lit(lit) = &expr.kind {
|
&& let ast::ExprKind::Lit(lit) = &expr.kind
|
||||||
|
{
|
||||||
return Ok(lit.clone());
|
return Ok(lit.clone());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return Err(LitError::NotLiteral);
|
return Err(LitError::NotLiteral);
|
||||||
}
|
}
|
||||||
_ => return Err(LitError::NotLiteral),
|
_ => return Err(LitError::NotLiteral),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue