Skip to content

Commit 5c4909b

Browse files
committed
Track mutability of deref patterns
1 parent 1dabacd commit 5c4909b

File tree

6 files changed

+10
-7
lines changed

6 files changed

+10
-7
lines changed

compiler/rustc_middle/src/thir.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl<'tcx> Pat<'tcx> {
642642
AscribeUserType { subpattern, .. }
643643
| Binding { subpattern: Some(subpattern), .. }
644644
| Deref { subpattern }
645-
| DerefPattern { subpattern }
645+
| DerefPattern { subpattern, .. }
646646
| InlineConstant { subpattern, .. } => subpattern.walk_(it),
647647
Leaf { subpatterns } | Variant { subpatterns, .. } => {
648648
subpatterns.iter().for_each(|field| field.pattern.walk_(it))
@@ -760,6 +760,7 @@ pub enum PatKind<'tcx> {
760760
/// Deref pattern, written `box P` for now.
761761
DerefPattern {
762762
subpattern: Box<Pat<'tcx>>,
763+
mutability: hir::Mutability,
763764
},
764765

765766
/// One of the following:
@@ -1163,7 +1164,7 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
11631164
}
11641165
write!(f, "{subpattern}")
11651166
}
1166-
PatKind::DerefPattern { ref subpattern } => {
1167+
PatKind::DerefPattern { ref subpattern, .. } => {
11671168
write!(f, "deref!({subpattern})")
11681169
}
11691170
PatKind::Constant { value } => write!(f, "{value}"),

compiler/rustc_middle/src/thir/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ pub fn walk_pat<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
229229
match &pat.kind {
230230
AscribeUserType { subpattern, ascription: _ }
231231
| Deref { subpattern }
232-
| DerefPattern { subpattern }
232+
| DerefPattern { subpattern, .. }
233233
| Binding { subpattern: Some(subpattern), .. } => visitor.visit_pat(subpattern),
234234
Binding { .. } | Wild | Never | Error(_) => {}
235235
Variant { subpatterns, adt_def: _, args: _, variant_index: _ } | Leaf { subpatterns } => {

compiler/rustc_mir_build/src/build/matches/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
938938
self.visit_primary_bindings(subpattern, pattern_user_ty.deref(), f);
939939
}
940940

941-
PatKind::DerefPattern { ref subpattern } => {
941+
PatKind::DerefPattern { ref subpattern, .. } => {
942942
self.visit_primary_bindings(subpattern, UserTypeProjections::none(), f);
943943
}
944944

compiler/rustc_mir_build/src/build/matches/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
249249
default_irrefutable()
250250
}
251251

252-
PatKind::DerefPattern { ref subpattern } => {
252+
PatKind::DerefPattern { ref subpattern, .. } => {
253253
// Create a new temporary for each deref pattern.
254254
// FIXME(deref_patterns): dedup temporaries to avoid multiple `deref()` calls?
255255
let temp = cx.temp(

compiler/rustc_mir_build/src/thir/pattern/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
264264
}
265265

266266
hir::PatKind::Deref(subpattern) => {
267-
PatKind::DerefPattern { subpattern: self.lower_pattern(subpattern) }
267+
let mutable = self.typeck_results.pat_has_ref_mut_binding(subpattern);
268+
let mutability = if mutable { hir::Mutability::Mut } else { hir::Mutability::Not };
269+
PatKind::DerefPattern { subpattern: self.lower_pattern(subpattern), mutability }
268270
}
269271
hir::PatKind::Ref(subpattern, _) | hir::PatKind::Box(subpattern) => {
270272
PatKind::Deref { subpattern: self.lower_pattern(subpattern) }

compiler/rustc_mir_build/src/thir/print.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
688688
self.print_pat(subpattern, depth_lvl + 2);
689689
print_indented!(self, "}", depth_lvl + 1);
690690
}
691-
PatKind::DerefPattern { subpattern } => {
691+
PatKind::DerefPattern { subpattern, .. } => {
692692
print_indented!(self, "DerefPattern { ", depth_lvl + 1);
693693
print_indented!(self, "subpattern:", depth_lvl + 2);
694694
self.print_pat(subpattern, depth_lvl + 2);

0 commit comments

Comments
 (0)