diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index a66da50c48437..e0fc90931696e 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -67,7 +67,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { block.and(Rvalue::Repeat(value_operand, count)) } ExprKind::Borrow { - region, borrow_kind, arg, } => { @@ -75,7 +74,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { BorrowKind::Shared => unpack!(block = this.as_read_only_place(block, arg)), _ => unpack!(block = this.as_place(block, arg)), }; - block.and(Rvalue::Ref(region, borrow_kind, arg_place)) + block.and(Rvalue::Ref(this.hir.tcx().types.re_erased, borrow_kind, arg_place)) } ExprKind::Binary { op, lhs, rhs } => { let lhs = unpack!(block = this.as_operand(block, scope, lhs)); @@ -249,11 +248,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { BorrowKind::Mut { allow_two_phase_borrow: false, }, - region, arg, } => unpack!( block = this.limit_capture_mutability( - upvar.span, upvar.ty, scope, block, arg, region, + upvar.span, upvar.ty, scope, block, arg, ) ), _ => unpack!(block = this.as_operand(block, scope, upvar)), @@ -500,7 +498,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { temp_lifetime: Option, mut block: BasicBlock, arg: ExprRef<'tcx>, - region: &'tcx ty::RegionKind, ) -> BlockAnd> { let this = self; @@ -582,7 +579,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { block, source_info, &Place::Local(temp), - Rvalue::Ref(region, borrow_kind, arg_place), + Rvalue::Ref(this.hir.tcx().types.re_erased, borrow_kind, arg_place), ); // In constants, temp_lifetime is None. We should not need to drop diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index bc7bb485563ad..d52ce9a67d29a 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -640,7 +640,7 @@ struct Binding<'tcx> { var_id: NodeId, var_ty: Ty<'tcx>, mutability: Mutability, - binding_mode: BindingMode<'tcx>, + binding_mode: BindingMode, } /// Indicates that the type of `source` must be a subtype of the @@ -1369,7 +1369,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { // Assign each of the bindings. Since we are binding for a // guard expression, this will never trigger moves out of the // candidate. - let re_empty = self.hir.tcx().types.re_empty; + let re_erased = self.hir.tcx().types.re_erased; for binding in bindings { let source_info = self.source_info(binding.span); @@ -1385,11 +1385,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { self.schedule_drop_for_binding(binding.var_id, binding.span, RefWithinGuard); match binding.binding_mode { BindingMode::ByValue => { - let rvalue = Rvalue::Ref(re_empty, BorrowKind::Shared, binding.source.clone()); + let rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, binding.source.clone()); self.cfg .push_assign(block, source_info, &ref_for_guard, rvalue); } - BindingMode::ByRef(region, borrow_kind) => { + BindingMode::ByRef(borrow_kind) => { // Tricky business: For `ref id` and `ref mut id` // patterns, we want `id` within the guard to // correspond to a temp of type `& &T` or `& &mut @@ -1429,10 +1429,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { allow_two_phase_borrow: true, }, }; - let rvalue = Rvalue::Ref(region, borrow_kind, binding.source.clone()); + let rvalue = Rvalue::Ref(re_erased, borrow_kind, binding.source.clone()); self.cfg .push_assign(block, source_info, &val_for_guard, rvalue); - let rvalue = Rvalue::Ref(region, BorrowKind::Shared, val_for_guard); + let rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, val_for_guard); self.cfg .push_assign(block, source_info, &ref_for_guard, rvalue); } @@ -1450,6 +1450,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { block, bindings ); + + let re_erased = self.hir.tcx().types.re_erased; // Assign each of the bindings. This may trigger moves out of the candidate. for binding in bindings { let source_info = self.source_info(binding.span); @@ -1460,8 +1462,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { BindingMode::ByValue => { Rvalue::Use(self.consume_by_copy_or_move(binding.source.clone())) } - BindingMode::ByRef(region, borrow_kind) => { - Rvalue::Ref(region, borrow_kind, binding.source.clone()) + BindingMode::ByRef(borrow_kind) => { + Rvalue::Ref(re_erased, borrow_kind, binding.source.clone()) } }; self.cfg.push_assign(block, source_info, &local, rvalue); @@ -1507,7 +1509,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let tcx = self.hir.tcx(); let binding_mode = match mode { BindingMode::ByValue => ty::BindingMode::BindByValue(mutability.into()), - BindingMode::ByRef { .. } => ty::BindingMode::BindByReference(mutability.into()), + BindingMode::ByRef(_) => ty::BindingMode::BindByReference(mutability.into()), }; debug!("declare_binding: user_ty={:?}", user_ty); let local = LocalDecl::<'tcx> { @@ -1545,7 +1547,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let ref_for_guard = self.local_decls.push(LocalDecl::<'tcx> { // See previous comment. mutability: Mutability::Not, - ty: tcx.mk_imm_ref(tcx.types.re_empty, var_ty), + ty: tcx.mk_imm_ref(tcx.types.re_erased, var_ty), user_ty: UserTypeProjections::none(), name: Some(name), source_info, @@ -1614,7 +1616,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { for (matched_place, borrow_kind) in all_fake_borrows { let borrowed_input = - Rvalue::Ref(tcx.types.re_empty, borrow_kind, matched_place.clone()); + Rvalue::Ref(tcx.types.re_erased, borrow_kind, matched_place.clone()); let borrowed_input_ty = borrowed_input.ty(&self.local_decls, tcx); let borrowed_input_temp = self.temp(borrowed_input_ty, source_info.span); self.cfg.push_assign( diff --git a/src/librustc_mir/build/matches/test.rs b/src/librustc_mir/build/matches/test.rs index aae3de68aaae0..696c173b048ad 100644 --- a/src/librustc_mir/build/matches/test.rs +++ b/src/librustc_mir/build/matches/test.rs @@ -304,17 +304,16 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { let (mty, method) = self.hir.trait_method(eq_def_id, "eq", ty, &[ty.into()]); let method = self.hir.tcx().intern_lazy_const(ty::LazyConst::Evaluated(method)); + let re_erased = self.hir.tcx().types.re_erased; // take the argument by reference - let region_scope = self.topmost_scope(); - let region = self.hir.tcx().mk_region(ty::ReScope(region_scope)); let tam = ty::TypeAndMut { ty, mutbl: Mutability::MutImmutable, }; - let ref_ty = self.hir.tcx().mk_ref(region, tam); + let ref_ty = self.hir.tcx().mk_ref(re_erased, tam); // let lhs_ref_place = &lhs; - let ref_rvalue = Rvalue::Ref(region, BorrowKind::Shared, place); + let ref_rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, place); let lhs_ref_place = self.temp(ref_ty, test.span); self.cfg.push_assign(block, source_info, &lhs_ref_place, ref_rvalue); let val = Operand::Move(lhs_ref_place); @@ -324,7 +323,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { self.cfg.push_assign(block, source_info, &rhs_place, Rvalue::Use(expect)); // let rhs_ref_place = &rhs_place; - let ref_rvalue = Rvalue::Ref(region, BorrowKind::Shared, rhs_place); + let ref_rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, rhs_place); let rhs_ref_place = self.temp(ref_ty, test.span); self.cfg.push_assign(block, source_info, &rhs_ref_place, ref_rvalue); let expect = Operand::Move(rhs_ref_place); diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 532e6783f2f2b..eb536fbcf69bb 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -124,7 +124,6 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, }), span, kind: ExprKind::Borrow { - region: deref.region, borrow_kind: deref.mutbl.to_borrow_kind(), arg: expr.to_ref(), }, @@ -132,32 +131,24 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, overloaded_place(cx, hir_expr, adjustment.target, Some(call), vec![expr.to_ref()]) } - Adjust::Borrow(AutoBorrow::Ref(r, m)) => { + Adjust::Borrow(AutoBorrow::Ref(_, m)) => { ExprKind::Borrow { - region: r, borrow_kind: m.to_borrow_kind(), arg: expr.to_ref(), } } Adjust::Borrow(AutoBorrow::RawPtr(m)) => { // Convert this to a suitable `&foo` and - // then an unsafe coercion. Limit the region to be just this - // expression. - let region = ty::ReScope(region::Scope { - id: hir_expr.hir_id.local_id, - data: region::ScopeData::Node - }); - let region = cx.tcx.mk_region(region); + // then an unsafe coercion. expr = Expr { temp_lifetime, - ty: cx.tcx.mk_ref(region, + ty: cx.tcx.mk_ref(cx.tcx.types.re_erased, ty::TypeAndMut { ty: expr.ty, mutbl: m, }), span, kind: ExprKind::Borrow { - region, borrow_kind: m.to_borrow_kind(), arg: expr.to_ref(), }, @@ -323,12 +314,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, } hir::ExprKind::AddrOf(mutbl, ref expr) => { - let region = match expr_ty.sty { - ty::Ref(r, _, _) => r, - _ => span_bug!(expr.span, "type of & not region"), - }; ExprKind::Borrow { - region, borrow_kind: mutbl.to_borrow_kind(), arg: expr.to_ref(), } @@ -1222,7 +1208,6 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, ty: freevar_ty, span: closure_expr.span, kind: ExprKind::Borrow { - region: upvar_borrow.region, borrow_kind, arg: captured_var.to_ref(), }, diff --git a/src/librustc_mir/hair/mod.rs b/src/librustc_mir/hair/mod.rs index 676b98457489f..e902423cd30fc 100644 --- a/src/librustc_mir/hair/mod.rs +++ b/src/librustc_mir/hair/mod.rs @@ -9,7 +9,7 @@ use rustc::hir::def_id::DefId; use rustc::infer::canonical::Canonical; use rustc::middle::region; use rustc::ty::subst::Substs; -use rustc::ty::{AdtDef, UpvarSubsts, Region, Ty, Const, LazyConst, UserTypeAnnotation}; +use rustc::ty::{AdtDef, UpvarSubsts, Ty, Const, LazyConst, UserTypeAnnotation}; use rustc::ty::layout::VariantIdx; use rustc::hir; use syntax::ast; @@ -235,7 +235,6 @@ pub enum ExprKind<'tcx> { id: DefId, }, Borrow { - region: Region<'tcx>, borrow_kind: BorrowKind, arg: ExprRef<'tcx>, }, diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 761bca21fec03..8991a90737c7e 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -39,9 +39,9 @@ pub enum PatternError { } #[derive(Copy, Clone, Debug)] -pub enum BindingMode<'tcx> { +pub enum BindingMode { ByValue, - ByRef(Region<'tcx>, BorrowKind), + ByRef(BorrowKind), } #[derive(Clone, Debug)] @@ -117,7 +117,7 @@ pub enum PatternKind<'tcx> { Binding { mutability: Mutability, name: ast::Name, - mode: BindingMode<'tcx>, + mode: BindingMode, var: ast::NodeId, ty: Ty<'tcx>, subpattern: Option>, @@ -181,7 +181,7 @@ impl<'tcx> fmt::Display for Pattern<'tcx> { PatternKind::Binding { mutability, name, mode, ref subpattern, .. } => { let is_mut = match mode { BindingMode::ByValue => mutability == Mutability::Mut, - BindingMode::ByRef(_, bk) => { + BindingMode::ByRef(bk) => { write!(f, "ref ")?; match bk { BorrowKind::Mut { .. } => true, _ => false } } @@ -512,12 +512,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { PatKind::Binding(_, id, ident, ref sub) => { let var_ty = self.tables.node_id_to_type(pat.hir_id); - let region = match var_ty.sty { - ty::Ref(r, _, _) => Some(r), - ty::Error => { // Avoid ICE - return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) }; - } - _ => None, + if let ty::Error = var_ty.sty { + // Avoid ICE + return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) }; }; let bm = *self.tables.pat_binding_modes().get(pat.hir_id) .expect("missing binding mode"); @@ -528,10 +525,10 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { (Mutability::Not, BindingMode::ByValue), ty::BindByReference(hir::MutMutable) => (Mutability::Not, BindingMode::ByRef( - region.unwrap(), BorrowKind::Mut { allow_two_phase_borrow: false })), + BorrowKind::Mut { allow_two_phase_borrow: false })), ty::BindByReference(hir::MutImmutable) => (Mutability::Not, BindingMode::ByRef( - region.unwrap(), BorrowKind::Shared)), + BorrowKind::Shared)), }; // A ref x pattern is the same node used for x, and as such it has @@ -1042,7 +1039,7 @@ macro_rules! CloneImpls { CloneImpls!{ <'tcx> Span, Field, Mutability, ast::Name, ast::NodeId, usize, ty::Const<'tcx>, - Region<'tcx>, Ty<'tcx>, BindingMode<'tcx>, &'tcx AdtDef, + Region<'tcx>, Ty<'tcx>, BindingMode, &'tcx AdtDef, &'tcx Substs<'tcx>, &'tcx Kind<'tcx>, UserTypeAnnotation<'tcx>, UserTypeProjection<'tcx>, PatternTypeProjection<'tcx> }