Skip to content

Commit 5230f86

Browse files
committed
middle::resolve_lifetime: Map BlockScope to DestructionScope in fn resolve_free_lifetime.
1 parent f5324d2 commit 5230f86

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/librustc/middle/resolve_lifetime.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,17 +361,40 @@ impl<'a> LifetimeContext<'a> {
361361
scope_data: region::CodeExtent,
362362
lifetime_ref: &ast::Lifetime,
363363
scope: Scope) {
364+
debug!("resolve_free_lifetime_ref \
365+
scope_data: {} lifetime_ref: {} scope: {}",
366+
scope_data, lifetime_ref, scope);
367+
364368
// Walk up the scope chain, tracking the outermost free scope,
365369
// until we encounter a scope that contains the named lifetime
366370
// or we run out of scopes.
367371
let mut scope_data = scope_data;
368372
let mut scope = scope;
369373
let mut search_result = None;
374+
let mut loop_count = 0u;
370375
loop {
376+
debug!("resolve_free_lifetime_ref loop: {} \
377+
scope_data: {} scope: {} search_result: {}",
378+
loop_count, scope_data, scope, search_result);
371379
match *scope {
372380
BlockScope(blk_scope_data, s) => {
373-
scope_data = blk_scope_data;
374-
scope = s;
381+
// FIXME (pnkfelix): I still need to work through
382+
// the theoretical justification for this
383+
// transition from the block itself to its
384+
// enclosing destruction scope. (In particular,
385+
// perhaps athis *actually* belongs as part of the
386+
// `RootScope` case, or maybe following the loop
387+
// (either of which I think would resolve my
388+
// problem), but not here, where it has a broad
389+
// effect.
390+
if let CodeExtent::Misc(node_id) = blk_scope_data {
391+
let d = CodeExtent::DestructionScope(node_id);
392+
scope_data = d;
393+
scope = s;
394+
} else {
395+
self.sess.bug(
396+
"found unexpected CodeExtent associated with blk_scope")
397+
}
375398
}
376399

377400
RootScope => {
@@ -393,8 +416,9 @@ impl<'a> LifetimeContext<'a> {
393416
Some((_depth, decl_id)) => {
394417
let def = DefFreeRegion(scope_data, decl_id);
395418
debug!("resolve_free_lifetime_ref: \
419+
from parent scope {} \
396420
insert_lifetime(lifetime_ref: {} def: {})",
397-
lifetime_ref, def);
421+
lifetime_ref, *scope, def);
398422
self.insert_lifetime(lifetime_ref, def);
399423
}
400424

0 commit comments

Comments
 (0)