Skip to content

Commit

Permalink
Fix ICE in manual_map lint
Browse files Browse the repository at this point in the history
node_args doesn't work with struct literals and expr_ty must be used instead
  • Loading branch information
flip1995 committed Feb 28, 2025
1 parent 2cdb90d commit 900aab7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/crashes/ice-14325.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit 900aab7

Please sign in to comment.