]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/zero_sized_map_values.rs
Merge remote-tracking branch 'upstream/master' into rustup
[rust.git] / clippy_lints / src / zero_sized_map_values.rs
index 1d5fa8d06a996092ba5ff39d066a68fb40c319c2..319b85ac42a805d29336cff18f3196eb3206fa30 100644 (file)
@@ -6,7 +6,7 @@
 use rustc_target::abi::LayoutOf as _;
 use rustc_typeck::hir_ty_to_ty;
 
-use crate::utils::{is_type_diagnostic_item, match_type, paths, span_lint_and_help};
+use crate::utils::{is_normalizable, is_type_diagnostic_item, match_type, paths, span_lint_and_help};
 
 declare_clippy_lint! {
     /// **What it does:** Checks for maps with zero-sized value types anywhere in the code.
@@ -50,6 +50,8 @@ fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>) {
             if is_type_diagnostic_item(cx, ty, sym!(hashmap_type)) || match_type(cx, ty, &paths::BTREEMAP);
             if let Adt(_, ref substs) = ty.kind();
             let ty = substs.type_at(1);
+            // Do this to prevent `layout_of` crashing, being unable to fully normalize `ty`.
+            if is_normalizable(cx, cx.param_env, ty);
             if let Ok(layout) = cx.layout_of(ty);
             if layout.is_zst();
             then {
@@ -62,7 +64,7 @@ fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>) {
 fn in_trait_impl(cx: &LateContext<'_>, hir_id: HirId) -> bool {
     let parent_id = cx.tcx.hir().get_parent_item(hir_id);
     if let Some(Node::Item(item)) = cx.tcx.hir().find(cx.tcx.hir().get_parent_item(parent_id)) {
-        if let ItemKind::Impl { of_trait: Some(_), .. } = item.kind {
+        if let ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) = item.kind {
             return true;
         }
     }