about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_utils/src/lib.rs5
-rw-r--r--tests/ui/crashes/ice-14325.rs17
2 files changed, 21 insertions, 1 deletions
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs
index 3e9429399b3..64955003bd2 100644
--- a/clippy_utils/src/lib.rs
+++ b/clippy_utils/src/lib.rs
@@ -3651,7 +3651,10 @@ pub fn expr_requires_coercion<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -
         ExprKind::Struct(qpath, _, _) => {
             let res = cx.typeck_results().qpath_res(qpath, expr.hir_id);
             if let Some((_, v_def)) = adt_and_variant_of_res(cx, res) {
-                let generic_args = cx.typeck_results().node_args(expr.hir_id);
+                let rustc_ty::Adt(_, generic_args) = cx.typeck_results().expr_ty_adjusted(expr).kind() else {
+                    // This should never happen, but when it does, not linting is the better option.
+                    return true;
+                };
                 v_def
                     .fields
                     .iter()
diff --git a/tests/ui/crashes/ice-14325.rs b/tests/ui/crashes/ice-14325.rs
new file mode 100644
index 00000000000..d762bd6c9e0
--- /dev/null
+++ b/tests/ui/crashes/ice-14325.rs
@@ -0,0 +1,17 @@
+//@check-pass
+
+#![allow(clippy::redundant_pattern_matching)]
+
+struct S<'a> {
+    s: &'a str,
+}
+
+fn foo() -> Option<S<'static>> {
+    if let Some(_) = Some(0) {
+        Some(S { s: "xyz" })
+    } else {
+        None
+    }
+}
+
+fn main() {}