Add WalkItemKind::Ctxt so AssocCtxt is not sent to non-Assoc ItemKinds
This commit is contained in:
parent
1236656319
commit
6180173612
7 changed files with 35 additions and 27 deletions
|
@ -37,13 +37,14 @@ impl<A: Array> ExpectOne<A> for SmallVec<A> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait WalkItemKind {
|
pub trait WalkItemKind {
|
||||||
|
type Ctxt;
|
||||||
fn walk(
|
fn walk(
|
||||||
&mut self,
|
&mut self,
|
||||||
span: Span,
|
span: Span,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
ident: &mut Ident,
|
ident: &mut Ident,
|
||||||
visibility: &mut Visibility,
|
visibility: &mut Visibility,
|
||||||
ctxt: AssocCtxt,
|
ctxt: Self::Ctxt,
|
||||||
visitor: &mut impl MutVisitor,
|
visitor: &mut impl MutVisitor,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1088,26 +1089,27 @@ pub fn walk_block<T: MutVisitor>(vis: &mut T, block: &mut P<Block>) {
|
||||||
vis.visit_span(span);
|
vis.visit_span(span);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_item_kind(
|
pub fn walk_item_kind<K: WalkItemKind>(
|
||||||
kind: &mut impl WalkItemKind,
|
kind: &mut K,
|
||||||
span: Span,
|
span: Span,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
ident: &mut Ident,
|
ident: &mut Ident,
|
||||||
visibility: &mut Visibility,
|
visibility: &mut Visibility,
|
||||||
ctxt: AssocCtxt,
|
ctxt: K::Ctxt,
|
||||||
vis: &mut impl MutVisitor,
|
vis: &mut impl MutVisitor,
|
||||||
) {
|
) {
|
||||||
kind.walk(span, id, ident, visibility, ctxt, vis)
|
kind.walk(span, id, ident, visibility, ctxt, vis)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WalkItemKind for ItemKind {
|
impl WalkItemKind for ItemKind {
|
||||||
|
type Ctxt = ();
|
||||||
fn walk(
|
fn walk(
|
||||||
&mut self,
|
&mut self,
|
||||||
span: Span,
|
span: Span,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
ident: &mut Ident,
|
ident: &mut Ident,
|
||||||
visibility: &mut Visibility,
|
visibility: &mut Visibility,
|
||||||
_ctxt: AssocCtxt,
|
_ctxt: Self::Ctxt,
|
||||||
vis: &mut impl MutVisitor,
|
vis: &mut impl MutVisitor,
|
||||||
) {
|
) {
|
||||||
match self {
|
match self {
|
||||||
|
@ -1225,13 +1227,14 @@ impl WalkItemKind for ItemKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WalkItemKind for AssocItemKind {
|
impl WalkItemKind for AssocItemKind {
|
||||||
|
type Ctxt = AssocCtxt;
|
||||||
fn walk(
|
fn walk(
|
||||||
&mut self,
|
&mut self,
|
||||||
span: Span,
|
span: Span,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
ident: &mut Ident,
|
ident: &mut Ident,
|
||||||
visibility: &mut Visibility,
|
visibility: &mut Visibility,
|
||||||
ctxt: AssocCtxt,
|
ctxt: Self::Ctxt,
|
||||||
visitor: &mut impl MutVisitor,
|
visitor: &mut impl MutVisitor,
|
||||||
) {
|
) {
|
||||||
match self {
|
match self {
|
||||||
|
@ -1324,17 +1327,17 @@ pub fn walk_crate<T: MutVisitor>(vis: &mut T, krate: &mut Crate) {
|
||||||
vis.visit_span(inject_use_span);
|
vis.visit_span(inject_use_span);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_flat_map_item<K: WalkItemKind>(
|
pub fn walk_flat_map_item<K: WalkItemKind<Ctxt = ()>>(
|
||||||
visitor: &mut impl MutVisitor,
|
visitor: &mut impl MutVisitor,
|
||||||
item: P<Item<K>>,
|
item: P<Item<K>>,
|
||||||
) -> SmallVec<[P<Item<K>>; 1]> {
|
) -> SmallVec<[P<Item<K>>; 1]> {
|
||||||
walk_flat_map_assoc_item(visitor, item, AssocCtxt::Trait /* ignored */)
|
walk_flat_map_assoc_item(visitor, item, ())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_flat_map_assoc_item<K: WalkItemKind>(
|
pub fn walk_flat_map_assoc_item<K: WalkItemKind>(
|
||||||
visitor: &mut impl MutVisitor,
|
visitor: &mut impl MutVisitor,
|
||||||
mut item: P<Item<K>>,
|
mut item: P<Item<K>>,
|
||||||
ctxt: AssocCtxt,
|
ctxt: K::Ctxt,
|
||||||
) -> SmallVec<[P<Item<K>>; 1]> {
|
) -> SmallVec<[P<Item<K>>; 1]> {
|
||||||
let Item { ident, attrs, id, kind, vis, span, tokens } = item.deref_mut();
|
let Item { ident, attrs, id, kind, vis, span, tokens } = item.deref_mut();
|
||||||
visitor.visit_id(id);
|
visitor.visit_id(id);
|
||||||
|
@ -1348,13 +1351,14 @@ pub fn walk_flat_map_assoc_item<K: WalkItemKind>(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WalkItemKind for ForeignItemKind {
|
impl WalkItemKind for ForeignItemKind {
|
||||||
|
type Ctxt = ();
|
||||||
fn walk(
|
fn walk(
|
||||||
&mut self,
|
&mut self,
|
||||||
span: Span,
|
span: Span,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
ident: &mut Ident,
|
ident: &mut Ident,
|
||||||
visibility: &mut Visibility,
|
visibility: &mut Visibility,
|
||||||
_ctxt: AssocCtxt,
|
_ctxt: Self::Ctxt,
|
||||||
visitor: &mut impl MutVisitor,
|
visitor: &mut impl MutVisitor,
|
||||||
) {
|
) {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
@ -113,10 +113,11 @@ pub enum LifetimeCtxt {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait WalkItemKind: Sized {
|
pub trait WalkItemKind: Sized {
|
||||||
|
type Ctxt;
|
||||||
fn walk<'a, V: Visitor<'a>>(
|
fn walk<'a, V: Visitor<'a>>(
|
||||||
&'a self,
|
&'a self,
|
||||||
item: &'a Item<Self>,
|
item: &'a Item<Self>,
|
||||||
ctxt: AssocCtxt,
|
ctxt: Self::Ctxt,
|
||||||
visitor: &mut V,
|
visitor: &mut V,
|
||||||
) -> V::Result;
|
) -> V::Result;
|
||||||
}
|
}
|
||||||
|
@ -337,10 +338,11 @@ pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitR
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WalkItemKind for ItemKind {
|
impl WalkItemKind for ItemKind {
|
||||||
|
type Ctxt = ();
|
||||||
fn walk<'a, V: Visitor<'a>>(
|
fn walk<'a, V: Visitor<'a>>(
|
||||||
&'a self,
|
&'a self,
|
||||||
item: &'a Item<Self>,
|
item: &'a Item<Self>,
|
||||||
_ctxt: AssocCtxt,
|
_ctxt: Self::Ctxt,
|
||||||
visitor: &mut V,
|
visitor: &mut V,
|
||||||
) -> V::Result {
|
) -> V::Result {
|
||||||
let Item { id, span, vis, ident, .. } = item;
|
let Item { id, span, vis, ident, .. } = item;
|
||||||
|
@ -449,9 +451,9 @@ impl WalkItemKind for ItemKind {
|
||||||
|
|
||||||
pub fn walk_item<'a, V: Visitor<'a>>(
|
pub fn walk_item<'a, V: Visitor<'a>>(
|
||||||
visitor: &mut V,
|
visitor: &mut V,
|
||||||
item: &'a Item<impl WalkItemKind>,
|
item: &'a Item<impl WalkItemKind<Ctxt = ()>>,
|
||||||
) -> V::Result {
|
) -> V::Result {
|
||||||
walk_assoc_item(visitor, item, AssocCtxt::Trait /*ignored*/)
|
walk_assoc_item(visitor, item, ())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_enum_def<'a, V: Visitor<'a>>(
|
pub fn walk_enum_def<'a, V: Visitor<'a>>(
|
||||||
|
@ -681,10 +683,11 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) -> V::Res
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WalkItemKind for ForeignItemKind {
|
impl WalkItemKind for ForeignItemKind {
|
||||||
|
type Ctxt = ();
|
||||||
fn walk<'a, V: Visitor<'a>>(
|
fn walk<'a, V: Visitor<'a>>(
|
||||||
&'a self,
|
&'a self,
|
||||||
item: &'a Item<Self>,
|
item: &'a Item<Self>,
|
||||||
_ctxt: AssocCtxt,
|
_ctxt: Self::Ctxt,
|
||||||
visitor: &mut V,
|
visitor: &mut V,
|
||||||
) -> V::Result {
|
) -> V::Result {
|
||||||
let Item { id, span, ident, vis, .. } = item;
|
let Item { id, span, ident, vis, .. } = item;
|
||||||
|
@ -844,10 +847,11 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WalkItemKind for AssocItemKind {
|
impl WalkItemKind for AssocItemKind {
|
||||||
|
type Ctxt = AssocCtxt;
|
||||||
fn walk<'a, V: Visitor<'a>>(
|
fn walk<'a, V: Visitor<'a>>(
|
||||||
&'a self,
|
&'a self,
|
||||||
item: &'a Item<Self>,
|
item: &'a Item<Self>,
|
||||||
ctxt: AssocCtxt,
|
ctxt: Self::Ctxt,
|
||||||
visitor: &mut V,
|
visitor: &mut V,
|
||||||
) -> V::Result {
|
) -> V::Result {
|
||||||
let Item { id, span, ident, vis, .. } = item;
|
let Item { id, span, ident, vis, .. } = item;
|
||||||
|
@ -906,10 +910,10 @@ impl WalkItemKind for AssocItemKind {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_assoc_item<'a, V: Visitor<'a>>(
|
pub fn walk_assoc_item<'a, V: Visitor<'a>, K: WalkItemKind>(
|
||||||
visitor: &mut V,
|
visitor: &mut V,
|
||||||
item: &'a Item<impl WalkItemKind>,
|
item: &'a Item<K>,
|
||||||
ctxt: AssocCtxt,
|
ctxt: K::Ctxt,
|
||||||
) -> V::Result {
|
) -> V::Result {
|
||||||
let Item { id: _, span: _, ident, vis, attrs, kind, tokens: _ } = item;
|
let Item { id: _, span: _, ident, vis, attrs, kind, tokens: _ } = item;
|
||||||
walk_list!(visitor, visit_attribute, attrs);
|
walk_list!(visitor, visit_attribute, attrs);
|
||||||
|
|
|
@ -247,10 +247,10 @@ impl MutVisitor for CfgEval<'_> {
|
||||||
fn flat_map_assoc_item(
|
fn flat_map_assoc_item(
|
||||||
&mut self,
|
&mut self,
|
||||||
item: P<ast::AssocItem>,
|
item: P<ast::AssocItem>,
|
||||||
_ctxt: AssocCtxt,
|
ctxt: AssocCtxt,
|
||||||
) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
||||||
let item = configure!(self, item);
|
let item = configure!(self, item);
|
||||||
mut_visit::walk_flat_map_item(self, item)
|
mut_visit::walk_flat_map_assoc_item(self, item, ctxt)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flat_map_foreign_item(
|
fn flat_map_foreign_item(
|
||||||
|
|
|
@ -6,7 +6,7 @@ use rustc_ast as ast;
|
||||||
use rustc_ast::entry::EntryPointType;
|
use rustc_ast::entry::EntryPointType;
|
||||||
use rustc_ast::mut_visit::*;
|
use rustc_ast::mut_visit::*;
|
||||||
use rustc_ast::ptr::P;
|
use rustc_ast::ptr::P;
|
||||||
use rustc_ast::visit::{AssocCtxt, Visitor, walk_item};
|
use rustc_ast::visit::{Visitor, walk_item};
|
||||||
use rustc_ast::{ModKind, attr};
|
use rustc_ast::{ModKind, attr};
|
||||||
use rustc_errors::DiagCtxtHandle;
|
use rustc_errors::DiagCtxtHandle;
|
||||||
use rustc_expand::base::{ExtCtxt, ResolverExpand};
|
use rustc_expand::base::{ExtCtxt, ResolverExpand};
|
||||||
|
@ -150,7 +150,7 @@ impl<'a> MutVisitor for TestHarnessGenerator<'a> {
|
||||||
item.id,
|
item.id,
|
||||||
&mut item.ident,
|
&mut item.ident,
|
||||||
&mut item.vis,
|
&mut item.vis,
|
||||||
AssocCtxt::Trait, /* ignored */
|
(),
|
||||||
self,
|
self,
|
||||||
);
|
);
|
||||||
self.add_test_cases(item.id, span, prev_tests);
|
self.add_test_cases(item.id, span, prev_tests);
|
||||||
|
|
|
@ -1303,7 +1303,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag>
|
||||||
fragment.make_trait_items()
|
fragment.make_trait_items()
|
||||||
}
|
}
|
||||||
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||||
walk_flat_map_item(visitor, self.wrapped)
|
walk_flat_map_assoc_item(visitor, self.wrapped, AssocCtxt::Trait)
|
||||||
}
|
}
|
||||||
fn is_mac_call(&self) -> bool {
|
fn is_mac_call(&self) -> bool {
|
||||||
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
|
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
|
||||||
|
@ -1344,7 +1344,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag>
|
||||||
fragment.make_impl_items()
|
fragment.make_impl_items()
|
||||||
}
|
}
|
||||||
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
fn walk_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
|
||||||
walk_flat_map_item(visitor, self.wrapped)
|
walk_flat_map_assoc_item(visitor, self.wrapped, AssocCtxt::Impl)
|
||||||
}
|
}
|
||||||
fn is_mac_call(&self) -> bool {
|
fn is_mac_call(&self) -> bool {
|
||||||
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
|
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
|
||||||
|
|
|
@ -286,7 +286,7 @@ impl MutVisitor for PlaceholderExpander {
|
||||||
AssocCtxt::Impl => it.make_impl_items(),
|
AssocCtxt::Impl => it.make_impl_items(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => walk_flat_map_item(self, item),
|
_ => walk_flat_map_assoc_item(self, item, ctxt),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1324,7 +1324,7 @@ impl<'a, 'ra, 'tcx> Visitor<'a> for BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
|
||||||
// This way they can use `macro_rules` defined later.
|
// This way they can use `macro_rules` defined later.
|
||||||
self.visit_vis(&item.vis);
|
self.visit_vis(&item.vis);
|
||||||
self.visit_ident(&item.ident);
|
self.visit_ident(&item.ident);
|
||||||
item.kind.walk(item, AssocCtxt::Trait, self);
|
item.kind.walk(item, (), self);
|
||||||
visit::walk_list!(self, visit_attribute, &item.attrs);
|
visit::walk_list!(self, visit_attribute, &item.attrs);
|
||||||
}
|
}
|
||||||
_ => visit::walk_item(self, item),
|
_ => visit::walk_item(self, item),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue