Skip to content

Commit 7312611

Browse files
committed
Add check if ty has_escaping_bound_vars in zero_sized_map_values lint
1 parent 78ffcd9 commit 7312611

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

clippy_lints/src/zero_sized_map_values.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use clippy_utils::ty::{is_normalizable, is_type_diagnostic_item, match_type};
44
use if_chain::if_chain;
55
use rustc_hir::{self as hir, HirId, ItemKind, Node};
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_middle::ty::{Adt, Ty};
7+
use rustc_middle::ty::{Adt, Ty, TypeFoldable};
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
99
use rustc_span::sym;
1010
use rustc_target::abi::LayoutOf as _;
@@ -52,6 +52,9 @@ impl LateLintPass<'_> for ZeroSizedMapValues {
5252
if is_type_diagnostic_item(cx, ty, sym::hashmap_type) || match_type(cx, ty, &paths::BTREEMAP);
5353
if let Adt(_, substs) = ty.kind();
5454
let ty = substs.type_at(1);
55+
// Fixes https://github.com/rust-lang/rust-clippy/issues/7447 because of
56+
// https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/sty.rs#L968
57+
if !ty.has_escaping_bound_vars();
5558
// Do this to prevent `layout_of` crashing, being unable to fully normalize `ty`.
5659
if is_normalizable(cx, cx.param_env, ty);
5760
if let Ok(layout) = cx.layout_of(ty);

tests/ui/issue-7447.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use std::{borrow::Cow, collections::BTreeMap, marker::PhantomData, sync::Arc};
2+
3+
fn byte_view<'a>(s: &'a ByteView<'_>) -> BTreeMap<&'a str, ByteView<'a>> {
4+
panic!()
5+
}
6+
7+
fn group_entries(s: &()) -> BTreeMap<Cow<'_, str>, Vec<Cow<'_, str>>> {
8+
todo!()
9+
}
10+
11+
struct Mmap;
12+
13+
enum ByteViewBacking<'a> {
14+
Buf(Cow<'a, [u8]>),
15+
Mmap(Mmap),
16+
}
17+
18+
pub struct ByteView<'a> {
19+
backing: Arc<ByteViewBacking<'a>>,
20+
}
21+
22+
fn main() {
23+
byte_view(panic!());
24+
group_entries(panic!());
25+
}

0 commit comments

Comments
 (0)