Fix ICE in redundant_pattern_matching

This commit is contained in:
flip1995 2021-07-16 10:45:28 +02:00
parent 78ffcd9959
commit b98e2ec527
No known key found for this signature in database
GPG key ID: 1CA0DF2AF59D68A5
2 changed files with 35 additions and 2 deletions

View file

@ -257,10 +257,12 @@ pub fn is_type_diagnostic_item(cx: &LateContext<'_>, ty: Ty<'_>, diag_item: Symb
}
}
/// Checks if the type is equal to a lang item
/// Checks if the type is equal to a lang item.
///
/// Returns `false` if the `LangItem` is not defined.
pub fn is_type_lang_item(cx: &LateContext<'_>, ty: Ty<'_>, lang_item: hir::LangItem) -> bool {
match ty.kind() {
ty::Adt(adt, _) => cx.tcx.lang_items().require(lang_item).unwrap() == adt.did,
ty::Adt(adt, _) => cx.tcx.lang_items().require(lang_item).map_or(false, |li| li == adt.did),
_ => false,
}
}

View file

@ -0,0 +1,31 @@
// compile-flags: -Clink-arg=-nostartfiles
// ignore-macos
// ignore-windows
#![feature(lang_items, start, libc)]
#![no_std]
#![allow(clippy::redundant_pattern_matching)]
use core::panic::PanicInfo;
struct S;
impl Drop for S {
fn drop(&mut self) {}
}
#[start]
fn main(argc: isize, argv: *const *const u8) -> isize {
if let Some(_) = Some(S) {
} else {
}
0
}
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
#[lang = "eh_personality"]
extern "C" fn eh_personality() {}