提交 ed943976 编写于 作者: B bors

Auto merge of #54260 - maxdeviant:public-scope-fields, r=petrochenkov

Make rustc::middle::region::Scope's fields public

This PR makes the following changes to `rustc::middle::region::Scope`:

- [x] Makes `region::Scope`'s fields public
- [x] Removes the `impl Scope` block with constructors (as per [this comment](https://github.com/rust-lang/rust/pull/54032#discussion_r216618208))
- [x] Updates call sites throughout the compiler

Closes #54122.
......@@ -556,7 +556,10 @@ fn add_exiting_edge(&mut self,
target_scope: region::Scope,
to_index: CFGIndex) {
let mut data = CFGEdgeData { exiting_scopes: vec![] };
let mut scope = region::Scope::Node(from_expr.hir_id.local_id);
let mut scope = region::Scope {
id: from_expr.hir_id.local_id,
data: region::ScopeData::Node
};
let region_scope_tree = self.tcx.region_scope_tree(self.owner_def_id);
while scope != target_scope {
data.exiting_scopes.push(scope.item_local_id());
......@@ -586,8 +589,11 @@ fn find_scope_edge(&self,
Ok(loop_id) => {
for b in &self.breakable_block_scopes {
if b.block_expr_id == self.tcx.hir.node_to_hir_id(loop_id).local_id {
let scope_id = self.tcx.hir.node_to_hir_id(loop_id).local_id;
return (region::Scope::Node(scope_id), match scope_cf_kind {
let scope = region::Scope {
id: self.tcx.hir.node_to_hir_id(loop_id).local_id,
data: region::ScopeData::Node
};
return (scope, match scope_cf_kind {
ScopeCfKind::Break => b.break_index,
ScopeCfKind::Continue => bug!("can't continue to block"),
});
......@@ -595,8 +601,11 @@ fn find_scope_edge(&self,
}
for l in &self.loop_scopes {
if l.loop_id == self.tcx.hir.node_to_hir_id(loop_id).local_id {
let scope_id = self.tcx.hir.node_to_hir_id(loop_id).local_id;
return (region::Scope::Node(scope_id), match scope_cf_kind {
let scope = region::Scope {
id: self.tcx.hir.node_to_hir_id(loop_id).local_id,
data: region::ScopeData::Node
};
return (scope, match scope_cf_kind {
ScopeCfKind::Break => l.break_index,
ScopeCfKind::Continue => l.continue_index,
});
......
......@@ -118,7 +118,7 @@ pub fn note_and_explain_region(
return;
}
};
let scope_decorated_tag = match scope.data() {
let scope_decorated_tag = match scope.data {
region::ScopeData::Node => tag,
region::ScopeData::CallSite => "scope of call-site for function",
region::ScopeData::Arguments => "scope of function body",
......
......@@ -317,7 +317,11 @@ pub fn consume_body(&mut self, body: &hir::Body) {
debug!("consume_body: arg_ty = {:?}", arg_ty);
let fn_body_scope_r =
self.tcx().mk_region(ty::ReScope(region::Scope::Node(body.value.hir_id.local_id)));
self.tcx().mk_region(ty::ReScope(
region::Scope {
id: body.value.hir_id.local_id,
data: region::ScopeData::Node
}));
let arg_cmt = Rc::new(self.mc.cat_rvalue(
arg.hir_id,
arg.pat.span,
......@@ -558,7 +562,10 @@ fn walk_callee(&mut self, call: &hir::Expr, callee: &hir::Expr) {
_ => {
if let Some(def) = self.mc.tables.type_dependent_defs().get(call.hir_id) {
let def_id = def.def_id();
let call_scope = region::Scope::Node(call.hir_id.local_id);
let call_scope = region::Scope {
id: call.hir_id.local_id,
data: region::ScopeData::Node
};
match OverloadedCallType::from_method_id(self.tcx(), def_id) {
FnMutOverloadedCall => {
let call_scope_r = self.tcx().mk_region(ty::ReScope(call_scope));
......@@ -766,7 +773,10 @@ fn walk_autoref(&mut self,
// treated as borrowing it for the enclosing temporary
// scope.
let r = self.tcx().mk_region(ty::ReScope(
region::Scope::Node(expr.hir_id.local_id)));
region::Scope {
id: expr.hir_id.local_id,
data: region::ScopeData::Node
}));
self.delegate.borrow(expr.id,
expr.span,
......
......@@ -102,8 +102,8 @@
/// generated via deriving here.
#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Hash, Copy, RustcEncodable, RustcDecodable)]
pub struct Scope {
pub(crate) id: hir::ItemLocalId,
pub(crate) data: ScopeData,
pub id: hir::ItemLocalId,
pub data: ScopeData,
}
impl fmt::Debug for Scope {
......@@ -172,48 +172,6 @@ pub struct FirstStatementIndex { .. }
#[cfg(not(stage0))]
static ASSERT: () = [()][!(mem::size_of::<ScopeData>() == 4) as usize];
#[allow(non_snake_case)]
impl Scope {
#[inline]
pub fn data(self) -> ScopeData {
self.data
}
#[inline]
pub fn new(id: hir::ItemLocalId, data: ScopeData) -> Self {
Scope { id, data }
}
#[inline]
pub fn Node(id: hir::ItemLocalId) -> Self {
Self::new(id, ScopeData::Node)
}
#[inline]
pub fn CallSite(id: hir::ItemLocalId) -> Self {
Self::new(id, ScopeData::CallSite)
}
#[inline]
pub fn Arguments(id: hir::ItemLocalId) -> Self {
Self::new(id, ScopeData::Arguments)
}
#[inline]
pub fn Destruction(id: hir::ItemLocalId) -> Self {
Self::new(id, ScopeData::Destruction)
}
#[inline]
pub fn Remainder(
id: hir::ItemLocalId,
first: FirstStatementIndex,
) -> Self {
Self::new(id, ScopeData::Remainder(first))
}
}
impl Scope {
/// Returns a item-local id associated with this scope.
///
......@@ -244,7 +202,7 @@ pub fn span(&self, tcx: TyCtxt, scope_tree: &ScopeTree) -> Span {
return DUMMY_SP;
}
let span = tcx.hir.span(node_id);
if let ScopeData::Remainder(first_statement_index) = self.data() {
if let ScopeData::Remainder(first_statement_index) = self.data {
if let Node::Block(ref blk) = tcx.hir.get(node_id) {
// Want span for scope starting after the
// indexed statement and ending at end of
......@@ -498,7 +456,7 @@ pub fn record_scope_parent(&mut self, child: Scope, parent: Option<(Scope, Scope
}
// record the destruction scopes for later so we can query them
if let ScopeData::Destruction = child.data() {
if let ScopeData::Destruction = child.data {
self.destruction_scopes.insert(child.item_local_id(), child);
}
}
......@@ -578,10 +536,10 @@ pub fn temporary_scope(&self, expr_id: hir::ItemLocalId) -> Option<Scope> {
// if there's one. Static items, for instance, won't
// have an enclosing scope, hence no scope will be
// returned.
let mut id = Scope::Node(expr_id);
let mut id = Scope { id: expr_id, data: ScopeData::Node };
while let Some(&(p, _)) = self.parent_map.get(&id) {
match p.data() {
match p.data {
ScopeData::Destruction => {
debug!("temporary_scope({:?}) = {:?} [enclosing]",
expr_id, id);
......@@ -637,7 +595,7 @@ pub fn is_subscope_of(&self,
/// Returns the id of the innermost containing body
pub fn containing_body(&self, mut scope: Scope)-> Option<hir::ItemLocalId> {
loop {
if let ScopeData::CallSite = scope.data() {
if let ScopeData::CallSite = scope.data {
return Some(scope.item_local_id());
}
......@@ -730,7 +688,7 @@ pub fn early_free_scope<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
self.root_body.unwrap().local_id
});
Scope::CallSite(scope)
Scope { id: scope, data: ScopeData::CallSite }
}
/// Assuming that the provided region was defined within this `ScopeTree`,
......@@ -750,7 +708,7 @@ pub fn free_scope<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, fr: &ty::FreeReg
let param_owner_id = tcx.hir.as_local_node_id(param_owner).unwrap();
let body_id = tcx.hir.body_owned_by(param_owner_id);
Scope::CallSite(tcx.hir.body(body_id).value.hir_id.local_id)
Scope { id: tcx.hir.body(body_id).value.hir_id.local_id, data: ScopeData::CallSite }
}
/// Checks whether the given scope contains a `yield`. If so,
......@@ -854,7 +812,10 @@ fn resolve_block<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, blk:
// except for the first such subscope, which has the
// block itself as a parent.
visitor.enter_scope(
Scope::Remainder(blk.hir_id.local_id, FirstStatementIndex::new(i))
Scope {
id: blk.hir_id.local_id,
data: ScopeData::Remainder(FirstStatementIndex::new(i))
}
);
visitor.cx.var_parent = visitor.cx.parent;
}
......@@ -879,7 +840,7 @@ fn resolve_arm<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, arm: &
}
fn resolve_pat<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, pat: &'tcx hir::Pat) {
visitor.record_child_scope(Scope::Node(pat.hir_id.local_id));
visitor.record_child_scope(Scope { id: pat.hir_id.local_id, data: ScopeData::Node });
// If this is a binding then record the lifetime of that binding.
if let PatKind::Binding(..) = pat.node {
......@@ -1008,7 +969,7 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr:
if let hir::ExprKind::Yield(..) = expr.node {
// Mark this expr's scope and all parent scopes as containing `yield`.
let mut scope = Scope::Node(expr.hir_id.local_id);
let mut scope = Scope { id: expr.hir_id.local_id, data: ScopeData::Node };
loop {
visitor.scope_tree.yield_in_scope.insert(scope,
(expr.span, visitor.expr_and_pat_count));
......@@ -1016,7 +977,7 @@ fn resolve_expr<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, expr:
// Keep traversing up while we can.
match visitor.scope_tree.parent_map.get(&scope) {
// Don't cross from closure bodies to their parent.
Some(&(superscope, _)) => match superscope.data() {
Some(&(superscope, _)) => match superscope.data {
ScopeData::CallSite => break,
_ => scope = superscope
},
......@@ -1280,9 +1241,9 @@ fn enter_node_scope_with_dtor(&mut self, id: hir::ItemLocalId) {
// account for the destruction scope representing the scope of
// the destructors that run immediately after it completes.
if self.terminating_scopes.contains(&id) {
self.enter_scope(Scope::Destruction(id));
self.enter_scope(Scope { id, data: ScopeData::Destruction });
}
self.enter_scope(Scope::Node(id));
self.enter_scope(Scope { id, data: ScopeData::Node });
}
}
......@@ -1315,8 +1276,8 @@ fn visit_body(&mut self, body: &'tcx hir::Body) {
}
self.cx.root_id = Some(body.value.hir_id.local_id);
self.enter_scope(Scope::CallSite(body.value.hir_id.local_id));
self.enter_scope(Scope::Arguments(body.value.hir_id.local_id));
self.enter_scope(Scope { id: body.value.hir_id.local_id, data: ScopeData::CallSite });
self.enter_scope(Scope { id: body.value.hir_id.local_id, data: ScopeData::Arguments });
// The arguments and `self` are parented to the fn.
self.cx.var_parent = self.cx.parent.take();
......
......@@ -769,7 +769,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", br)
}
ty::ReScope(scope) if cx.identify_regions => {
match scope.data() {
match scope.data {
region::ScopeData::Node =>
write!(f, "'{}s", scope.item_local_id().as_usize()),
region::ScopeData::CallSite =>
......
......@@ -767,8 +767,12 @@ pub fn analyze_restrictions_on_use(&self,
let mut ret = UseOk;
let scope = region::Scope {
id: expr_id,
data: region::ScopeData::Node
};
self.each_in_scope_loan_affecting_path(
region::Scope::Node(expr_id), use_path, |loan| {
scope, use_path, |loan| {
if !compatible_borrow_kinds(loan.kind, borrow_kind) {
ret = UseWhileBorrowed(loan.loan_path.clone(), loan.span);
false
......@@ -886,7 +890,10 @@ fn check_assignment(&self,
// Check that we don't invalidate any outstanding loans
if let Some(loan_path) = opt_loan_path(assignee_cmt) {
let scope = region::Scope::Node(assignment_id);
let scope = region::Scope {
id: assignment_id,
data: region::ScopeData::Node
};
self.each_in_scope_loan_affecting_path(scope, &loan_path, |loan| {
self.report_illegal_mutation(assignment_span, &loan_path, loan);
false
......
......@@ -43,7 +43,10 @@ pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>,
let mut glcx = GatherLoanCtxt {
bccx,
all_loans: Vec::new(),
item_ub: region::Scope::Node(bccx.tcx.hir.body(body).value.hir_id.local_id),
item_ub: region::Scope {
id: bccx.tcx.hir.body(body).value.hir_id.local_id,
data: region::ScopeData::Node
},
move_data: MoveData::default(),
move_error_collector: move_error::MoveErrorCollector::new(),
};
......@@ -375,7 +378,10 @@ fn guarantee_valid(&mut self,
};
debug!("loan_scope = {:?}", loan_scope);
let borrow_scope = region::Scope::Node(borrow_id);
let borrow_scope = region::Scope {
id: borrow_id,
data: region::ScopeData::Node
};
let gen_scope = self.compute_gen_scope(borrow_scope, loan_scope);
debug!("gen_scope = {:?}", gen_scope);
......
......@@ -441,7 +441,7 @@ pub fn kill_scope(&self, bccx: &BorrowckCtxt<'a, 'tcx>) -> region::Scope {
LpUpvar(upvar_id) => {
let block_id = closure_to_block(upvar_id.closure_expr_id, bccx.tcx);
let hir_id = bccx.tcx.hir.node_to_hir_id(block_id);
region::Scope::Node(hir_id.local_id)
region::Scope { id: hir_id.local_id, data: region::ScopeData::Node }
}
LpDowncast(ref base, _) |
LpExtend(ref base, ..) => base.kill_scope(bccx),
......
......@@ -198,7 +198,7 @@ pub fn tcx(&self) -> TyCtxt<'a, 'gcx, 'tcx> {
pub fn create_region_hierarchy(&mut self, rh: &RH,
parent: (region::Scope, region::ScopeDepth)) {
let me = region::Scope::Node(rh.id);
let me = region::Scope { id: rh.id, data: region::ScopeData::Node };
self.region_scope_tree.record_scope_parent(me, Some(parent));
for child_rh in rh.sub {
self.create_region_hierarchy(child_rh, (me, parent.1 + 1));
......@@ -209,7 +209,10 @@ pub fn create_simple_region_hierarchy(&mut self) {
// creates a region hierarchy where 1 is root, 10 and 11 are
// children of 1, etc
let dscope = region::Scope::Destruction(hir::ItemLocalId(1));
let dscope = region::Scope {
id: hir::ItemLocalId(1),
data: region::ScopeData::Destruction
};
self.region_scope_tree.record_scope_parent(dscope, None);
self.create_region_hierarchy(&RH {
id: hir::ItemLocalId(1),
......@@ -355,7 +358,10 @@ pub fn t_rptr_late_bound_with_debruijn(&self,
}
pub fn t_rptr_scope(&self, id: u32) -> Ty<'tcx> {
let r = ty::ReScope(region::Scope::Node(hir::ItemLocalId(id)));
let r = ty::ReScope(region::Scope {
id: hir::ItemLocalId(id),
data: region::ScopeData::Node
});
self.infcx.tcx.mk_imm_ref(self.infcx.tcx.mk_region(r), self.tcx().types.isize)
}
......
......@@ -51,7 +51,7 @@ pub fn push_end_region<'a, 'gcx:'a+'tcx>(&mut self,
source_info: SourceInfo,
region_scope: region::Scope) {
if tcx.emit_end_regions() {
if let region::ScopeData::CallSite = region_scope.data() {
if let region::ScopeData::CallSite = region_scope.data {
// The CallSite scope (aka the root scope) is sort of weird, in that it is
// supposed to "separate" the "interior" and "exterior" of a closure. Being
// that, it is not really a part of the region hierarchy, but for some
......
......@@ -550,8 +550,14 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
upvar_decls);
let fn_def_id = tcx.hir.local_def_id(fn_id);
let call_site_scope = region::Scope::CallSite(body.value.hir_id.local_id);
let arg_scope = region::Scope::Arguments(body.value.hir_id.local_id);
let call_site_scope = region::Scope {
id: body.value.hir_id.local_id,
data: region::ScopeData::CallSite
};
let arg_scope = region::Scope {
id: body.value.hir_id.local_id,
data: region::ScopeData::Arguments
};
let mut block = START_BLOCK;
let source_info = builder.source_info(span);
let call_site_s = (call_site_scope, source_info);
......
......@@ -565,7 +565,7 @@ pub fn region_scope_of_return_scope(&self) -> region::Scope {
// The outermost scope (`scopes[0]`) will be the `CallSiteScope`.
// We want `scopes[1]`, which is the `ParameterScope`.
assert!(self.scopes.len() >= 2);
assert!(match self.scopes[1].region_scope.data() {
assert!(match self.scopes[1].region_scope.data {
region::ScopeData::Arguments => true,
_ => false,
});
......
......@@ -157,7 +157,10 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
) -> Self {
let scope_tree = tcx.region_scope_tree(def_id);
let root_scope = body_id.map(|body_id| {
region::Scope::CallSite(tcx.hir.body(body_id).value.hir_id.local_id)
region::Scope {
id: tcx.hir.body(body_id).value.hir_id.local_id,
data: region::ScopeData::CallSite
}
});
let mut borrows_out_of_scope_at_location = FxHashMap();
......
......@@ -27,7 +27,10 @@ fn make_mirror<'a, 'gcx>(self, cx: &mut Cx<'a, 'gcx, 'tcx>) -> Block<'tcx> {
cx.region_scope_tree.opt_destruction_scope(self.hir_id.local_id);
Block {
targeted_by_break: self.targeted_by_break,
region_scope: region::Scope::Node(self.hir_id.local_id),
region_scope: region::Scope {
id: self.hir_id.local_id,
data: region::ScopeData::Node
},
opt_destruction_scope,
span: self.span,
stmts,
......@@ -59,7 +62,10 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
hir::StmtKind::Semi(ref expr, _) => {
result.push(StmtRef::Mirror(Box::new(Stmt {
kind: StmtKind::Expr {
scope: region::Scope::Node(hir_id.local_id),
scope: region::Scope {
id: hir_id.local_id,
data: region::ScopeData::Node
},
expr: expr.to_ref(),
},
opt_destruction_scope: opt_dxn_ext,
......@@ -71,10 +77,11 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
// ignore for purposes of the MIR
}
hir::DeclKind::Local(ref local) => {
let remainder_scope = region::Scope::Remainder(
block_id,
region::FirstStatementIndex::new(index),
);
let remainder_scope = region::Scope {
id: block_id,
data: region::ScopeData::Remainder(
region::FirstStatementIndex::new(index)),
};
let mut pattern = cx.pattern_from_hir(&local.pat);
......@@ -94,7 +101,10 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
result.push(StmtRef::Mirror(Box::new(Stmt {
kind: StmtKind::Let {
remainder_scope: remainder_scope,
init_scope: region::Scope::Node(hir_id.local_id),
init_scope: region::Scope {
id: hir_id.local_id,
data: region::ScopeData::Node
},
pattern,
initializer: local.init.to_ref(),
lint_level: cx.lint_level_of(local.id),
......
......@@ -27,7 +27,10 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
fn make_mirror<'a, 'gcx>(self, cx: &mut Cx<'a, 'gcx, 'tcx>) -> Expr<'tcx> {
let temp_lifetime = cx.region_scope_tree.temporary_scope(self.hir_id.local_id);
let expr_scope = region::Scope::Node(self.hir_id.local_id);
let expr_scope = region::Scope {
id: self.hir_id.local_id,
data: region::ScopeData::Node
};
debug!("Expr::make_mirror(): id={}, span={:?}", self.id, self.span);
......@@ -148,7 +151,10 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
// 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::Node(hir_expr.hir_id.local_id));
let region = ty::ReScope(region::Scope {
id: hir_expr.hir_id.local_id,
data: region::ScopeData::Node
});
let region = cx.tcx.mk_region(region);
expr = Expr {
temp_lifetime,
......@@ -581,7 +587,10 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
hir::ExprKind::Break(dest, ref value) => {
match dest.target_id {
Ok(target_id) => ExprKind::Break {
label: region::Scope::Node(cx.tcx.hir.node_to_hir_id(target_id).local_id),
label: region::Scope {
id: cx.tcx.hir.node_to_hir_id(target_id).local_id,
data: region::ScopeData::Node
},
value: value.to_ref(),
},
Err(err) => bug!("invalid loop id for break: {}", err)
......@@ -590,7 +599,10 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
hir::ExprKind::Continue(dest) => {
match dest.target_id {
Ok(loop_id) => ExprKind::Continue {
label: region::Scope::Node(cx.tcx.hir.node_to_hir_id(loop_id).local_id),
label: region::Scope {
id: cx.tcx.hir.node_to_hir_id(loop_id).local_id,
data: region::ScopeData::Node
},
},
Err(err) => bug!("invalid loop id for continue: {}", err)
}
......
......@@ -622,7 +622,10 @@ fn new(infcx: InferCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> Self {
let body_id = item_id.and_then(|id| tcx.hir.maybe_body_owned_by(id));
let implicit_region_bound = body_id.map(|body_id| {
let body = tcx.hir.body(body_id);
tcx.mk_region(ty::ReScope(region::Scope::CallSite(body.value.hir_id.local_id)))
tcx.mk_region(ty::ReScope(region::Scope {
id: body.value.hir_id.local_id,
data: region::ScopeData::CallSite
}))
});
Inherited {
......
......@@ -307,7 +307,10 @@ fn visit_fn_body(&mut self,
let body_id = body.id();
self.body_id = body_id.node_id;
let call_site = region::Scope::CallSite(body.value.hir_id.local_id);
let call_site = region::Scope {
id: body.value.hir_id.local_id,
data: region::ScopeData::CallSite
};
self.call_site_scope = Some(call_site);
let fn_sig = {
......@@ -333,7 +336,12 @@ fn visit_fn_body(&mut self,
&fn_sig_tys[..],
body_id.node_id,
span);
self.link_fn_args(region::Scope::Node(body.value.hir_id.local_id), &body.arguments);
self.link_fn_args(
region::Scope {
id: body.value.hir_id.local_id,
data: region::ScopeData::Node
},
&body.arguments);
self.visit_body(body);
self.visit_region_obligations(body_id.node_id);
......@@ -483,7 +491,10 @@ fn visit_expr(&mut self, expr: &'gcx hir::Expr) {
let expr_ty = self.resolve_node_type(expr.hir_id);
// the region corresponding to this expression
let expr_region = self.tcx.mk_region(ty::ReScope(
region::Scope::Node(expr.hir_id.local_id)));
region::Scope {
id: expr.hir_id.local_id,
data: region::ScopeData::Node
}));
self.type_must_outlive(infer::ExprTypeIsNotInScope(expr_ty, expr.span),
expr_ty, expr_region);
......@@ -766,7 +777,10 @@ fn constrain_call<'b, I: Iterator<Item=&'b hir::Expr>>(&mut self,
// call occurs.
//
// FIXME(#6268) to support nested method calls, should be callee_id
let callee_scope = region::Scope::Node(call_expr.hir_id.local_id);
let callee_scope = region::Scope {
id: call_expr.hir_id.local_id,
data: region::ScopeData::Node
};
let callee_region = self.tcx.mk_region(ty::ReScope(callee_scope));
debug!("callee_region={:?}", callee_region);
......@@ -819,7 +833,10 @@ fn constrain_adjustments(&mut self, expr: &hir::Expr) -> mc::McResult<mc::cmt_<'
self.check_safety_of_rvalue_destructor_if_necessary(&cmt, expr.span);
let expr_region = self.tcx.mk_region(ty::ReScope(
region::Scope::Node(expr.hir_id.local_id)));
region::Scope {
id: expr.hir_id.local_id,
data: region::ScopeData::Node
}));
for adjustment in adjustments {
debug!("constrain_adjustments: adjustment={:?}, cmt={:?}",
adjustment, cmt);
......@@ -913,7 +930,10 @@ fn constrain_index(&mut self,
debug!("constrain_index(index_expr=?, indexed_ty={}",
self.ty_to_string(indexed_ty));
let r_index_expr = ty::ReScope(region::Scope::Node(index_expr.hir_id.local_id));
let r_index_expr = ty::ReScope(region::Scope {
id: index_expr.hir_id.local_id,
data: region::ScopeData::Node
});
if let ty::Ref(r_ptr, r_ty, _) = indexed_ty.sty {
match r_ty.sty {
ty::Slice(_) | ty::Str => {
......@@ -1072,7 +1092,10 @@ fn link_autoref(&self,
}
adjustment::AutoBorrow::RawPtr(m) => {
let r = self.tcx.mk_region(ty::ReScope(region::Scope::Node(expr.hir_id.local_id)));
let r = self.tcx.mk_region(ty::ReScope(region::Scope {
id: expr.hir_id.local_id,
data: region::ScopeData::Node
}));
self.link_region(expr.span, r, ty::BorrowKind::from_mutbl(m), expr_cmt);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册