From e57441a4adc3b927e088d03a29e81004a81283af Mon Sep 17 00:00:00 2001 From: Devin Ragotzy Date: Mon, 7 Jun 2021 06:58:12 -0400 Subject: [PATCH] Replace use of node_type -> node_type_opt, fix clippy warnings --- clippy_lints/src/disallowed_type.rs | 30 +++++++++---------- .../toml_unknown_key/conf_unknown_key.stderr | 2 +- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/clippy_lints/src/disallowed_type.rs b/clippy_lints/src/disallowed_type.rs index 77f82f1518e9..a0956a90abba 100644 --- a/clippy_lints/src/disallowed_type.rs +++ b/clippy_lints/src/disallowed_type.rs @@ -38,7 +38,7 @@ declare_clippy_lint! { /// ``` pub DISALLOWED_TYPE, nursery, - "default lint description" + "use of a disallowed type" } #[derive(Clone, Debug)] pub struct DisallowedType { @@ -101,8 +101,7 @@ fn walk_to_path(cx: &LateContext<'_>, ty: &Ty<'_>, disallowed: &FxHashSet walk_to_path(cx, mutable.ty, disallowed), - TyKind::Rptr(_, mutable) => walk_to_path(cx, mutable.ty, disallowed), + TyKind::Ptr(mutable) | TyKind::Rptr(_, mutable) => walk_to_path(cx, mutable.ty, disallowed), TyKind::BareFn(barefn) => { for input in barefn.decl.inputs { walk_to_path(cx, input, disallowed); @@ -111,7 +110,6 @@ fn walk_to_path(cx: &LateContext<'_>, ty: &Ty<'_>, disallowed: &FxHashSet {}, TyKind::Tup(tup) => { for t in *tup { walk_to_path(cx, t, disallowed); @@ -147,7 +145,8 @@ fn walk_to_path(cx: &LateContext<'_>, ty: &Ty<'_>, disallowed: &FxHashSet { if_chain! { if let Some(tyck) = cx.maybe_typeck_results(); - if let ty::Adt(ty::AdtDef { did, .. }, _) = tyck.node_type(anonconst.hir_id).kind(); + if let Some(var_ty) = tyck.node_type_opt(anonconst.hir_id); + if let ty::Adt(ty::AdtDef { did, .. }, _) = var_ty.kind(); let use_path = cx.get_def_path(*did); if let Some(name) = disallowed.iter().find(|path| **path == use_path); then { @@ -164,14 +163,13 @@ fn walk_to_path(cx: &LateContext<'_>, ty: &Ty<'_>, disallowed: &FxHashSet {}, - TyKind::Err => {}, + TyKind::Infer | TyKind::Never | TyKind::Err => {}, } } fn walk_path_segments(cx: &LateContext<'_>, path: &Path<'_>, disallowed: &FxHashSet>) { - for arg in path.segments.iter().flat_map(|s| s.args) { - walk_gen_args(cx, arg, disallowed) + for arg in path.segments.iter().filter_map(|s| s.args) { + walk_gen_args(cx, arg, disallowed); } } @@ -199,12 +197,12 @@ fn walk_trait_obj(cx: &LateContext<'_>, poly: &[&PolyTraitRef<'_>], disallowed: for param in poly.bound_generic_params { walk_gen_bounds(cx, param.bounds, disallowed); match param.kind { - GenericParamKind::Type { default: Some(ty), .. } => walk_to_path(cx, &ty, disallowed), + GenericParamKind::Type { default: Some(ty), .. } => walk_to_path(cx, ty, disallowed), GenericParamKind::Const { ty, default: Some(anon), } => { - walk_to_path(cx, &ty, disallowed); + walk_to_path(cx, ty, disallowed); walk_to_path( cx, &Ty { @@ -222,7 +220,7 @@ fn walk_trait_obj(cx: &LateContext<'_>, poly: &[&PolyTraitRef<'_>], disallowed: } fn walk_gen_args(cx: &LateContext<'_>, gen_args: &GenericArgs<'_>, disallowed: &FxHashSet>) { - for arg in gen_args.args.into_iter() { + for arg in gen_args.args { match arg { GenericArg::Type(t) => walk_to_path(cx, t, disallowed), GenericArg::Const(c) => walk_to_path( @@ -234,12 +232,12 @@ fn walk_gen_args(cx: &LateContext<'_>, gen_args: &GenericArgs<'_>, disallowed: & }, disallowed, ), - _ => {}, + GenericArg::Lifetime(_) => {}, } } - for bind in gen_args.bindings.into_iter() { + for bind in gen_args.bindings { match bind.kind { - TypeBindingKind::Equality { ty } => walk_to_path(cx, &ty, disallowed), + TypeBindingKind::Equality { ty } => walk_to_path(cx, ty, disallowed), TypeBindingKind::Constraint { bounds } => walk_gen_bounds(cx, bounds, disallowed), } walk_gen_args(cx, bind.gen_args, disallowed); @@ -251,7 +249,7 @@ fn walk_gen_bounds(cx: &LateContext<'_>, bounds: &[GenericBound<'_>], disallowed match b { GenericBound::Trait(poly, _) => walk_trait_obj(cx, &[poly], disallowed), GenericBound::LangItemTrait(_, _, _, gen) => walk_gen_args(cx, gen, disallowed), - _ => {}, + GenericBound::Outlives(_) => {}, } } } diff --git a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr index a7be00426c41..06d70b66fda8 100644 --- a/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr +++ b/tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr @@ -1,4 +1,4 @@ -error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `avoid-breaking-exported-api`, `msrv`, `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `pass-by-value-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `max-trait-bounds`, `max-struct-bools`, `max-fn-params-bools`, `warn-on-all-wildcard-imports`, `disallowed-methods`, `unreadable-literal-lint-fractions`, `upper-case-acronyms-aggressive`, `cargo-ignore-publish`, `third-party` at line 5 column 1 +error: error reading Clippy's configuration file `$DIR/clippy.toml`: unknown field `foobar`, expected one of `avoid-breaking-exported-api`, `msrv`, `blacklisted-names`, `cognitive-complexity-threshold`, `cyclomatic-complexity-threshold`, `doc-valid-idents`, `too-many-arguments-threshold`, `type-complexity-threshold`, `single-char-binding-names-threshold`, `too-large-for-stack`, `enum-variant-name-threshold`, `enum-variant-size-threshold`, `verbose-bit-mask-threshold`, `literal-representation-threshold`, `trivial-copy-size-limit`, `pass-by-value-size-limit`, `too-many-lines-threshold`, `array-size-threshold`, `vec-box-size-threshold`, `max-trait-bounds`, `max-struct-bools`, `max-fn-params-bools`, `warn-on-all-wildcard-imports`, `disallowed-methods`, `disallowed-types`, `unreadable-literal-lint-fractions`, `upper-case-acronyms-aggressive`, `cargo-ignore-publish`, `third-party` at line 5 column 1 error: aborting due to previous error