]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/build/matches/test.rs
Auto merge of #52733 - pnkfelix:issue-51348-make-temp-for-each-candidate-in-arm,...
[rust.git] / src / librustc_mir / build / matches / test.rs
index 913cb944835550be0e97234721aa643bcc5607ed..afa0d28dd77180ebb6eef5e916cda5d9827d2939 100644 (file)
@@ -74,8 +74,8 @@ pub fn test<'pat>(&mut self, match_pair: &MatchPair<'pat, 'tcx>) -> Test<'tcx> {
                 Test {
                     span: match_pair.pattern.span,
                     kind: TestKind::Range {
-                        lo: Literal::Value { value: lo },
-                        hi: Literal::Value { value: hi },
+                        lo,
+                        hi,
                         ty: match_pair.pattern.ty.clone(),
                         end,
                     },
@@ -122,9 +122,10 @@ pub fn add_cases_to_switch<'pat>(&mut self,
 
         match *match_pair.pattern.kind {
             PatternKind::Constant { value } => {
+                let switch_ty = ty::ParamEnv::empty().and(switch_ty);
                 indices.entry(value)
                        .or_insert_with(|| {
-                           options.push(value.unwrap_bits(switch_ty));
+                           options.push(value.unwrap_bits(self.hir.tcx(), switch_ty));
                            options.len() - 1
                        });
                 true
@@ -148,7 +149,7 @@ pub fn add_cases_to_switch<'pat>(&mut self,
     pub fn add_variants_to_switch<'pat>(&mut self,
                                         test_place: &Place<'tcx>,
                                         candidate: &Candidate<'pat, 'tcx>,
-                                        variants: &mut BitVector)
+                                        variants: &mut BitVector<usize>)
                                         -> bool
     {
         let match_pair = match candidate.match_pairs.iter().find(|mp| mp.place == *test_place) {
@@ -259,9 +260,7 @@ pub fn perform_test(&mut self,
 
             TestKind::Eq { value, mut ty } => {
                 let mut val = Operand::Copy(place.clone());
-                let mut expect = self.literal_operand(test.span, ty, Literal::Value {
-                    value
-                });
+                let mut expect = self.literal_operand(test.span, ty, value);
                 // Use PartialEq::eq instead of BinOp::Eq
                 // (the binop can only handle primitives)
                 let fail = self.cfg.start_new_block();
@@ -299,9 +298,7 @@ pub fn perform_test(&mut self,
                                 let array = self.literal_operand(
                                     test.span,
                                     value.ty,
-                                    Literal::Value {
-                                        value
-                                    },
+                                    value,
                                 );
 
                                 let slice = self.temp(ty, test.span);
@@ -312,7 +309,7 @@ pub fn perform_test(&mut self,
                         },
                     }
                     let eq_def_id = self.hir.tcx().lang_items().eq_trait().unwrap();
-                    let (mty, method) = self.hir.trait_method(eq_def_id, "eq", ty, &[ty]);
+                    let (mty, method) = self.hir.trait_method(eq_def_id, "eq", ty, &[ty.into()]);
 
                     // take the argument by reference
                     let region_scope = self.topmost_scope();
@@ -634,6 +631,7 @@ fn candidate_without_match_pair<'pat>(&mut self,
             bindings: candidate.bindings.clone(),
             guard: candidate.guard.clone(),
             arm_index: candidate.arm_index,
+            pat_index: candidate.pat_index,
             pre_binding_block: candidate.pre_binding_block,
             next_candidate_pre_binding_block: candidate.next_candidate_pre_binding_block,
         }
@@ -697,6 +695,7 @@ fn candidate_after_variant_switch<'pat>(&mut self,
             bindings: candidate.bindings.clone(),
             guard: candidate.guard.clone(),
             arm_index: candidate.arm_index,
+            pat_index: candidate.pat_index,
             pre_binding_block: candidate.pre_binding_block,
             next_candidate_pre_binding_block: candidate.next_candidate_pre_binding_block,
         }