ast: Introduce some traits to get AST node properties generically
And use them to avoid constructing some artificial `Nonterminal` tokens during expansion
This commit is contained in:
parent
ee6eaabdd4
commit
f2b7fa4847
24 changed files with 593 additions and 500 deletions
|
@ -929,16 +929,6 @@ pub struct Stmt {
|
|||
}
|
||||
|
||||
impl Stmt {
|
||||
pub fn tokens(&self) -> Option<&LazyTokenStream> {
|
||||
match self.kind {
|
||||
StmtKind::Local(ref local) => local.tokens.as_ref(),
|
||||
StmtKind::Item(ref item) => item.tokens.as_ref(),
|
||||
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => expr.tokens.as_ref(),
|
||||
StmtKind::Empty => None,
|
||||
StmtKind::MacCall(ref mac) => mac.tokens.as_ref(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_trailing_semicolon(&self) -> bool {
|
||||
match &self.kind {
|
||||
StmtKind::Semi(_) => true,
|
||||
|
@ -2684,13 +2674,6 @@ impl Item {
|
|||
}
|
||||
}
|
||||
|
||||
impl<K: Into<ItemKind>> Item<K> {
|
||||
pub fn into_item(self) -> Item {
|
||||
let Item { attrs, id, span, vis, ident, kind, tokens } = self;
|
||||
Item { attrs, id, span, vis, ident, kind: kind.into(), tokens }
|
||||
}
|
||||
}
|
||||
|
||||
/// `extern` qualifier on a function item or function type.
|
||||
#[derive(Clone, Copy, Encodable, Decodable, Debug)]
|
||||
pub enum Extern {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue