Auto merge of #101709 - nnethercote:simplify-visitors-more, r=cjgillot
Simplify visitors more A successor to #100392. r? `@cjgillot`
This commit is contained in:
commit
a0d1df4a5d
26 changed files with 115 additions and 156 deletions
|
@ -156,8 +156,8 @@ pub trait Visitor<'ast>: Sized {
|
||||||
fn visit_where_predicate(&mut self, p: &'ast WherePredicate) {
|
fn visit_where_predicate(&mut self, p: &'ast WherePredicate) {
|
||||||
walk_where_predicate(self, p)
|
walk_where_predicate(self, p)
|
||||||
}
|
}
|
||||||
fn visit_fn(&mut self, fk: FnKind<'ast>, s: Span, _: NodeId) {
|
fn visit_fn(&mut self, fk: FnKind<'ast>, _: Span, _: NodeId) {
|
||||||
walk_fn(self, fk, s)
|
walk_fn(self, fk)
|
||||||
}
|
}
|
||||||
fn visit_assoc_item(&mut self, i: &'ast AssocItem, ctxt: AssocCtxt) {
|
fn visit_assoc_item(&mut self, i: &'ast AssocItem, ctxt: AssocCtxt) {
|
||||||
walk_assoc_item(self, i, ctxt)
|
walk_assoc_item(self, i, ctxt)
|
||||||
|
@ -201,11 +201,11 @@ pub trait Visitor<'ast>: Sized {
|
||||||
fn visit_use_tree(&mut self, use_tree: &'ast UseTree, id: NodeId, _nested: bool) {
|
fn visit_use_tree(&mut self, use_tree: &'ast UseTree, id: NodeId, _nested: bool) {
|
||||||
walk_use_tree(self, use_tree, id)
|
walk_use_tree(self, use_tree, id)
|
||||||
}
|
}
|
||||||
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'ast PathSegment) {
|
fn visit_path_segment(&mut self, path_segment: &'ast PathSegment) {
|
||||||
walk_path_segment(self, path_span, path_segment)
|
walk_path_segment(self, path_segment)
|
||||||
}
|
}
|
||||||
fn visit_generic_args(&mut self, path_span: Span, generic_args: &'ast GenericArgs) {
|
fn visit_generic_args(&mut self, generic_args: &'ast GenericArgs) {
|
||||||
walk_generic_args(self, path_span, generic_args)
|
walk_generic_args(self, generic_args)
|
||||||
}
|
}
|
||||||
fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArg) {
|
fn visit_generic_arg(&mut self, generic_arg: &'ast GenericArg) {
|
||||||
walk_generic_arg(self, generic_arg)
|
walk_generic_arg(self, generic_arg)
|
||||||
|
@ -435,7 +435,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
|
||||||
|
|
||||||
pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) {
|
pub fn walk_path<'a, V: Visitor<'a>>(visitor: &mut V, path: &'a Path) {
|
||||||
for segment in &path.segments {
|
for segment in &path.segments {
|
||||||
visitor.visit_path_segment(path.span, segment);
|
visitor.visit_path_segment(segment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,18 +457,14 @@ 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>>(
|
pub fn walk_path_segment<'a, V: Visitor<'a>>(visitor: &mut V, segment: &'a PathSegment) {
|
||||||
visitor: &mut V,
|
|
||||||
path_span: Span,
|
|
||||||
segment: &'a PathSegment,
|
|
||||||
) {
|
|
||||||
visitor.visit_ident(segment.ident);
|
visitor.visit_ident(segment.ident);
|
||||||
if let Some(ref args) = segment.args {
|
if let Some(ref args) = segment.args {
|
||||||
visitor.visit_generic_args(path_span, args);
|
visitor.visit_generic_args(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_generic_args<'a, V>(visitor: &mut V, _path_span: Span, generic_args: &'a GenericArgs)
|
pub fn walk_generic_args<'a, V>(visitor: &mut V, generic_args: &'a GenericArgs)
|
||||||
where
|
where
|
||||||
V: Visitor<'a>,
|
V: Visitor<'a>,
|
||||||
{
|
{
|
||||||
|
@ -502,7 +498,7 @@ 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(ref gen_args) = constraint.gen_args {
|
||||||
visitor.visit_generic_args(gen_args.span(), gen_args);
|
visitor.visit_generic_args(gen_args);
|
||||||
}
|
}
|
||||||
match constraint.kind {
|
match constraint.kind {
|
||||||
AssocConstraintKind::Equality { ref term } => match term {
|
AssocConstraintKind::Equality { ref term } => match term {
|
||||||
|
@ -659,7 +655,7 @@ pub fn walk_fn_decl<'a, V: Visitor<'a>>(visitor: &mut V, function_declaration: &
|
||||||
visitor.visit_fn_ret_ty(&function_declaration.output);
|
visitor.visit_fn_ret_ty(&function_declaration.output);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>, _span: Span) {
|
pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) {
|
||||||
match kind {
|
match kind {
|
||||||
FnKind::Fn(_, _, sig, _, generics, body) => {
|
FnKind::Fn(_, _, sig, _, generics, body) => {
|
||||||
visitor.visit_generics(generics);
|
visitor.visit_generics(generics);
|
||||||
|
@ -800,7 +796,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
|
||||||
walk_list!(visitor, visit_expr, arguments);
|
walk_list!(visitor, visit_expr, arguments);
|
||||||
}
|
}
|
||||||
ExprKind::MethodCall(ref segment, ref receiver, ref arguments, _span) => {
|
ExprKind::MethodCall(ref segment, ref receiver, ref arguments, _span) => {
|
||||||
visitor.visit_path_segment(expression.span, segment);
|
visitor.visit_path_segment(segment);
|
||||||
visitor.visit_expr(receiver);
|
visitor.visit_expr(receiver);
|
||||||
walk_list!(visitor, visit_expr, arguments);
|
walk_list!(visitor, visit_expr, arguments);
|
||||||
}
|
}
|
||||||
|
|
|
@ -246,9 +246,9 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'hir PathSegment<'hir>) {
|
fn visit_path_segment(&mut self, path_segment: &'hir PathSegment<'hir>) {
|
||||||
self.insert(path_span, path_segment.hir_id, Node::PathSegment(path_segment));
|
self.insert(path_segment.ident.span, path_segment.hir_id, Node::PathSegment(path_segment));
|
||||||
intravisit::walk_path_segment(self, path_span, path_segment);
|
intravisit::walk_path_segment(self, path_segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_ty(&mut self, ty: &'hir Ty<'hir>) {
|
fn visit_ty(&mut self, ty: &'hir Ty<'hir>) {
|
||||||
|
@ -280,12 +280,12 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
||||||
fk: intravisit::FnKind<'hir>,
|
fk: intravisit::FnKind<'hir>,
|
||||||
fd: &'hir FnDecl<'hir>,
|
fd: &'hir FnDecl<'hir>,
|
||||||
b: BodyId,
|
b: BodyId,
|
||||||
s: Span,
|
_: Span,
|
||||||
id: HirId,
|
id: HirId,
|
||||||
) {
|
) {
|
||||||
assert_eq!(self.owner, id.owner);
|
assert_eq!(self.owner, id.owner);
|
||||||
assert_eq!(self.parent_node, id.local_id);
|
assert_eq!(self.parent_node, id.local_id);
|
||||||
intravisit::walk_fn(self, fk, fd, b, s, id);
|
intravisit::walk_fn(self, fk, fd, b, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_block(&mut self, block: &'hir Block<'hir>) {
|
fn visit_block(&mut self, block: &'hir Block<'hir>) {
|
||||||
|
|
|
@ -63,9 +63,9 @@ impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
|
||||||
self.record_lifetime_use(*lifetime);
|
self.record_lifetime_use(*lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'ast PathSegment) {
|
fn visit_path_segment(&mut self, path_segment: &'ast PathSegment) {
|
||||||
self.record_elided_anchor(path_segment.id, path_span);
|
self.record_elided_anchor(path_segment.id, path_segment.ident.span);
|
||||||
visit::walk_path_segment(self, path_span, path_segment);
|
visit::walk_path_segment(self, path_segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef) {
|
fn visit_poly_trait_ref(&mut self, t: &'ast PolyTraitRef) {
|
||||||
|
|
|
@ -223,11 +223,9 @@ impl<'a> AstValidator<'a> {
|
||||||
for (i, segment) in path.segments.iter().enumerate() {
|
for (i, segment) in path.segments.iter().enumerate() {
|
||||||
// Allow `impl Trait` iff we're on the final path segment
|
// Allow `impl Trait` iff we're on the final path segment
|
||||||
if i == path.segments.len() - 1 {
|
if i == path.segments.len() - 1 {
|
||||||
self.visit_path_segment(path.span, segment);
|
self.visit_path_segment(segment);
|
||||||
} else {
|
} else {
|
||||||
self.with_banned_impl_trait(|this| {
|
self.with_banned_impl_trait(|this| this.visit_path_segment(segment));
|
||||||
this.visit_path_segment(path.span, segment)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1293,7 +1291,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mirrors `visit::walk_generic_args`, but tracks relevant state.
|
// Mirrors `visit::walk_generic_args`, but tracks relevant state.
|
||||||
fn visit_generic_args(&mut self, _: Span, generic_args: &'a GenericArgs) {
|
fn visit_generic_args(&mut self, generic_args: &'a GenericArgs) {
|
||||||
match *generic_args {
|
match *generic_args {
|
||||||
GenericArgs::AngleBracketed(ref data) => {
|
GenericArgs::AngleBracketed(ref data) => {
|
||||||
self.check_generic_args_before_constraints(data);
|
self.check_generic_args_before_constraints(data);
|
||||||
|
@ -1529,7 +1527,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
matches!(fk.header(), Some(FnHeader { constness: Const::Yes(_), .. }))
|
matches!(fk.header(), Some(FnHeader { constness: Const::Yes(_), .. }))
|
||||||
|| matches!(fk.ctxt(), Some(FnCtxt::Assoc(_)));
|
|| matches!(fk.ctxt(), Some(FnCtxt::Assoc(_)));
|
||||||
|
|
||||||
self.with_tilde_const(tilde_const_allowed, |this| visit::walk_fn(this, fk, span));
|
self.with_tilde_const(tilde_const_allowed, |this| visit::walk_fn(this, fk));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
|
fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
|
||||||
|
|
|
@ -680,7 +680,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||||
gate_feature_post!(&self, c_variadic, span, "C-variadic functions are unstable");
|
gate_feature_post!(&self, c_variadic, span, "C-variadic functions are unstable");
|
||||||
}
|
}
|
||||||
|
|
||||||
visit::walk_fn(self, fn_kind, span)
|
visit::walk_fn(self, fn_kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_assoc_constraint(&mut self, constraint: &'a AssocConstraint) {
|
fn visit_assoc_constraint(&mut self, constraint: &'a AssocConstraint) {
|
||||||
|
|
|
@ -63,9 +63,9 @@ impl<'ast> Visitor<'ast> for NodeCounter {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
walk_generics(self, g)
|
walk_generics(self, g)
|
||||||
}
|
}
|
||||||
fn visit_fn(&mut self, fk: visit::FnKind<'_>, s: Span, _: NodeId) {
|
fn visit_fn(&mut self, fk: visit::FnKind<'_>, _: Span, _: NodeId) {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
walk_fn(self, fk, s)
|
walk_fn(self, fk)
|
||||||
}
|
}
|
||||||
fn visit_assoc_item(&mut self, ti: &AssocItem, ctxt: AssocCtxt) {
|
fn visit_assoc_item(&mut self, ti: &AssocItem, ctxt: AssocCtxt) {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
|
@ -115,9 +115,9 @@ impl<'ast> Visitor<'ast> for NodeCounter {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
walk_use_tree(self, use_tree, id)
|
walk_use_tree(self, use_tree, id)
|
||||||
}
|
}
|
||||||
fn visit_generic_args(&mut self, path_span: Span, generic_args: &GenericArgs) {
|
fn visit_generic_args(&mut self, generic_args: &GenericArgs) {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
walk_generic_args(self, path_span, generic_args)
|
walk_generic_args(self, generic_args)
|
||||||
}
|
}
|
||||||
fn visit_assoc_constraint(&mut self, constraint: &AssocConstraint) {
|
fn visit_assoc_constraint(&mut self, constraint: &AssocConstraint) {
|
||||||
self.count += 1;
|
self.count += 1;
|
||||||
|
|
|
@ -298,7 +298,7 @@ pub trait Visitor<'v>: Sized {
|
||||||
fn visit_id(&mut self, _hir_id: HirId) {
|
fn visit_id(&mut self, _hir_id: HirId) {
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
}
|
}
|
||||||
fn visit_name(&mut self, _span: Span, _name: Symbol) {
|
fn visit_name(&mut self, _name: Symbol) {
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
}
|
}
|
||||||
fn visit_ident(&mut self, ident: Ident) {
|
fn visit_ident(&mut self, ident: Ident) {
|
||||||
|
@ -361,8 +361,8 @@ pub trait Visitor<'v>: Sized {
|
||||||
fn visit_fn_decl(&mut self, fd: &'v FnDecl<'v>) {
|
fn visit_fn_decl(&mut self, fd: &'v FnDecl<'v>) {
|
||||||
walk_fn_decl(self, fd)
|
walk_fn_decl(self, fd)
|
||||||
}
|
}
|
||||||
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl<'v>, b: BodyId, s: Span, id: HirId) {
|
fn visit_fn(&mut self, fk: FnKind<'v>, fd: &'v FnDecl<'v>, b: BodyId, _: Span, id: HirId) {
|
||||||
walk_fn(self, fk, fd, b, s, id)
|
walk_fn(self, fk, fd, b, id)
|
||||||
}
|
}
|
||||||
fn visit_use(&mut self, path: &'v Path<'v>, hir_id: HirId) {
|
fn visit_use(&mut self, path: &'v Path<'v>, hir_id: HirId) {
|
||||||
walk_use(self, path, hir_id)
|
walk_use(self, path, hir_id)
|
||||||
|
@ -388,8 +388,8 @@ pub trait Visitor<'v>: Sized {
|
||||||
fn visit_param_bound(&mut self, bounds: &'v GenericBound<'v>) {
|
fn visit_param_bound(&mut self, bounds: &'v GenericBound<'v>) {
|
||||||
walk_param_bound(self, bounds)
|
walk_param_bound(self, bounds)
|
||||||
}
|
}
|
||||||
fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef<'v>, m: TraitBoundModifier) {
|
fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef<'v>) {
|
||||||
walk_poly_trait_ref(self, t, m)
|
walk_poly_trait_ref(self, t)
|
||||||
}
|
}
|
||||||
fn visit_variant_data(&mut self, s: &'v VariantData<'v>) {
|
fn visit_variant_data(&mut self, s: &'v VariantData<'v>) {
|
||||||
walk_struct_def(self, s)
|
walk_struct_def(self, s)
|
||||||
|
@ -420,17 +420,18 @@ pub trait Visitor<'v>: Sized {
|
||||||
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
|
fn visit_lifetime(&mut self, lifetime: &'v Lifetime) {
|
||||||
walk_lifetime(self, lifetime)
|
walk_lifetime(self, lifetime)
|
||||||
}
|
}
|
||||||
fn visit_qpath(&mut self, qpath: &'v QPath<'v>, id: HirId, span: Span) {
|
// The span is that of the surrounding type/pattern/expr/whatever.
|
||||||
walk_qpath(self, qpath, id, span)
|
fn visit_qpath(&mut self, qpath: &'v QPath<'v>, id: HirId, _span: Span) {
|
||||||
|
walk_qpath(self, qpath, id)
|
||||||
}
|
}
|
||||||
fn visit_path(&mut self, path: &'v Path<'v>, _id: HirId) {
|
fn visit_path(&mut self, path: &'v Path<'v>, _id: HirId) {
|
||||||
walk_path(self, path)
|
walk_path(self, path)
|
||||||
}
|
}
|
||||||
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment<'v>) {
|
fn visit_path_segment(&mut self, path_segment: &'v PathSegment<'v>) {
|
||||||
walk_path_segment(self, path_span, path_segment)
|
walk_path_segment(self, path_segment)
|
||||||
}
|
}
|
||||||
fn visit_generic_args(&mut self, path_span: Span, generic_args: &'v GenericArgs<'v>) {
|
fn visit_generic_args(&mut self, generic_args: &'v GenericArgs<'v>) {
|
||||||
walk_generic_args(self, path_span, generic_args)
|
walk_generic_args(self, generic_args)
|
||||||
}
|
}
|
||||||
fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding<'v>) {
|
fn visit_assoc_type_binding(&mut self, type_binding: &'v TypeBinding<'v>) {
|
||||||
walk_assoc_type_binding(self, type_binding)
|
walk_assoc_type_binding(self, type_binding)
|
||||||
|
@ -472,7 +473,7 @@ pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local<'v>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) {
|
pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) {
|
||||||
visitor.visit_name(ident.span, ident.name);
|
visitor.visit_name(ident.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) {
|
pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) {
|
||||||
|
@ -494,11 +495,7 @@ pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_poly_trait_ref<'v, V: Visitor<'v>>(
|
pub fn walk_poly_trait_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_ref: &'v PolyTraitRef<'v>) {
|
||||||
visitor: &mut V,
|
|
||||||
trait_ref: &'v PolyTraitRef<'v>,
|
|
||||||
_modifier: TraitBoundModifier,
|
|
||||||
) {
|
|
||||||
walk_list!(visitor, visit_generic_param, trait_ref.bound_generic_params);
|
walk_list!(visitor, visit_generic_param, trait_ref.bound_generic_params);
|
||||||
visitor.visit_trait_ref(&trait_ref.trait_ref);
|
visitor.visit_trait_ref(&trait_ref.trait_ref);
|
||||||
}
|
}
|
||||||
|
@ -519,7 +516,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
|
||||||
ItemKind::ExternCrate(orig_name) => {
|
ItemKind::ExternCrate(orig_name) => {
|
||||||
visitor.visit_id(item.hir_id());
|
visitor.visit_id(item.hir_id());
|
||||||
if let Some(orig_name) = orig_name {
|
if let Some(orig_name) = orig_name {
|
||||||
visitor.visit_name(item.span, orig_name);
|
visitor.visit_name(orig_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ItemKind::Use(ref path, _) => {
|
ItemKind::Use(ref path, _) => {
|
||||||
|
@ -680,7 +677,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
|
||||||
}
|
}
|
||||||
TyKind::TraitObject(bounds, ref lifetime, _syntax) => {
|
TyKind::TraitObject(bounds, ref lifetime, _syntax) => {
|
||||||
for bound in bounds {
|
for bound in bounds {
|
||||||
visitor.visit_poly_trait_ref(bound, TraitBoundModifier::None);
|
visitor.visit_poly_trait_ref(bound);
|
||||||
}
|
}
|
||||||
visitor.visit_lifetime(lifetime);
|
visitor.visit_lifetime(lifetime);
|
||||||
}
|
}
|
||||||
|
@ -693,12 +690,7 @@ pub fn walk_inf<'v, V: Visitor<'v>>(visitor: &mut V, inf: &'v InferArg) {
|
||||||
visitor.visit_id(inf.hir_id);
|
visitor.visit_id(inf.hir_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_qpath<'v, V: Visitor<'v>>(
|
pub fn walk_qpath<'v, V: Visitor<'v>>(visitor: &mut V, qpath: &'v QPath<'v>, id: HirId) {
|
||||||
visitor: &mut V,
|
|
||||||
qpath: &'v QPath<'v>,
|
|
||||||
id: HirId,
|
|
||||||
span: Span,
|
|
||||||
) {
|
|
||||||
match *qpath {
|
match *qpath {
|
||||||
QPath::Resolved(ref maybe_qself, ref path) => {
|
QPath::Resolved(ref maybe_qself, ref path) => {
|
||||||
walk_list!(visitor, visit_ty, maybe_qself);
|
walk_list!(visitor, visit_ty, maybe_qself);
|
||||||
|
@ -706,7 +698,7 @@ pub fn walk_qpath<'v, V: Visitor<'v>>(
|
||||||
}
|
}
|
||||||
QPath::TypeRelative(ref qself, ref segment) => {
|
QPath::TypeRelative(ref qself, ref segment) => {
|
||||||
visitor.visit_ty(qself);
|
visitor.visit_ty(qself);
|
||||||
visitor.visit_path_segment(span, segment);
|
visitor.visit_path_segment(segment);
|
||||||
}
|
}
|
||||||
QPath::LangItem(..) => {}
|
QPath::LangItem(..) => {}
|
||||||
}
|
}
|
||||||
|
@ -714,27 +706,19 @@ pub fn walk_qpath<'v, V: Visitor<'v>>(
|
||||||
|
|
||||||
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>) {
|
pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path<'v>) {
|
||||||
for segment in path.segments {
|
for segment in path.segments {
|
||||||
visitor.visit_path_segment(path.span, segment);
|
visitor.visit_path_segment(segment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_path_segment<'v, V: Visitor<'v>>(
|
pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, segment: &'v PathSegment<'v>) {
|
||||||
visitor: &mut V,
|
|
||||||
path_span: Span,
|
|
||||||
segment: &'v PathSegment<'v>,
|
|
||||||
) {
|
|
||||||
visitor.visit_ident(segment.ident);
|
visitor.visit_ident(segment.ident);
|
||||||
visitor.visit_id(segment.hir_id);
|
visitor.visit_id(segment.hir_id);
|
||||||
if let Some(ref args) = segment.args {
|
if let Some(ref args) = segment.args {
|
||||||
visitor.visit_generic_args(path_span, args);
|
visitor.visit_generic_args(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_generic_args<'v, V: Visitor<'v>>(
|
pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V, generic_args: &'v GenericArgs<'v>) {
|
||||||
visitor: &mut V,
|
|
||||||
_path_span: Span,
|
|
||||||
generic_args: &'v GenericArgs<'v>,
|
|
||||||
) {
|
|
||||||
walk_list!(visitor, visit_generic_arg, generic_args.args);
|
walk_list!(visitor, visit_generic_arg, generic_args.args);
|
||||||
walk_list!(visitor, visit_assoc_type_binding, generic_args.bindings);
|
walk_list!(visitor, visit_assoc_type_binding, generic_args.bindings);
|
||||||
}
|
}
|
||||||
|
@ -745,7 +729,7 @@ pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(
|
||||||
) {
|
) {
|
||||||
visitor.visit_id(type_binding.hir_id);
|
visitor.visit_id(type_binding.hir_id);
|
||||||
visitor.visit_ident(type_binding.ident);
|
visitor.visit_ident(type_binding.ident);
|
||||||
visitor.visit_generic_args(type_binding.span, type_binding.gen_args);
|
visitor.visit_generic_args(type_binding.gen_args);
|
||||||
match type_binding.kind {
|
match type_binding.kind {
|
||||||
TypeBindingKind::Equality { ref term } => match term {
|
TypeBindingKind::Equality { ref term } => match term {
|
||||||
Term::Ty(ref ty) => visitor.visit_ty(ty),
|
Term::Ty(ref ty) => visitor.visit_ty(ty),
|
||||||
|
@ -819,12 +803,12 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v
|
||||||
|
|
||||||
pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound<'v>) {
|
pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound<'v>) {
|
||||||
match *bound {
|
match *bound {
|
||||||
GenericBound::Trait(ref typ, modifier) => {
|
GenericBound::Trait(ref typ, _modifier) => {
|
||||||
visitor.visit_poly_trait_ref(typ, modifier);
|
visitor.visit_poly_trait_ref(typ);
|
||||||
}
|
}
|
||||||
GenericBound::LangItemTrait(_, span, hir_id, args) => {
|
GenericBound::LangItemTrait(_, _span, hir_id, args) => {
|
||||||
visitor.visit_id(hir_id);
|
visitor.visit_id(hir_id);
|
||||||
visitor.visit_generic_args(span, args);
|
visitor.visit_generic_args(args);
|
||||||
}
|
}
|
||||||
GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime),
|
GenericBound::Outlives(ref lifetime) => visitor.visit_lifetime(lifetime),
|
||||||
}
|
}
|
||||||
|
@ -910,7 +894,6 @@ pub fn walk_fn<'v, V: Visitor<'v>>(
|
||||||
function_kind: FnKind<'v>,
|
function_kind: FnKind<'v>,
|
||||||
function_declaration: &'v FnDecl<'v>,
|
function_declaration: &'v FnDecl<'v>,
|
||||||
body_id: BodyId,
|
body_id: BodyId,
|
||||||
_span: Span,
|
|
||||||
id: HirId,
|
id: HirId,
|
||||||
) {
|
) {
|
||||||
visitor.visit_id(id);
|
visitor.visit_id(id);
|
||||||
|
@ -1095,7 +1078,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
|
||||||
walk_list!(visitor, visit_expr, arguments);
|
walk_list!(visitor, visit_expr, arguments);
|
||||||
}
|
}
|
||||||
ExprKind::MethodCall(ref segment, receiver, arguments, _) => {
|
ExprKind::MethodCall(ref segment, receiver, arguments, _) => {
|
||||||
visitor.visit_path_segment(expression.span, segment);
|
visitor.visit_path_segment(segment);
|
||||||
visitor.visit_expr(receiver);
|
visitor.visit_expr(receiver);
|
||||||
walk_list!(visitor, visit_expr, arguments);
|
walk_list!(visitor, visit_expr, arguments);
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
|
||||||
hir::TyKind::TraitObject(bounds, ..) => {
|
hir::TyKind::TraitObject(bounds, ..) => {
|
||||||
for bound in bounds {
|
for bound in bounds {
|
||||||
self.current_index.shift_in(1);
|
self.current_index.shift_in(1);
|
||||||
self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
|
self.visit_poly_trait_ref(bound);
|
||||||
self.current_index.shift_out(1);
|
self.current_index.shift_out(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1467,7 +1467,7 @@ impl TypeAliasBounds {
|
||||||
if TypeAliasBounds::is_type_variable_assoc(qpath) {
|
if TypeAliasBounds::is_type_variable_assoc(qpath) {
|
||||||
self.err.span_help(span, fluent::lint::builtin_type_alias_bounds_help);
|
self.err.span_help(span, fluent::lint::builtin_type_alias_bounds_help);
|
||||||
}
|
}
|
||||||
intravisit::walk_qpath(self, qpath, id, span)
|
intravisit::walk_qpath(self, qpath, id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2000,7 +2000,7 @@ impl KeywordIdents {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EarlyLintPass for KeywordIdents {
|
impl EarlyLintPass for KeywordIdents {
|
||||||
fn check_mac_def(&mut self, cx: &EarlyContext<'_>, mac_def: &ast::MacroDef, _id: ast::NodeId) {
|
fn check_mac_def(&mut self, cx: &EarlyContext<'_>, mac_def: &ast::MacroDef) {
|
||||||
self.check_tokens(cx, mac_def.body.inner_tokens());
|
self.check_tokens(cx, mac_def.body.inner_tokens());
|
||||||
}
|
}
|
||||||
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::MacCall) {
|
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::MacCall) {
|
||||||
|
|
|
@ -147,7 +147,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
|
||||||
fn visit_fn(&mut self, fk: ast_visit::FnKind<'a>, span: Span, id: ast::NodeId) {
|
fn visit_fn(&mut self, fk: ast_visit::FnKind<'a>, span: Span, id: ast::NodeId) {
|
||||||
run_early_pass!(self, check_fn, fk, span, id);
|
run_early_pass!(self, check_fn, fk, span, id);
|
||||||
self.check_id(id);
|
self.check_id(id);
|
||||||
ast_visit::walk_fn(self, fk, span);
|
ast_visit::walk_fn(self, fk);
|
||||||
|
|
||||||
// Explicitly check for lints associated with 'closure_id', since
|
// Explicitly check for lints associated with 'closure_id', since
|
||||||
// it does not have a corresponding AST node
|
// it does not have a corresponding AST node
|
||||||
|
@ -266,9 +266,9 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
|
||||||
ast_visit::walk_path(self, p);
|
ast_visit::walk_path(self, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_path_segment(&mut self, path_span: Span, s: &'a ast::PathSegment) {
|
fn visit_path_segment(&mut self, s: &'a ast::PathSegment) {
|
||||||
self.check_id(s.id);
|
self.check_id(s.id);
|
||||||
ast_visit::walk_path_segment(self, path_span, s);
|
ast_visit::walk_path_segment(self, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
|
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
|
||||||
|
@ -276,7 +276,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mac_def(&mut self, mac: &'a ast::MacroDef, id: ast::NodeId) {
|
fn visit_mac_def(&mut self, mac: &'a ast::MacroDef, id: ast::NodeId) {
|
||||||
run_early_pass!(self, check_mac_def, mac, id);
|
run_early_pass!(self, check_mac_def, mac);
|
||||||
self.check_id(id);
|
self.check_id(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,8 +76,8 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> {
|
||||||
self.context.param_env = old_param_env;
|
self.context.param_env = old_param_env;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_mod(&mut self, m: &'tcx hir::Mod<'tcx>, s: Span, n: hir::HirId) {
|
fn process_mod(&mut self, m: &'tcx hir::Mod<'tcx>, n: hir::HirId) {
|
||||||
lint_callback!(self, check_mod, m, s, n);
|
lint_callback!(self, check_mod, m, n);
|
||||||
hir_visit::walk_mod(self, m, n);
|
hir_visit::walk_mod(self, m, n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
||||||
let old_cached_typeck_results = self.context.cached_typeck_results.take();
|
let old_cached_typeck_results = self.context.cached_typeck_results.take();
|
||||||
let body = self.context.tcx.hir().body(body_id);
|
let body = self.context.tcx.hir().body(body_id);
|
||||||
lint_callback!(self, check_fn, fk, decl, body, span, id);
|
lint_callback!(self, check_fn, fk, decl, body, span, id);
|
||||||
hir_visit::walk_fn(self, fk, decl, body_id, span, id);
|
hir_visit::walk_fn(self, fk, decl, body_id, id);
|
||||||
self.context.enclosing_body = old_enclosing_body;
|
self.context.enclosing_body = old_enclosing_body;
|
||||||
self.context.cached_typeck_results.set(old_cached_typeck_results);
|
self.context.cached_typeck_results.set(old_cached_typeck_results);
|
||||||
}
|
}
|
||||||
|
@ -220,9 +220,9 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
||||||
hir_visit::walk_inf(self, inf);
|
hir_visit::walk_inf(self, inf);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_mod(&mut self, m: &'tcx hir::Mod<'tcx>, s: Span, n: hir::HirId) {
|
fn visit_mod(&mut self, m: &'tcx hir::Mod<'tcx>, _: Span, n: hir::HirId) {
|
||||||
if !self.context.only_module {
|
if !self.context.only_module {
|
||||||
self.process_mod(m, s, n);
|
self.process_mod(m, n);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,13 +258,9 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
||||||
hir_visit::walk_where_predicate(self, p);
|
hir_visit::walk_where_predicate(self, p);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_poly_trait_ref(
|
fn visit_poly_trait_ref(&mut self, t: &'tcx hir::PolyTraitRef<'tcx>) {
|
||||||
&mut self,
|
lint_callback!(self, check_poly_trait_ref, t);
|
||||||
t: &'tcx hir::PolyTraitRef<'tcx>,
|
hir_visit::walk_poly_trait_ref(self, t);
|
||||||
m: hir::TraitBoundModifier,
|
|
||||||
) {
|
|
||||||
lint_callback!(self, check_poly_trait_ref, t, m);
|
|
||||||
hir_visit::walk_poly_trait_ref(self, t, m);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
|
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
|
||||||
|
@ -358,8 +354,8 @@ fn late_lint_mod_pass<'tcx, T: LateLintPass<'tcx>>(
|
||||||
|
|
||||||
let mut cx = LateContextAndPass { context, pass };
|
let mut cx = LateContextAndPass { context, pass };
|
||||||
|
|
||||||
let (module, span, hir_id) = tcx.hir().get_module(module_def_id);
|
let (module, _span, hir_id) = tcx.hir().get_module(module_def_id);
|
||||||
cx.process_mod(module, span, hir_id);
|
cx.process_mod(module, hir_id);
|
||||||
|
|
||||||
// Visit the crate attributes
|
// Visit the crate attributes
|
||||||
if hir_id == hir::CRATE_HIR_ID {
|
if hir_id == hir::CRATE_HIR_ID {
|
||||||
|
|
|
@ -327,13 +327,7 @@ impl NonSnakeCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
|
impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
|
||||||
fn check_mod(
|
fn check_mod(&mut self, cx: &LateContext<'_>, _: &'tcx hir::Mod<'tcx>, id: hir::HirId) {
|
||||||
&mut self,
|
|
||||||
cx: &LateContext<'_>,
|
|
||||||
_: &'tcx hir::Mod<'tcx>,
|
|
||||||
_: Span,
|
|
||||||
id: hir::HirId,
|
|
||||||
) {
|
|
||||||
if id != hir::CRATE_HIR_ID {
|
if id != hir::CRATE_HIR_ID {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ macro_rules! late_lint_methods {
|
||||||
fn check_body_post(a: &$hir hir::Body<$hir>);
|
fn check_body_post(a: &$hir hir::Body<$hir>);
|
||||||
fn check_crate();
|
fn check_crate();
|
||||||
fn check_crate_post();
|
fn check_crate_post();
|
||||||
fn check_mod(a: &$hir hir::Mod<$hir>, b: Span, c: hir::HirId);
|
fn check_mod(a: &$hir hir::Mod<$hir>, b: hir::HirId);
|
||||||
fn check_foreign_item(a: &$hir hir::ForeignItem<$hir>);
|
fn check_foreign_item(a: &$hir hir::ForeignItem<$hir>);
|
||||||
fn check_item(a: &$hir hir::Item<$hir>);
|
fn check_item(a: &$hir hir::Item<$hir>);
|
||||||
fn check_item_post(a: &$hir hir::Item<$hir>);
|
fn check_item_post(a: &$hir hir::Item<$hir>);
|
||||||
|
@ -31,7 +31,7 @@ macro_rules! late_lint_methods {
|
||||||
fn check_ty(a: &$hir hir::Ty<$hir>);
|
fn check_ty(a: &$hir hir::Ty<$hir>);
|
||||||
fn check_generic_param(a: &$hir hir::GenericParam<$hir>);
|
fn check_generic_param(a: &$hir hir::GenericParam<$hir>);
|
||||||
fn check_generics(a: &$hir hir::Generics<$hir>);
|
fn check_generics(a: &$hir hir::Generics<$hir>);
|
||||||
fn check_poly_trait_ref(a: &$hir hir::PolyTraitRef<$hir>, b: hir::TraitBoundModifier);
|
fn check_poly_trait_ref(a: &$hir hir::PolyTraitRef<$hir>);
|
||||||
fn check_fn(
|
fn check_fn(
|
||||||
a: rustc_hir::intravisit::FnKind<$hir>,
|
a: rustc_hir::intravisit::FnKind<$hir>,
|
||||||
b: &$hir hir::FnDecl<$hir>,
|
b: &$hir hir::FnDecl<$hir>,
|
||||||
|
@ -162,7 +162,7 @@ macro_rules! early_lint_methods {
|
||||||
fn check_impl_item(a: &ast::AssocItem);
|
fn check_impl_item(a: &ast::AssocItem);
|
||||||
fn check_variant(a: &ast::Variant);
|
fn check_variant(a: &ast::Variant);
|
||||||
fn check_attribute(a: &ast::Attribute);
|
fn check_attribute(a: &ast::Attribute);
|
||||||
fn check_mac_def(a: &ast::MacroDef, b: ast::NodeId);
|
fn check_mac_def(a: &ast::MacroDef);
|
||||||
fn check_mac(a: &ast::MacCall);
|
fn check_mac(a: &ast::MacCall);
|
||||||
|
|
||||||
/// Called when entering a syntax node that can have lint attributes such
|
/// Called when entering a syntax node that can have lint attributes such
|
||||||
|
|
|
@ -362,11 +362,11 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
|
||||||
fk: hir_visit::FnKind<'v>,
|
fk: hir_visit::FnKind<'v>,
|
||||||
fd: &'v hir::FnDecl<'v>,
|
fd: &'v hir::FnDecl<'v>,
|
||||||
b: hir::BodyId,
|
b: hir::BodyId,
|
||||||
s: Span,
|
_: Span,
|
||||||
id: hir::HirId,
|
id: hir::HirId,
|
||||||
) {
|
) {
|
||||||
self.record("FnDecl", Id::None, fd);
|
self.record("FnDecl", Id::None, fd);
|
||||||
hir_visit::walk_fn(self, fk, fd, b, s, id)
|
hir_visit::walk_fn(self, fk, fd, b, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_use(&mut self, p: &'v hir::Path<'v>, hir_id: hir::HirId) {
|
fn visit_use(&mut self, p: &'v hir::Path<'v>, hir_id: hir::HirId) {
|
||||||
|
@ -447,14 +447,14 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
|
||||||
hir_visit::walk_path(self, path)
|
hir_visit::walk_path(self, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v hir::PathSegment<'v>) {
|
fn visit_path_segment(&mut self, path_segment: &'v hir::PathSegment<'v>) {
|
||||||
self.record("PathSegment", Id::None, path_segment);
|
self.record("PathSegment", Id::None, path_segment);
|
||||||
hir_visit::walk_path_segment(self, path_span, path_segment)
|
hir_visit::walk_path_segment(self, path_segment)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_generic_args(&mut self, sp: Span, ga: &'v hir::GenericArgs<'v>) {
|
fn visit_generic_args(&mut self, ga: &'v hir::GenericArgs<'v>) {
|
||||||
self.record("GenericArgs", Id::None, ga);
|
self.record("GenericArgs", Id::None, ga);
|
||||||
hir_visit::walk_generic_args(self, sp, ga)
|
hir_visit::walk_generic_args(self, ga)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_assoc_type_binding(&mut self, type_binding: &'v hir::TypeBinding<'v>) {
|
fn visit_assoc_type_binding(&mut self, type_binding: &'v hir::TypeBinding<'v>) {
|
||||||
|
@ -612,9 +612,9 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
|
||||||
ast_visit::walk_where_predicate(self, p)
|
ast_visit::walk_where_predicate(self, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_fn(&mut self, fk: ast_visit::FnKind<'v>, s: Span, _: NodeId) {
|
fn visit_fn(&mut self, fk: ast_visit::FnKind<'v>, _: Span, _: NodeId) {
|
||||||
self.record("FnDecl", Id::None, fk.decl());
|
self.record("FnDecl", Id::None, fk.decl());
|
||||||
ast_visit::walk_fn(self, fk, s)
|
ast_visit::walk_fn(self, fk)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_assoc_item(&mut self, i: &'v ast::AssocItem, ctxt: ast_visit::AssocCtxt) {
|
fn visit_assoc_item(&mut self, i: &'v ast::AssocItem, ctxt: ast_visit::AssocCtxt) {
|
||||||
|
@ -652,21 +652,21 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> {
|
||||||
// one non-inline use (in `ast::Path::segments`). The latter case is more
|
// one non-inline use (in `ast::Path::segments`). The latter case is more
|
||||||
// common than the former case, so we implement this visitor and tolerate
|
// common than the former case, so we implement this visitor and tolerate
|
||||||
// the double counting in the former case.
|
// the double counting in the former case.
|
||||||
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v ast::PathSegment) {
|
fn visit_path_segment(&mut self, path_segment: &'v ast::PathSegment) {
|
||||||
self.record("PathSegment", Id::None, path_segment);
|
self.record("PathSegment", Id::None, path_segment);
|
||||||
ast_visit::walk_path_segment(self, path_span, path_segment)
|
ast_visit::walk_path_segment(self, path_segment)
|
||||||
}
|
}
|
||||||
|
|
||||||
// `GenericArgs` has one inline use (in `ast::AssocConstraint::gen_args`) and one
|
// `GenericArgs` has one inline use (in `ast::AssocConstraint::gen_args`) and one
|
||||||
// non-inline use (in `ast::PathSegment::args`). The latter case is more
|
// non-inline use (in `ast::PathSegment::args`). The latter case is more
|
||||||
// common, so we implement `visit_generic_args` and tolerate the double
|
// common, so we implement `visit_generic_args` and tolerate the double
|
||||||
// counting in the former case.
|
// counting in the former case.
|
||||||
fn visit_generic_args(&mut self, sp: Span, g: &'v ast::GenericArgs) {
|
fn visit_generic_args(&mut self, g: &'v ast::GenericArgs) {
|
||||||
record_variants!(
|
record_variants!(
|
||||||
(self, g, g, Id::None, ast, GenericArgs, GenericArgs),
|
(self, g, g, Id::None, ast, GenericArgs, GenericArgs),
|
||||||
[AngleBracketed, Parenthesized]
|
[AngleBracketed, Parenthesized]
|
||||||
);
|
);
|
||||||
ast_visit::walk_generic_args(self, sp, g)
|
ast_visit::walk_generic_args(self, g)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_attribute(&mut self, attr: &'v ast::Attribute) {
|
fn visit_attribute(&mut self, attr: &'v ast::Attribute) {
|
||||||
|
|
|
@ -1314,7 +1314,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
intravisit::walk_qpath(self, qpath, id, span);
|
intravisit::walk_qpath(self, qpath, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check types of patterns.
|
// Check types of patterns.
|
||||||
|
|
|
@ -154,7 +154,7 @@ impl<'a, 'b> visit::Visitor<'a> for DefCollector<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
visit::walk_fn(self, fn_kind, span);
|
visit::walk_fn(self, fn_kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
|
fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
|
||||||
|
|
|
@ -1030,7 +1030,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
if let Some(ref gen_args) = constraint.gen_args {
|
if let Some(ref gen_args) = constraint.gen_args {
|
||||||
// Forbid anonymous lifetimes in GAT parameters until proper semantics are decided.
|
// Forbid anonymous lifetimes in GAT parameters until proper semantics are decided.
|
||||||
self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
|
self.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
|
||||||
this.visit_generic_args(gen_args.span(), gen_args)
|
this.visit_generic_args(gen_args)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
match constraint.kind {
|
match constraint.kind {
|
||||||
|
@ -1044,10 +1044,10 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'ast PathSegment) {
|
fn visit_path_segment(&mut self, path_segment: &'ast PathSegment) {
|
||||||
if let Some(ref args) = path_segment.args {
|
if let Some(ref args) = path_segment.args {
|
||||||
match &**args {
|
match &**args {
|
||||||
GenericArgs::AngleBracketed(..) => visit::walk_generic_args(self, path_span, args),
|
GenericArgs::AngleBracketed(..) => visit::walk_generic_args(self, args),
|
||||||
GenericArgs::Parenthesized(p_args) => {
|
GenericArgs::Parenthesized(p_args) => {
|
||||||
// Probe the lifetime ribs to know how to behave.
|
// Probe the lifetime ribs to know how to behave.
|
||||||
for rib in self.lifetime_ribs.iter().rev() {
|
for rib in self.lifetime_ribs.iter().rev() {
|
||||||
|
@ -1078,7 +1078,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
||||||
// We have nowhere to introduce generics. Code is malformed,
|
// We have nowhere to introduce generics. Code is malformed,
|
||||||
// so use regular lifetime resolution to avoid spurious errors.
|
// so use regular lifetime resolution to avoid spurious errors.
|
||||||
LifetimeRibKind::Item | LifetimeRibKind::Generics { .. } => {
|
LifetimeRibKind::Item | LifetimeRibKind::Generics { .. } => {
|
||||||
visit::walk_generic_args(self, path_span, args);
|
visit::walk_generic_args(self, args);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
LifetimeRibKind::AnonymousCreateParameter { .. }
|
LifetimeRibKind::AnonymousCreateParameter { .. }
|
||||||
|
@ -3798,7 +3798,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||||
for argument in arguments {
|
for argument in arguments {
|
||||||
self.resolve_expr(argument, None);
|
self.resolve_expr(argument, None);
|
||||||
}
|
}
|
||||||
self.visit_path_segment(expr.span, segment);
|
self.visit_path_segment(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExprKind::Call(ref callee, ref arguments) => {
|
ExprKind::Call(ref callee, ref arguments) => {
|
||||||
|
|
|
@ -682,7 +682,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||||
let scope = Scope::TraitRefBoundary { s: self.scope };
|
let scope = Scope::TraitRefBoundary { s: self.scope };
|
||||||
self.with(scope, |this| {
|
self.with(scope, |this| {
|
||||||
for bound in bounds {
|
for bound in bounds {
|
||||||
this.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None);
|
this.visit_poly_trait_ref(bound);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
match lifetime.name {
|
match lifetime.name {
|
||||||
|
@ -1105,11 +1105,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_poly_trait_ref(
|
fn visit_poly_trait_ref(&mut self, trait_ref: &'tcx hir::PolyTraitRef<'tcx>) {
|
||||||
&mut self,
|
|
||||||
trait_ref: &'tcx hir::PolyTraitRef<'tcx>,
|
|
||||||
_modifier: hir::TraitBoundModifier,
|
|
||||||
) {
|
|
||||||
debug!("visit_poly_trait_ref(trait_ref={:?})", trait_ref);
|
debug!("visit_poly_trait_ref(trait_ref={:?})", trait_ref);
|
||||||
|
|
||||||
let (mut binders, scope_type) = self.poly_trait_ref_binder_info();
|
let (mut binders, scope_type) = self.poly_trait_ref_binder_info();
|
||||||
|
@ -1827,7 +1823,7 @@ fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxIndexSet<
|
||||||
// is, those would be potentially inputs to
|
// is, those would be potentially inputs to
|
||||||
// projections
|
// projections
|
||||||
if let Some(last_segment) = path.segments.last() {
|
if let Some(last_segment) = path.segments.last() {
|
||||||
self.visit_path_segment(path.span, last_segment);
|
self.visit_path_segment(last_segment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1306,7 +1306,7 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
|
||||||
if let hir::QPath::Resolved(_, path) = path {
|
if let hir::QPath::Resolved(_, path) = path {
|
||||||
self.write_sub_paths_truncated(path);
|
self.write_sub_paths_truncated(path);
|
||||||
}
|
}
|
||||||
intravisit::walk_qpath(self, path, t.hir_id, t.span);
|
intravisit::walk_qpath(self, path, t.hir_id);
|
||||||
}
|
}
|
||||||
hir::TyKind::Array(ref ty, ref length) => {
|
hir::TyKind::Array(ref ty, ref length) => {
|
||||||
self.visit_ty(ty);
|
self.visit_ty(ty);
|
||||||
|
|
|
@ -1346,16 +1346,12 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_poly_trait_ref(
|
fn visit_poly_trait_ref(&mut self, tr: &'tcx hir::PolyTraitRef<'tcx>) {
|
||||||
&mut self,
|
|
||||||
tr: &'tcx hir::PolyTraitRef<'tcx>,
|
|
||||||
m: hir::TraitBoundModifier,
|
|
||||||
) {
|
|
||||||
if self.has_late_bound_regions.is_some() {
|
if self.has_late_bound_regions.is_some() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self.outer_index.shift_in(1);
|
self.outer_index.shift_in(1);
|
||||||
intravisit::walk_poly_trait_ref(self, tr, m);
|
intravisit::walk_poly_trait_ref(self, tr);
|
||||||
self.outer_index.shift_out(1);
|
self.outer_index.shift_out(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -425,7 +425,7 @@ struct UnsafeVisitor<'a, 'tcx> {
|
||||||
impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
|
impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
|
||||||
type NestedFilter = nested_filter::All;
|
type NestedFilter = nested_filter::All;
|
||||||
|
|
||||||
fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, span: Span, id: HirId) {
|
fn visit_fn(&mut self, kind: FnKind<'tcx>, decl: &'tcx FnDecl<'_>, body_id: BodyId, _: Span, id: HirId) {
|
||||||
if self.has_unsafe {
|
if self.has_unsafe {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -438,7 +438,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
walk_fn(self, kind, decl, body_id, span, id);
|
walk_fn(self, kind, decl, body_id, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||||
|
|
|
@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_hir::{
|
use rustc_hir::{
|
||||||
def::Res, def_id::DefId, Item, ItemKind, PolyTraitRef, PrimTy, TraitBoundModifier, Ty, TyKind, UseKind,
|
def::Res, def_id::DefId, Item, ItemKind, PolyTraitRef, PrimTy, Ty, TyKind, UseKind,
|
||||||
};
|
};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||||
|
@ -120,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedTypes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_poly_trait_ref(&mut self, cx: &LateContext<'tcx>, poly: &'tcx PolyTraitRef<'tcx>, _: TraitBoundModifier) {
|
fn check_poly_trait_ref(&mut self, cx: &LateContext<'tcx>, poly: &'tcx PolyTraitRef<'tcx>) {
|
||||||
self.check_res_emit(cx, &poly.trait_ref.path.res, poly.trait_ref.path.span);
|
self.check_res_emit(cx, &poly.trait_ref.path.res, poly.trait_ref.path.span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use rustc_hir::FnRetTy::Return;
|
||||||
use rustc_hir::{
|
use rustc_hir::{
|
||||||
BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem,
|
BareFnTy, BodyId, FnDecl, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl, ImplItem,
|
||||||
ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin,
|
ImplItemKind, Item, ItemKind, LangItem, Lifetime, LifetimeName, ParamName, PolyTraitRef, PredicateOrigin,
|
||||||
TraitBoundModifier, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate,
|
TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate,
|
||||||
};
|
};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::hir::nested_filter as middle_nested_filter;
|
use rustc_middle::hir::nested_filter as middle_nested_filter;
|
||||||
|
@ -422,7 +422,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
|
||||||
self.record(&Some(*lifetime));
|
self.record(&Some(*lifetime));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_poly_trait_ref(&mut self, poly_tref: &'tcx PolyTraitRef<'tcx>, tbm: TraitBoundModifier) {
|
fn visit_poly_trait_ref(&mut self, poly_tref: &'tcx PolyTraitRef<'tcx>) {
|
||||||
let trait_ref = &poly_tref.trait_ref;
|
let trait_ref = &poly_tref.trait_ref;
|
||||||
if CLOSURE_TRAIT_BOUNDS.iter().any(|&item| {
|
if CLOSURE_TRAIT_BOUNDS.iter().any(|&item| {
|
||||||
self.cx
|
self.cx
|
||||||
|
@ -435,7 +435,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
|
||||||
sub_visitor.visit_trait_ref(trait_ref);
|
sub_visitor.visit_trait_ref(trait_ref);
|
||||||
self.nested_elision_site_lts.append(&mut sub_visitor.all_lts());
|
self.nested_elision_site_lts.append(&mut sub_visitor.all_lts());
|
||||||
} else {
|
} else {
|
||||||
walk_poly_trait_ref(self, poly_tref, tbm);
|
walk_poly_trait_ref(self, poly_tref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -466,7 +466,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
|
||||||
self.unelided_trait_object_lifetime = true;
|
self.unelided_trait_object_lifetime = true;
|
||||||
}
|
}
|
||||||
for bound in bounds {
|
for bound in bounds {
|
||||||
self.visit_poly_trait_ref(bound, TraitBoundModifier::None);
|
self.visit_poly_trait_ref(bound);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => walk_ty(self, ty),
|
_ => walk_ty(self, ty),
|
||||||
|
|
|
@ -70,7 +70,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
|
||||||
) {
|
) {
|
||||||
if !span.from_expansion() && fn_kind.asyncness() == IsAsync::Async {
|
if !span.from_expansion() && fn_kind.asyncness() == IsAsync::Async {
|
||||||
let mut visitor = AsyncFnVisitor { cx, found_await: false };
|
let mut visitor = AsyncFnVisitor { cx, found_await: false };
|
||||||
walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), span, hir_id);
|
walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), hir_id);
|
||||||
if !visitor.found_await {
|
if !visitor.found_await {
|
||||||
span_lint_and_help(
|
span_lint_and_help(
|
||||||
cx,
|
cx,
|
||||||
|
|
|
@ -326,6 +326,6 @@ impl<'tcx> LateLintPass<'tcx> for Unwrap {
|
||||||
unwrappables: Vec::new(),
|
unwrappables: Vec::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
walk_fn(&mut v, kind, decl, body.id(), span, fn_id);
|
walk_fn(&mut v, kind, decl, body.id(), fn_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1121,7 +1121,7 @@ pub struct ContainsName {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Visitor<'tcx> for ContainsName {
|
impl<'tcx> Visitor<'tcx> for ContainsName {
|
||||||
fn visit_name(&mut self, _: Span, name: Symbol) {
|
fn visit_name(&mut self, name: Symbol) {
|
||||||
if self.name == name {
|
if self.name == name {
|
||||||
self.result = true;
|
self.result = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue