Skip to content

Commit d03596f

Browse files
committed
guard rest_when_destructuring_struct against panics
1 parent c86fea7 commit d03596f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

clippy_lints/src/rest_when_destructuring_struct.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::rustc_lint::LintContext as _;
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use itertools::Itertools;
4+
use rustc_abi::VariantIdx;
45
use rustc_lint::LateLintPass;
56
use rustc_middle::ty;
67
use rustc_session::declare_lint_pass;
@@ -53,7 +54,9 @@ impl<'tcx> LateLintPass<'tcx> for RestWhenDestructuringStruct {
5354
let qty = cx.typeck_results().qpath_res(&path, pat.hir_id);
5455
let ty = cx.typeck_results().pat_ty(pat);
5556
if let ty::Adt(a, _) = ty.kind() {
56-
let vid = a.variant_index_with_id(qty.def_id());
57+
let vid = qty
58+
.opt_def_id()
59+
.map_or(VariantIdx::ZERO, |x| a.variant_index_with_id(x));
5760
let mut rest_fields = a.variants()[vid]
5861
.fields
5962
.iter()

0 commit comments

Comments
 (0)