1
Fork 0

Remove ref patterns from rustc_ast

Also use if let chains in one case.
This commit is contained in:
Maybe Waffle 2022-11-16 19:26:38 +00:00
parent 736c675d2a
commit 417ed9fee2
6 changed files with 214 additions and 224 deletions

View file

@ -175,9 +175,9 @@ impl GenericArgs {
} }
pub fn span(&self) -> Span { pub fn span(&self) -> Span {
match *self { match self {
AngleBracketed(ref data) => data.span, AngleBracketed(data) => data.span,
Parenthesized(ref data) => data.span, Parenthesized(data) => data.span,
} }
} }
} }
@ -312,8 +312,8 @@ pub enum GenericBound {
impl GenericBound { impl GenericBound {
pub fn span(&self) -> Span { pub fn span(&self) -> Span {
match self { match self {
GenericBound::Trait(ref t, ..) => t.span, GenericBound::Trait(t, ..) => t.span,
GenericBound::Outlives(ref l) => l.ident.span, GenericBound::Outlives(l) => l.ident.span,
} }
} }
} }
@ -1115,23 +1115,23 @@ impl Expr {
/// If this is not the case, name resolution does not resolve `N` when using /// If this is not the case, name resolution does not resolve `N` when using
/// `min_const_generics` as more complex expressions are not supported. /// `min_const_generics` as more complex expressions are not supported.
pub fn is_potential_trivial_const_param(&self) -> bool { pub fn is_potential_trivial_const_param(&self) -> bool {
let this = if let ExprKind::Block(ref block, None) = self.kind { let this = if let ExprKind::Block(block, None) = &self.kind
if block.stmts.len() == 1 { && block.stmts.len() == 1
if let StmtKind::Expr(ref expr) = block.stmts[0].kind { expr } else { self } && let StmtKind::Expr(expr) = &block.stmts[0].kind
} else { {
self expr
}
} else { } else {
self self
}; };
if let ExprKind::Path(None, ref path) = this.kind { if let ExprKind::Path(None, path) = &this.kind
if path.segments.len() == 1 && path.segments[0].args.is_none() { && path.segments.len() == 1
return true; && path.segments[0].args.is_none()
} {
true
} else {
false
} }
false
} }
pub fn to_bound(&self) -> Option<GenericBound> { pub fn to_bound(&self) -> Option<GenericBound> {
@ -2393,9 +2393,9 @@ pub enum FnRetTy {
impl FnRetTy { impl FnRetTy {
pub fn span(&self) -> Span { pub fn span(&self) -> Span {
match *self { match self {
FnRetTy::Default(span) => span, &FnRetTy::Default(span) => span,
FnRetTy::Ty(ref ty) => ty.span, FnRetTy::Ty(ty) => ty.span,
} }
} }
} }
@ -2657,8 +2657,8 @@ pub enum VariantData {
impl VariantData { impl VariantData {
/// Return the fields of this variant. /// Return the fields of this variant.
pub fn fields(&self) -> &[FieldDef] { pub fn fields(&self) -> &[FieldDef] {
match *self { match self {
VariantData::Struct(ref fields, ..) | VariantData::Tuple(ref fields, _) => fields, VariantData::Struct(fields, ..) | VariantData::Tuple(fields, _) => fields,
_ => &[], _ => &[],
} }
} }

View file

@ -44,16 +44,16 @@ impl MarkedAttrs {
impl NestedMetaItem { impl NestedMetaItem {
/// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem`. /// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem`.
pub fn meta_item(&self) -> Option<&MetaItem> { pub fn meta_item(&self) -> Option<&MetaItem> {
match *self { match self {
NestedMetaItem::MetaItem(ref item) => Some(item), NestedMetaItem::MetaItem(item) => Some(item),
_ => None, _ => None,
} }
} }
/// Returns the `Lit` if `self` is a `NestedMetaItem::Literal`s. /// Returns the `Lit` if `self` is a `NestedMetaItem::Literal`s.
pub fn literal(&self) -> Option<&Lit> { pub fn literal(&self) -> Option<&Lit> {
match *self { match self {
NestedMetaItem::Literal(ref lit) => Some(lit), NestedMetaItem::Literal(lit) => Some(lit),
_ => None, _ => None,
} }
} }
@ -116,18 +116,18 @@ impl NestedMetaItem {
impl Attribute { impl Attribute {
#[inline] #[inline]
pub fn has_name(&self, name: Symbol) -> bool { pub fn has_name(&self, name: Symbol) -> bool {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => normal.item.path == name, AttrKind::Normal(normal) => normal.item.path == name,
AttrKind::DocComment(..) => false, AttrKind::DocComment(..) => false,
} }
} }
/// For a single-segment attribute, returns its name; otherwise, returns `None`. /// For a single-segment attribute, returns its name; otherwise, returns `None`.
pub fn ident(&self) -> Option<Ident> { pub fn ident(&self) -> Option<Ident> {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => { AttrKind::Normal(normal) => {
if normal.item.path.segments.len() == 1 { if let [ident] = &*normal.item.path.segments {
Some(normal.item.path.segments[0].ident) Some(ident.ident)
} else { } else {
None None
} }
@ -140,17 +140,15 @@ impl Attribute {
} }
pub fn value_str(&self) -> Option<Symbol> { pub fn value_str(&self) -> Option<Symbol> {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => { AttrKind::Normal(normal) => normal.item.meta_kind().and_then(|kind| kind.value_str()),
normal.item.meta_kind().and_then(|kind| kind.value_str())
}
AttrKind::DocComment(..) => None, AttrKind::DocComment(..) => None,
} }
} }
pub fn meta_item_list(&self) -> Option<Vec<NestedMetaItem>> { pub fn meta_item_list(&self) -> Option<Vec<NestedMetaItem>> {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => match normal.item.meta_kind() { AttrKind::Normal(normal) => match normal.item.meta_kind() {
Some(MetaItemKind::List(list)) => Some(list), Some(MetaItemKind::List(list)) => Some(list),
_ => None, _ => None,
}, },
@ -191,8 +189,8 @@ impl MetaItem {
} }
pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> { pub fn meta_item_list(&self) -> Option<&[NestedMetaItem]> {
match self.kind { match &self.kind {
MetaItemKind::List(ref l) => Some(&l[..]), MetaItemKind::List(l) => Some(&**l),
_ => None, _ => None,
} }
} }
@ -268,9 +266,9 @@ impl Attribute {
/// * `#[doc = "doc"]` returns `Some("doc")`. /// * `#[doc = "doc"]` returns `Some("doc")`.
/// * `#[doc(...)]` returns `None`. /// * `#[doc(...)]` returns `None`.
pub fn doc_str(&self) -> Option<Symbol> { pub fn doc_str(&self) -> Option<Symbol> {
match self.kind { match &self.kind {
AttrKind::DocComment(.., data) => Some(data), AttrKind::DocComment(.., data) => Some(*data),
AttrKind::Normal(ref normal) if normal.item.path == sym::doc => { AttrKind::Normal(normal) if normal.item.path == sym::doc => {
normal.item.meta_kind().and_then(|kind| kind.value_str()) normal.item.meta_kind().and_then(|kind| kind.value_str())
} }
_ => None, _ => None,
@ -282,8 +280,8 @@ impl Attribute {
} }
pub fn get_normal_item(&self) -> &AttrItem { pub fn get_normal_item(&self) -> &AttrItem {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => &normal.item, AttrKind::Normal(normal) => &normal.item,
AttrKind::DocComment(..) => panic!("unexpected doc comment"), AttrKind::DocComment(..) => panic!("unexpected doc comment"),
} }
} }
@ -297,28 +295,28 @@ impl Attribute {
/// Extracts the MetaItem from inside this Attribute. /// Extracts the MetaItem from inside this Attribute.
pub fn meta(&self) -> Option<MetaItem> { pub fn meta(&self) -> Option<MetaItem> {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => normal.item.meta(self.span), AttrKind::Normal(normal) => normal.item.meta(self.span),
AttrKind::DocComment(..) => None, AttrKind::DocComment(..) => None,
} }
} }
pub fn meta_kind(&self) -> Option<MetaItemKind> { pub fn meta_kind(&self) -> Option<MetaItemKind> {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => normal.item.meta_kind(), AttrKind::Normal(normal) => normal.item.meta_kind(),
AttrKind::DocComment(..) => None, AttrKind::DocComment(..) => None,
} }
} }
pub fn tokens(&self) -> TokenStream { pub fn tokens(&self) -> TokenStream {
match self.kind { match &self.kind {
AttrKind::Normal(ref normal) => normal AttrKind::Normal(normal) => normal
.tokens .tokens
.as_ref() .as_ref()
.unwrap_or_else(|| panic!("attribute is missing tokens: {:?}", self)) .unwrap_or_else(|| panic!("attribute is missing tokens: {:?}", self))
.to_attr_token_stream() .to_attr_token_stream()
.to_tokenstream(), .to_tokenstream(),
AttrKind::DocComment(comment_kind, data) => TokenStream::new(vec![TokenTree::Token( &AttrKind::DocComment(comment_kind, data) => TokenStream::new(vec![TokenTree::Token(
Token::new(token::DocComment(comment_kind, self.style, data), self.span), Token::new(token::DocComment(comment_kind, self.style, data), self.span),
Spacing::Alone, Spacing::Alone,
)]), )]),
@ -496,17 +494,17 @@ impl MetaItem {
let span = span.with_hi(segments.last().unwrap().ident.span.hi()); let span = span.with_hi(segments.last().unwrap().ident.span.hi());
Path { span, segments, tokens: None } Path { span, segments, tokens: None }
} }
Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. }, _)) => match *nt { Some(TokenTree::Token(Token { kind: token::Interpolated(nt), .. }, _)) => match &*nt {
token::Nonterminal::NtMeta(ref item) => return item.meta(item.path.span), token::Nonterminal::NtMeta(item) => return item.meta(item.path.span),
token::Nonterminal::NtPath(ref path) => (**path).clone(), token::Nonterminal::NtPath(path) => (**path).clone(),
_ => return None, _ => return None,
}, },
_ => return None, _ => return None,
}; };
let list_closing_paren_pos = tokens.peek().map(|tt| tt.span().hi()); let list_closing_paren_pos = tokens.peek().map(|tt| tt.span().hi());
let kind = MetaItemKind::from_tokens(tokens)?; let kind = MetaItemKind::from_tokens(tokens)?;
let hi = match kind { let hi = match &kind {
MetaItemKind::NameValue(ref lit) => lit.span.hi(), MetaItemKind::NameValue(lit) => lit.span.hi(),
MetaItemKind::List(..) => list_closing_paren_pos.unwrap_or(path.span.hi()), MetaItemKind::List(..) => list_closing_paren_pos.unwrap_or(path.span.hi()),
_ => path.span.hi(), _ => path.span.hi(),
}; };
@ -518,8 +516,8 @@ impl MetaItem {
impl MetaItemKind { impl MetaItemKind {
pub fn value_str(&self) -> Option<Symbol> { pub fn value_str(&self) -> Option<Symbol> {
match self { match self {
MetaItemKind::NameValue(ref v) => match v.kind { MetaItemKind::NameValue(v) => match v.kind {
LitKind::Str(ref s, _) => Some(*s), LitKind::Str(s, _) => Some(s),
_ => None, _ => None,
}, },
_ => None, _ => None,
@ -557,15 +555,15 @@ impl MetaItemKind {
} }
fn token_trees(&self, span: Span) -> Vec<TokenTree> { fn token_trees(&self, span: Span) -> Vec<TokenTree> {
match *self { match self {
MetaItemKind::Word => vec![], MetaItemKind::Word => vec![],
MetaItemKind::NameValue(ref lit) => { MetaItemKind::NameValue(lit) => {
vec![ vec![
TokenTree::token_alone(token::Eq, span), TokenTree::token_alone(token::Eq, span),
TokenTree::Token(lit.to_token(), Spacing::Alone), TokenTree::Token(lit.to_token(), Spacing::Alone),
] ]
} }
MetaItemKind::List(ref list) => { MetaItemKind::List(list) => {
let mut tokens = Vec::new(); let mut tokens = Vec::new();
for (i, item) in list.iter().enumerate() { for (i, item) in list.iter().enumerate() {
if i > 0 { if i > 0 {
@ -648,16 +646,16 @@ impl MetaItemKind {
impl NestedMetaItem { impl NestedMetaItem {
pub fn span(&self) -> Span { pub fn span(&self) -> Span {
match *self { match self {
NestedMetaItem::MetaItem(ref item) => item.span, NestedMetaItem::MetaItem(item) => item.span,
NestedMetaItem::Literal(ref lit) => lit.span, NestedMetaItem::Literal(lit) => lit.span,
} }
} }
fn token_trees(&self) -> Vec<TokenTree> { fn token_trees(&self) -> Vec<TokenTree> {
match *self { match self {
NestedMetaItem::MetaItem(ref item) => item.token_trees(), NestedMetaItem::MetaItem(item) => item.token_trees(),
NestedMetaItem::Literal(ref lit) => { NestedMetaItem::Literal(lit) => {
vec![TokenTree::Token(lit.to_token(), Spacing::Alone)] vec![TokenTree::Token(lit.to_token(), Spacing::Alone)]
} }
} }

View file

@ -439,15 +439,15 @@ pub fn noop_visit_constraint<T: MutVisitor>(
) { ) {
vis.visit_id(id); vis.visit_id(id);
vis.visit_ident(ident); vis.visit_ident(ident);
if let Some(ref mut gen_args) = gen_args { if let Some(gen_args) = gen_args {
vis.visit_generic_args(gen_args); vis.visit_generic_args(gen_args);
} }
match kind { match kind {
AssocConstraintKind::Equality { ref mut term } => match term { AssocConstraintKind::Equality { term } => match term {
Term::Ty(ty) => vis.visit_ty(ty), Term::Ty(ty) => vis.visit_ty(ty),
Term::Const(c) => vis.visit_anon_const(c), Term::Const(c) => vis.visit_anon_const(c),
}, },
AssocConstraintKind::Bound { ref mut bounds } => visit_bounds(bounds, vis), AssocConstraintKind::Bound { bounds } => visit_bounds(bounds, vis),
} }
vis.visit_span(span); vis.visit_span(span);
} }
@ -880,7 +880,7 @@ pub fn noop_flat_map_generic_param<T: MutVisitor>(
let GenericParam { id, ident, attrs, bounds, kind, colon_span, is_placeholder: _ } = &mut param; let GenericParam { id, ident, attrs, bounds, kind, colon_span, is_placeholder: _ } = &mut param;
vis.visit_id(id); vis.visit_id(id);
vis.visit_ident(ident); vis.visit_ident(ident);
if let Some(ref mut colon_span) = colon_span { if let Some(colon_span) = colon_span {
vis.visit_span(colon_span); vis.visit_span(colon_span);
} }
visit_attrs(attrs, vis); visit_attrs(attrs, vis);

View file

@ -601,9 +601,10 @@ impl Token {
/// Returns `true` if the token is an interpolated path. /// Returns `true` if the token is an interpolated path.
fn is_path(&self) -> bool { fn is_path(&self) -> bool {
if let Interpolated(ref nt) = self.kind && let NtPath(..) = **nt { if let Interpolated(nt) = &self.kind && let NtPath(..) = **nt {
return true; return true;
} }
false false
} }
@ -611,7 +612,7 @@ impl Token {
/// That is, is this a pre-parsed expression dropped into the token stream /// That is, is this a pre-parsed expression dropped into the token stream
/// (which happens while parsing the result of macro expansion)? /// (which happens while parsing the result of macro expansion)?
pub fn is_whole_expr(&self) -> bool { pub fn is_whole_expr(&self) -> bool {
if let Interpolated(ref nt) = self.kind if let Interpolated(nt) = &self.kind
&& let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtBlock(_) = **nt && let NtExpr(_) | NtLiteral(_) | NtPath(_) | NtBlock(_) = **nt
{ {
return true; return true;
@ -622,9 +623,10 @@ impl Token {
// Is the token an interpolated block (`$b:block`)? // Is the token an interpolated block (`$b:block`)?
pub fn is_whole_block(&self) -> bool { pub fn is_whole_block(&self) -> bool {
if let Interpolated(ref nt) = self.kind && let NtBlock(..) = **nt { if let Interpolated(nt) = &self.kind && let NtBlock(..) = **nt {
return true; return true;
} }
false false
} }

View file

@ -377,26 +377,26 @@ pub fn needs_par_as_let_scrutinee(order: i8) -> bool {
/// parens or other delimiters, e.g., `X { y: 1 }`, `X { y: 1 }.method()`, `foo == X { y: 1 }` and /// parens or other delimiters, e.g., `X { y: 1 }`, `X { y: 1 }.method()`, `foo == X { y: 1 }` and
/// `X { y: 1 } == foo` all do, but `(X { y: 1 }) == foo` does not. /// `X { y: 1 } == foo` all do, but `(X { y: 1 }) == foo` does not.
pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool { pub fn contains_exterior_struct_lit(value: &ast::Expr) -> bool {
match value.kind { match &value.kind {
ast::ExprKind::Struct(..) => true, ast::ExprKind::Struct(..) => true,
ast::ExprKind::Assign(ref lhs, ref rhs, _) ast::ExprKind::Assign(lhs, rhs, _)
| ast::ExprKind::AssignOp(_, ref lhs, ref rhs) | ast::ExprKind::AssignOp(_, lhs, rhs)
| ast::ExprKind::Binary(_, ref lhs, ref rhs) => { | ast::ExprKind::Binary(_, lhs, rhs) => {
// X { y: 1 } + X { y: 2 } // X { y: 1 } + X { y: 2 }
contains_exterior_struct_lit(&lhs) || contains_exterior_struct_lit(&rhs) contains_exterior_struct_lit(&lhs) || contains_exterior_struct_lit(&rhs)
} }
ast::ExprKind::Await(ref x) ast::ExprKind::Await(x)
| ast::ExprKind::Unary(_, ref x) | ast::ExprKind::Unary(_, x)
| ast::ExprKind::Cast(ref x, _) | ast::ExprKind::Cast(x, _)
| ast::ExprKind::Type(ref x, _) | ast::ExprKind::Type(x, _)
| ast::ExprKind::Field(ref x, _) | ast::ExprKind::Field(x, _)
| ast::ExprKind::Index(ref x, _) => { | ast::ExprKind::Index(x, _) => {
// &X { y: 1 }, X { y: 1 }.y // &X { y: 1 }, X { y: 1 }.y
contains_exterior_struct_lit(&x) contains_exterior_struct_lit(&x)
} }
ast::ExprKind::MethodCall(box ast::MethodCall { ref receiver, .. }) => { ast::ExprKind::MethodCall(box ast::MethodCall { receiver, .. }) => {
// X { y: 1 }.bar(...) // X { y: 1 }.bar(...)
contains_exterior_struct_lit(&receiver) contains_exterior_struct_lit(&receiver)
} }

View file

@ -299,74 +299,68 @@ pub fn walk_trait_ref<'a, V: Visitor<'a>>(visitor: &mut V, trait_ref: &'a TraitR
pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
visitor.visit_vis(&item.vis); visitor.visit_vis(&item.vis);
visitor.visit_ident(item.ident); visitor.visit_ident(item.ident);
match item.kind { match &item.kind {
ItemKind::ExternCrate(_) => {} ItemKind::ExternCrate(_) => {}
ItemKind::Use(ref use_tree) => visitor.visit_use_tree(use_tree, item.id, false), ItemKind::Use(use_tree) => visitor.visit_use_tree(use_tree, item.id, false),
ItemKind::Static(ref typ, _, ref expr) | ItemKind::Const(_, ref typ, ref expr) => { ItemKind::Static(typ, _, expr) | ItemKind::Const(_, typ, expr) => {
visitor.visit_ty(typ); visitor.visit_ty(typ);
walk_list!(visitor, visit_expr, expr); walk_list!(visitor, visit_expr, expr);
} }
ItemKind::Fn(box Fn { defaultness: _, ref generics, ref sig, ref body }) => { ItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
let kind = let kind =
FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, generics, body.as_deref()); FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, generics, body.as_deref());
visitor.visit_fn(kind, item.span, item.id) visitor.visit_fn(kind, item.span, item.id)
} }
ItemKind::Mod(_unsafety, ref mod_kind) => match mod_kind { ItemKind::Mod(_unsafety, mod_kind) => match mod_kind {
ModKind::Loaded(items, _inline, _inner_span) => { ModKind::Loaded(items, _inline, _inner_span) => {
walk_list!(visitor, visit_item, items) walk_list!(visitor, visit_item, items)
} }
ModKind::Unloaded => {} ModKind::Unloaded => {}
}, },
ItemKind::ForeignMod(ref foreign_module) => { ItemKind::ForeignMod(foreign_module) => {
walk_list!(visitor, visit_foreign_item, &foreign_module.items); walk_list!(visitor, visit_foreign_item, &foreign_module.items);
} }
ItemKind::GlobalAsm(ref asm) => visitor.visit_inline_asm(asm), ItemKind::GlobalAsm(asm) => visitor.visit_inline_asm(asm),
ItemKind::TyAlias(box TyAlias { ref generics, ref bounds, ref ty, .. }) => { ItemKind::TyAlias(box TyAlias { generics, bounds, ty, .. }) => {
visitor.visit_generics(generics); visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
walk_list!(visitor, visit_ty, ty); walk_list!(visitor, visit_ty, ty);
} }
ItemKind::Enum(ref enum_definition, ref generics) => { ItemKind::Enum(enum_definition, generics) => {
visitor.visit_generics(generics); visitor.visit_generics(generics);
visitor.visit_enum_def(enum_definition) visitor.visit_enum_def(enum_definition)
} }
ItemKind::Impl(box Impl { ItemKind::Impl(box Impl {
defaultness: _, defaultness: _,
unsafety: _, unsafety: _,
ref generics, generics,
constness: _, constness: _,
polarity: _, polarity: _,
ref of_trait, of_trait,
ref self_ty, self_ty,
ref items, items,
}) => { }) => {
visitor.visit_generics(generics); visitor.visit_generics(generics);
walk_list!(visitor, visit_trait_ref, of_trait); walk_list!(visitor, visit_trait_ref, of_trait);
visitor.visit_ty(self_ty); visitor.visit_ty(self_ty);
walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Impl); walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Impl);
} }
ItemKind::Struct(ref struct_definition, ref generics) ItemKind::Struct(struct_definition, generics)
| ItemKind::Union(ref struct_definition, ref generics) => { | ItemKind::Union(struct_definition, generics) => {
visitor.visit_generics(generics); visitor.visit_generics(generics);
visitor.visit_variant_data(struct_definition); visitor.visit_variant_data(struct_definition);
} }
ItemKind::Trait(box Trait { ItemKind::Trait(box Trait { unsafety: _, is_auto: _, generics, bounds, items }) => {
unsafety: _,
is_auto: _,
ref generics,
ref bounds,
ref items,
}) => {
visitor.visit_generics(generics); visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds, BoundKind::SuperTraits); walk_list!(visitor, visit_param_bound, bounds, BoundKind::SuperTraits);
walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Trait); walk_list!(visitor, visit_assoc_item, items, AssocCtxt::Trait);
} }
ItemKind::TraitAlias(ref generics, ref bounds) => { ItemKind::TraitAlias(generics, bounds) => {
visitor.visit_generics(generics); visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
} }
ItemKind::MacCall(ref mac) => visitor.visit_mac_call(mac), ItemKind::MacCall(mac) => visitor.visit_mac_call(mac),
ItemKind::MacroDef(ref ts) => visitor.visit_mac_def(ts, item.id), ItemKind::MacroDef(ts) => visitor.visit_mac_def(ts, item.id),
} }
walk_list!(visitor, visit_attribute, &item.attrs); walk_list!(visitor, visit_attribute, &item.attrs);
} }
@ -399,39 +393,39 @@ pub fn walk_pat_field<'a, V: Visitor<'a>>(visitor: &mut V, fp: &'a PatField) {
} }
pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) { pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
match typ.kind { match &typ.kind {
TyKind::Slice(ref ty) | TyKind::Paren(ref ty) => visitor.visit_ty(ty), TyKind::Slice(ty) | TyKind::Paren(ty) => visitor.visit_ty(ty),
TyKind::Ptr(ref mutable_type) => visitor.visit_ty(&mutable_type.ty), TyKind::Ptr(mutable_type) => visitor.visit_ty(&mutable_type.ty),
TyKind::Rptr(ref opt_lifetime, ref mutable_type) => { TyKind::Rptr(opt_lifetime, mutable_type) => {
walk_list!(visitor, visit_lifetime, opt_lifetime, LifetimeCtxt::Rptr); walk_list!(visitor, visit_lifetime, opt_lifetime, LifetimeCtxt::Rptr);
visitor.visit_ty(&mutable_type.ty) visitor.visit_ty(&mutable_type.ty)
} }
TyKind::Tup(ref tuple_element_types) => { TyKind::Tup(tuple_element_types) => {
walk_list!(visitor, visit_ty, tuple_element_types); walk_list!(visitor, visit_ty, tuple_element_types);
} }
TyKind::BareFn(ref function_declaration) => { TyKind::BareFn(function_declaration) => {
walk_list!(visitor, visit_generic_param, &function_declaration.generic_params); walk_list!(visitor, visit_generic_param, &function_declaration.generic_params);
walk_fn_decl(visitor, &function_declaration.decl); walk_fn_decl(visitor, &function_declaration.decl);
} }
TyKind::Path(ref maybe_qself, ref path) => { TyKind::Path(maybe_qself, path) => {
if let Some(ref qself) = *maybe_qself { if let Some(qself) = maybe_qself {
visitor.visit_ty(&qself.ty); visitor.visit_ty(&qself.ty);
} }
visitor.visit_path(path, typ.id); visitor.visit_path(path, typ.id);
} }
TyKind::Array(ref ty, ref length) => { TyKind::Array(ty, length) => {
visitor.visit_ty(ty); visitor.visit_ty(ty);
visitor.visit_anon_const(length) visitor.visit_anon_const(length)
} }
TyKind::TraitObject(ref bounds, ..) => { TyKind::TraitObject(bounds, ..) => {
walk_list!(visitor, visit_param_bound, bounds, BoundKind::TraitObject); walk_list!(visitor, visit_param_bound, bounds, BoundKind::TraitObject);
} }
TyKind::ImplTrait(_, ref bounds) => { TyKind::ImplTrait(_, bounds) => {
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Impl); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Impl);
} }
TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression), TyKind::Typeof(expression) => visitor.visit_anon_const(expression),
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {} TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
TyKind::MacCall(ref mac) => visitor.visit_mac_call(mac), TyKind::MacCall(mac) => visitor.visit_mac_call(mac),
TyKind::Never | TyKind::CVarArgs => {} TyKind::Never | TyKind::CVarArgs => {}
} }
} }
@ -444,15 +438,15 @@ pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) {
pub fn walk_use_tree<'a, V: Visitor<'a>>(visitor: &mut V, use_tree: &'a UseTree, id: NodeId) { pub fn walk_use_tree<'a, V: Visitor<'a>>(visitor: &mut V, use_tree: &'a UseTree, id: NodeId) {
visitor.visit_path(&use_tree.prefix, id); visitor.visit_path(&use_tree.prefix, id);
match use_tree.kind { match &use_tree.kind {
UseTreeKind::Simple(rename, ..) => { UseTreeKind::Simple(rename, ..) => {
// The extra IDs are handled during HIR lowering. // The extra IDs are handled during HIR lowering.
if let Some(rename) = rename { if let &Some(rename) = rename {
visitor.visit_ident(rename); visitor.visit_ident(rename);
} }
} }
UseTreeKind::Glob => {} UseTreeKind::Glob => {}
UseTreeKind::Nested(ref use_trees) => { UseTreeKind::Nested(use_trees) => {
for &(ref nested_tree, nested_id) in use_trees { for &(ref nested_tree, nested_id) in use_trees {
visitor.visit_use_tree(nested_tree, nested_id, true); visitor.visit_use_tree(nested_tree, nested_id, true);
} }
@ -462,7 +456,7 @@ pub fn walk_use_tree<'a, V: Visitor<'a>>(visitor: &mut V, use_tree: &'a UseTree,
pub fn walk_path_segment<'a, V: Visitor<'a>>(visitor: &mut V, segment: &'a PathSegment) { pub fn walk_path_segment<'a, V: Visitor<'a>>(visitor: &mut V, segment: &'a PathSegment) {
visitor.visit_ident(segment.ident); visitor.visit_ident(segment.ident);
if let Some(ref args) = segment.args { if let Some(args) = &segment.args {
visitor.visit_generic_args(args); visitor.visit_generic_args(args);
} }
} }
@ -471,8 +465,8 @@ pub fn walk_generic_args<'a, V>(visitor: &mut V, generic_args: &'a GenericArgs)
where where
V: Visitor<'a>, V: Visitor<'a>,
{ {
match *generic_args { match generic_args {
GenericArgs::AngleBracketed(ref data) => { GenericArgs::AngleBracketed(data) => {
for arg in &data.args { for arg in &data.args {
match arg { match arg {
AngleBracketedArg::Arg(a) => visitor.visit_generic_arg(a), AngleBracketedArg::Arg(a) => visitor.visit_generic_arg(a),
@ -480,7 +474,7 @@ where
} }
} }
} }
GenericArgs::Parenthesized(ref data) => { GenericArgs::Parenthesized(data) => {
walk_list!(visitor, visit_ty, &data.inputs); walk_list!(visitor, visit_ty, &data.inputs);
walk_fn_ret_ty(visitor, &data.output); walk_fn_ret_ty(visitor, &data.output);
} }
@ -500,64 +494,64 @@ where
pub fn walk_assoc_constraint<'a, V: Visitor<'a>>(visitor: &mut V, constraint: &'a AssocConstraint) { pub fn walk_assoc_constraint<'a, V: Visitor<'a>>(visitor: &mut V, constraint: &'a AssocConstraint) {
visitor.visit_ident(constraint.ident); visitor.visit_ident(constraint.ident);
if let Some(ref gen_args) = constraint.gen_args { if let Some(gen_args) = &constraint.gen_args {
visitor.visit_generic_args(gen_args); visitor.visit_generic_args(gen_args);
} }
match constraint.kind { match &constraint.kind {
AssocConstraintKind::Equality { ref term } => match term { AssocConstraintKind::Equality { term } => match term {
Term::Ty(ty) => visitor.visit_ty(ty), Term::Ty(ty) => visitor.visit_ty(ty),
Term::Const(c) => visitor.visit_anon_const(c), Term::Const(c) => visitor.visit_anon_const(c),
}, },
AssocConstraintKind::Bound { ref bounds } => { AssocConstraintKind::Bound { bounds } => {
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
} }
} }
} }
pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) { pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) {
match pattern.kind { match &pattern.kind {
PatKind::TupleStruct(ref opt_qself, ref path, ref elems) => { PatKind::TupleStruct(opt_qself, path, elems) => {
if let Some(ref qself) = *opt_qself { if let Some(qself) = opt_qself {
visitor.visit_ty(&qself.ty); visitor.visit_ty(&qself.ty);
} }
visitor.visit_path(path, pattern.id); visitor.visit_path(path, pattern.id);
walk_list!(visitor, visit_pat, elems); walk_list!(visitor, visit_pat, elems);
} }
PatKind::Path(ref opt_qself, ref path) => { PatKind::Path(opt_qself, path) => {
if let Some(ref qself) = *opt_qself { if let Some(qself) = opt_qself {
visitor.visit_ty(&qself.ty); visitor.visit_ty(&qself.ty);
} }
visitor.visit_path(path, pattern.id) visitor.visit_path(path, pattern.id)
} }
PatKind::Struct(ref opt_qself, ref path, ref fields, _) => { PatKind::Struct(opt_qself, path, fields, _) => {
if let Some(ref qself) = *opt_qself { if let Some(qself) = opt_qself {
visitor.visit_ty(&qself.ty); visitor.visit_ty(&qself.ty);
} }
visitor.visit_path(path, pattern.id); visitor.visit_path(path, pattern.id);
walk_list!(visitor, visit_pat_field, fields); walk_list!(visitor, visit_pat_field, fields);
} }
PatKind::Box(ref subpattern) PatKind::Box(subpattern) | PatKind::Ref(subpattern, _) | PatKind::Paren(subpattern) => {
| PatKind::Ref(ref subpattern, _) visitor.visit_pat(subpattern)
| PatKind::Paren(ref subpattern) => visitor.visit_pat(subpattern), }
PatKind::Ident(_, ident, ref optional_subpattern) => { PatKind::Ident(_, ident, optional_subpattern) => {
visitor.visit_ident(ident); visitor.visit_ident(*ident);
walk_list!(visitor, visit_pat, optional_subpattern); walk_list!(visitor, visit_pat, optional_subpattern);
} }
PatKind::Lit(ref expression) => visitor.visit_expr(expression), PatKind::Lit(expression) => visitor.visit_expr(expression),
PatKind::Range(ref lower_bound, ref upper_bound, _) => { PatKind::Range(lower_bound, upper_bound, _) => {
walk_list!(visitor, visit_expr, lower_bound); walk_list!(visitor, visit_expr, lower_bound);
walk_list!(visitor, visit_expr, upper_bound); walk_list!(visitor, visit_expr, upper_bound);
} }
PatKind::Wild | PatKind::Rest => {} PatKind::Wild | PatKind::Rest => {}
PatKind::Tuple(ref elems) | PatKind::Slice(ref elems) | PatKind::Or(ref elems) => { PatKind::Tuple(elems) | PatKind::Slice(elems) | PatKind::Or(elems) => {
walk_list!(visitor, visit_pat, elems); walk_list!(visitor, visit_pat, elems);
} }
PatKind::MacCall(ref mac) => visitor.visit_mac_call(mac), PatKind::MacCall(mac) => visitor.visit_mac_call(mac),
} }
} }
pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignItem) { pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignItem) {
let Item { id, span, ident, ref vis, ref attrs, ref kind, tokens: _ } = *item; let &Item { id, span, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
visitor.visit_vis(vis); visitor.visit_vis(vis);
visitor.visit_ident(ident); visitor.visit_ident(ident);
walk_list!(visitor, visit_attribute, attrs); walk_list!(visitor, visit_attribute, attrs);
@ -566,7 +560,7 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI
visitor.visit_ty(ty); visitor.visit_ty(ty);
walk_list!(visitor, visit_expr, expr); walk_list!(visitor, visit_expr, expr);
} }
ForeignItemKind::Fn(box Fn { defaultness: _, ref generics, ref sig, ref body }) => { ForeignItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
let kind = FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body.as_deref()); let kind = FnKind::Fn(FnCtxt::Foreign, ident, sig, vis, generics, body.as_deref());
visitor.visit_fn(kind, span, id); visitor.visit_fn(kind, span, id);
} }
@ -582,11 +576,9 @@ pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignI
} }
pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) { pub fn walk_param_bound<'a, V: Visitor<'a>>(visitor: &mut V, bound: &'a GenericBound) {
match *bound { match bound {
GenericBound::Trait(ref typ, ref _modifier) => visitor.visit_poly_trait_ref(typ), GenericBound::Trait(typ, _modifier) => visitor.visit_poly_trait_ref(typ),
GenericBound::Outlives(ref lifetime) => { GenericBound::Outlives(lifetime) => visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound),
visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound)
}
} }
} }
@ -594,10 +586,10 @@ pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Generi
visitor.visit_ident(param.ident); visitor.visit_ident(param.ident);
walk_list!(visitor, visit_attribute, param.attrs.iter()); walk_list!(visitor, visit_attribute, param.attrs.iter());
walk_list!(visitor, visit_param_bound, &param.bounds, BoundKind::Bound); walk_list!(visitor, visit_param_bound, &param.bounds, BoundKind::Bound);
match param.kind { match &param.kind {
GenericParamKind::Lifetime => (), GenericParamKind::Lifetime => (),
GenericParamKind::Type { ref default } => walk_list!(visitor, visit_ty, default), GenericParamKind::Type { default } => walk_list!(visitor, visit_ty, default),
GenericParamKind::Const { ref ty, ref default, .. } => { GenericParamKind::Const { ty, default, .. } => {
visitor.visit_ty(ty); visitor.visit_ty(ty);
if let Some(default) = default { if let Some(default) = default {
visitor.visit_anon_const(default); visitor.visit_anon_const(default);
@ -621,24 +613,22 @@ pub fn walk_closure_binder<'a, V: Visitor<'a>>(visitor: &mut V, binder: &'a Clos
} }
pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a WherePredicate) { pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a WherePredicate) {
match *predicate { match predicate {
WherePredicate::BoundPredicate(WhereBoundPredicate { WherePredicate::BoundPredicate(WhereBoundPredicate {
ref bounded_ty, bounded_ty,
ref bounds, bounds,
ref bound_generic_params, bound_generic_params,
.. ..
}) => { }) => {
visitor.visit_ty(bounded_ty); visitor.visit_ty(bounded_ty);
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
walk_list!(visitor, visit_generic_param, bound_generic_params); walk_list!(visitor, visit_generic_param, bound_generic_params);
} }
WherePredicate::RegionPredicate(WhereRegionPredicate { WherePredicate::RegionPredicate(WhereRegionPredicate { lifetime, bounds, .. }) => {
ref lifetime, ref bounds, ..
}) => {
visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound); visitor.visit_lifetime(lifetime, LifetimeCtxt::Bound);
walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound); walk_list!(visitor, visit_param_bound, bounds, BoundKind::Bound);
} }
WherePredicate::EqPredicate(WhereEqPredicate { ref lhs_ty, ref rhs_ty, .. }) => { WherePredicate::EqPredicate(WhereEqPredicate { lhs_ty, rhs_ty, .. }) => {
visitor.visit_ty(lhs_ty); visitor.visit_ty(lhs_ty);
visitor.visit_ty(rhs_ty); visitor.visit_ty(rhs_ty);
} }
@ -646,7 +636,7 @@ pub fn walk_where_predicate<'a, V: Visitor<'a>>(visitor: &mut V, predicate: &'a
} }
pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy) { pub fn walk_fn_ret_ty<'a, V: Visitor<'a>>(visitor: &mut V, ret_ty: &'a FnRetTy) {
if let FnRetTy::Ty(ref output_ty) = *ret_ty { if let FnRetTy::Ty(output_ty) = ret_ty {
visitor.visit_ty(output_ty) visitor.visit_ty(output_ty)
} }
} }
@ -675,7 +665,7 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) {
} }
pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem, ctxt: AssocCtxt) { pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem, ctxt: AssocCtxt) {
let Item { id, span, ident, ref vis, ref attrs, ref kind, tokens: _ } = *item; let &Item { id, span, ident, ref vis, ref attrs, ref kind, tokens: _ } = item;
visitor.visit_vis(vis); visitor.visit_vis(vis);
visitor.visit_ident(ident); visitor.visit_ident(ident);
walk_list!(visitor, visit_attribute, attrs); walk_list!(visitor, visit_attribute, attrs);
@ -684,7 +674,7 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem,
visitor.visit_ty(ty); visitor.visit_ty(ty);
walk_list!(visitor, visit_expr, expr); walk_list!(visitor, visit_expr, expr);
} }
AssocItemKind::Fn(box Fn { defaultness: _, ref generics, ref sig, ref body }) => { AssocItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => {
let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, generics, body.as_deref()); let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), ident, sig, vis, generics, body.as_deref());
visitor.visit_fn(kind, span, id); visitor.visit_fn(kind, span, id);
} }
@ -717,13 +707,13 @@ pub fn walk_block<'a, V: Visitor<'a>>(visitor: &mut V, block: &'a Block) {
} }
pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) { pub fn walk_stmt<'a, V: Visitor<'a>>(visitor: &mut V, statement: &'a Stmt) {
match statement.kind { match &statement.kind {
StmtKind::Local(ref local) => visitor.visit_local(local), StmtKind::Local(local) => visitor.visit_local(local),
StmtKind::Item(ref item) => visitor.visit_item(item), StmtKind::Item(item) => visitor.visit_item(item),
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => visitor.visit_expr(expr), StmtKind::Expr(expr) | StmtKind::Semi(expr) => visitor.visit_expr(expr),
StmtKind::Empty => {} StmtKind::Empty => {}
StmtKind::MacCall(ref mac) => { StmtKind::MacCall(mac) => {
let MacCallStmt { ref mac, style: _, ref attrs, tokens: _ } = **mac; let MacCallStmt { mac, attrs, style: _, tokens: _ } = &**mac;
visitor.visit_mac_call(mac); visitor.visit_mac_call(mac);
for attr in attrs.iter() { for attr in attrs.iter() {
visitor.visit_attribute(attr); visitor.visit_attribute(attr);
@ -760,7 +750,7 @@ pub fn walk_inline_asm<'a, V: Visitor<'a>>(visitor: &mut V, asm: &'a InlineAsm)
} }
pub fn walk_inline_asm_sym<'a, V: Visitor<'a>>(visitor: &mut V, sym: &'a InlineAsmSym) { pub fn walk_inline_asm_sym<'a, V: Visitor<'a>>(visitor: &mut V, sym: &'a InlineAsmSym) {
if let Some(ref qself) = sym.qself { if let Some(qself) = &sym.qself {
visitor.visit_ty(&qself.ty); visitor.visit_ty(&qself.ty);
} }
visitor.visit_path(&sym.path, sym.id); visitor.visit_path(&sym.path, sym.id);
@ -769,18 +759,18 @@ pub fn walk_inline_asm_sym<'a, V: Visitor<'a>>(visitor: &mut V, sym: &'a InlineA
pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) { pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
walk_list!(visitor, visit_attribute, expression.attrs.iter()); walk_list!(visitor, visit_attribute, expression.attrs.iter());
match expression.kind { match &expression.kind {
ExprKind::Box(ref subexpression) => visitor.visit_expr(subexpression), ExprKind::Box(subexpression) => visitor.visit_expr(subexpression),
ExprKind::Array(ref subexpressions) => { ExprKind::Array(subexpressions) => {
walk_list!(visitor, visit_expr, subexpressions); walk_list!(visitor, visit_expr, subexpressions);
} }
ExprKind::ConstBlock(ref anon_const) => visitor.visit_anon_const(anon_const), ExprKind::ConstBlock(anon_const) => visitor.visit_anon_const(anon_const),
ExprKind::Repeat(ref element, ref count) => { ExprKind::Repeat(element, count) => {
visitor.visit_expr(element); visitor.visit_expr(element);
visitor.visit_anon_const(count) visitor.visit_anon_const(count)
} }
ExprKind::Struct(ref se) => { ExprKind::Struct(se) => {
if let Some(ref qself) = se.qself { if let Some(qself) = &se.qself {
visitor.visit_ty(&qself.ty); visitor.visit_ty(&qself.ty);
} }
visitor.visit_path(&se.path, expression.id); visitor.visit_path(&se.path, expression.id);
@ -791,124 +781,124 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
StructRest::None => {} StructRest::None => {}
} }
} }
ExprKind::Tup(ref subexpressions) => { ExprKind::Tup(subexpressions) => {
walk_list!(visitor, visit_expr, subexpressions); walk_list!(visitor, visit_expr, subexpressions);
} }
ExprKind::Call(ref callee_expression, ref arguments) => { ExprKind::Call(callee_expression, arguments) => {
visitor.visit_expr(callee_expression); visitor.visit_expr(callee_expression);
walk_list!(visitor, visit_expr, arguments); walk_list!(visitor, visit_expr, arguments);
} }
ExprKind::MethodCall(box MethodCall { ref seg, ref receiver, ref args, span: _ }) => { ExprKind::MethodCall(box MethodCall { seg, receiver, args, span: _ }) => {
visitor.visit_path_segment(seg); visitor.visit_path_segment(seg);
visitor.visit_expr(receiver); visitor.visit_expr(receiver);
walk_list!(visitor, visit_expr, args); walk_list!(visitor, visit_expr, args);
} }
ExprKind::Binary(_, ref left_expression, ref right_expression) => { ExprKind::Binary(_, left_expression, right_expression) => {
visitor.visit_expr(left_expression); visitor.visit_expr(left_expression);
visitor.visit_expr(right_expression) visitor.visit_expr(right_expression)
} }
ExprKind::AddrOf(_, _, ref subexpression) | ExprKind::Unary(_, ref subexpression) => { ExprKind::AddrOf(_, _, subexpression) | ExprKind::Unary(_, subexpression) => {
visitor.visit_expr(subexpression) visitor.visit_expr(subexpression)
} }
ExprKind::Cast(ref subexpression, ref typ) | ExprKind::Type(ref subexpression, ref typ) => { ExprKind::Cast(subexpression, typ) | ExprKind::Type(subexpression, typ) => {
visitor.visit_expr(subexpression); visitor.visit_expr(subexpression);
visitor.visit_ty(typ) visitor.visit_ty(typ)
} }
ExprKind::Let(ref pat, ref expr, _) => { ExprKind::Let(pat, expr, _) => {
visitor.visit_pat(pat); visitor.visit_pat(pat);
visitor.visit_expr(expr); visitor.visit_expr(expr);
} }
ExprKind::If(ref head_expression, ref if_block, ref optional_else) => { ExprKind::If(head_expression, if_block, optional_else) => {
visitor.visit_expr(head_expression); visitor.visit_expr(head_expression);
visitor.visit_block(if_block); visitor.visit_block(if_block);
walk_list!(visitor, visit_expr, optional_else); walk_list!(visitor, visit_expr, optional_else);
} }
ExprKind::While(ref subexpression, ref block, ref opt_label) => { ExprKind::While(subexpression, block, opt_label) => {
walk_list!(visitor, visit_label, opt_label); walk_list!(visitor, visit_label, opt_label);
visitor.visit_expr(subexpression); visitor.visit_expr(subexpression);
visitor.visit_block(block); visitor.visit_block(block);
} }
ExprKind::ForLoop(ref pattern, ref subexpression, ref block, ref opt_label) => { ExprKind::ForLoop(pattern, subexpression, block, opt_label) => {
walk_list!(visitor, visit_label, opt_label); walk_list!(visitor, visit_label, opt_label);
visitor.visit_pat(pattern); visitor.visit_pat(pattern);
visitor.visit_expr(subexpression); visitor.visit_expr(subexpression);
visitor.visit_block(block); visitor.visit_block(block);
} }
ExprKind::Loop(ref block, ref opt_label) => { ExprKind::Loop(block, opt_label) => {
walk_list!(visitor, visit_label, opt_label); walk_list!(visitor, visit_label, opt_label);
visitor.visit_block(block); visitor.visit_block(block);
} }
ExprKind::Match(ref subexpression, ref arms) => { ExprKind::Match(subexpression, arms) => {
visitor.visit_expr(subexpression); visitor.visit_expr(subexpression);
walk_list!(visitor, visit_arm, arms); walk_list!(visitor, visit_arm, arms);
} }
ExprKind::Closure(box Closure { ExprKind::Closure(box Closure {
ref binder, binder,
capture_clause: _, capture_clause: _,
asyncness: _, asyncness: _,
movability: _, movability: _,
ref fn_decl, fn_decl,
ref body, body,
fn_decl_span: _, fn_decl_span: _,
}) => { }) => {
visitor.visit_fn(FnKind::Closure(binder, fn_decl, body), expression.span, expression.id) visitor.visit_fn(FnKind::Closure(binder, fn_decl, body), expression.span, expression.id)
} }
ExprKind::Block(ref block, ref opt_label) => { ExprKind::Block(block, opt_label) => {
walk_list!(visitor, visit_label, opt_label); walk_list!(visitor, visit_label, opt_label);
visitor.visit_block(block); visitor.visit_block(block);
} }
ExprKind::Async(_, _, ref body) => { ExprKind::Async(_, _, body) => {
visitor.visit_block(body); visitor.visit_block(body);
} }
ExprKind::Await(ref expr) => visitor.visit_expr(expr), ExprKind::Await(expr) => visitor.visit_expr(expr),
ExprKind::Assign(ref lhs, ref rhs, _) => { ExprKind::Assign(lhs, rhs, _) => {
visitor.visit_expr(lhs); visitor.visit_expr(lhs);
visitor.visit_expr(rhs); visitor.visit_expr(rhs);
} }
ExprKind::AssignOp(_, ref left_expression, ref right_expression) => { ExprKind::AssignOp(_, left_expression, right_expression) => {
visitor.visit_expr(left_expression); visitor.visit_expr(left_expression);
visitor.visit_expr(right_expression); visitor.visit_expr(right_expression);
} }
ExprKind::Field(ref subexpression, ident) => { ExprKind::Field(subexpression, ident) => {
visitor.visit_expr(subexpression); visitor.visit_expr(subexpression);
visitor.visit_ident(ident); visitor.visit_ident(*ident);
} }
ExprKind::Index(ref main_expression, ref index_expression) => { ExprKind::Index(main_expression, index_expression) => {
visitor.visit_expr(main_expression); visitor.visit_expr(main_expression);
visitor.visit_expr(index_expression) visitor.visit_expr(index_expression)
} }
ExprKind::Range(ref start, ref end, _) => { ExprKind::Range(start, end, _) => {
walk_list!(visitor, visit_expr, start); walk_list!(visitor, visit_expr, start);
walk_list!(visitor, visit_expr, end); walk_list!(visitor, visit_expr, end);
} }
ExprKind::Underscore => {} ExprKind::Underscore => {}
ExprKind::Path(ref maybe_qself, ref path) => { ExprKind::Path(maybe_qself, path) => {
if let Some(ref qself) = *maybe_qself { if let Some(qself) = maybe_qself {
visitor.visit_ty(&qself.ty); visitor.visit_ty(&qself.ty);
} }
visitor.visit_path(path, expression.id) visitor.visit_path(path, expression.id)
} }
ExprKind::Break(ref opt_label, ref opt_expr) => { ExprKind::Break(opt_label, opt_expr) => {
walk_list!(visitor, visit_label, opt_label); walk_list!(visitor, visit_label, opt_label);
walk_list!(visitor, visit_expr, opt_expr); walk_list!(visitor, visit_expr, opt_expr);
} }
ExprKind::Continue(ref opt_label) => { ExprKind::Continue(opt_label) => {
walk_list!(visitor, visit_label, opt_label); walk_list!(visitor, visit_label, opt_label);
} }
ExprKind::Ret(ref optional_expression) => { ExprKind::Ret(optional_expression) => {
walk_list!(visitor, visit_expr, optional_expression); walk_list!(visitor, visit_expr, optional_expression);
} }
ExprKind::Yeet(ref optional_expression) => { ExprKind::Yeet(optional_expression) => {
walk_list!(visitor, visit_expr, optional_expression); walk_list!(visitor, visit_expr, optional_expression);
} }
ExprKind::MacCall(ref mac) => visitor.visit_mac_call(mac), ExprKind::MacCall(mac) => visitor.visit_mac_call(mac),
ExprKind::Paren(ref subexpression) => visitor.visit_expr(subexpression), ExprKind::Paren(subexpression) => visitor.visit_expr(subexpression),
ExprKind::InlineAsm(ref asm) => visitor.visit_inline_asm(asm), ExprKind::InlineAsm(asm) => visitor.visit_inline_asm(asm),
ExprKind::Yield(ref optional_expression) => { ExprKind::Yield(optional_expression) => {
walk_list!(visitor, visit_expr, optional_expression); walk_list!(visitor, visit_expr, optional_expression);
} }
ExprKind::Try(ref subexpression) => visitor.visit_expr(subexpression), ExprKind::Try(subexpression) => visitor.visit_expr(subexpression),
ExprKind::TryBlock(ref body) => visitor.visit_block(body), ExprKind::TryBlock(body) => visitor.visit_block(body),
ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err => {} ExprKind::Lit(_) | ExprKind::IncludedBytes(..) | ExprKind::Err => {}
} }
@ -935,8 +925,8 @@ pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) {
} }
pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) { pub fn walk_attribute<'a, V: Visitor<'a>>(visitor: &mut V, attr: &'a Attribute) {
match attr.kind { match &attr.kind {
AttrKind::Normal(ref normal) => walk_mac_args(visitor, &normal.item.args), AttrKind::Normal(normal) => walk_mac_args(visitor, &normal.item.args),
AttrKind::DocComment(..) => {} AttrKind::DocComment(..) => {}
} }
} }