Skip to content

Commit 2c0889c

Browse files
committed
EUV: fix place of deref pattern's interior's scrutinee
The place previously used here was that of the temporary holding the reference returned by `Deref::deref` or `DerefMut::deref_mut`. However, since the inner pattern of `deref!(inner)` expects the deref-target type itself, this would ICE when that type was inspected (e.g. by the EUV case for slice patterns). This adds a deref projection to fix that. Since current in-tree consumers of EUV (upvar inference and clippy) don't care about Rvalues, the place could be simplified to `self.cat_rvalue(pat.hir_id, self.pat_ty_adjusted(subpat)?)` to save some cycles. I personally find EUV to be a bit fragile, so I've opted for pedantic correctness. Maybe a `HACK` comment would suffice though?
1 parent 0e76f8b commit 2c0889c

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,8 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
18401840
let ty = self.pat_ty_adjusted(subpat)?;
18411841
let ty = Ty::new_ref(self.cx.tcx(), re_erased, ty, mutability);
18421842
// A deref pattern generates a temporary.
1843-
let place = self.cat_rvalue(pat.hir_id, ty);
1843+
let base = self.cat_rvalue(pat.hir_id, ty);
1844+
let place = self.cat_deref(pat.hir_id, base)?;
18441845
self.cat_pattern(place, subpat, op)?;
18451846
}
18461847

tests/crashes/125059.rs renamed to tests/ui/pattern/deref-patterns/euv-ice-125059.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
//@ known-bug: rust-lang/rust#125059
1+
//@ run-pass
2+
//! Regression test for ICE in `rustc_hir_typeck::expr_use_visitor`: rust-lang/rust#125059
3+
24
#![feature(deref_patterns)]
3-
#![allow(incomplete_features)]
5+
#![allow(incomplete_features, unused)]
46

57
fn simple_vec(vec: Vec<u32>) -> u32 {
68
(|| match Vec::<u32>::new() {

0 commit comments

Comments
 (0)