diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-05-01 20:58:24 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-05-11 12:43:27 +0300 |
| commit | f77fd90affcf794354ca8d120e9cc55dc64f4cf1 (patch) | |
| tree | 3ca8316e497030846578d739c6fa7b01a454a840 | |
| parent | 8fcf113743a06756a024ecae49a571d96d9bc24e (diff) | |
| download | rust-f77fd90affcf794354ca8d120e9cc55dc64f4cf1.tar.gz rust-f77fd90affcf794354ca8d120e9cc55dc64f4cf1.zip | |
ast: Introduce some traits to get AST node properties generically
And use them to avoid constructing some artificial `Nonterminal` tokens during expansion
| -rw-r--r-- | src/attr.rs | 2 | ||||
| -rw-r--r-- | src/formatting.rs | 1 | ||||
| -rw-r--r-- | src/modules.rs | 12 | ||||
| -rw-r--r-- | src/visitor.rs | 2 |
4 files changed, 3 insertions, 14 deletions
diff --git a/src/attr.rs b/src/attr.rs index befe12ae2c4..41ba9a847e6 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -1,7 +1,7 @@ //! Format attributes and meta items. use rustc_ast::ast; -use rustc_ast::AstLike; +use rustc_ast::HasAttrs; use rustc_span::{symbol::sym, Span, Symbol}; use self::doc_comment::DocCommentFormatter; diff --git a/src/formatting.rs b/src/formatting.rs index ca93955a549..ebadf3dd598 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -5,7 +5,6 @@ use std::io::{self, Write}; use std::time::{Duration, Instant}; use rustc_ast::ast; -use rustc_ast::AstLike; use rustc_span::Span; use self::newline_style::apply_newline_style; diff --git a/src/modules.rs b/src/modules.rs index a65dc66f797..81da724329f 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -4,7 +4,6 @@ use std::path::{Path, PathBuf}; use rustc_ast::ast; use rustc_ast::visit::Visitor; -use rustc_ast::AstLike; use rustc_span::symbol::{self, sym, Symbol}; use rustc_span::Span; use thiserror::Error; @@ -50,19 +49,10 @@ impl<'a> Module<'a> { ast_mod_kind, } } -} -impl<'a> AstLike for Module<'a> { - const SUPPORTS_CUSTOM_INNER_ATTRS: bool = true; - fn attrs(&self) -> &[ast::Attribute] { + pub(crate) fn attrs(&self) -> &[ast::Attribute] { &self.inner_attr } - fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<ast::Attribute>)) { - f(&mut self.inner_attr) - } - fn tokens_mut(&mut self) -> Option<&mut Option<rustc_ast::tokenstream::LazyTokenStream>> { - unimplemented!() - } } /// Maps each module to the corresponding file. diff --git a/src/visitor.rs b/src/visitor.rs index f04fb2e0446..9a0e0752c12 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -1,7 +1,7 @@ use std::cell::{Cell, RefCell}; use std::rc::Rc; -use rustc_ast::{ast, token::Delimiter, visit, AstLike}; +use rustc_ast::{ast, token::Delimiter, visit}; use rustc_data_structures::sync::Lrc; use rustc_span::{symbol, BytePos, Pos, Span}; |
