about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-07-19 09:22:34 +0000
committerbors <bors@rust-lang.org>2021-07-19 09:22:34 +0000
commitf467750680987427d7ff045bbe9e84317140d0aa (patch)
treebb994fa3c4933cbff02e7d7e5899f623e70e5b5e
parentf70a07454b2d1ee44262ceed27a94dd0674cf5ea (diff)
parent7312611207b8f917f1ea9ed759c684d5ca817bfe (diff)
downloadrust-f467750680987427d7ff045bbe9e84317140d0aa.tar.gz
rust-f467750680987427d7ff045bbe9e84317140d0aa.zip
Auto merge of #7470 - DevinR528:fix-ice7447, r=flip1995
Add check if ty has_escaping_bound_vars in zero_sized_map_values lint

Fixes: #7447

changelog: fix ICE in [`zero_sized_map_values`]
-rw-r--r--clippy_lints/src/zero_sized_map_values.rs5
-rw-r--r--tests/ui/issue-7447.rs25
2 files changed, 29 insertions, 1 deletions
diff --git a/clippy_lints/src/zero_sized_map_values.rs b/clippy_lints/src/zero_sized_map_values.rs
index f93f0047f51..053bbc9aea6 100644
--- a/clippy_lints/src/zero_sized_map_values.rs
+++ b/clippy_lints/src/zero_sized_map_values.rs
@@ -4,7 +4,7 @@ use clippy_utils::ty::{is_normalizable, is_type_diagnostic_item, match_type};
 use if_chain::if_chain;
 use rustc_hir::{self as hir, HirId, ItemKind, Node};
 use rustc_lint::{LateContext, LateLintPass};
-use rustc_middle::ty::{Adt, Ty};
+use rustc_middle::ty::{Adt, Ty, TypeFoldable};
 use rustc_session::{declare_lint_pass, declare_tool_lint};
 use rustc_span::sym;
 use rustc_target::abi::LayoutOf as _;
@@ -52,6 +52,9 @@ impl LateLintPass<'_> for ZeroSizedMapValues {
             if is_type_diagnostic_item(cx, ty, sym::hashmap_type) || match_type(cx, ty, &paths::BTREEMAP);
             if let Adt(_, substs) = ty.kind();
             let ty = substs.type_at(1);
+            // Fixes https://github.com/rust-lang/rust-clippy/issues/7447 because of
+            // https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/sty.rs#L968
+            if !ty.has_escaping_bound_vars();
             // 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);
diff --git a/tests/ui/issue-7447.rs b/tests/ui/issue-7447.rs
new file mode 100644
index 00000000000..fdb77f32257
--- /dev/null
+++ b/tests/ui/issue-7447.rs
@@ -0,0 +1,25 @@
+use std::{borrow::Cow, collections::BTreeMap, marker::PhantomData, sync::Arc};
+
+fn byte_view<'a>(s: &'a ByteView<'_>) -> BTreeMap<&'a str, ByteView<'a>> {
+    panic!()
+}
+
+fn group_entries(s: &()) -> BTreeMap<Cow<'_, str>, Vec<Cow<'_, str>>> {
+    todo!()
+}
+
+struct Mmap;
+
+enum ByteViewBacking<'a> {
+    Buf(Cow<'a, [u8]>),
+    Mmap(Mmap),
+}
+
+pub struct ByteView<'a> {
+    backing: Arc<ByteViewBacking<'a>>,
+}
+
+fn main() {
+    byte_view(panic!());
+    group_entries(panic!());
+}