Skip to content

Commit 7f0c8f6

Browse files
committed
Review feedback: Remove a fixme/tbd note and just add a note for the post-NLL future.
Driveby: just inline the two-line `fn inject_borrow` into its one call site and remove its definition.
1 parent a4a5fa2 commit 7f0c8f6

File tree

1 file changed

+10
-13
lines changed
  • src/librustc_mir/build/matches

1 file changed

+10
-13
lines changed

src/librustc_mir/build/matches/mod.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ mod simplify;
3030
mod test;
3131
mod util;
3232

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.
36-
fn 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-
4333
/// ArmHasGuard is isomorphic to a boolean flag. It indicates whether
4434
/// a match arm has a guard expression attached to it.
4535
#[derive(Copy, Clone, Debug)]
@@ -67,8 +57,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
6757
// of `discriminant_place`, specifically by applying `Rvalue::Discriminant`
6858
// (which will work regardless of type) and storing the result in a temp.
6959
//
70-
// FIXME: would just the borrow into `borrowed_input_temp`
71-
// also achieve the desired effect here? TBD.
60+
// NOTE: Under NLL, the above issue should no longer occur because it
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+
7264
let dummy_source_info = self.source_info(span);
7365
let dummy_access = Rvalue::Discriminant(discriminant_place.clone());
7466
let dummy_ty = dummy_access.ty(&self.local_decls, tcx);
@@ -77,7 +69,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
7769

7870
let source_info = self.source_info(span);
7971
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());
8178
let borrowed_input_ty = borrowed_input.ty(&self.local_decls, tcx);
8279
let borrowed_input_temp = self.temp(borrowed_input_ty, span);
8380
self.cfg.push_assign(block, source_info, &borrowed_input_temp, borrowed_input);

0 commit comments

Comments
 (0)