Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f505572

Browse files
authoredMar 14, 2025
Rollup merge of #138442 - dianne:deref-pat-euv-fix, r=compiler-errors
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? Fixes #125059 r? `@compiler-errors`
2 parents 7de35c8 + 36ff87e commit f505572

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
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

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ check-pass
2+
//! Regression test for ICE in `rustc_hir_typeck::expr_use_visitor` on nesting a slice pattern
3+
//! inside a deref pattern inside a closure: rust-lang/rust#125059
4+
5+
#![feature(deref_patterns)]
6+
#![allow(incomplete_features, unused)]
7+
8+
fn simple_vec(vec: Vec<u32>) -> u32 {
9+
(|| match Vec::<u32>::new() {
10+
deref!([]) => 100,
11+
_ => 2000,
12+
})()
13+
}
14+
15+
fn main() {}

0 commit comments

Comments
 (0)
Failed to load comments.