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`]
This commit is contained in:
bors 2021-07-19 09:22:34 +00:00
commit f467750680
2 changed files with 29 additions and 1 deletions

View file

@ -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);

25
tests/ui/issue-7447.rs Normal file
View file

@ -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!());
}