Skip to content

Commit

Permalink
Replace use of node_type -> node_type_opt, fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
DevinR528 committed Jun 7, 2021
1 parent 27274e0 commit 2b008d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
28 changes: 13 additions & 15 deletions clippy_lints/src/disallowed_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ fn walk_to_path(cx: &LateContext<'_>, ty: &Ty<'_>, disallowed: &FxHashSet<Vec<Sy
disallowed,
);
},
TyKind::Ptr(mutable) => 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);
Expand All @@ -111,7 +110,6 @@ fn walk_to_path(cx: &LateContext<'_>, ty: &Ty<'_>, disallowed: &FxHashSet<Vec<Sy
walk_to_path(cx, t, disallowed);
}
},
TyKind::Never => {},
TyKind::Tup(tup) => {
for t in *tup {
walk_to_path(cx, t, disallowed);
Expand Down Expand Up @@ -147,7 +145,8 @@ fn walk_to_path(cx: &LateContext<'_>, ty: &Ty<'_>, disallowed: &FxHashSet<Vec<Sy
TyKind::Typeof(anonconst) => {
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 {
Expand All @@ -164,14 +163,13 @@ fn walk_to_path(cx: &LateContext<'_>, ty: &Ty<'_>, disallowed: &FxHashSet<Vec<Sy
}
}
},
TyKind::Infer => {},
TyKind::Err => {},
TyKind::Infer | TyKind::Never | TyKind::Err => {},
}
}

fn walk_path_segments(cx: &LateContext<'_>, path: &Path<'_>, disallowed: &FxHashSet<Vec<Symbol>>) {
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);
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -222,7 +220,7 @@ fn walk_trait_obj(cx: &LateContext<'_>, poly: &[&PolyTraitRef<'_>], disallowed:
}

fn walk_gen_args(cx: &LateContext<'_>, gen_args: &GenericArgs<'_>, disallowed: &FxHashSet<Vec<Symbol>>) {
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(
Expand All @@ -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);
Expand All @@ -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(_) => {},
}
}
}
2 changes: 1 addition & 1 deletion tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2b008d8

Please sign in to comment.