]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_mir_build/src/build/matches/util.rs
Rollup merge of #99480 - miam-miam100:arg-format, r=oli-obk
[rust.git] / compiler / rustc_mir_build / src / build / matches / util.rs
index 4a7edc517f4e4436a73c8e16f16709acabd8e8c3..9a1e98d3bb18ddc8d6b6e646a1de00610ae4ae33 100644 (file)
@@ -31,15 +31,21 @@ pub(crate) fn prefix_slice_suffix<'pat>(
         suffix: &'pat [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 Ok(place_resolved) =
+            place.clone().try_upvars_resolved(tcx, self.typeck_results)
+        {
+            match place_resolved
+                .into_place(tcx, self.typeck_results)
+                .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 =
@@ -94,14 +100,10 @@ pub(crate) fn false_edges(
 }
 
 impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
-    pub(in crate::build) fn new(
+    pub(crate) fn new(
         place: PlaceBuilder<'tcx>,
         pattern: &'pat Pat<'tcx>,
     ) -> MatchPair<'pat, 'tcx> {
-        // Force the place type to the pattern's type.
-        // FIXME(oli-obk): only do this when we don't already know the place type.
-        // FIXME(oli-obk): can we use this to simplify slice/array pattern hacks?
-        let place = place.project(ProjectionElem::OpaqueCast(pattern.ty));
         MatchPair { place, pattern }
     }
 }