diff --git a/clippy_lints/src/enum_glob_use.rs b/clippy_lints/src/enum_glob_use.rs index fc15be2476a1..4641bb054313 100644 --- a/clippy_lints/src/enum_glob_use.rs +++ b/clippy_lints/src/enum_glob_use.rs @@ -60,7 +60,7 @@ impl EnumGlobUse { } else { let child = cx.sess().cstore.item_children(def.full_def().def_id()); if let Some(child) = child.first() { - if let Some(Def::Variant(..)) = cx.tcx.sess.cstore.describe_def(child.def_id) { + if let Def::Variant(..) = child.def { span_lint(cx, ENUM_GLOB_USE, item.span, "don't use glob imports for enum variants"); } } diff --git a/clippy_lints/src/no_effect.rs b/clippy_lints/src/no_effect.rs index c0950de6d1ab..f397714e31e0 100644 --- a/clippy_lints/src/no_effect.rs +++ b/clippy_lints/src/no_effect.rs @@ -71,7 +71,9 @@ fn has_no_effect(cx: &LateContext, expr: &Expr) -> bool { let def = cx.tcx.def_map.borrow().get(&callee.id).map(|d| d.full_def()); match def { Some(Def::Struct(..)) | - Some(Def::Variant(..)) => args.iter().all(|arg| has_no_effect(cx, arg)), + Some(Def::Variant(..)) | + Some(Def::StructCtor(..)) | + Some(Def::VariantCtor(..)) => args.iter().all(|arg| has_no_effect(cx, arg)), _ => false, } } @@ -146,7 +148,9 @@ fn reduce_expression<'a>(cx: &LateContext, expr: &'a Expr) -> Option { match cx.tcx.def_map.borrow().get(&callee.id).map(PathResolution::full_def) { Some(Def::Struct(..)) | - Some(Def::Variant(..)) => Some(args.iter().map(Deref::deref).collect()), + Some(Def::Variant(..)) | + Some(Def::StructCtor(..)) | + Some(Def::VariantCtor(..)) => Some(args.iter().map(Deref::deref).collect()), _ => None, } } diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index edec67a8b2bf..6c83d328a004 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -234,10 +234,10 @@ pub fn path_to_def(cx: &LateContext, path: &[&str]) -> Option { for item in &mem::replace(&mut items, vec![]) { if item.name.as_str() == *segment { if path_it.peek().is_none() { - return cx.tcx.sess.cstore.describe_def(item.def_id); + return Some(item.def); } - items = cstore.item_children(item.def_id); + items = cstore.item_children(item.def.def_id()); break; } } @@ -723,7 +723,7 @@ pub fn is_copy<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>, env: Node /// Return whether a pattern is refutable. pub fn is_refutable(cx: &LateContext, pat: &Pat) -> bool { fn is_enum_variant(cx: &LateContext, did: NodeId) -> bool { - matches!(cx.tcx.def_map.borrow().get(&did).map(|d| d.full_def()), Some(def::Def::Variant(..))) + matches!(cx.tcx.def_map.borrow().get(&did).map(|d| d.full_def()), Some(def::Def::Variant(..)) | Some(def::Def::VariantCtor(..))) } fn are_refutable<'a, I: Iterator>(cx: &LateContext, mut i: I) -> bool {