Merge impl and trait item mut visitor methods to mirror immut visitor
This commit is contained in:
parent
aee3dc4c6c
commit
5241d8bb19
@ -11,6 +11,7 @@
|
|||||||
use crate::ptr::P;
|
use crate::ptr::P;
|
||||||
use crate::token::{self, Token};
|
use crate::token::{self, Token};
|
||||||
use crate::tokenstream::*;
|
use crate::tokenstream::*;
|
||||||
|
use crate::visit::AssocCtxt;
|
||||||
|
|
||||||
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
|
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
|
||||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||||
@ -109,11 +110,11 @@ fn visit_fn_header(&mut self, header: &mut FnHeader) {
|
|||||||
noop_flat_map_field_def(fd, self)
|
noop_flat_map_field_def(fd, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flat_map_trait_item(&mut self, i: P<AssocItem>) -> SmallVec<[P<AssocItem>; 1]> {
|
fn flat_map_assoc_item(
|
||||||
noop_flat_map_item(i, self)
|
&mut self,
|
||||||
}
|
i: P<AssocItem>,
|
||||||
|
_ctxt: AssocCtxt,
|
||||||
fn flat_map_impl_item(&mut self, i: P<AssocItem>) -> SmallVec<[P<AssocItem>; 1]> {
|
) -> SmallVec<[P<AssocItem>; 1]> {
|
||||||
noop_flat_map_item(i, self)
|
noop_flat_map_item(i, self)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1127,13 +1128,13 @@ fn noop_visit(&mut self, vis: &mut impl MutVisitor) {
|
|||||||
visit_polarity(polarity, vis);
|
visit_polarity(polarity, vis);
|
||||||
visit_opt(of_trait, |trait_ref| vis.visit_trait_ref(trait_ref));
|
visit_opt(of_trait, |trait_ref| vis.visit_trait_ref(trait_ref));
|
||||||
vis.visit_ty(self_ty);
|
vis.visit_ty(self_ty);
|
||||||
items.flat_map_in_place(|item| vis.flat_map_impl_item(item));
|
items.flat_map_in_place(|item| vis.flat_map_assoc_item(item, AssocCtxt::Impl));
|
||||||
}
|
}
|
||||||
ItemKind::Trait(box Trait { safety, is_auto: _, generics, bounds, items }) => {
|
ItemKind::Trait(box Trait { safety, is_auto: _, generics, bounds, items }) => {
|
||||||
visit_safety(safety, vis);
|
visit_safety(safety, vis);
|
||||||
vis.visit_generics(generics);
|
vis.visit_generics(generics);
|
||||||
visit_bounds(bounds, vis);
|
visit_bounds(bounds, vis);
|
||||||
items.flat_map_in_place(|item| vis.flat_map_trait_item(item));
|
items.flat_map_in_place(|item| vis.flat_map_assoc_item(item, AssocCtxt::Trait));
|
||||||
}
|
}
|
||||||
ItemKind::TraitAlias(generics, bounds) => {
|
ItemKind::TraitAlias(generics, bounds) => {
|
||||||
vis.visit_generics(generics);
|
vis.visit_generics(generics);
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
use rustc_ast::mut_visit::MutVisitor;
|
use rustc_ast::mut_visit::MutVisitor;
|
||||||
use rustc_ast::ptr::P;
|
use rustc_ast::ptr::P;
|
||||||
use rustc_ast::visit::Visitor;
|
use rustc_ast::visit::{AssocCtxt, Visitor};
|
||||||
use rustc_ast::NodeId;
|
use rustc_ast::NodeId;
|
||||||
use rustc_ast::{mut_visit, visit};
|
use rustc_ast::{mut_visit, visit};
|
||||||
use rustc_ast::{Attribute, HasAttrs, HasTokens};
|
use rustc_ast::{Attribute, HasAttrs, HasTokens};
|
||||||
@ -53,11 +53,8 @@ fn flat_map_annotatable(
|
|||||||
) -> Option<Annotatable> {
|
) -> Option<Annotatable> {
|
||||||
match annotatable {
|
match annotatable {
|
||||||
Annotatable::Item(item) => vis.flat_map_item(item).pop().map(Annotatable::Item),
|
Annotatable::Item(item) => vis.flat_map_item(item).pop().map(Annotatable::Item),
|
||||||
Annotatable::TraitItem(item) => {
|
Annotatable::AssocItem(item, ctxt) => {
|
||||||
vis.flat_map_trait_item(item).pop().map(Annotatable::TraitItem)
|
Some(Annotatable::AssocItem(vis.flat_map_assoc_item(item, ctxt).pop()?, ctxt))
|
||||||
}
|
|
||||||
Annotatable::ImplItem(item) => {
|
|
||||||
vis.flat_map_impl_item(item).pop().map(Annotatable::ImplItem)
|
|
||||||
}
|
}
|
||||||
Annotatable::ForeignItem(item) => {
|
Annotatable::ForeignItem(item) => {
|
||||||
vis.flat_map_foreign_item(item).pop().map(Annotatable::ForeignItem)
|
vis.flat_map_foreign_item(item).pop().map(Annotatable::ForeignItem)
|
||||||
@ -106,8 +103,7 @@ fn visit_attribute(&mut self, attr: &'ast Attribute) -> ControlFlow<()> {
|
|||||||
|
|
||||||
let res = match annotatable {
|
let res = match annotatable {
|
||||||
Annotatable::Item(item) => CfgFinder.visit_item(item),
|
Annotatable::Item(item) => CfgFinder.visit_item(item),
|
||||||
Annotatable::TraitItem(item) => CfgFinder.visit_assoc_item(item, visit::AssocCtxt::Trait),
|
Annotatable::AssocItem(item, ctxt) => CfgFinder.visit_assoc_item(item, *ctxt),
|
||||||
Annotatable::ImplItem(item) => CfgFinder.visit_assoc_item(item, visit::AssocCtxt::Impl),
|
|
||||||
Annotatable::ForeignItem(item) => CfgFinder.visit_foreign_item(item),
|
Annotatable::ForeignItem(item) => CfgFinder.visit_foreign_item(item),
|
||||||
Annotatable::Stmt(stmt) => CfgFinder.visit_stmt(stmt),
|
Annotatable::Stmt(stmt) => CfgFinder.visit_stmt(stmt),
|
||||||
Annotatable::Expr(expr) => CfgFinder.visit_expr(expr),
|
Annotatable::Expr(expr) => CfgFinder.visit_expr(expr),
|
||||||
@ -150,14 +146,16 @@ fn configure_annotatable(&mut self, mut annotatable: Annotatable) -> Option<Anno
|
|||||||
Annotatable::Item(_) => {
|
Annotatable::Item(_) => {
|
||||||
|parser| Ok(Annotatable::Item(parser.parse_item(ForceCollect::Yes)?.unwrap()))
|
|parser| Ok(Annotatable::Item(parser.parse_item(ForceCollect::Yes)?.unwrap()))
|
||||||
}
|
}
|
||||||
Annotatable::TraitItem(_) => |parser| {
|
Annotatable::AssocItem(_, AssocCtxt::Trait) => |parser| {
|
||||||
Ok(Annotatable::TraitItem(
|
Ok(Annotatable::AssocItem(
|
||||||
parser.parse_trait_item(ForceCollect::Yes)?.unwrap().unwrap(),
|
parser.parse_trait_item(ForceCollect::Yes)?.unwrap().unwrap(),
|
||||||
|
AssocCtxt::Trait,
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
Annotatable::ImplItem(_) => |parser| {
|
Annotatable::AssocItem(_, AssocCtxt::Impl) => |parser| {
|
||||||
Ok(Annotatable::ImplItem(
|
Ok(Annotatable::AssocItem(
|
||||||
parser.parse_impl_item(ForceCollect::Yes)?.unwrap().unwrap(),
|
parser.parse_impl_item(ForceCollect::Yes)?.unwrap().unwrap(),
|
||||||
|
AssocCtxt::Impl,
|
||||||
))
|
))
|
||||||
},
|
},
|
||||||
Annotatable::ForeignItem(_) => |parser| {
|
Annotatable::ForeignItem(_) => |parser| {
|
||||||
@ -244,11 +242,11 @@ fn flat_map_generic_param(
|
|||||||
mut_visit::noop_flat_map_item(configure!(self, item), self)
|
mut_visit::noop_flat_map_item(configure!(self, item), self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flat_map_impl_item(&mut self, item: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
fn flat_map_assoc_item(
|
||||||
mut_visit::noop_flat_map_item(configure!(self, item), self)
|
&mut self,
|
||||||
}
|
item: P<ast::AssocItem>,
|
||||||
|
_ctxt: AssocCtxt,
|
||||||
fn flat_map_trait_item(&mut self, item: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
||||||
mut_visit::noop_flat_map_item(configure!(self, item), self)
|
mut_visit::noop_flat_map_item(configure!(self, item), self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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) {
|
pub(crate) fn warn_on_duplicate_attribute(ecx: &ExtCtxt<'_>, item: &Annotatable, name: Symbol) {
|
||||||
let attrs: Option<&[Attribute]> = match item {
|
let attrs: Option<&[Attribute]> = match item {
|
||||||
Annotatable::Item(item) => Some(&item.attrs),
|
Annotatable::Item(item) => Some(&item.attrs),
|
||||||
Annotatable::TraitItem(item) => Some(&item.attrs),
|
Annotatable::AssocItem(item, _) => Some(&item.attrs),
|
||||||
Annotatable::ImplItem(item) => Some(&item.attrs),
|
|
||||||
Annotatable::ForeignItem(item) => Some(&item.attrs),
|
Annotatable::ForeignItem(item) => Some(&item.attrs),
|
||||||
Annotatable::Expr(expr) => Some(&expr.attrs),
|
Annotatable::Expr(expr) => Some(&expr.attrs),
|
||||||
Annotatable::Arm(arm) => Some(&arm.attrs),
|
Annotatable::Arm(arm) => Some(&arm.attrs),
|
||||||
|
@ -37,8 +37,7 @@
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum Annotatable {
|
pub enum Annotatable {
|
||||||
Item(P<ast::Item>),
|
Item(P<ast::Item>),
|
||||||
TraitItem(P<ast::AssocItem>),
|
AssocItem(P<ast::AssocItem>, AssocCtxt),
|
||||||
ImplItem(P<ast::AssocItem>),
|
|
||||||
ForeignItem(P<ast::ForeignItem>),
|
ForeignItem(P<ast::ForeignItem>),
|
||||||
Stmt(P<ast::Stmt>),
|
Stmt(P<ast::Stmt>),
|
||||||
Expr(P<ast::Expr>),
|
Expr(P<ast::Expr>),
|
||||||
@ -56,8 +55,7 @@ impl Annotatable {
|
|||||||
pub fn span(&self) -> Span {
|
pub fn span(&self) -> Span {
|
||||||
match self {
|
match self {
|
||||||
Annotatable::Item(item) => item.span,
|
Annotatable::Item(item) => item.span,
|
||||||
Annotatable::TraitItem(trait_item) => trait_item.span,
|
Annotatable::AssocItem(assoc_item, _) => assoc_item.span,
|
||||||
Annotatable::ImplItem(impl_item) => impl_item.span,
|
|
||||||
Annotatable::ForeignItem(foreign_item) => foreign_item.span,
|
Annotatable::ForeignItem(foreign_item) => foreign_item.span,
|
||||||
Annotatable::Stmt(stmt) => stmt.span,
|
Annotatable::Stmt(stmt) => stmt.span,
|
||||||
Annotatable::Expr(expr) => expr.span,
|
Annotatable::Expr(expr) => expr.span,
|
||||||
@ -75,8 +73,7 @@ pub fn span(&self) -> Span {
|
|||||||
pub fn visit_attrs(&mut self, f: impl FnOnce(&mut AttrVec)) {
|
pub fn visit_attrs(&mut self, f: impl FnOnce(&mut AttrVec)) {
|
||||||
match self {
|
match self {
|
||||||
Annotatable::Item(item) => item.visit_attrs(f),
|
Annotatable::Item(item) => item.visit_attrs(f),
|
||||||
Annotatable::TraitItem(trait_item) => trait_item.visit_attrs(f),
|
Annotatable::AssocItem(assoc_item, _) => assoc_item.visit_attrs(f),
|
||||||
Annotatable::ImplItem(impl_item) => impl_item.visit_attrs(f),
|
|
||||||
Annotatable::ForeignItem(foreign_item) => foreign_item.visit_attrs(f),
|
Annotatable::ForeignItem(foreign_item) => foreign_item.visit_attrs(f),
|
||||||
Annotatable::Stmt(stmt) => stmt.visit_attrs(f),
|
Annotatable::Stmt(stmt) => stmt.visit_attrs(f),
|
||||||
Annotatable::Expr(expr) => expr.visit_attrs(f),
|
Annotatable::Expr(expr) => expr.visit_attrs(f),
|
||||||
@ -94,8 +91,7 @@ pub fn visit_attrs(&mut self, f: impl FnOnce(&mut AttrVec)) {
|
|||||||
pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) -> V::Result {
|
pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) -> V::Result {
|
||||||
match self {
|
match self {
|
||||||
Annotatable::Item(item) => visitor.visit_item(item),
|
Annotatable::Item(item) => visitor.visit_item(item),
|
||||||
Annotatable::TraitItem(item) => visitor.visit_assoc_item(item, AssocCtxt::Trait),
|
Annotatable::AssocItem(item, ctxt) => visitor.visit_assoc_item(item, *ctxt),
|
||||||
Annotatable::ImplItem(item) => visitor.visit_assoc_item(item, AssocCtxt::Impl),
|
|
||||||
Annotatable::ForeignItem(foreign_item) => visitor.visit_foreign_item(foreign_item),
|
Annotatable::ForeignItem(foreign_item) => visitor.visit_foreign_item(foreign_item),
|
||||||
Annotatable::Stmt(stmt) => visitor.visit_stmt(stmt),
|
Annotatable::Stmt(stmt) => visitor.visit_stmt(stmt),
|
||||||
Annotatable::Expr(expr) => visitor.visit_expr(expr),
|
Annotatable::Expr(expr) => visitor.visit_expr(expr),
|
||||||
@ -113,9 +109,7 @@ pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) -> V::Result {
|
|||||||
pub fn to_tokens(&self) -> TokenStream {
|
pub fn to_tokens(&self) -> TokenStream {
|
||||||
match self {
|
match self {
|
||||||
Annotatable::Item(node) => TokenStream::from_ast(node),
|
Annotatable::Item(node) => TokenStream::from_ast(node),
|
||||||
Annotatable::TraitItem(node) | Annotatable::ImplItem(node) => {
|
Annotatable::AssocItem(node, _) => TokenStream::from_ast(node),
|
||||||
TokenStream::from_ast(node)
|
|
||||||
}
|
|
||||||
Annotatable::ForeignItem(node) => TokenStream::from_ast(node),
|
Annotatable::ForeignItem(node) => TokenStream::from_ast(node),
|
||||||
Annotatable::Stmt(node) => {
|
Annotatable::Stmt(node) => {
|
||||||
assert!(!matches!(node.kind, ast::StmtKind::Empty));
|
assert!(!matches!(node.kind, ast::StmtKind::Empty));
|
||||||
@ -142,14 +136,14 @@ pub fn expect_item(self) -> P<ast::Item> {
|
|||||||
|
|
||||||
pub fn expect_trait_item(self) -> P<ast::AssocItem> {
|
pub fn expect_trait_item(self) -> P<ast::AssocItem> {
|
||||||
match self {
|
match self {
|
||||||
Annotatable::TraitItem(i) => i,
|
Annotatable::AssocItem(i, AssocCtxt::Trait) => i,
|
||||||
_ => panic!("expected Item"),
|
_ => panic!("expected Item"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn expect_impl_item(self) -> P<ast::AssocItem> {
|
pub fn expect_impl_item(self) -> P<ast::AssocItem> {
|
||||||
match self {
|
match self {
|
||||||
Annotatable::ImplItem(i) => i,
|
Annotatable::AssocItem(i, AssocCtxt::Impl) => i,
|
||||||
_ => panic!("expected Item"),
|
_ => panic!("expected Item"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ pub(crate) fn mut_visit_with<F: MutVisitor>(&mut self, vis: &mut F) {
|
|||||||
AstFragment::MethodReceiverExpr(expr) => vis.visit_method_receiver_expr(expr),
|
AstFragment::MethodReceiverExpr(expr) => vis.visit_method_receiver_expr(expr),
|
||||||
$($(AstFragment::$Kind(ast) => vis.$mut_visit_ast(ast),)?)*
|
$($(AstFragment::$Kind(ast) => vis.$mut_visit_ast(ast),)?)*
|
||||||
$($(AstFragment::$Kind(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 @@ impl<'a> MacResult for crate::mbe::macro_rules::ParserAnyMacro<'a> {
|
|||||||
}
|
}
|
||||||
TraitItems(SmallVec<[P<ast::AssocItem>; 1]>) {
|
TraitItems(SmallVec<[P<ast::AssocItem>; 1]>) {
|
||||||
"trait item";
|
"trait item";
|
||||||
many fn flat_map_trait_item;
|
many fn flat_map_assoc_item;
|
||||||
fn visit_assoc_item(AssocCtxt::Trait);
|
fn visit_assoc_item(AssocCtxt::Trait);
|
||||||
fn make_trait_items;
|
fn make_trait_items;
|
||||||
}
|
}
|
||||||
ImplItems(SmallVec<[P<ast::AssocItem>; 1]>) {
|
ImplItems(SmallVec<[P<ast::AssocItem>; 1]>) {
|
||||||
"impl item";
|
"impl item";
|
||||||
many fn flat_map_impl_item;
|
many fn flat_map_assoc_item;
|
||||||
fn visit_assoc_item(AssocCtxt::Impl);
|
fn visit_assoc_item(AssocCtxt::Impl);
|
||||||
fn make_impl_items;
|
fn make_impl_items;
|
||||||
}
|
}
|
||||||
@ -833,7 +833,7 @@ fn expand_invoc(
|
|||||||
self.cx, deleg, &item, &suffixes, item.span, true,
|
self.cx, deleg, &item, &suffixes, item.span, true,
|
||||||
);
|
);
|
||||||
fragment_kind.expect_from_annotatables(
|
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 @@ fn expand_invoc(
|
|||||||
fn gate_proc_macro_attr_item(&self, span: Span, item: &Annotatable) {
|
fn gate_proc_macro_attr_item(&self, span: Span, item: &Annotatable) {
|
||||||
let kind = match item {
|
let kind = match item {
|
||||||
Annotatable::Item(_)
|
Annotatable::Item(_)
|
||||||
| Annotatable::TraitItem(_)
|
| Annotatable::AssocItem(..)
|
||||||
| Annotatable::ImplItem(_)
|
|
||||||
| Annotatable::ForeignItem(_)
|
| Annotatable::ForeignItem(_)
|
||||||
| Annotatable::Crate(..) => return,
|
| Annotatable::Crate(..) => return,
|
||||||
Annotatable::Stmt(stmt) => {
|
Annotatable::Stmt(stmt) => {
|
||||||
@ -1288,7 +1287,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag>
|
|||||||
type ItemKind = AssocItemKind;
|
type ItemKind = AssocItemKind;
|
||||||
const KIND: AstFragmentKind = AstFragmentKind::TraitItems;
|
const KIND: AstFragmentKind = AstFragmentKind::TraitItems;
|
||||||
fn to_annotatable(self) -> Annotatable {
|
fn to_annotatable(self) -> Annotatable {
|
||||||
Annotatable::TraitItem(self.wrapped)
|
Annotatable::AssocItem(self.wrapped, AssocCtxt::Trait)
|
||||||
}
|
}
|
||||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||||
fragment.make_trait_items()
|
fragment.make_trait_items()
|
||||||
@ -1329,7 +1328,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag>
|
|||||||
type ItemKind = AssocItemKind;
|
type ItemKind = AssocItemKind;
|
||||||
const KIND: AstFragmentKind = AstFragmentKind::ImplItems;
|
const KIND: AstFragmentKind = AstFragmentKind::ImplItems;
|
||||||
fn to_annotatable(self) -> Annotatable {
|
fn to_annotatable(self) -> Annotatable {
|
||||||
Annotatable::ImplItem(self.wrapped)
|
Annotatable::AssocItem(self.wrapped, AssocCtxt::Impl)
|
||||||
}
|
}
|
||||||
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
|
||||||
fragment.make_impl_items()
|
fragment.make_impl_items()
|
||||||
@ -1993,9 +1992,9 @@ fn flat_map_node<Node: InvocationCollectorNode<OutputTy: Default>>(
|
|||||||
let traitless_qself =
|
let traitless_qself =
|
||||||
matches!(&deleg.qself, Some(qself) if qself.position == 0);
|
matches!(&deleg.qself, Some(qself) if qself.position == 0);
|
||||||
let item = match node.to_annotatable() {
|
let item = match node.to_annotatable() {
|
||||||
Annotatable::ImplItem(item) => item,
|
Annotatable::AssocItem(item, AssocCtxt::Impl) => item,
|
||||||
ann @ (Annotatable::Item(_)
|
ann @ (Annotatable::Item(_)
|
||||||
| Annotatable::TraitItem(_)
|
| Annotatable::AssocItem(..)
|
||||||
| Annotatable::Stmt(_)) => {
|
| Annotatable::Stmt(_)) => {
|
||||||
let span = ann.span();
|
let span = ann.span();
|
||||||
self.cx.dcx().emit_err(GlobDelegationOutsideImpls { span });
|
self.cx.dcx().emit_err(GlobDelegationOutsideImpls { span });
|
||||||
@ -2081,12 +2080,15 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
|
|||||||
self.flat_map_node(node)
|
self.flat_map_node(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flat_map_trait_item(&mut self, node: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
fn flat_map_assoc_item(
|
||||||
self.flat_map_node(AstNodeWrapper::new(node, TraitItemTag))
|
&mut self,
|
||||||
}
|
node: P<ast::AssocItem>,
|
||||||
|
ctxt: AssocCtxt,
|
||||||
fn flat_map_impl_item(&mut self, node: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
) -> SmallVec<[P<ast::AssocItem>; 1]> {
|
||||||
self.flat_map_node(AstNodeWrapper::new(node, ImplItemTag))
|
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(
|
fn flat_map_foreign_item(
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
use crate::expand::{AstFragment, AstFragmentKind};
|
use crate::expand::{AstFragment, AstFragmentKind};
|
||||||
use rustc_ast as ast;
|
|
||||||
use rustc_ast::mut_visit::*;
|
use rustc_ast::mut_visit::*;
|
||||||
use rustc_ast::ptr::P;
|
use rustc_ast::ptr::P;
|
||||||
use rustc_ast::token::Delimiter;
|
use rustc_ast::token::Delimiter;
|
||||||
|
use rustc_ast::{self as ast, visit::AssocCtxt};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_span::symbol::Ident;
|
use rustc_span::symbol::Ident;
|
||||||
use rustc_span::DUMMY_SP;
|
use rustc_span::DUMMY_SP;
|
||||||
@ -271,16 +271,19 @@ fn flat_map_generic_param(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
match item.kind {
|
||||||
ast::AssocItemKind::MacCall(_) => self.remove(item.id).make_trait_items(),
|
ast::AssocItemKind::MacCall(_) => {
|
||||||
_ => noop_flat_map_item(item, self),
|
let it = self.remove(item.id);
|
||||||
}
|
match ctxt {
|
||||||
}
|
AssocCtxt::Trait => it.make_trait_items(),
|
||||||
|
AssocCtxt::Impl => it.make_impl_items(),
|
||||||
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),
|
_ => noop_flat_map_item(item, self),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user