Skip to content

Commit 1e507d4

Browse files
committed
address nits
1 parent 581e5ee commit 1e507d4

File tree

4 files changed

+46
-38
lines changed

4 files changed

+46
-38
lines changed

src/librustc/metadata/tydecode.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,10 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
207207
}
208208
'B' => {
209209
assert_eq!(self.next(), '[');
210-
// this is totally wrong, but nobody relevant cares about
211-
// this field - it will die soon(TM).
210+
// this is the wrong NodeId, but `param_id` is only accessed
211+
// by the receiver-matching code in collect, which won't
212+
// be going down this code path, and anyway I will kill it
213+
// the moment wfcheck becomes the standard.
212214
let node_id = self.parse_uint() as ast::NodeId;
213215
assert_eq!(self.next(), '|');
214216
let space = self.parse_param_space();
@@ -249,8 +251,12 @@ impl<'a,'tcx> TyDecoder<'a,'tcx> {
249251

250252
fn parse_scope(&mut self) -> region::CodeExtent {
251253
self.tcx.region_maps.bogus_code_extent(match self.next() {
252-
// the scopes created here are totally bogus with their
253-
// NodeIDs
254+
// This creates scopes with the wrong NodeId. This isn't
255+
// actually a problem because scopes only exist *within*
256+
// functions, and functions aren't loaded until trans which
257+
// doesn't care about regions.
258+
//
259+
// May still be worth fixing though.
254260
'P' => {
255261
assert_eq!(self.next(), '[');
256262
let fn_id = self.parse_uint() as ast::NodeId;

src/librustc/middle/astencode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1365,7 +1365,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
13651365
/// the crate numbers back to the original source crate.
13661366
///
13671367
/// Scopes will end up as being totally bogus. This can actually
1368-
/// be fixed through.
1368+
/// be fixed though.
13691369
///
13701370
/// Unboxed closures are cloned along with the function being
13711371
/// inlined, and all side tables use interned node IDs, so we

src/librustc/middle/infer/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl<'tcx> ty::ctxt<'tcx> {
201201
// ReFree rather than dumping Debug output on the user.
202202
//
203203
// We shouldn't really be having unification failures with ReVar
204-
// and ReLateBound through.
204+
// and ReLateBound though.
205205
ty::ReSkolemized(..) | ty::ReVar(_) | ty::ReLateBound(..) => {
206206
(format!("lifetime {:?}", region), None)
207207
}

src/librustc/middle/region.rs

+34-32
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ impl CodeExtentData {
177177
}
178178

179179
impl CodeExtent {
180+
#[inline]
181+
fn into_option(self) -> Option<CodeExtent> {
182+
if self == ROOT_CODE_EXTENT {
183+
None
184+
} else {
185+
Some(self)
186+
}
187+
}
180188
pub fn node_id(&self, region_maps: &RegionMaps) -> ast::NodeId {
181189
region_maps.code_extent_data(*self).node_id()
182190
}
@@ -325,7 +333,7 @@ impl RegionMaps {
325333
// have (bogus) NodeId-s that overlap items created during
326334
// inlining.
327335
// We probably shouldn't be creating bogus code extents
328-
// through.
336+
// though.
329337
let idx = *o.get();
330338
if parent == DUMMY_CODE_EXTENT {
331339
info!("CodeExtent({}) = {:?} [parent={}] BOGUS!",
@@ -413,10 +421,7 @@ impl RegionMaps {
413421

414422
pub fn opt_encl_scope(&self, id: CodeExtent) -> Option<CodeExtent> {
415423
//! Returns the narrowest scope that encloses `id`, if any.
416-
match self.scope_map.borrow()[id.0 as usize] {
417-
ROOT_CODE_EXTENT => None,
418-
c => Some(c)
419-
}
424+
self.scope_map.borrow()[id.0 as usize].into_option()
420425
}
421426

422427
#[allow(dead_code)] // used in middle::cfg
@@ -445,32 +450,33 @@ impl RegionMaps {
445450
None => { }
446451
}
447452

453+
let scope_map : &[CodeExtent] = &self.scope_map.borrow();
454+
let code_extents: &[CodeExtentData] = &self.code_extents.borrow();
455+
448456
// else, locate the innermost terminating scope
449457
// if there's one. Static items, for instance, won't
450458
// have an enclosing scope, hence no scope will be
451459
// returned.
460+
let expr_extent = self.node_extent(expr_id);
452461
// For some reason, the expr's scope itself is skipped here.
453-
let mut id = match self.opt_encl_scope(self.node_extent(expr_id)) {
462+
let mut id = match scope_map[expr_extent.0 as usize].into_option() {
454463
Some(i) => i,
455-
None => { return None; }
464+
_ => return None
456465
};
457466

458-
loop { match self.opt_encl_scope(id) {
459-
Some(p) => {
460-
match self.code_extent_data(p) {
461-
CodeExtentData::DestructionScope(..) => {
462-
debug!("temporary_scope({:?}) = {:?} [enclosing]",
463-
expr_id, id);
464-
return Some(id);
465-
}
466-
_ => id = p
467+
while let Some(p) = scope_map[id.0 as usize].into_option() {
468+
match code_extents[p.0 as usize] {
469+
CodeExtentData::DestructionScope(..) => {
470+
debug!("temporary_scope({:?}) = {:?} [enclosing]",
471+
expr_id, id);
472+
return Some(id);
467473
}
474+
_ => id = p
468475
}
469-
None => {
470-
debug!("temporary_scope({:?}) = None", expr_id);
471-
return None;
472-
}
473-
} }
476+
}
477+
478+
debug!("temporary_scope({:?}) = None", expr_id);
479+
return None;
474480
}
475481

476482
pub fn var_region(&self, id: ast::NodeId) -> ty::Region {
@@ -591,24 +597,20 @@ impl RegionMaps {
591597
let mut i = 0;
592598
while i < 32 {
593599
buf[i] = scope;
594-
let superscope = scope_map[scope.0 as usize];
595-
if superscope == ROOT_CODE_EXTENT {
596-
return &buf[..i+1];
597-
} else {
598-
scope = superscope;
600+
match scope_map[scope.0 as usize].into_option() {
601+
Some(superscope) => scope = superscope,
602+
_ => return &buf[..i+1]
599603
}
600604
i += 1;
601605
}
602606

603607
*vec = Vec::with_capacity(64);
604-
vec.extend((*buf).into_iter());
608+
vec.push_all(buf);
605609
loop {
606610
vec.push(scope);
607-
let superscope = scope_map[scope.0 as usize];
608-
if superscope == ROOT_CODE_EXTENT {
609-
return &*vec;
610-
} else {
611-
scope = superscope;
611+
match scope_map[scope.0 as usize].into_option() {
612+
Some(superscope) => scope = superscope,
613+
_ => return &*vec
612614
}
613615
}
614616
}

0 commit comments

Comments
 (0)