Skip to content

Commit

Permalink
Review feedback: Remove a fixme/tbd note and just add a note for the …
Browse files Browse the repository at this point in the history
…post-NLL future.

Driveby: just inline the two-line `fn inject_borrow` into its one call
site and remove its definition.
  • Loading branch information
pnkfelix committed May 29, 2018
1 parent a4a5fa2 commit 7f0c8f6
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/librustc_mir/build/matches/mod.rs
Expand Up @@ -30,16 +30,6 @@ mod simplify;
mod test;
mod util;

/// Injects a borrow of `place`. The region is unknown at this point; we rely on NLL
/// inference to find an appropriate one. Therefore you can only call this when NLL
/// is turned on.
fn inject_borrow<'a, 'gcx, 'tcx>(tcx: ty::TyCtxt<'a, 'gcx, 'tcx>,
place: Place<'tcx>)
-> Rvalue<'tcx> {
assert!(tcx.use_mir_borrowck());
Rvalue::Ref(tcx.types.re_empty, BorrowKind::Shared, place)
}

/// ArmHasGuard is isomorphic to a boolean flag. It indicates whether
/// a match arm has a guard expression attached to it.
#[derive(Copy, Clone, Debug)]
Expand Down Expand Up @@ -67,8 +57,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
// of `discriminant_place`, specifically by applying `Rvalue::Discriminant`
// (which will work regardless of type) and storing the result in a temp.
//
// FIXME: would just the borrow into `borrowed_input_temp`
// also achieve the desired effect here? TBD.
// NOTE: Under NLL, the above issue should no longer occur because it
// injects a borrow of the matched input, which should have the same effect
// as eddyb's hack. Once NLL is the default, we can remove the hack.

let dummy_source_info = self.source_info(span);
let dummy_access = Rvalue::Discriminant(discriminant_place.clone());
let dummy_ty = dummy_access.ty(&self.local_decls, tcx);
Expand All @@ -77,7 +69,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {

let source_info = self.source_info(span);
let borrowed_input_temp = if tcx.generate_borrow_of_any_match_input() {
let borrowed_input = inject_borrow(tcx, discriminant_place.clone());
// The region is unknown at this point; we rely on NLL
// inference to find an appropriate one. Therefore you can
// only use this when NLL is turned on.
assert!(tcx.use_mir_borrowck());
let borrowed_input =
Rvalue::Ref(tcx.types.re_empty, BorrowKind::Shared, discriminant_place.clone());
let borrowed_input_ty = borrowed_input.ty(&self.local_decls, tcx);
let borrowed_input_temp = self.temp(borrowed_input_ty, span);
self.cfg.push_assign(block, source_info, &borrowed_input_temp, borrowed_input);
Expand Down

0 comments on commit 7f0c8f6

Please sign in to comment.