Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
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.
  • Loading branch information
pnkfelix committed May 29, 2018
commit 7f0c8f6638cba650d5a18aaa91d3fdd4ce3c01fa
23 changes: 10 additions & 13 deletions src/librustc_mir/build/matches/mod.rs
Original file line number Diff line number Diff line change
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