Skip to content

Commit 6f66a60

Browse files
authored
Fix ICE in manual_map lint (#14326)
node_args doesn't work with struct literals and expr_ty must be used instead r? @y21 changelog: none (No changelog, as this ICE didn't make it to the Rust repo, as it was caught during the sync) Fixes #14325
2 parents 2cdb90d + 900aab7 commit 6f66a60

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clippy_utils/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3651,7 +3651,10 @@ pub fn expr_requires_coercion<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -
36513651
ExprKind::Struct(qpath, _, _) => {
36523652
let res = cx.typeck_results().qpath_res(qpath, expr.hir_id);
36533653
if let Some((_, v_def)) = adt_and_variant_of_res(cx, res) {
3654-
let generic_args = cx.typeck_results().node_args(expr.hir_id);
3654+
let rustc_ty::Adt(_, generic_args) = cx.typeck_results().expr_ty_adjusted(expr).kind() else {
3655+
// This should never happen, but when it does, not linting is the better option.
3656+
return true;
3657+
};
36553658
v_def
36563659
.fields
36573660
.iter()

tests/ui/crashes/ice-14325.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@check-pass
2+
3+
#![allow(clippy::redundant_pattern_matching)]
4+
5+
struct S<'a> {
6+
s: &'a str,
7+
}
8+
9+
fn foo() -> Option<S<'static>> {
10+
if let Some(_) = Some(0) {
11+
Some(S { s: "xyz" })
12+
} else {
13+
None
14+
}
15+
}
16+
17+
fn main() {}

0 commit comments

Comments
 (0)