0
0
mirror of https://github.com/rust-lang/rust.git synced 2024-11-24 00:58:00 +01:00
This commit is contained in:
maxcabrajac 2024-11-17 20:11:49 -03:00
parent 5c2de73700
commit 1dc12367b9
6 changed files with 71 additions and 28 deletions

View File

@ -104,8 +104,16 @@ pub trait MutVisitor: Sized {
walk_use_tree(self, use_tree);
}
fn visit_foreign_item(&mut self, ni: &mut P<ForeignItem>) {
walk_item(self, ni);
}
fn flat_map_foreign_item(&mut self, ni: P<ForeignItem>) -> SmallVec<[P<ForeignItem>; 1]> {
walk_flat_map_item(self, ni)
walk_flat_map_foreign_item(self, ni)
}
fn visit_item(&mut self, i: &mut P<Item>) {
walk_item(self, i);
}
fn flat_map_item(&mut self, i: P<Item>) -> SmallVec<[P<Item>; 1]> {
@ -124,6 +132,10 @@ pub trait MutVisitor: Sized {
walk_flat_map_field_def(self, fd)
}
fn visit_assoc_item(&mut self, i: &mut P<AssocItem>, ctxt: AssocCtxt) {
walk_assoc_item(self, i, ctxt)
}
fn flat_map_assoc_item(
&mut self,
i: P<AssocItem>,
@ -1383,18 +1395,19 @@ pub fn walk_crate<T: MutVisitor>(vis: &mut T, krate: &mut Crate) {
vis.visit_span(inject_use_span);
}
pub fn walk_flat_map_item<K: WalkItemKind<Ctxt = ()>>(
visitor: &mut impl MutVisitor,
item: P<Item<K>>,
) -> SmallVec<[P<Item<K>>; 1]> {
walk_flat_map_assoc_item(visitor, item, ())
pub fn walk_item(visitor: &mut impl MutVisitor, item: &mut P<Item<impl WalkItemKind<Ctxt = ()>>>) {
walk_item_ctxt(visitor, item, ())
}
pub fn walk_flat_map_assoc_item<K: WalkItemKind>(
pub fn walk_assoc_item(visitor: &mut impl MutVisitor, item: &mut P<AssocItem>, ctxt: AssocCtxt) {
walk_item_ctxt(visitor, item, ctxt)
}
fn walk_item_ctxt<K: WalkItemKind>(
visitor: &mut impl MutVisitor,
mut item: P<Item<K>>,
item: &mut P<Item<K>>,
ctxt: K::Ctxt,
) -> SmallVec<[P<Item<K>>; 1]> {
) {
let Item { ident, attrs, id, kind, vis, span, tokens } = item.deref_mut();
visitor.visit_id(id);
visit_attrs(visitor, attrs);
@ -1403,6 +1416,27 @@ pub fn walk_flat_map_assoc_item<K: WalkItemKind>(
kind.walk(*span, *id, ident, vis, ctxt, visitor);
visit_lazy_tts(visitor, tokens);
visitor.visit_span(span);
}
pub fn walk_flat_map_item(vis: &mut impl MutVisitor, mut item: P<Item>) -> SmallVec<[P<Item>; 1]> {
vis.visit_item(&mut item);
smallvec![item]
}
pub fn walk_flat_map_foreign_item(
vis: &mut impl MutVisitor,
mut item: P<ForeignItem>,
) -> SmallVec<[P<ForeignItem>; 1]> {
vis.visit_foreign_item(&mut item);
smallvec![item]
}
pub fn walk_flat_map_assoc_item(
vis: &mut impl MutVisitor,
mut item: P<AssocItem>,
ctxt: AssocCtxt,
) -> SmallVec<[P<AssocItem>; 1]> {
vis.visit_assoc_item(&mut item, ctxt);
smallvec![item]
}

View File

@ -457,13 +457,6 @@ impl WalkItemKind for ItemKind {
}
}
pub fn walk_item<'a, V: Visitor<'a>>(
visitor: &mut V,
item: &'a Item<impl WalkItemKind<Ctxt = ()>>,
) -> V::Result {
walk_assoc_item(visitor, item, ())
}
pub fn walk_enum_def<'a, V: Visitor<'a>>(
visitor: &mut V,
EnumDef { variants }: &'a EnumDef,
@ -925,7 +918,22 @@ impl WalkItemKind for AssocItemKind {
}
}
pub fn walk_assoc_item<'a, V: Visitor<'a>, K: WalkItemKind>(
pub fn walk_item<'a, V: Visitor<'a>>(
visitor: &mut V,
item: &'a Item<impl WalkItemKind<Ctxt = ()>>,
) -> V::Result {
walk_item_ctxt(visitor, item, ())
}
pub fn walk_assoc_item<'a, V: Visitor<'a>>(
visitor: &mut V,
item: &'a AssocItem,
ctxt: AssocCtxt,
) -> V::Result {
walk_item_ctxt(visitor, item, ctxt)
}
fn walk_item_ctxt<'a, V: Visitor<'a>, K: WalkItemKind>(
visitor: &mut V,
item: &'a Item<K>,
ctxt: K::Ctxt,

View File

@ -215,7 +215,7 @@ impl MutVisitor for CfgEval<'_> {
foreign_item: P<ast::ForeignItem>,
) -> SmallVec<[P<ast::ForeignItem>; 1]> {
let foreign_item = configure!(self, foreign_item);
mut_visit::walk_flat_map_item(self, foreign_item)
mut_visit::walk_flat_map_foreign_item(self, foreign_item)
}
fn flat_map_arm(&mut self, arm: ast::Arm) -> SmallVec<[ast::Arm; 1]> {

View File

@ -1382,7 +1382,7 @@ impl InvocationCollectorNode for P<ast::ForeignItem> {
fragment.make_foreign_items()
}
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
walk_flat_map_item(visitor, self)
walk_flat_map_foreign_item(visitor, self)
}
fn is_mac_call(&self) -> bool {
matches!(self.kind, ForeignItemKind::MacCall(..))

View File

@ -296,7 +296,7 @@ impl MutVisitor for PlaceholderExpander {
) -> SmallVec<[P<ast::ForeignItem>; 1]> {
match item.kind {
ast::ForeignItemKind::MacCall(_) => self.remove(item.id).make_foreign_items(),
_ => walk_flat_map_item(self, item),
_ => walk_flat_map_foreign_item(self, item),
}
}

View File

@ -230,15 +230,16 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
}
fn visit_assoc_item(&mut self, item: &'a ast::AssocItem, ctxt: ast_visit::AssocCtxt) {
self.with_lint_attrs(item.id, &item.attrs, |cx| match ctxt {
ast_visit::AssocCtxt::Trait => {
lint_callback!(cx, check_trait_item, item);
ast_visit::walk_assoc_item(cx, item, ctxt);
}
ast_visit::AssocCtxt::Impl => {
lint_callback!(cx, check_impl_item, item);
ast_visit::walk_assoc_item(cx, item, ctxt);
self.with_lint_attrs(item.id, &item.attrs, |cx| {
match ctxt {
ast_visit::AssocCtxt::Trait => {
lint_callback!(cx, check_trait_item, item);
}
ast_visit::AssocCtxt::Impl => {
lint_callback!(cx, check_impl_item, item);
}
}
ast_visit::walk_assoc_item(cx, item, ctxt);
});
}