Skip to content

Commit e9c3991

Browse files
committed
Auto merge of #7471 - flip1995:ice-7410, r=giraffate
Fix ICE in redundant_pattern_matching Fixes #7410 changelog: Fix ICE in `redundant_pattern_matching` in `no_std` crates.
2 parents 78ffcd9 + b98e2ec commit e9c3991

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

clippy_utils/src/ty.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,12 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symb
257257
}
258258
}
259259

260-
/// Checks if the type is equal to a lang item
260+
/// Checks if the type is equal to a lang item.
261+
///
262+
/// Returns `false` if the `LangItem` is not defined.
261263
pub fn is_type_lang_item(cx: &LateContext<'_>, ty: Ty<'_>, lang_item: hir::LangItem) -> bool {
262264
match ty.kind() {
263-
ty::Adt(adt, _) => cx.tcx.lang_items().require(lang_item).unwrap() == adt.did,
265+
ty::Adt(adt, _) => cx.tcx.lang_items().require(lang_item).map_or(false, |li| li == adt.did),
264266
_ => false,
265267
}
266268
}

tests/ui/crashes/ice-7410.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// compile-flags: -Clink-arg=-nostartfiles
2+
// ignore-macos
3+
// ignore-windows
4+
5+
#![feature(lang_items, start, libc)]
6+
#![no_std]
7+
#![allow(clippy::redundant_pattern_matching)]
8+
9+
use core::panic::PanicInfo;
10+
11+
struct S;
12+
13+
impl Drop for S {
14+
fn drop(&mut self) {}
15+
}
16+
17+
#[start]
18+
fn main(argc: isize, argv: *const *const u8) -> isize {
19+
if let Some(_) = Some(S) {
20+
} else {
21+
}
22+
0
23+
}
24+
25+
#[panic_handler]
26+
fn panic(_info: &PanicInfo) -> ! {
27+
loop {}
28+
}
29+
30+
#[lang = "eh_personality"]
31+
extern "C" fn eh_personality() {}

0 commit comments

Comments
 (0)