Skip to content

Commit 5ccf677

Browse files
committed
---
yaml --- r: 235059 b: refs/heads/stable c: b23ddc6 h: refs/heads/master i: 235057: 3ef90ae 235055: 0600fe4 v: v3
1 parent a168f11 commit 5ccf677

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: afae2ff723393b3ab4ccffef6ac7c6d1809e2da0
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: f859507de8c410b648d934d8f5ec1c52daac971d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: bbf0daa19276354d5759d0b0bd7d31bcd3cc301c
32+
refs/heads/stable: b23ddc60e9fcb188421060a83f1af2b815fc60e2
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/librustc/ast_map/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,34 @@ impl<'ast> Map<'ast> {
321321
self.find_entry(id).and_then(|x| x.parent_node()).unwrap_or(id)
322322
}
323323

324+
/// Returns the nearest enclosing scope. A scope is an item or block.
325+
/// FIXME it is not clear to me that all items qualify as scopes - statics
326+
/// and associated types probably shouldn't, for example. Behaviour in this
327+
/// regard should be expected to be highly unstable.
328+
pub fn get_enclosing_scope(&self, id: NodeId) -> Option<NodeId> {
329+
let mut last_id = id;
330+
// Walk up the chain of parents until we find a 'scope'.
331+
loop {
332+
let cur_id = self.get_parent_node(last_id);
333+
if cur_id == last_id {
334+
return None;
335+
}
336+
337+
match self.get(cur_id) {
338+
NodeItem(_) |
339+
NodeForeignItem(_) |
340+
NodeTraitItem(_) |
341+
NodeImplItem(_) |
342+
NodeBlock(_) => {
343+
return Some(cur_id);
344+
}
345+
_ => {}
346+
}
347+
348+
last_id = cur_id;
349+
}
350+
}
351+
324352
pub fn get_parent_did(&self, id: NodeId) -> DefId {
325353
let parent = self.get_parent(id);
326354
match self.find_entry(parent) {

branches/stable/src/librustc_trans/save/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
172172
qualname: qualname,
173173
declaration: None,
174174
span: sub_span.unwrap(),
175-
scope: self.tcx.map.get_parent(item.id),
175+
scope: self.tcx.map.get_enclosing_scope(item.id).unwrap(),
176176
})
177177
}
178178
ast::ItemStatic(ref typ, mt, ref expr) => {
@@ -191,7 +191,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
191191
name: get_ident(item.ident).to_string(),
192192
qualname: qualname,
193193
span: sub_span.unwrap(),
194-
scope: self.tcx.map.get_parent(item.id),
194+
scope: self.tcx.map.get_enclosing_scope(item.id).unwrap(),
195195
value: value,
196196
type_value: ty_to_string(&typ),
197197
})
@@ -205,7 +205,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
205205
name: get_ident(item.ident).to_string(),
206206
qualname: qualname,
207207
span: sub_span.unwrap(),
208-
scope: self.tcx.map.get_parent(item.id),
208+
scope: self.tcx.map.get_enclosing_scope(item.id).unwrap(),
209209
value: self.span_utils.snippet(expr.span),
210210
type_value: ty_to_string(&typ),
211211
})
@@ -223,7 +223,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
223223
name: get_ident(item.ident).to_string(),
224224
qualname: qualname,
225225
span: sub_span.unwrap(),
226-
scope: self.tcx.map.get_parent(item.id),
226+
scope: self.tcx.map.get_enclosing_scope(item.id).unwrap(),
227227
filename: filename,
228228
})
229229
},
@@ -237,14 +237,14 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
237237
value: val,
238238
span: sub_span.unwrap(),
239239
qualname: enum_name,
240-
scope: self.tcx.map.get_parent(item.id),
240+
scope: self.tcx.map.get_enclosing_scope(item.id).unwrap(),
241241
})
242242
},
243243
ast::ItemImpl(_, _, _, ref trait_ref, ref typ, _) => {
244244
let mut type_data = None;
245245
let sub_span;
246246

247-
let parent = self.tcx.map.get_parent(item.id);
247+
let parent = self.tcx.map.get_enclosing_scope(item.id).unwrap();
248248

249249
match typ.node {
250250
// Common case impl for a struct or something basic.
@@ -337,7 +337,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
337337
return Some(Data::VariableRefData(VariableRefData {
338338
name: get_ident(ident.node).to_string(),
339339
span: sub_span.unwrap(),
340-
scope: self.tcx.map.get_parent(expr.id),
340+
scope: self.tcx.map.get_enclosing_scope(expr.id).unwrap(),
341341
ref_id: f.id,
342342
}));
343343
}
@@ -360,7 +360,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
360360
let sub_span = self.span_utils.span_for_last_ident(path.span);
361361
Some(Data::TypeRefData(TypeRefData {
362362
span: sub_span.unwrap(),
363-
scope: self.tcx.map.get_parent(expr.id),
363+
scope: self.tcx.map.get_enclosing_scope(expr.id).unwrap(),
364364
ref_id: def_id,
365365
}))
366366
}

0 commit comments

Comments
 (0)