Skip to content

Commit 2f2b8b3

Browse files
committed
Auto merge of #44253 - eddyb:nice-scope, r=nikomatsakis
rustc: rename CodeExtent to Scope and RegionMaps to ScopeTree. r? @nikomatsakis
2 parents 23ade23 + 8bdfd8a commit 2f2b8b3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+673
-659
lines changed

src/librustc/cfg/construct.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use rustc_data_structures::graph;
1212
use cfg::*;
13-
use middle::region::CodeExtent;
13+
use middle::region;
1414
use ty::{self, TyCtxt};
1515
use syntax::ptr::P;
1616

@@ -579,14 +579,14 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
579579
fn add_exiting_edge(&mut self,
580580
from_expr: &hir::Expr,
581581
from_index: CFGIndex,
582-
target_scope: CodeExtent,
582+
target_scope: region::Scope,
583583
to_index: CFGIndex) {
584584
let mut data = CFGEdgeData { exiting_scopes: vec![] };
585-
let mut scope = CodeExtent::Misc(from_expr.hir_id.local_id);
586-
let region_maps = self.tcx.region_maps(self.owner_def_id);
585+
let mut scope = region::Scope::Node(from_expr.hir_id.local_id);
586+
let region_scope_tree = self.tcx.region_scope_tree(self.owner_def_id);
587587
while scope != target_scope {
588588
data.exiting_scopes.push(scope.item_local_id());
589-
scope = region_maps.encl_scope(scope);
589+
scope = region_scope_tree.encl_scope(scope);
590590
}
591591
self.graph.add_edge(from_index, to_index, data);
592592
}
@@ -606,14 +606,14 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
606606
fn find_scope_edge(&self,
607607
expr: &hir::Expr,
608608
destination: hir::Destination,
609-
scope_cf_kind: ScopeCfKind) -> (CodeExtent, CFGIndex) {
609+
scope_cf_kind: ScopeCfKind) -> (region::Scope, CFGIndex) {
610610

611611
match destination.target_id {
612612
hir::ScopeTarget::Block(block_expr_id) => {
613613
for b in &self.breakable_block_scopes {
614614
if b.block_expr_id == self.tcx.hir.node_to_hir_id(block_expr_id).local_id {
615615
let scope_id = self.tcx.hir.node_to_hir_id(block_expr_id).local_id;
616-
return (CodeExtent::Misc(scope_id), match scope_cf_kind {
616+
return (region::Scope::Node(scope_id), match scope_cf_kind {
617617
ScopeCfKind::Break => b.break_index,
618618
ScopeCfKind::Continue => bug!("can't continue to block"),
619619
});
@@ -625,7 +625,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
625625
for l in &self.loop_scopes {
626626
if l.loop_id == self.tcx.hir.node_to_hir_id(loop_id).local_id {
627627
let scope_id = self.tcx.hir.node_to_hir_id(loop_id).local_id;
628-
return (CodeExtent::Misc(scope_id), match scope_cf_kind {
628+
return (region::Scope::Node(scope_id), match scope_cf_kind {
629629
ScopeCfKind::Break => l.break_index,
630630
ScopeCfKind::Continue => l.continue_index,
631631
});

src/librustc/dep_graph/dep_node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ define_dep_nodes!( <'tcx>
395395
[] WorkProduct(WorkProductId),
396396

397397
// Represents different phases in the compiler.
398-
[] RegionMaps(DefId),
398+
[] RegionScopeTree(DefId),
399399
[] Coherence,
400400
[] CoherenceInherentImplOverlapCheck,
401401
[] Resolve,

src/librustc/ich/impls_mir.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ for mir::StatementKind<'gcx> {
239239
mir::StatementKind::StorageDead(ref lvalue) => {
240240
lvalue.hash_stable(hcx, hasher);
241241
}
242-
mir::StatementKind::EndRegion(ref extent) => {
243-
extent.hash_stable(hcx, hasher);
242+
mir::StatementKind::EndRegion(ref region_scope) => {
243+
region_scope.hash_stable(hcx, hasher);
244244
}
245245
mir::StatementKind::Validate(ref op, ref lvalues) => {
246246
op.hash_stable(hcx, hasher);
@@ -271,7 +271,7 @@ impl<'a, 'gcx, 'tcx, T> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
271271
}
272272
}
273273

274-
impl_stable_hash_for!(enum mir::ValidationOp { Acquire, Release, Suspend(extent) });
274+
impl_stable_hash_for!(enum mir::ValidationOp { Acquire, Release, Suspend(region_scope) });
275275

276276
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for mir::Lvalue<'gcx> {
277277
fn hash_stable<W: StableHasherResult>(&self,

src/librustc/ich/impls_ty.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
1717
use std::hash as std_hash;
1818
use std::mem;
1919
use syntax_pos::symbol::InternedString;
20+
use middle::region;
2021
use ty;
2122

2223
impl<'a, 'gcx, 'tcx, T> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
@@ -65,8 +66,8 @@ for ty::RegionKind {
6566
index.hash_stable(hcx, hasher);
6667
name.hash_stable(hcx, hasher);
6768
}
68-
ty::ReScope(code_extent) => {
69-
code_extent.hash_stable(hcx, hasher);
69+
ty::ReScope(scope) => {
70+
scope.hash_stable(hcx, hasher);
7071
}
7172
ty::ReFree(ref free_region) => {
7273
free_region.hash_stable(hcx, hasher);
@@ -450,24 +451,22 @@ impl_stable_hash_for!(enum ty::cast::CastKind {
450451
});
451452

452453
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
453-
for ::middle::region::CodeExtent
454+
for region::Scope
454455
{
455456
fn hash_stable<W: StableHasherResult>(&self,
456457
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
457458
hasher: &mut StableHasher<W>) {
458-
use middle::region::CodeExtent;
459-
460459
mem::discriminant(self).hash_stable(hcx, hasher);
461460
match *self {
462-
CodeExtent::Misc(node_id) |
463-
CodeExtent::DestructionScope(node_id) => {
461+
region::Scope::Node(node_id) |
462+
region::Scope::Destruction(node_id) => {
464463
node_id.hash_stable(hcx, hasher);
465464
}
466-
CodeExtent::CallSiteScope(body_id) |
467-
CodeExtent::ParameterScope(body_id) => {
465+
region::Scope::CallSite(body_id) |
466+
region::Scope::Arguments(body_id) => {
468467
body_id.hash_stable(hcx, hasher);
469468
}
470-
CodeExtent::Remainder(block_remainder) => {
469+
region::Scope::Remainder(block_remainder) => {
471470
block_remainder.hash_stable(hcx, hasher);
472471
}
473472
}

src/librustc/infer/error_reporting/mod.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use std::fmt;
6464
use hir;
6565
use hir::map as hir_map;
6666
use hir::def_id::DefId;
67-
use middle::region::{self, RegionMaps};
67+
use middle::region;
6868
use traits::{ObligationCause, ObligationCauseCode};
6969
use ty::{self, Region, TyCtxt, TypeFoldable};
7070
use ty::error::TypeError;
@@ -83,7 +83,7 @@ mod anon_anon_conflict;
8383

8484
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
8585
pub fn note_and_explain_region(self,
86-
region_maps: &RegionMaps,
86+
region_scope_tree: &region::ScopeTree,
8787
err: &mut DiagnosticBuilder,
8888
prefix: &str,
8989
region: ty::Region<'tcx>,
@@ -131,8 +131,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
131131
format!("{}unknown scope: {:?}{}. Please report a bug.",
132132
prefix, scope, suffix)
133133
};
134-
let span = scope.span(self, region_maps);
135-
let tag = match self.hir.find(scope.node_id(self, region_maps)) {
134+
let span = scope.span(self, region_scope_tree);
135+
let tag = match self.hir.find(scope.node_id(self, region_scope_tree)) {
136136
Some(hir_map::NodeBlock(_)) => "block",
137137
Some(hir_map::NodeExpr(expr)) => match expr.node {
138138
hir::ExprCall(..) => "call",
@@ -153,18 +153,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
153153
}
154154
};
155155
let scope_decorated_tag = match scope {
156-
region::CodeExtent::Misc(_) => tag,
157-
region::CodeExtent::CallSiteScope(_) => {
156+
region::Scope::Node(_) => tag,
157+
region::Scope::CallSite(_) => {
158158
"scope of call-site for function"
159159
}
160-
region::CodeExtent::ParameterScope(_) => {
160+
region::Scope::Arguments(_) => {
161161
"scope of function body"
162162
}
163-
region::CodeExtent::DestructionScope(_) => {
163+
region::Scope::Destruction(_) => {
164164
new_string = format!("destruction scope surrounding {}", tag);
165165
&new_string[..]
166166
}
167-
region::CodeExtent::Remainder(r) => {
167+
region::Scope::Remainder(r) => {
168168
new_string = format!("block suffix following statement {}",
169169
r.first_statement_index);
170170
&new_string[..]
@@ -256,7 +256,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
256256

257257
impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
258258
pub fn report_region_errors(&self,
259-
region_maps: &RegionMaps,
259+
region_scope_tree: &region::ScopeTree,
260260
errors: &Vec<RegionResolutionError<'tcx>>) {
261261
debug!("report_region_errors(): {} errors to start", errors.len());
262262

@@ -281,15 +281,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
281281
// the error. If all of these fails, we fall back to a rather
282282
// general bit of code that displays the error information
283283
ConcreteFailure(origin, sub, sup) => {
284-
self.report_concrete_failure(region_maps, origin, sub, sup).emit();
284+
self.report_concrete_failure(region_scope_tree, origin, sub, sup).emit();
285285
}
286286

287287
GenericBoundFailure(kind, param_ty, sub) => {
288-
self.report_generic_bound_failure(region_maps, kind, param_ty, sub);
288+
self.report_generic_bound_failure(region_scope_tree, kind, param_ty, sub);
289289
}
290290

291291
SubSupConflict(var_origin, sub_origin, sub_r, sup_origin, sup_r) => {
292-
self.report_sub_sup_conflict(region_maps,
292+
self.report_sub_sup_conflict(region_scope_tree,
293293
var_origin,
294294
sub_origin,
295295
sub_r,
@@ -769,7 +769,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
769769
}
770770

771771
fn report_generic_bound_failure(&self,
772-
region_maps: &RegionMaps,
772+
region_scope_tree: &region::ScopeTree,
773773
origin: SubregionOrigin<'tcx>,
774774
bound_kind: GenericKind<'tcx>,
775775
sub: Region<'tcx>)
@@ -837,7 +837,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
837837
err.help(&format!("consider adding an explicit lifetime bound for `{}`",
838838
bound_kind));
839839
self.tcx.note_and_explain_region(
840-
region_maps,
840+
region_scope_tree,
841841
&mut err,
842842
&format!("{} must be valid for ", labeled_user_string),
843843
sub,
@@ -851,22 +851,22 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
851851
}
852852

853853
fn report_sub_sup_conflict(&self,
854-
region_maps: &RegionMaps,
854+
region_scope_tree: &region::ScopeTree,
855855
var_origin: RegionVariableOrigin,
856856
sub_origin: SubregionOrigin<'tcx>,
857857
sub_region: Region<'tcx>,
858858
sup_origin: SubregionOrigin<'tcx>,
859859
sup_region: Region<'tcx>) {
860860
let mut err = self.report_inference_failure(var_origin);
861861

862-
self.tcx.note_and_explain_region(region_maps, &mut err,
862+
self.tcx.note_and_explain_region(region_scope_tree, &mut err,
863863
"first, the lifetime cannot outlive ",
864864
sup_region,
865865
"...");
866866

867867
self.note_region_origin(&mut err, &sup_origin);
868868

869-
self.tcx.note_and_explain_region(region_maps, &mut err,
869+
self.tcx.note_and_explain_region(region_scope_tree, &mut err,
870870
"but, the lifetime must be valid for ",
871871
sub_region,
872872
"...");

0 commit comments

Comments
 (0)