diff options
| author | bors <bors@rust-lang.org> | 2022-07-25 08:12:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-07-25 08:12:15 +0000 |
| commit | af33de7d35262b2bd24394cabd83bd17204802cc (patch) | |
| tree | a5fd6716e3ae7f5212519a5ad4a5607f413a8ec1 | |
| parent | 20e420473064e899c1079c65dddf942b8ca23b7e (diff) | |
| parent | 2255cfd2abd089d14a682c9df0cf2dd2ef697552 (diff) | |
| download | rust-af33de7d35262b2bd24394cabd83bd17204802cc.tar.gz rust-af33de7d35262b2bd24394cabd83bd17204802cc.zip | |
Auto merge of #9244 - Jarcho:ice-9242, r=flip1995
Fix ICE in `question_mark` fixes #9242 changelog: [`question_mark`](https://rust-lang.github.io/rust-clippy/master/#question_mark): Fix ICE on zero field tuple structs
| -rw-r--r-- | clippy_lints/src/question_mark.rs | 4 | ||||
| -rw-r--r-- | tests/ui/crashes/ice-9242.rs | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/clippy_lints/src/question_mark.rs b/clippy_lints/src/question_mark.rs index f0155ed6051..fd0a53839e6 100644 --- a/clippy_lints/src/question_mark.rs +++ b/clippy_lints/src/question_mark.rs @@ -123,8 +123,8 @@ fn check_if_let_some_or_err_and_early_return<'tcx>(cx: &LateContext<'tcx>, expr: if_chain! { if let Some(higher::IfLet { let_pat, let_expr, if_then, if_else }) = higher::IfLet::hir(cx, expr); if !is_else_clause(cx.tcx, expr); - if let PatKind::TupleStruct(ref path1, fields, None) = let_pat.kind; - if let PatKind::Binding(annot, bind_id, ident, _) = fields[0].kind; + if let PatKind::TupleStruct(ref path1, [field], None) = let_pat.kind; + if let PatKind::Binding(annot, bind_id, ident, _) = field.kind; let caller_ty = cx.typeck_results().expr_ty(let_expr); let if_block = IfBlockType::IfLet(path1, caller_ty, ident.name, let_expr, if_then, if_else); if (is_early_return(sym::Option, cx, &if_block) && path_to_local_id(peel_blocks(if_then), bind_id)) diff --git a/tests/ui/crashes/ice-9242.rs b/tests/ui/crashes/ice-9242.rs new file mode 100644 index 00000000000..0099e6e2f34 --- /dev/null +++ b/tests/ui/crashes/ice-9242.rs @@ -0,0 +1,8 @@ +enum E { + X(), + Y, +} + +fn main() { + let _ = if let E::X() = E::X() { 1 } else { 2 }; +} |
