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:
Vadim Petrochenkov 2022-05-01 20:58:24 +03:00
parent 8fcf113743
commit f77fd90aff
4 changed files with 3 additions and 14 deletions

View File

@ -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;

View File

@ -5,7 +5,6 @@
use std::time::{Duration, Instant};
use rustc_ast::ast;
use rustc_ast::AstLike;
use rustc_span::Span;
use self::newline_style::apply_newline_style;

View File

@ -4,7 +4,6 @@
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 @@ pub(crate) fn new(
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.

View File

@ -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};