diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 3c08e6d6ca6..8387e4499ae 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -11,7 +11,7 @@ use crate::ast::*; use crate::ptr::P; use crate::token::{self, Token}; use crate::tokenstream::*; -use crate::visit::{AssocCtxt, BoundKind, FnCtxt}; +use crate::visit::{AssocCtxt, BoundKind}; use rustc_data_structures::flat_map_in_place::FlatMapInPlace; use rustc_data_structures::stack::ensure_sufficient_stack; @@ -36,14 +36,7 @@ impl ExpectOne for SmallVec { } pub trait WalkItemKind { - fn walk( - &mut self, - ctxt: Option, - ident: Ident, - span: Span, - id: NodeId, - visitor: &mut impl MutVisitor, - ); + fn walk(&mut self, span: Span, id: NodeId, visitor: &mut impl MutVisitor); } pub trait MutVisitor: Sized { @@ -102,11 +95,11 @@ pub trait MutVisitor: Sized { } fn flat_map_foreign_item(&mut self, ni: P) -> SmallVec<[P; 1]> { - walk_flat_map_item(self, ni, None) + walk_flat_map_item(self, ni) } fn flat_map_item(&mut self, i: P) -> SmallVec<[P; 1]> { - walk_flat_map_item(self, i, None) + walk_flat_map_item(self, i) } fn visit_fn_header(&mut self, header: &mut FnHeader) { @@ -120,9 +113,9 @@ pub trait MutVisitor: Sized { fn flat_map_assoc_item( &mut self, i: P, - ctxt: AssocCtxt, + _ctxt: AssocCtxt, ) -> SmallVec<[P; 1]> { - walk_flat_map_item(self, i, Some(ctxt)) + walk_flat_map_item(self, i) } fn visit_fn_decl(&mut self, d: &mut P) { @@ -890,7 +883,7 @@ fn walk_coroutine_kind(vis: &mut T, coroutine_kind: &mut Coroutin fn walk_fn(vis: &mut T, kind: FnKind<'_>) { match kind { - FnKind::Fn(_ctxt, _ident, FnSig { header, decl, span }, generics, body) => { + FnKind::Fn(FnSig { header, decl, span }, generics, body) => { // Identifier and visibility are visited as a part of the item. vis.visit_fn_header(header); vis.visit_generics(generics); @@ -1091,24 +1084,15 @@ pub fn walk_block(vis: &mut T, block: &mut P) { pub fn walk_item_kind( kind: &mut impl WalkItemKind, - ident: Ident, span: Span, id: NodeId, vis: &mut impl MutVisitor, ) { - kind.walk(None, ident, span, id, vis) + kind.walk(span, id, vis) } impl WalkItemKind for ItemKind { - fn walk( - &mut self, - ctxt: Option, - ident: Ident, - span: Span, - id: NodeId, - vis: &mut impl MutVisitor, - ) { - assert_eq!(ctxt, None); + fn walk(&mut self, span: Span, id: NodeId, vis: &mut impl MutVisitor) { match self { ItemKind::ExternCrate(_orig_name) => {} ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree), @@ -1121,7 +1105,7 @@ impl WalkItemKind for ItemKind { } ItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(vis, defaultness); - vis.visit_fn(FnKind::Fn(FnCtxt::Free, ident, sig, generics, body), span, id); + vis.visit_fn(FnKind::Fn(sig, generics, body), span, id); } ItemKind::Mod(safety, mod_kind) => { visit_safety(vis, safety); @@ -1220,26 +1204,14 @@ impl WalkItemKind for ItemKind { } impl WalkItemKind for AssocItemKind { - fn walk( - &mut self, - ctxt: Option, - ident: Ident, - span: Span, - id: NodeId, - visitor: &mut impl MutVisitor, - ) { - let ctxt = ctxt.unwrap(); + fn walk(&mut self, span: Span, id: NodeId, visitor: &mut impl MutVisitor) { match self { AssocItemKind::Const(item) => { visit_const_item(item, visitor); } AssocItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(visitor, defaultness); - visitor.visit_fn( - FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, generics, body), - span, - id, - ); + visitor.visit_fn(FnKind::Fn(sig, generics, body), span, id); } AssocItemKind::Type(box TyAlias { defaultness, @@ -1323,29 +1295,20 @@ pub fn walk_crate(vis: &mut T, krate: &mut Crate) { pub fn walk_flat_map_item( visitor: &mut impl MutVisitor, mut item: P>, - ctxt: Option, ) -> SmallVec<[P>; 1]> { let Item { ident, attrs, id, kind, vis, span, tokens } = item.deref_mut(); visitor.visit_id(id); visit_attrs(visitor, attrs); visitor.visit_vis(vis); visitor.visit_ident(ident); - kind.walk(ctxt, *ident, *span, *id, visitor); + kind.walk(*span, *id, visitor); visit_lazy_tts(visitor, tokens); visitor.visit_span(span); smallvec![item] } impl WalkItemKind for ForeignItemKind { - fn walk( - &mut self, - ctxt: Option, - ident: Ident, - span: Span, - id: NodeId, - visitor: &mut impl MutVisitor, - ) { - assert_eq!(ctxt, None); + fn walk(&mut self, span: Span, id: NodeId, visitor: &mut impl MutVisitor) { match self { ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => { visitor.visit_ty(ty); @@ -1353,7 +1316,7 @@ impl WalkItemKind for ForeignItemKind { } ForeignItemKind::Fn(box Fn { defaultness, generics, sig, body }) => { visit_defaultness(visitor, defaultness); - visitor.visit_fn(FnKind::Fn(FnCtxt::Foreign, ident, sig, generics, body), span, id); + visitor.visit_fn(FnKind::Fn(sig, generics, body), span, id); } ForeignItemKind::TyAlias(box TyAlias { defaultness, @@ -1824,7 +1787,7 @@ impl DummyAstNode for crate::ast_traits::AstNo #[derive(Debug)] pub enum FnKind<'a> { /// E.g., `fn foo()`, `fn foo(&self)`, or `extern "Abi" fn foo()`. - Fn(FnCtxt, Ident, &'a mut FnSig, &'a mut Generics, &'a mut Option>), + Fn(&'a mut FnSig, &'a mut Generics, &'a mut Option>), /// E.g., `|x, y| body`. Closure(&'a mut ClosureBinder, &'a mut P, &'a mut P), diff --git a/compiler/rustc_builtin_macros/src/cfg_eval.rs b/compiler/rustc_builtin_macros/src/cfg_eval.rs index b45f5e83220..b3d252e06a5 100644 --- a/compiler/rustc_builtin_macros/src/cfg_eval.rs +++ b/compiler/rustc_builtin_macros/src/cfg_eval.rs @@ -242,16 +242,16 @@ impl MutVisitor for CfgEval<'_> { fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { let item = configure!(self, item); - mut_visit::walk_flat_map_item(self, item, None) + mut_visit::walk_flat_map_item(self, item) } fn flat_map_assoc_item( &mut self, item: P, - ctxt: AssocCtxt, + _ctxt: AssocCtxt, ) -> SmallVec<[P; 1]> { let item = configure!(self, item); - mut_visit::walk_flat_map_item(self, item, Some(ctxt)) + mut_visit::walk_flat_map_item(self, item) } fn flat_map_foreign_item( @@ -259,7 +259,7 @@ impl MutVisitor for CfgEval<'_> { foreign_item: P, ) -> SmallVec<[P; 1]> { let foreign_item = configure!(self, foreign_item); - mut_visit::walk_flat_map_item(self, foreign_item, None) + mut_visit::walk_flat_map_item(self, foreign_item) } fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> { diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index f6b23c52b42..bbafb0ac299 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -144,7 +144,7 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> { item.kind { let prev_tests = mem::take(&mut self.tests); - walk_item_kind(&mut item.kind, item.ident, item.span, item.id, 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. @@ -192,7 +192,7 @@ struct EntryPointCleaner<'a> { impl<'a> MutVisitor for EntryPointCleaner<'a> { fn flat_map_item(&mut self, i: P) -> SmallVec<[P; 1]> { self.depth += 1; - let item = walk_flat_map_item(self, i, None).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 diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index b7c5a52eb4a..3c43d47292f 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1149,7 +1149,7 @@ impl InvocationCollectorNode for P { fragment.make_items() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_item(visitor, self, None) + walk_flat_map_item(visitor, self) } fn is_mac_call(&self) -> bool { matches!(self.kind, ItemKind::MacCall(..)) @@ -1293,7 +1293,7 @@ impl InvocationCollectorNode for AstNodeWrapper, TraitItemTag> fragment.make_trait_items() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_item(visitor, self.wrapped, Some(AssocCtxt::Trait)) + walk_flat_map_item(visitor, self.wrapped) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) @@ -1334,7 +1334,7 @@ impl InvocationCollectorNode for AstNodeWrapper, ImplItemTag> fragment.make_impl_items() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_item(visitor, self.wrapped, Some(AssocCtxt::Impl)) + walk_flat_map_item(visitor, self.wrapped) } fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) @@ -1372,7 +1372,7 @@ impl InvocationCollectorNode for P { fragment.make_foreign_items() } fn walk_flat_map(self, visitor: &mut V) -> Self::OutputTy { - walk_flat_map_item(visitor, self, None) + walk_flat_map_item(visitor, self) } fn is_mac_call(&self) -> bool { matches!(self.kind, ForeignItemKind::MacCall(..)) diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index dd19405d453..3fa909877cc 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -267,7 +267,7 @@ impl MutVisitor for PlaceholderExpander { fn flat_map_item(&mut self, item: P) -> SmallVec<[P; 1]> { match item.kind { ast::ItemKind::MacCall(_) => self.remove(item.id).make_items(), - _ => walk_flat_map_item(self, item, None), + _ => walk_flat_map_item(self, item), } } @@ -284,7 +284,7 @@ impl MutVisitor for PlaceholderExpander { AssocCtxt::Impl => it.make_impl_items(), } } - _ => walk_flat_map_item(self, item, Some(ctxt)), + _ => walk_flat_map_item(self, item), } } @@ -294,7 +294,7 @@ impl MutVisitor for PlaceholderExpander { ) -> SmallVec<[P; 1]> { match item.kind { ast::ForeignItemKind::MacCall(_) => self.remove(item.id).make_foreign_items(), - _ => walk_flat_map_item(self, item, None), + _ => walk_flat_map_item(self, item), } }