about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTimo <30553356+y21@users.noreply.github.com>2025-02-28 20:19:03 +0000
committerGitHub <noreply@github.com>2025-02-28 20:19:03 +0000
commit6f66a6037e4246305559e503a53fd42b83d809b3 (patch)
treec16b546629babb79384cbbc1998057ba8ebb317d
parent2cdb90d96136278732c6b1fbe6a79cce2f0292ea (diff)
parent900aab72cd801926ee52ba02d982ae6d92c0df4d (diff)
downloadrust-6f66a6037e4246305559e503a53fd42b83d809b3.tar.gz
rust-6f66a6037e4246305559e503a53fd42b83d809b3.zip
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
-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() {}