mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-16 14:07:04 +00:00
Auto merge of #127524 - oli-obk:feed_item_attrs2, r=petrochenkov
Make ast `MutVisitor` have the same method name and style as `Visitor` It doesn't map 100% because some `MutVisitor` methods can filter or even expand to multiple items, but consistency seems nicer. tracking issue: https://github.com/rust-lang/rust/issues/127615
This commit is contained in:
commit
d24930ceb4
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,7 @@ use core::ops::ControlFlow;
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::mut_visit::MutVisitor;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::visit::Visitor;
|
||||
use rustc_ast::visit::{AssocCtxt, Visitor};
|
||||
use rustc_ast::NodeId;
|
||||
use rustc_ast::{mut_visit, visit};
|
||||
use rustc_ast::{Attribute, HasAttrs, HasTokens};
|
||||
@ -53,11 +53,8 @@ fn flat_map_annotatable(
|
||||
) -> Option<Annotatable> {
|
||||
match annotatable {
|
||||
Annotatable::Item(item) => vis.flat_map_item(item).pop().map(Annotatable::Item),
|
||||
Annotatable::TraitItem(item) => {
|
||||
vis.flat_map_trait_item(item).pop().map(Annotatable::TraitItem)
|
||||
}
|
||||
Annotatable::ImplItem(item) => {
|
||||
vis.flat_map_impl_item(item).pop().map(Annotatable::ImplItem)
|
||||
Annotatable::AssocItem(item, ctxt) => {
|
||||
Some(Annotatable::AssocItem(vis.flat_map_assoc_item(item, ctxt).pop()?, ctxt))
|
||||
}
|
||||
Annotatable::ForeignItem(item) => {
|
||||
vis.flat_map_foreign_item(item).pop().map(Annotatable::ForeignItem)
|
||||
@ -106,8 +103,7 @@ fn has_cfg_or_cfg_attr(annotatable: &Annotatable) -> bool {
|
||||
|
||||
let res = match annotatable {
|
||||
Annotatable::Item(item) => CfgFinder.visit_item(item),
|
||||
Annotatable::TraitItem(item) => CfgFinder.visit_assoc_item(item, visit::AssocCtxt::Trait),
|
||||
Annotatable::ImplItem(item) => CfgFinder.visit_assoc_item(item, visit::AssocCtxt::Impl),
|
||||
Annotatable::AssocItem(item, ctxt) => CfgFinder.visit_assoc_item(item, *ctxt),
|
||||
Annotatable::ForeignItem(item) => CfgFinder.visit_foreign_item(item),
|
||||
Annotatable::Stmt(stmt) => CfgFinder.visit_stmt(stmt),
|
||||
Annotatable::Expr(expr) => CfgFinder.visit_expr(expr),
|
||||
@ -150,14 +146,16 @@ impl CfgEval<'_> {
|
||||
Annotatable::Item(_) => {
|
||||
|parser| Ok(Annotatable::Item(parser.parse_item(ForceCollect::Yes)?.unwrap()))
|
||||
}
|
||||
Annotatable::TraitItem(_) => |parser| {
|
||||
Ok(Annotatable::TraitItem(
|
||||
Annotatable::AssocItem(_, AssocCtxt::Trait) => |parser| {
|
||||
Ok(Annotatable::AssocItem(
|
||||
parser.parse_trait_item(ForceCollect::Yes)?.unwrap().unwrap(),
|
||||
AssocCtxt::Trait,
|
||||
))
|
||||
},
|
||||
Annotatable::ImplItem(_) => |parser| {
|
||||
Ok(Annotatable::ImplItem(
|
||||
Annotatable::AssocItem(_, AssocCtxt::Impl) => |parser| {
|
||||
Ok(Annotatable::AssocItem(
|
||||
parser.parse_impl_item(ForceCollect::Yes)?.unwrap().unwrap(),
|
||||
AssocCtxt::Impl,
|
||||
))
|
||||
},
|
||||
Annotatable::ForeignItem(_) => |parser| {
|
||||
@ -214,18 +212,18 @@ impl MutVisitor for CfgEval<'_> {
|
||||
#[instrument(level = "trace", skip(self))]
|
||||
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
|
||||
self.0.configure_expr(expr, false);
|
||||
mut_visit::noop_visit_expr(expr, self);
|
||||
mut_visit::walk_expr(self, expr);
|
||||
}
|
||||
|
||||
#[instrument(level = "trace", skip(self))]
|
||||
fn visit_method_receiver_expr(&mut self, expr: &mut P<ast::Expr>) {
|
||||
self.0.configure_expr(expr, true);
|
||||
mut_visit::noop_visit_expr(expr, self);
|
||||
mut_visit::walk_expr(self, expr);
|
||||
}
|
||||
|
||||
fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
|
||||
let mut expr = configure!(self, expr);
|
||||
mut_visit::noop_visit_expr(&mut expr, self);
|
||||
mut_visit::walk_expr(self, &mut expr);
|
||||
Some(expr)
|
||||
}
|
||||
|
||||
@ -233,53 +231,64 @@ impl MutVisitor for CfgEval<'_> {
|
||||
&mut self,
|
||||
param: ast::GenericParam,
|
||||
) -> SmallVec<[ast::GenericParam; 1]> {
|
||||
mut_visit::noop_flat_map_generic_param(configure!(self, param), self)
|
||||
let param = configure!(self, param);
|
||||
mut_visit::walk_flat_map_generic_param(self, param)
|
||||
}
|
||||
|
||||
fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
|
||||
mut_visit::noop_flat_map_stmt(configure!(self, stmt), self)
|
||||
let stmt = configure!(self, stmt);
|
||||
mut_visit::walk_flat_map_stmt(self, stmt)
|
||||
}
|
||||
|
||||
fn flat_map_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
|
||||
mut_visit::noop_flat_map_item(configure!(self, item), self)
|
||||
let item = configure!(self, item);
|
||||
mut_visit::walk_flat_map_item(self, item)
|
||||
}
|
||||
|
||||
fn flat_map_impl_item(&mut self, item: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
||||
mut_visit::noop_flat_map_item(configure!(self, item), self)
|
||||
}
|
||||
|
||||
fn flat_map_trait_item(&mut self, item: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
||||
mut_visit::noop_flat_map_item(configure!(self, item), self)
|
||||
fn flat_map_assoc_item(
|
||||
&mut self,
|
||||
item: P<ast::AssocItem>,
|
||||
_ctxt: AssocCtxt,
|
||||
) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
||||
let item = configure!(self, item);
|
||||
mut_visit::walk_flat_map_item(self, item)
|
||||
}
|
||||
|
||||
fn flat_map_foreign_item(
|
||||
&mut self,
|
||||
foreign_item: P<ast::ForeignItem>,
|
||||
) -> SmallVec<[P<ast::ForeignItem>; 1]> {
|
||||
mut_visit::noop_flat_map_item(configure!(self, foreign_item), self)
|
||||
let foreign_item = configure!(self, foreign_item);
|
||||
mut_visit::walk_flat_map_item(self, foreign_item)
|
||||
}
|
||||
|
||||
fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> {
|
||||
mut_visit::noop_flat_map_arm(configure!(self, arm), self)
|
||||
let arm = configure!(self, arm);
|
||||
mut_visit::walk_flat_map_arm(self, arm)
|
||||
}
|
||||
|
||||
fn flat_map_expr_field(&mut self, field: ast::ExprField) -> SmallVec<[ast::ExprField; 1]> {
|
||||
mut_visit::noop_flat_map_expr_field(configure!(self, field), self)
|
||||
let field = configure!(self, field);
|
||||
mut_visit::walk_flat_map_expr_field(self, field)
|
||||
}
|
||||
|
||||
fn flat_map_pat_field(&mut self, fp: ast::PatField) -> SmallVec<[ast::PatField; 1]> {
|
||||
mut_visit::noop_flat_map_pat_field(configure!(self, fp), self)
|
||||
let fp = configure!(self, fp);
|
||||
mut_visit::walk_flat_map_pat_field(self, fp)
|
||||
}
|
||||
|
||||
fn flat_map_param(&mut self, p: ast::Param) -> SmallVec<[ast::Param; 1]> {
|
||||
mut_visit::noop_flat_map_param(configure!(self, p), self)
|
||||
let p = configure!(self, p);
|
||||
mut_visit::walk_flat_map_param(self, p)
|
||||
}
|
||||
|
||||
fn flat_map_field_def(&mut self, sf: ast::FieldDef) -> SmallVec<[ast::FieldDef; 1]> {
|
||||
mut_visit::noop_flat_map_field_def(configure!(self, sf), self)
|
||||
let sf = configure!(self, sf);
|
||||
mut_visit::walk_flat_map_field_def(self, sf)
|
||||
}
|
||||
|
||||
fn flat_map_variant(&mut self, variant: ast::Variant) -> SmallVec<[ast::Variant; 1]> {
|
||||
mut_visit::noop_flat_map_variant(configure!(self, variant), self)
|
||||
let variant = configure!(self, variant);
|
||||
mut_visit::walk_flat_map_variant(self, variant)
|
||||
}
|
||||
}
|
||||
|
@ -122,15 +122,15 @@ impl TestHarnessGenerator<'_> {
|
||||
impl<'a> MutVisitor for TestHarnessGenerator<'a> {
|
||||
fn visit_crate(&mut self, c: &mut ast::Crate) {
|
||||
let prev_tests = mem::take(&mut self.tests);
|
||||
noop_visit_crate(c, self);
|
||||
walk_crate(self, c);
|
||||
self.add_test_cases(ast::CRATE_NODE_ID, c.spans.inner_span, prev_tests);
|
||||
|
||||
// Create a main function to run our tests
|
||||
c.items.push(mk_main(&mut self.cx));
|
||||
}
|
||||
|
||||
fn flat_map_item(&mut self, i: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
|
||||
let mut item = i.into_inner();
|
||||
fn flat_map_item(&mut self, mut i: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
|
||||
let item = &mut *i;
|
||||
if let Some(name) = get_test_name(&item) {
|
||||
debug!("this is a test item");
|
||||
|
||||
@ -144,13 +144,13 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
|
||||
item.kind
|
||||
{
|
||||
let prev_tests = mem::take(&mut self.tests);
|
||||
noop_visit_item_kind(&mut item.kind, self);
|
||||
walk_item_kind(&mut item.kind, item.span, item.id, self);
|
||||
self.add_test_cases(item.id, span, prev_tests);
|
||||
} else {
|
||||
// But in those cases, we emit a lint to warn the user of these missing tests.
|
||||
walk_item(&mut InnerItemLinter { sess: self.cx.ext_cx.sess }, &item);
|
||||
}
|
||||
smallvec![P(item)]
|
||||
smallvec![i]
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,7 +192,7 @@ struct EntryPointCleaner<'a> {
|
||||
impl<'a> MutVisitor for EntryPointCleaner<'a> {
|
||||
fn flat_map_item(&mut self, i: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
|
||||
self.depth += 1;
|
||||
let item = noop_flat_map_item(i, self).expect_one("noop did something");
|
||||
let item = walk_flat_map_item(self, i).expect_one("noop did something");
|
||||
self.depth -= 1;
|
||||
|
||||
// Remove any #[rustc_main] or #[start] from the AST so it doesn't
|
||||
|
@ -27,8 +27,7 @@ pub(crate) fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaI
|
||||
pub(crate) fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable, name: Symbol) {
|
||||
let attrs: Option<&[Attribute]> = match item {
|
||||
Annotatable::Item(item) => Some(&item.attrs),
|
||||
Annotatable::TraitItem(item) => Some(&item.attrs),
|
||||
Annotatable::ImplItem(item) => Some(&item.attrs),
|
||||
Annotatable::AssocItem(item, _) => Some(&item.attrs),
|
||||
Annotatable::ForeignItem(item) => Some(&item.attrs),
|
||||
Annotatable::Expr(expr) => Some(&expr.attrs),
|
||||
Annotatable::Arm(arm) => Some(&arm.attrs),
|
||||
|
@ -37,8 +37,7 @@ use thin_vec::ThinVec;
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Annotatable {
|
||||
Item(P<ast::Item>),
|
||||
TraitItem(P<ast::AssocItem>),
|
||||
ImplItem(P<ast::AssocItem>),
|
||||
AssocItem(P<ast::AssocItem>, AssocCtxt),
|
||||
ForeignItem(P<ast::ForeignItem>),
|
||||
Stmt(P<ast::Stmt>),
|
||||
Expr(P<ast::Expr>),
|
||||
@ -56,8 +55,7 @@ impl Annotatable {
|
||||
pub fn span(&self) -> Span {
|
||||
match self {
|
||||
Annotatable::Item(item) => item.span,
|
||||
Annotatable::TraitItem(trait_item) => trait_item.span,
|
||||
Annotatable::ImplItem(impl_item) => impl_item.span,
|
||||
Annotatable::AssocItem(assoc_item, _) => assoc_item.span,
|
||||
Annotatable::ForeignItem(foreign_item) => foreign_item.span,
|
||||
Annotatable::Stmt(stmt) => stmt.span,
|
||||
Annotatable::Expr(expr) => expr.span,
|
||||
@ -75,8 +73,7 @@ impl Annotatable {
|
||||
pub fn visit_attrs(&mut self, f: impl FnOnce(&mut AttrVec)) {
|
||||
match self {
|
||||
Annotatable::Item(item) => item.visit_attrs(f),
|
||||
Annotatable::TraitItem(trait_item) => trait_item.visit_attrs(f),
|
||||
Annotatable::ImplItem(impl_item) => impl_item.visit_attrs(f),
|
||||
Annotatable::AssocItem(assoc_item, _) => assoc_item.visit_attrs(f),
|
||||
Annotatable::ForeignItem(foreign_item) => foreign_item.visit_attrs(f),
|
||||
Annotatable::Stmt(stmt) => stmt.visit_attrs(f),
|
||||
Annotatable::Expr(expr) => expr.visit_attrs(f),
|
||||
@ -94,8 +91,7 @@ impl Annotatable {
|
||||
pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) -> V::Result {
|
||||
match self {
|
||||
Annotatable::Item(item) => visitor.visit_item(item),
|
||||
Annotatable::TraitItem(item) => visitor.visit_assoc_item(item, AssocCtxt::Trait),
|
||||
Annotatable::ImplItem(item) => visitor.visit_assoc_item(item, AssocCtxt::Impl),
|
||||
Annotatable::AssocItem(item, ctxt) => visitor.visit_assoc_item(item, *ctxt),
|
||||
Annotatable::ForeignItem(foreign_item) => visitor.visit_foreign_item(foreign_item),
|
||||
Annotatable::Stmt(stmt) => visitor.visit_stmt(stmt),
|
||||
Annotatable::Expr(expr) => visitor.visit_expr(expr),
|
||||
@ -113,9 +109,7 @@ impl Annotatable {
|
||||
pub fn to_tokens(&self) -> TokenStream {
|
||||
match self {
|
||||
Annotatable::Item(node) => TokenStream::from_ast(node),
|
||||
Annotatable::TraitItem(node) | Annotatable::ImplItem(node) => {
|
||||
TokenStream::from_ast(node)
|
||||
}
|
||||
Annotatable::AssocItem(node, _) => TokenStream::from_ast(node),
|
||||
Annotatable::ForeignItem(node) => TokenStream::from_ast(node),
|
||||
Annotatable::Stmt(node) => {
|
||||
assert!(!matches!(node.kind, ast::StmtKind::Empty));
|
||||
@ -142,14 +136,14 @@ impl Annotatable {
|
||||
|
||||
pub fn expect_trait_item(self) -> P<ast::AssocItem> {
|
||||
match self {
|
||||
Annotatable::TraitItem(i) => i,
|
||||
Annotatable::AssocItem(i, AssocCtxt::Trait) => i,
|
||||
_ => panic!("expected Item"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expect_impl_item(self) -> P<ast::AssocItem> {
|
||||
match self {
|
||||
Annotatable::ImplItem(i) => i,
|
||||
Annotatable::AssocItem(i, AssocCtxt::Impl) => i,
|
||||
_ => panic!("expected Item"),
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ macro_rules! ast_fragments {
|
||||
AstFragment::MethodReceiverExpr(expr) => vis.visit_method_receiver_expr(expr),
|
||||
$($(AstFragment::$Kind(ast) => vis.$mut_visit_ast(ast),)?)*
|
||||
$($(AstFragment::$Kind(ast) =>
|
||||
ast.flat_map_in_place(|ast| vis.$flat_map_ast_elt(ast)),)?)*
|
||||
ast.flat_map_in_place(|ast| vis.$flat_map_ast_elt(ast, $($args)*)),)?)*
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,13 +177,13 @@ ast_fragments! {
|
||||
}
|
||||
TraitItems(SmallVec<[P<ast::AssocItem>; 1]>) {
|
||||
"trait item";
|
||||
many fn flat_map_trait_item;
|
||||
many fn flat_map_assoc_item;
|
||||
fn visit_assoc_item(AssocCtxt::Trait);
|
||||
fn make_trait_items;
|
||||
}
|
||||
ImplItems(SmallVec<[P<ast::AssocItem>; 1]>) {
|
||||
"impl item";
|
||||
many fn flat_map_impl_item;
|
||||
many fn flat_map_assoc_item;
|
||||
fn visit_assoc_item(AssocCtxt::Impl);
|
||||
fn make_impl_items;
|
||||
}
|
||||
@ -833,7 +833,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||
self.cx, deleg, &item, &suffixes, item.span, true,
|
||||
);
|
||||
fragment_kind.expect_from_annotatables(
|
||||
single_delegations.map(|item| Annotatable::ImplItem(P(item))),
|
||||
single_delegations.map(|item| Annotatable::AssocItem(P(item), AssocCtxt::Impl)),
|
||||
)
|
||||
}
|
||||
})
|
||||
@ -843,8 +843,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||
fn gate_proc_macro_attr_item(&self, span: Span, item: &Annotatable) {
|
||||
let kind = match item {
|
||||
Annotatable::Item(_)
|
||||
| Annotatable::TraitItem(_)
|
||||
| Annotatable::ImplItem(_)
|
||||
| Annotatable::AssocItem(..)
|
||||
| Annotatable::ForeignItem(_)
|
||||
| Annotatable::Crate(..) => return,
|
||||
Annotatable::Stmt(stmt) => {
|
||||
@ -1037,7 +1036,7 @@ pub(crate) fn ensure_complete_parse<'a>(
|
||||
}
|
||||
}
|
||||
|
||||
/// Wraps a call to `noop_visit_*` / `noop_flat_map_*`
|
||||
/// Wraps a call to `walk_*` / `walk_flat_map_*`
|
||||
/// for an AST node that supports attributes
|
||||
/// (see the `Annotatable` enum)
|
||||
/// This method assigns a `NodeId`, and sets that `NodeId`
|
||||
@ -1057,7 +1056,7 @@ pub(crate) fn ensure_complete_parse<'a>(
|
||||
/// * `id` is a mutable reference to the `NodeId` field
|
||||
/// of the current AST node.
|
||||
/// * `closure` is a closure that executes the
|
||||
/// `noop_visit_*` / `noop_flat_map_*` method
|
||||
/// `walk_*` / `walk_flat_map_*` method
|
||||
/// for the current AST node.
|
||||
macro_rules! assign_id {
|
||||
($self:ident, $id:expr, $closure:expr) => {{
|
||||
@ -1091,10 +1090,10 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized {
|
||||
fn descr() -> &'static str {
|
||||
unreachable!()
|
||||
}
|
||||
fn noop_flat_map<V: MutVisitor>(self, _visitor: &mut V) -> Self::OutputTy {
|
||||
fn walk_flat_map<V: MutVisitor>(self, _visitor: &mut V) -> Self::OutputTy {
|
||||
unreachable!()
|
||||
}
|
||||
fn noop_visit<V: MutVisitor>(&mut self, _visitor: &mut V) {
|
||||
fn walk<V: MutVisitor>(&mut self, _visitor: &mut V) {
|
||||
unreachable!()
|
||||
}
|
||||
fn is_mac_call(&self) -> bool {
|
||||
@ -1118,12 +1117,12 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized {
|
||||
fn pre_flat_map_node_collect_attr(_cfg: &StripUnconfigured<'_>, _attr: &ast::Attribute) {}
|
||||
fn post_flat_map_node_collect_bang(_output: &mut Self::OutputTy, _add_semicolon: AddSemicolon) {
|
||||
}
|
||||
fn wrap_flat_map_node_noop_flat_map(
|
||||
fn wrap_flat_map_node_walk_flat_map(
|
||||
node: Self,
|
||||
collector: &mut InvocationCollector<'_, '_>,
|
||||
noop_flat_map: impl FnOnce(Self, &mut InvocationCollector<'_, '_>) -> Self::OutputTy,
|
||||
walk_flat_map: impl FnOnce(Self, &mut InvocationCollector<'_, '_>) -> Self::OutputTy,
|
||||
) -> Result<Self::OutputTy, Self> {
|
||||
Ok(noop_flat_map(node, collector))
|
||||
Ok(walk_flat_map(node, collector))
|
||||
}
|
||||
fn expand_cfg_false(
|
||||
&mut self,
|
||||
@ -1149,8 +1148,8 @@ impl InvocationCollectorNode for P<ast::Item> {
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_items()
|
||||
}
|
||||
fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
noop_flat_map_item(self, visitor)
|
||||
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
walk_flat_map_item(visitor, self)
|
||||
}
|
||||
fn is_mac_call(&self) -> bool {
|
||||
matches!(self.kind, ItemKind::MacCall(..))
|
||||
@ -1177,13 +1176,13 @@ impl InvocationCollectorNode for P<ast::Item> {
|
||||
fn flatten_outputs(items: impl Iterator<Item = Self::OutputTy>) -> Self::OutputTy {
|
||||
items.flatten().collect()
|
||||
}
|
||||
fn wrap_flat_map_node_noop_flat_map(
|
||||
fn wrap_flat_map_node_walk_flat_map(
|
||||
mut node: Self,
|
||||
collector: &mut InvocationCollector<'_, '_>,
|
||||
noop_flat_map: impl FnOnce(Self, &mut InvocationCollector<'_, '_>) -> Self::OutputTy,
|
||||
walk_flat_map: impl FnOnce(Self, &mut InvocationCollector<'_, '_>) -> Self::OutputTy,
|
||||
) -> Result<Self::OutputTy, Self> {
|
||||
if !matches!(node.kind, ItemKind::Mod(..)) {
|
||||
return Ok(noop_flat_map(node, collector));
|
||||
return Ok(walk_flat_map(node, collector));
|
||||
}
|
||||
|
||||
// Work around borrow checker not seeing through `P`'s deref.
|
||||
@ -1253,7 +1252,7 @@ impl InvocationCollectorNode for P<ast::Item> {
|
||||
let orig_dir_ownership =
|
||||
mem::replace(&mut ecx.current_expansion.dir_ownership, dir_ownership);
|
||||
|
||||
let res = Ok(noop_flat_map(node, collector));
|
||||
let res = Ok(walk_flat_map(node, collector));
|
||||
|
||||
collector.cx.current_expansion.dir_ownership = orig_dir_ownership;
|
||||
collector.cx.current_expansion.module = orig_module;
|
||||
@ -1288,13 +1287,13 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag>
|
||||
type ItemKind = AssocItemKind;
|
||||
const KIND: AstFragmentKind = AstFragmentKind::TraitItems;
|
||||
fn to_annotatable(self) -> Annotatable {
|
||||
Annotatable::TraitItem(self.wrapped)
|
||||
Annotatable::AssocItem(self.wrapped, AssocCtxt::Trait)
|
||||
}
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_trait_items()
|
||||
}
|
||||
fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
noop_flat_map_item(self.wrapped, visitor)
|
||||
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
walk_flat_map_item(visitor, self.wrapped)
|
||||
}
|
||||
fn is_mac_call(&self) -> bool {
|
||||
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
|
||||
@ -1329,13 +1328,13 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag>
|
||||
type ItemKind = AssocItemKind;
|
||||
const KIND: AstFragmentKind = AstFragmentKind::ImplItems;
|
||||
fn to_annotatable(self) -> Annotatable {
|
||||
Annotatable::ImplItem(self.wrapped)
|
||||
Annotatable::AssocItem(self.wrapped, AssocCtxt::Impl)
|
||||
}
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_impl_items()
|
||||
}
|
||||
fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
noop_flat_map_item(self.wrapped, visitor)
|
||||
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
walk_flat_map_item(visitor, self.wrapped)
|
||||
}
|
||||
fn is_mac_call(&self) -> bool {
|
||||
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
|
||||
@ -1372,8 +1371,8 @@ impl InvocationCollectorNode for P<ast::ForeignItem> {
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_foreign_items()
|
||||
}
|
||||
fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
noop_flat_map_item(self, visitor)
|
||||
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
walk_flat_map_item(visitor, self)
|
||||
}
|
||||
fn is_mac_call(&self) -> bool {
|
||||
matches!(self.kind, ForeignItemKind::MacCall(..))
|
||||
@ -1395,8 +1394,8 @@ impl InvocationCollectorNode for ast::Variant {
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_variants()
|
||||
}
|
||||
fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
noop_flat_map_variant(self, visitor)
|
||||
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
walk_flat_map_variant(visitor, self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1408,8 +1407,8 @@ impl InvocationCollectorNode for ast::FieldDef {
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_field_defs()
|
||||
}
|
||||
fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
noop_flat_map_field_def(self, visitor)
|
||||
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
walk_flat_map_field_def(visitor, self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1421,8 +1420,8 @@ impl InvocationCollectorNode for ast::PatField {
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_pat_fields()
|
||||
}
|
||||
fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
noop_flat_map_pat_field(self, visitor)
|
||||
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
walk_flat_map_pat_field(visitor, self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1434,8 +1433,8 @@ impl InvocationCollectorNode for ast::ExprField {
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_expr_fields()
|
||||
}
|
||||
fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
noop_flat_map_expr_field(self, visitor)
|
||||
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
walk_flat_map_expr_field(visitor, self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1447,8 +1446,8 @@ impl InvocationCollectorNode for ast::Param {
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_params()
|
||||
}
|
||||
fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
noop_flat_map_param(self, visitor)
|
||||
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
walk_flat_map_param(visitor, self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1460,8 +1459,8 @@ impl InvocationCollectorNode for ast::GenericParam {
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_generic_params()
|
||||
}
|
||||
fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
noop_flat_map_generic_param(self, visitor)
|
||||
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
walk_flat_map_generic_param(visitor, self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1473,8 +1472,8 @@ impl InvocationCollectorNode for ast::Arm {
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_arms()
|
||||
}
|
||||
fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
noop_flat_map_arm(self, visitor)
|
||||
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
walk_flat_map_arm(visitor, self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1487,8 +1486,8 @@ impl InvocationCollectorNode for ast::Stmt {
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_stmts()
|
||||
}
|
||||
fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
noop_flat_map_stmt(self, visitor)
|
||||
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||
walk_flat_map_stmt(visitor, self)
|
||||
}
|
||||
fn is_mac_call(&self) -> bool {
|
||||
match &self.kind {
|
||||
@ -1561,8 +1560,8 @@ impl InvocationCollectorNode for ast::Crate {
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_crate()
|
||||
}
|
||||
fn noop_visit<V: MutVisitor>(&mut self, visitor: &mut V) {
|
||||
noop_visit_crate(self, visitor)
|
||||
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
|
||||
walk_crate(visitor, self)
|
||||
}
|
||||
fn expand_cfg_false(
|
||||
&mut self,
|
||||
@ -1587,8 +1586,8 @@ impl InvocationCollectorNode for P<ast::Ty> {
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_ty()
|
||||
}
|
||||
fn noop_visit<V: MutVisitor>(&mut self, visitor: &mut V) {
|
||||
noop_visit_ty(self, visitor)
|
||||
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
|
||||
walk_ty(visitor, self)
|
||||
}
|
||||
fn is_mac_call(&self) -> bool {
|
||||
matches!(self.kind, ast::TyKind::MacCall(..))
|
||||
@ -1611,8 +1610,8 @@ impl InvocationCollectorNode for P<ast::Pat> {
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_pat()
|
||||
}
|
||||
fn noop_visit<V: MutVisitor>(&mut self, visitor: &mut V) {
|
||||
noop_visit_pat(self, visitor)
|
||||
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
|
||||
walk_pat(visitor, self)
|
||||
}
|
||||
fn is_mac_call(&self) -> bool {
|
||||
matches!(self.kind, PatKind::MacCall(..))
|
||||
@ -1639,8 +1638,8 @@ impl InvocationCollectorNode for P<ast::Expr> {
|
||||
fn descr() -> &'static str {
|
||||
"an expression"
|
||||
}
|
||||
fn noop_visit<V: MutVisitor>(&mut self, visitor: &mut V) {
|
||||
noop_visit_expr(self, visitor)
|
||||
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
|
||||
walk_expr(visitor, self)
|
||||
}
|
||||
fn is_mac_call(&self) -> bool {
|
||||
matches!(self.kind, ExprKind::MacCall(..))
|
||||
@ -1665,8 +1664,8 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, OptExprTag> {
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
fragment.make_opt_expr()
|
||||
}
|
||||
fn noop_flat_map<V: MutVisitor>(mut self, visitor: &mut V) -> Self::OutputTy {
|
||||
noop_visit_expr(&mut self.wrapped, visitor);
|
||||
fn walk_flat_map<V: MutVisitor>(mut self, visitor: &mut V) -> Self::OutputTy {
|
||||
walk_expr(visitor, &mut self.wrapped);
|
||||
Some(self.wrapped)
|
||||
}
|
||||
fn is_mac_call(&self) -> bool {
|
||||
@ -1705,8 +1704,8 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, MethodReceiverTag>
|
||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||
AstNodeWrapper::new(fragment.make_method_receiver_expr(), MethodReceiverTag)
|
||||
}
|
||||
fn noop_visit<V: MutVisitor>(&mut self, visitor: &mut V) {
|
||||
noop_visit_expr(&mut self.wrapped, visitor)
|
||||
fn walk<V: MutVisitor>(&mut self, visitor: &mut V) {
|
||||
walk_expr(visitor, &mut self.wrapped)
|
||||
}
|
||||
fn is_mac_call(&self) -> bool {
|
||||
matches!(self.wrapped.kind, ast::ExprKind::MacCall(..))
|
||||
@ -1993,9 +1992,9 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
|
||||
let traitless_qself =
|
||||
matches!(&deleg.qself, Some(qself) if qself.position == 0);
|
||||
let item = match node.to_annotatable() {
|
||||
Annotatable::ImplItem(item) => item,
|
||||
Annotatable::AssocItem(item, AssocCtxt::Impl) => item,
|
||||
ann @ (Annotatable::Item(_)
|
||||
| Annotatable::TraitItem(_)
|
||||
| Annotatable::AssocItem(..)
|
||||
| Annotatable::Stmt(_)) => {
|
||||
let span = ann.span();
|
||||
self.cx.dcx().emit_err(GlobDelegationOutsideImpls { span });
|
||||
@ -2016,12 +2015,12 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
|
||||
);
|
||||
Node::flatten_outputs(single_delegations.map(|item| {
|
||||
let mut item = Node::from_item(item);
|
||||
assign_id!(self, item.node_id_mut(), || item.noop_flat_map(self))
|
||||
assign_id!(self, item.node_id_mut(), || item.walk_flat_map(self))
|
||||
}))
|
||||
}
|
||||
None => {
|
||||
match Node::wrap_flat_map_node_noop_flat_map(node, self, |mut node, this| {
|
||||
assign_id!(this, node.node_id_mut(), || node.noop_flat_map(this))
|
||||
match Node::wrap_flat_map_node_walk_flat_map(node, self, |mut node, this| {
|
||||
assign_id!(this, node.node_id_mut(), || node.walk_flat_map(this))
|
||||
}) {
|
||||
Ok(output) => output,
|
||||
Err(returned_node) => {
|
||||
@ -2069,7 +2068,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
|
||||
}
|
||||
None if node.delegation().is_some() => unreachable!(),
|
||||
None => {
|
||||
assign_id!(self, node.node_id_mut(), || node.noop_visit(self))
|
||||
assign_id!(self, node.node_id_mut(), || node.walk(self))
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -2081,12 +2080,15 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
||||
self.flat_map_node(node)
|
||||
}
|
||||
|
||||
fn flat_map_trait_item(&mut self, node: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
||||
self.flat_map_node(AstNodeWrapper::new(node, TraitItemTag))
|
||||
}
|
||||
|
||||
fn flat_map_impl_item(&mut self, node: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
||||
self.flat_map_node(AstNodeWrapper::new(node, ImplItemTag))
|
||||
fn flat_map_assoc_item(
|
||||
&mut self,
|
||||
node: P<ast::AssocItem>,
|
||||
ctxt: AssocCtxt,
|
||||
) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
||||
match ctxt {
|
||||
AssocCtxt::Trait => self.flat_map_node(AstNodeWrapper::new(node, TraitItemTag)),
|
||||
AssocCtxt::Impl => self.flat_map_node(AstNodeWrapper::new(node, ImplItemTag)),
|
||||
}
|
||||
}
|
||||
|
||||
fn flat_map_foreign_item(
|
||||
@ -2145,11 +2147,11 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
||||
self.cx.current_expansion.is_trailing_mac = true;
|
||||
// Don't use `assign_id` for this statement - it may get removed
|
||||
// entirely due to a `#[cfg]` on the contained expression
|
||||
let res = noop_flat_map_stmt(node, self);
|
||||
let res = walk_flat_map_stmt(self, node);
|
||||
self.cx.current_expansion.is_trailing_mac = false;
|
||||
res
|
||||
}
|
||||
_ => noop_flat_map_stmt(node, self),
|
||||
_ => walk_flat_map_stmt(self, node),
|
||||
};
|
||||
}
|
||||
|
||||
@ -2193,7 +2195,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
||||
&mut self.cx.current_expansion.dir_ownership,
|
||||
DirOwnership::UnownedViaBlock,
|
||||
);
|
||||
noop_visit_block(node, self);
|
||||
walk_block(self, node);
|
||||
self.cx.current_expansion.dir_ownership = orig_dir_ownership;
|
||||
}
|
||||
|
||||
|
@ -333,7 +333,7 @@ pub(super) fn transcribe<'a>(
|
||||
// jump back out of the Delimited, pop the result_stack and add the new results back to
|
||||
// the previous results (from outside the Delimited).
|
||||
mbe::TokenTree::Delimited(mut span, spacing, delimited) => {
|
||||
mut_visit::visit_delim_span(&mut span, &mut marker);
|
||||
mut_visit::visit_delim_span(&mut marker, &mut span);
|
||||
stack.push(Frame::new_delimited(delimited, span, *spacing));
|
||||
result_stack.push(mem::take(&mut result));
|
||||
}
|
||||
@ -342,7 +342,7 @@ pub(super) fn transcribe<'a>(
|
||||
// preserve syntax context.
|
||||
mbe::TokenTree::Token(token) => {
|
||||
let mut token = token.clone();
|
||||
mut_visit::visit_token(&mut token, &mut marker);
|
||||
mut_visit::visit_token(&mut marker, &mut token);
|
||||
let tt = TokenTree::Token(token, Spacing::Alone);
|
||||
result.push(tt);
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
use crate::expand::{AstFragment, AstFragmentKind};
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::mut_visit::*;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::Delimiter;
|
||||
use rustc_ast::{self as ast, visit::AssocCtxt};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::DUMMY_SP;
|
||||
@ -209,7 +209,7 @@ impl MutVisitor for PlaceholderExpander {
|
||||
if arm.is_placeholder {
|
||||
self.remove(arm.id).make_arms()
|
||||
} else {
|
||||
noop_flat_map_arm(arm, self)
|
||||
walk_flat_map_arm(self, arm)
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,7 +217,7 @@ impl MutVisitor for PlaceholderExpander {
|
||||
if field.is_placeholder {
|
||||
self.remove(field.id).make_expr_fields()
|
||||
} else {
|
||||
noop_flat_map_expr_field(field, self)
|
||||
walk_flat_map_expr_field(self, field)
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,7 +225,7 @@ impl MutVisitor for PlaceholderExpander {
|
||||
if fp.is_placeholder {
|
||||
self.remove(fp.id).make_pat_fields()
|
||||
} else {
|
||||
noop_flat_map_pat_field(fp, self)
|
||||
walk_flat_map_pat_field(self, fp)
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,7 +236,7 @@ impl MutVisitor for PlaceholderExpander {
|
||||
if param.is_placeholder {
|
||||
self.remove(param.id).make_generic_params()
|
||||
} else {
|
||||
noop_flat_map_generic_param(param, self)
|
||||
walk_flat_map_generic_param(self, param)
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,7 +244,7 @@ impl MutVisitor for PlaceholderExpander {
|
||||
if p.is_placeholder {
|
||||
self.remove(p.id).make_params()
|
||||
} else {
|
||||
noop_flat_map_param(p, self)
|
||||
walk_flat_map_param(self, p)
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,7 +252,7 @@ impl MutVisitor for PlaceholderExpander {
|
||||
if sf.is_placeholder {
|
||||
self.remove(sf.id).make_field_defs()
|
||||
} else {
|
||||
noop_flat_map_field_def(sf, self)
|
||||
walk_flat_map_field_def(self, sf)
|
||||
}
|
||||
}
|
||||
|
||||
@ -260,28 +260,31 @@ impl MutVisitor for PlaceholderExpander {
|
||||
if variant.is_placeholder {
|
||||
self.remove(variant.id).make_variants()
|
||||
} else {
|
||||
noop_flat_map_variant(variant, self)
|
||||
walk_flat_map_variant(self, variant)
|
||||
}
|
||||
}
|
||||
|
||||
fn flat_map_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> {
|
||||
match item.kind {
|
||||
ast::ItemKind::MacCall(_) => self.remove(item.id).make_items(),
|
||||
_ => noop_flat_map_item(item, self),
|
||||
_ => walk_flat_map_item(self, item),
|
||||
}
|
||||
}
|
||||
|
||||
fn flat_map_trait_item(&mut self, item: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
||||
fn flat_map_assoc_item(
|
||||
&mut self,
|
||||
item: P<ast::AssocItem>,
|
||||
ctxt: AssocCtxt,
|
||||
) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
||||
match item.kind {
|
||||
ast::AssocItemKind::MacCall(_) => self.remove(item.id).make_trait_items(),
|
||||
_ => noop_flat_map_item(item, self),
|
||||
}
|
||||
}
|
||||
|
||||
fn flat_map_impl_item(&mut self, item: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
||||
match item.kind {
|
||||
ast::AssocItemKind::MacCall(_) => self.remove(item.id).make_impl_items(),
|
||||
_ => noop_flat_map_item(item, self),
|
||||
ast::AssocItemKind::MacCall(_) => {
|
||||
let it = self.remove(item.id);
|
||||
match ctxt {
|
||||
AssocCtxt::Trait => it.make_trait_items(),
|
||||
AssocCtxt::Impl => it.make_impl_items(),
|
||||
}
|
||||
}
|
||||
_ => walk_flat_map_item(self, item),
|
||||
}
|
||||
}
|
||||
|
||||
@ -291,35 +294,35 @@ impl MutVisitor for PlaceholderExpander {
|
||||
) -> SmallVec<[P<ast::ForeignItem>; 1]> {
|
||||
match item.kind {
|
||||
ast::ForeignItemKind::MacCall(_) => self.remove(item.id).make_foreign_items(),
|
||||
_ => noop_flat_map_item(item, self),
|
||||
_ => walk_flat_map_item(self, item),
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
|
||||
match expr.kind {
|
||||
ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_expr(),
|
||||
_ => noop_visit_expr(expr, self),
|
||||
_ => walk_expr(self, expr),
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_method_receiver_expr(&mut self, expr: &mut P<ast::Expr>) {
|
||||
match expr.kind {
|
||||
ast::ExprKind::MacCall(_) => *expr = self.remove(expr.id).make_method_receiver_expr(),
|
||||
_ => noop_visit_expr(expr, self),
|
||||
_ => walk_expr(self, expr),
|
||||
}
|
||||
}
|
||||
|
||||
fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
|
||||
match expr.kind {
|
||||
ast::ExprKind::MacCall(_) => self.remove(expr.id).make_opt_expr(),
|
||||
_ => noop_filter_map_expr(expr, self),
|
||||
_ => noop_filter_map_expr(self, expr),
|
||||
}
|
||||
}
|
||||
|
||||
fn flat_map_stmt(&mut self, stmt: ast::Stmt) -> SmallVec<[ast::Stmt; 1]> {
|
||||
let (style, mut stmts) = match stmt.kind {
|
||||
ast::StmtKind::MacCall(mac) => (mac.style, self.remove(stmt.id).make_stmts()),
|
||||
_ => return noop_flat_map_stmt(stmt, self),
|
||||
_ => return walk_flat_map_stmt(self, stmt),
|
||||
};
|
||||
|
||||
if style == ast::MacStmtStyle::Semicolon {
|
||||
@ -365,14 +368,14 @@ impl MutVisitor for PlaceholderExpander {
|
||||
fn visit_pat(&mut self, pat: &mut P<ast::Pat>) {
|
||||
match pat.kind {
|
||||
ast::PatKind::MacCall(_) => *pat = self.remove(pat.id).make_pat(),
|
||||
_ => noop_visit_pat(pat, self),
|
||||
_ => walk_pat(self, pat),
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_ty(&mut self, ty: &mut P<ast::Ty>) {
|
||||
match ty.kind {
|
||||
ast::TyKind::MacCall(_) => *ty = self.remove(ty.id).make_ty(),
|
||||
_ => noop_visit_ty(ty, self),
|
||||
_ => walk_ty(self, ty),
|
||||
}
|
||||
}
|
||||
|
||||
@ -380,7 +383,7 @@ impl MutVisitor for PlaceholderExpander {
|
||||
if krate.is_placeholder {
|
||||
*krate = self.remove(krate.id).make_crate();
|
||||
} else {
|
||||
noop_visit_crate(krate, self)
|
||||
walk_crate(self, krate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ use super::{
|
||||
|
||||
use crate::errors;
|
||||
use crate::maybe_recover_from_interpolated_ty_qpath;
|
||||
use ast::mut_visit::{noop_visit_expr, MutVisitor};
|
||||
use ast::mut_visit::{self, MutVisitor};
|
||||
use ast::token::IdentIsRaw;
|
||||
use ast::{CoroutineKind, ForLoopKind, GenBlockKind, MatchKind, Pat, Path, PathSegment, Recovered};
|
||||
use core::mem;
|
||||
@ -3939,14 +3939,14 @@ impl MutVisitor for CondChecker<'_> {
|
||||
}
|
||||
}
|
||||
ExprKind::Binary(Spanned { node: BinOpKind::And, .. }, _, _) => {
|
||||
noop_visit_expr(e, self);
|
||||
mut_visit::walk_expr(self, e);
|
||||
}
|
||||
ExprKind::Binary(Spanned { node: BinOpKind::Or, span: or_span }, _, _)
|
||||
if let None | Some(NotSupportedOr(_)) = self.forbid_let_reason =>
|
||||
{
|
||||
let forbid_let_reason = self.forbid_let_reason;
|
||||
self.forbid_let_reason = Some(NotSupportedOr(or_span));
|
||||
noop_visit_expr(e, self);
|
||||
mut_visit::walk_expr(self, e);
|
||||
self.forbid_let_reason = forbid_let_reason;
|
||||
}
|
||||
ExprKind::Paren(ref inner)
|
||||
@ -3954,7 +3954,7 @@ impl MutVisitor for CondChecker<'_> {
|
||||
{
|
||||
let forbid_let_reason = self.forbid_let_reason;
|
||||
self.forbid_let_reason = Some(NotSupportedParentheses(inner.span));
|
||||
noop_visit_expr(e, self);
|
||||
mut_visit::walk_expr(self, e);
|
||||
self.forbid_let_reason = forbid_let_reason;
|
||||
}
|
||||
ExprKind::Assign(ref lhs, _, span) => {
|
||||
@ -3972,7 +3972,7 @@ impl MutVisitor for CondChecker<'_> {
|
||||
}
|
||||
let comparison = self.comparison;
|
||||
self.comparison = Some(errors::MaybeComparison { span: span.shrink_to_hi() });
|
||||
noop_visit_expr(e, self);
|
||||
mut_visit::walk_expr(self, e);
|
||||
self.forbid_let_reason = forbid_let_reason;
|
||||
self.missing_let = missing_let;
|
||||
self.comparison = comparison;
|
||||
@ -3992,7 +3992,7 @@ impl MutVisitor for CondChecker<'_> {
|
||||
| ExprKind::Paren(_) => {
|
||||
let forbid_let_reason = self.forbid_let_reason;
|
||||
self.forbid_let_reason = Some(OtherForbidden);
|
||||
noop_visit_expr(e, self);
|
||||
mut_visit::walk_expr(self, e);
|
||||
self.forbid_let_reason = forbid_let_reason;
|
||||
}
|
||||
ExprKind::Cast(ref mut op, _) | ExprKind::Type(ref mut op, _) => {
|
||||
|
@ -12,7 +12,7 @@ use crate::errors::{
|
||||
};
|
||||
use crate::parser::expr::{could_be_unclosed_char_literal, LhsExpr};
|
||||
use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole};
|
||||
use rustc_ast::mut_visit::{noop_visit_pat, MutVisitor};
|
||||
use rustc_ast::mut_visit::{walk_pat, MutVisitor};
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, BinOpToken, Delimiter, Token};
|
||||
use rustc_ast::{
|
||||
@ -810,7 +810,7 @@ impl<'a> Parser<'a> {
|
||||
self.0 = true;
|
||||
*m = Mutability::Mut;
|
||||
}
|
||||
noop_visit_pat(pat, self);
|
||||
walk_pat(self, pat);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,7 +121,7 @@ fn remove_all_parens(pat: &mut P<Pat>) {
|
||||
struct Visitor;
|
||||
impl MutVisitor for Visitor {
|
||||
fn visit_pat(&mut self, pat: &mut P<Pat>) {
|
||||
noop_visit_pat(pat, self);
|
||||
walk_pat(self, pat);
|
||||
let inner = match &mut pat.kind {
|
||||
Paren(i) => mem::replace(&mut i.kind, Wild),
|
||||
_ => return,
|
||||
@ -138,7 +138,7 @@ fn insert_necessary_parens(pat: &mut P<Pat>) {
|
||||
impl MutVisitor for Visitor {
|
||||
fn visit_pat(&mut self, pat: &mut P<Pat>) {
|
||||
use ast::BindingMode;
|
||||
noop_visit_pat(pat, self);
|
||||
walk_pat(self, pat);
|
||||
let target = match &mut pat.kind {
|
||||
// `i @ a | b`, `box a | b`, and `& mut? a | b`.
|
||||
Ident(.., Some(p)) | Box(p) | Ref(p, _) if matches!(&p.kind, Or(ps) if ps.len() > 1) => p,
|
||||
@ -160,7 +160,7 @@ fn unnest_or_patterns(pat: &mut P<Pat>) -> bool {
|
||||
impl MutVisitor for Visitor {
|
||||
fn visit_pat(&mut self, p: &mut P<Pat>) {
|
||||
// This is a bottom up transformation, so recurse first.
|
||||
noop_visit_pat(p, self);
|
||||
walk_pat(self, p);
|
||||
|
||||
// Don't have an or-pattern? Just quit early on.
|
||||
let Or(alternatives) = &mut p.kind else { return };
|
||||
@ -189,7 +189,7 @@ fn unnest_or_patterns(pat: &mut P<Pat>) -> bool {
|
||||
|
||||
// Deal with `Some(Some(0)) | Some(Some(1))`.
|
||||
if this_level_changed {
|
||||
noop_visit_pat(p, self);
|
||||
walk_pat(self, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,9 +46,11 @@ use thin_vec::{thin_vec, ThinVec};
|
||||
fn parse_expr(psess: &ParseSess, src: &str) -> Option<P<Expr>> {
|
||||
let src_as_string = src.to_string();
|
||||
|
||||
let mut p = unwrap_or_emit_fatal(
|
||||
new_parser_from_source_str(psess, FileName::Custom(src_as_string.clone()), src_as_string)
|
||||
);
|
||||
let mut p = unwrap_or_emit_fatal(new_parser_from_source_str(
|
||||
psess,
|
||||
FileName::Custom(src_as_string.clone()),
|
||||
src_as_string,
|
||||
));
|
||||
p.parse_expr().map_err(|e| e.cancel()).ok()
|
||||
}
|
||||
|
||||
@ -181,10 +183,9 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
|
||||
18 => {
|
||||
let pat =
|
||||
P(Pat { id: DUMMY_NODE_ID, kind: PatKind::Wild, span: DUMMY_SP, tokens: None });
|
||||
iter_exprs(
|
||||
depth - 1,
|
||||
&mut |e| g(ExprKind::Let(pat.clone(), e, DUMMY_SP, Recovered::No))
|
||||
)
|
||||
iter_exprs(depth - 1, &mut |e| {
|
||||
g(ExprKind::Let(pat.clone(), e, DUMMY_SP, Recovered::No))
|
||||
})
|
||||
}
|
||||
_ => panic!("bad counter value in iter_exprs"),
|
||||
}
|
||||
@ -202,7 +203,7 @@ impl MutVisitor for RemoveParens {
|
||||
ExprKind::Paren(inner) => *e = inner,
|
||||
_ => {}
|
||||
};
|
||||
mut_visit::noop_visit_expr(e, self);
|
||||
mut_visit::walk_expr(self, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,7 +212,7 @@ struct AddParens;
|
||||
|
||||
impl MutVisitor for AddParens {
|
||||
fn visit_expr(&mut self, e: &mut P<Expr>) {
|
||||
mut_visit::noop_visit_expr(e, self);
|
||||
mut_visit::walk_expr(self, e);
|
||||
visit_clobber(e, |e| {
|
||||
P(Expr {
|
||||
id: DUMMY_NODE_ID,
|
||||
|
Loading…
Reference in New Issue
Block a user