Skip to content

Fix ICE in redundant_pattern_matching #7471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions clippy_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
31 changes: 31 additions & 0 deletions tests/ui/crashes/ice-7410.rs
Original file line number Diff line number Diff line change
@@ -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() {}