Skip to content

Commit 55d6066

Browse files
committed
remove ROOT_CODE_EXTENT and DUMMY_CODE_EXTENT
Instead, thread around `Option<CodeExtent>` where applicable.
1 parent 119c38e commit 55d6066

File tree

22 files changed

+137
-158
lines changed

22 files changed

+137
-158
lines changed

src/librustc/infer/error_reporting/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ use traits::{ObligationCause, ObligationCauseCode};
6969
use ty::{self, TyCtxt, TypeFoldable};
7070
use ty::{Region, Issue32330};
7171
use ty::error::TypeError;
72+
use syntax::ast::DUMMY_NODE_ID;
7273
use syntax_pos::{Pos, Span};
7374
use errors::{DiagnosticBuilder, DiagnosticStyledString};
7475

@@ -183,7 +184,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
183184
}
184185
};
185186

186-
let node = fr.scope.node_id(&self.region_maps());
187+
let node = fr.scope.map(|s| s.node_id(&self.region_maps()))
188+
.unwrap_or(DUMMY_NODE_ID);
187189
let unknown;
188190
let tag = match self.hir.find(node) {
189191
Some(hir_map::NodeBlock(_)) |

src/librustc/infer/region_inference/mod.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -938,18 +938,19 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
938938
// A "free" region can be interpreted as "some region
939939
// at least as big as the block fr.scope_id". So, we can
940940
// reasonably compare free regions and scopes:
941-
let r_id = self.tcx.region_maps().nearest_common_ancestor(fr.scope, s_id);
942-
943-
if r_id == fr.scope {
944-
// if the free region's scope `fr.scope_id` is bigger than
945-
// the scope region `s_id`, then the LUB is the free
946-
// region itself:
947-
self.tcx.mk_region(ReFree(fr))
948-
} else {
949-
// otherwise, we don't know what the free region is,
950-
// so we must conservatively say the LUB is static:
951-
self.tcx.types.re_static
941+
if let Some(fr_scope) = fr.scope {
942+
let r_id = self.tcx.region_maps().nearest_common_ancestor(fr_scope, s_id);
943+
if r_id == fr_scope {
944+
// if the free region's scope `fr.scope_id` is bigger than
945+
// the scope region `s_id`, then the LUB is the free
946+
// region itself:
947+
return self.tcx.mk_region(ReFree(fr));
948+
}
952949
}
950+
951+
// otherwise, we don't know what the free region is,
952+
// so we must conservatively say the LUB is static:
953+
self.tcx.types.re_static
953954
}
954955

955956
(&ReScope(a_id), &ReScope(b_id)) => {

src/librustc/middle/free_region.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,14 @@ impl FreeRegionMap {
138138
(&ty::ReScope(sub_scope), &ty::ReScope(super_scope)) =>
139139
tcx.region_maps().is_subscope_of(sub_scope, super_scope),
140140

141-
(&ty::ReScope(sub_scope), &ty::ReFree(fr)) =>
142-
tcx.region_maps().is_subscope_of(sub_scope, fr.scope) ||
143-
self.is_static(fr),
141+
(&ty::ReScope(sub_scope), &ty::ReFree(fr)) => {
142+
// 1. It is safe to unwrap `fr.scope` because we
143+
// should only ever wind up comparing against
144+
// `ReScope` in the context of a method or fn
145+
// body, where `fr.scope` should be `Some`.
146+
tcx.region_maps().is_subscope_of(sub_scope, fr.scope.unwrap() /*1*/) ||
147+
self.is_static(fr)
148+
}
144149

145150
(&ty::ReFree(sub_fr), &ty::ReFree(super_fr)) =>
146151
self.sub_free_region(sub_fr, super_fr),
@@ -166,9 +171,7 @@ impl FreeRegionMap {
166171

167172
#[cfg(test)]
168173
fn free_region(index: u32) -> FreeRegion {
169-
use middle::region::DUMMY_CODE_EXTENT;
170-
FreeRegion { scope: DUMMY_CODE_EXTENT,
171-
bound_region: ty::BoundRegion::BrAnon(index) }
174+
FreeRegion { scope: None, bound_region: ty::BoundRegion::BrAnon(index) }
172175
}
173176

174177
#[test]

src/librustc/middle/liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
14411441
// and must outlive the *call-site* of the function.
14421442
let fn_ret =
14431443
self.ir.tcx.liberate_late_bound_regions(
1444-
self.ir.tcx.region_maps().call_site_extent(id, body.value.id),
1444+
Some(self.ir.tcx.region_maps().call_site_extent(id, body.value.id)),
14451445
&fn_ret);
14461446

14471447
if !fn_ret.is_never() && self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {

src/librustc/middle/mem_categorization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
796796
// The environment of a closure is guaranteed to
797797
// outlive any bindings introduced in the body of the
798798
// closure itself.
799-
scope: self.tcx().region_maps().item_extent(fn_body_id),
799+
scope: Some(self.tcx().region_maps().item_extent(fn_body_id)),
800800
bound_region: ty::BrEnv
801801
}));
802802

0 commit comments

Comments
 (0)