summary refs log tree commit diff
path: root/compiler/rustc_pattern_analysis
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-08-02 20:59:25 +1000
committerZalathar <Zalathar@users.noreply.github.com>2024-08-07 21:44:53 +1000
commit582208b0f26dd448b7a869f3a3e11ad07cd76346 (patch)
tree9e39850eaa8bab643c4511ab6b0b6e09882405b2 /compiler/rustc_pattern_analysis
parenta245bfa61792cfa4c9cf29adae7dbe1b833f705c (diff)
downloadrust-582208b0f26dd448b7a869f3a3e11ad07cd76346.tar.gz
rust-582208b0f26dd448b7a869f3a3e11ad07cd76346.zip
Simplify hoisting of ref patterns (`&` and `&mut`)
Diffstat (limited to 'compiler/rustc_pattern_analysis')
-rw-r--r--compiler/rustc_pattern_analysis/src/rustc.rs7
1 files changed, 1 insertions, 6 deletions
diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs
index bb882e79647..2ddd35923bc 100644
--- a/compiler/rustc_pattern_analysis/src/rustc.rs
+++ b/compiler/rustc_pattern_analysis/src/rustc.rs
@@ -828,7 +828,6 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
         use print::{FieldPat, Pat, PatKind};
         let cx = self;
         let hoist = |p| Box::new(cx.hoist_witness_pat(p));
-        let mut subpatterns = pat.iter_fields().map(hoist);
         let kind = match pat.ctor() {
             Bool(b) => PatKind::Constant { value: mir::Const::from_bool(cx.tcx, *b) },
             IntRange(range) => return self.hoist_pat_range(range, *pat.ty()),
@@ -855,11 +854,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
 
                 PatKind::StructLike { enum_info, subpatterns }
             }
-            // Note: given the expansion of `&str` patterns done in `expand_pattern`, we should
-            // be careful to reconstruct the correct constant pattern here. However a string
-            // literal pattern will never be reported as a non-exhaustiveness witness, so we
-            // ignore this issue.
-            Ref => PatKind::Deref { subpattern: subpatterns.next().unwrap() },
+            Ref => PatKind::Deref { subpattern: hoist(&pat.fields[0]) },
             Slice(slice) => {
                 let (prefix_len, has_dot_dot) = match slice.kind {
                     SliceKind::FixedLen(len) => (len, false),