]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_mir_build/src/build/matches/util.rs
Rollup merge of #105715 - estebank:unsatisfied-bounds-label, r=compiler-errors
[rust.git] / compiler / rustc_mir_build / src / build / matches / util.rs
index b854ba47f8f610e4d154a43f321e7a264d333442..cbd494862a01f09ee0debdb8d4bd0eacae39f3d9 100644 (file)
@@ -7,7 +7,6 @@
 use rustc_middle::ty;
 use rustc_middle::ty::TypeVisitable;
 use smallvec::SmallVec;
-use std::convert::TryInto;
 
 impl<'a, 'tcx> Builder<'a, 'tcx> {
     pub(crate) fn field_match_pairs<'pat>(
@@ -18,7 +17,8 @@ pub(crate) fn field_match_pairs<'pat>(
         subpatterns
             .iter()
             .map(|fieldpat| {
-                let place = place.clone().field(fieldpat.field, fieldpat.pattern.ty);
+                let place =
+                    place.clone_project(PlaceElem::Field(fieldpat.field, fieldpat.pattern.ty));
                 MatchPair::new(place, &fieldpat.pattern, self)
             })
             .collect()
@@ -33,26 +33,24 @@ pub(crate) fn prefix_slice_suffix<'pat>(
         suffix: &'pat [Box<Pat<'tcx>>],
     ) {
         let tcx = self.tcx;
-        let (min_length, exact_size) =
-            if let Ok(place_resolved) = place.clone().try_upvars_resolved(self) {
-                match place_resolved.into_place(self).ty(&self.local_decls, tcx).ty.kind() {
-                    ty::Array(_, length) => (length.eval_usize(tcx, self.param_env), true),
-                    _ => ((prefix.len() + suffix.len()).try_into().unwrap(), false),
-                }
-            } else {
-                ((prefix.len() + suffix.len()).try_into().unwrap(), false)
-            };
+        let (min_length, exact_size) = if let Some(place_resolved) = place.try_to_place(self) {
+            match place_resolved.ty(&self.local_decls, tcx).ty.kind() {
+                ty::Array(_, length) => (length.eval_usize(tcx, self.param_env), true),
+                _ => ((prefix.len() + suffix.len()).try_into().unwrap(), false),
+            }
+        } else {
+            ((prefix.len() + suffix.len()).try_into().unwrap(), false)
+        };
 
         match_pairs.extend(prefix.iter().enumerate().map(|(idx, subpattern)| {
             let elem =
                 ProjectionElem::ConstantIndex { offset: idx as u64, min_length, from_end: false };
-            let place = place.clone().project(elem);
-            MatchPair::new(place, subpattern, self)
+            MatchPair::new(place.clone_project(elem), subpattern, self)
         }));
 
         if let Some(subslice_pat) = opt_slice {
             let suffix_len = suffix.len() as u64;
-            let subslice = place.clone().project(ProjectionElem::Subslice {
+            let subslice = place.clone_project(PlaceElem::Subslice {
                 from: prefix.len() as u64,
                 to: if exact_size { min_length - suffix_len } else { suffix_len },
                 from_end: !exact_size,
@@ -67,7 +65,7 @@ pub(crate) fn prefix_slice_suffix<'pat>(
                 min_length,
                 from_end: !exact_size,
             };
-            let place = place.clone().project(elem);
+            let place = place.clone_project(elem);
             MatchPair::new(place, subpattern, self)
         }));
     }
@@ -97,15 +95,15 @@ pub(crate) fn false_edges(
 
 impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
     pub(in crate::build) fn new(
-        place: PlaceBuilder<'tcx>,
+        mut place: PlaceBuilder<'tcx>,
         pattern: &'pat Pat<'tcx>,
         cx: &Builder<'_, 'tcx>,
     ) -> MatchPair<'pat, 'tcx> {
         // Force the place type to the pattern's type.
         // FIXME(oli-obk): can we use this to simplify slice/array pattern hacks?
-        let mut place = match place.try_upvars_resolved(cx) {
-            Ok(val) | Err(val) => val,
-        };
+        if let Some(resolved) = place.resolve_upvar(cx) {
+            place = resolved;
+        }
 
         // Only add the OpaqueCast projection if the given place is an opaque type and the
         // expected type from the pattern is not.