summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/librustc_mir/build/matches/mod.rs23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs
index 552066e679..7555827ff0 100644
--- a/src/librustc_mir/build/matches/mod.rs
+++ b/src/librustc_mir/build/matches/mod.rs
@@ -30,16 +30,6 @@ mod simplify;
30mod test; 30mod test;
31mod util; 31mod util;
32 32
33/// Injects a borrow of `place`. The region is unknown at this point; we rely on NLL
34/// inference to find an appropriate one. Therefore you can only call this when NLL
35/// is turned on.
36fn inject_borrow<'a, 'gcx, 'tcx>(tcx: ty::TyCtxt<'a, 'gcx, 'tcx>,
37 place: Place<'tcx>)
38 -> Rvalue<'tcx> {
39 assert!(tcx.use_mir_borrowck());
40 Rvalue::Ref(tcx.types.re_empty, BorrowKind::Shared, place)
41}
42
43/// ArmHasGuard is isomorphic to a boolean flag. It indicates whether 33/// ArmHasGuard is isomorphic to a boolean flag. It indicates whether
44/// a match arm has a guard expression attached to it. 34/// a match arm has a guard expression attached to it.
45#[derive(Copy, Clone, Debug)] 35#[derive(Copy, Clone, Debug)]
@@ -67,8 +57,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
67 // of `discriminant_place`, specifically by applying `Rvalue::Discriminant` 57 // of `discriminant_place`, specifically by applying `Rvalue::Discriminant`
68 // (which will work regardless of type) and storing the result in a temp. 58 // (which will work regardless of type) and storing the result in a temp.
69 // 59 //
70 // FIXME: would just the borrow into `borrowed_input_temp` 60 // NOTE: Under NLL, the above issue should no longer occur because it
71 // also achieve the desired effect here? TBD. 61 // injects a borrow of the matched input, which should have the same effect
62 // as eddyb's hack. Once NLL is the default, we can remove the hack.
63
72 let dummy_source_info = self.source_info(span); 64 let dummy_source_info = self.source_info(span);
73 let dummy_access = Rvalue::Discriminant(discriminant_place.clone()); 65 let dummy_access = Rvalue::Discriminant(discriminant_place.clone());
74 let dummy_ty = dummy_access.ty(&self.local_decls, tcx); 66 let dummy_ty = dummy_access.ty(&self.local_decls, tcx);
@@ -77,7 +69,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
77 69
78 let source_info = self.source_info(span); 70 let source_info = self.source_info(span);
79 let borrowed_input_temp = if tcx.generate_borrow_of_any_match_input() { 71 let borrowed_input_temp = if tcx.generate_borrow_of_any_match_input() {
80 let borrowed_input = inject_borrow(tcx, discriminant_place.clone()); 72 // The region is unknown at this point; we rely on NLL
73 // inference to find an appropriate one. Therefore you can
74 // only use this when NLL is turned on.
75 assert!(tcx.use_mir_borrowck());
76 let borrowed_input =
77 Rvalue::Ref(tcx.types.re_empty, BorrowKind::Shared, discriminant_place.clone());
81 let borrowed_input_ty = borrowed_input.ty(&self.local_decls, tcx); 78 let borrowed_input_ty = borrowed_input.ty(&self.local_decls, tcx);
82 let borrowed_input_temp = self.temp(borrowed_input_ty, span); 79 let borrowed_input_temp = self.temp(borrowed_input_ty, span);
83 self.cfg.push_assign(block, source_info, &borrowed_input_temp, borrowed_input); 80 self.cfg.push_assign(block, source_info, &borrowed_input_temp, borrowed_input);