Skip to content

Commit 50e42ea

Browse files
committed
Correctly walk import lists in AST visitors
1 parent d3fc6e1 commit 50e42ea

File tree

15 files changed

+122
-50
lines changed

15 files changed

+122
-50
lines changed

src/liballoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
#![cfg_attr(stage0, feature(alloc_system))]
101101
#![cfg_attr(not(stage0), feature(needs_allocator))]
102102

103-
#![cfg_attr(test, feature(test, rustc_private))]
103+
#![cfg_attr(test, feature(test, rustc_private, box_heap))]
104104

105105
#[cfg(stage0)]
106106
extern crate alloc_system;

src/libcollections/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
#![feature(core_intrinsics)]
3939
#![feature(core_slice_ext)]
4040
#![feature(core_str_ext)]
41+
#![feature(fmt_internals)]
42+
#![feature(fmt_radix)]
4143
#![feature(heap_api)]
4244
#![feature(iter_order)]
4345
#![feature(iter_arith)]
@@ -47,6 +49,8 @@
4749
#![feature(oom)]
4850
#![feature(pattern)]
4951
#![feature(ptr_as_ref)]
52+
#![feature(ref_slice)]
53+
#![feature(slice_bytes)]
5054
#![feature(slice_patterns)]
5155
#![feature(staged_api)]
5256
#![feature(step_by)]

src/libcollections/str.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use slice::SliceConcatExt;
3838
use boxed::Box;
3939

4040
pub use core::str::{FromStr, Utf8Error};
41+
#[allow(deprecated)]
4142
pub use core::str::{Lines, LinesAny, CharRange};
4243
pub use core::str::{Split, RSplit};
4344
pub use core::str::{SplitN, RSplitN};

src/librustc/lint/context.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,11 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> {
915915
ast_visit::walk_path(self, p);
916916
}
917917

918+
fn visit_path_list_item(&mut self, prefix: &hir::Path, item: &hir::PathListItem) {
919+
run_lints!(self, check_path_list_item, item);
920+
visit::walk_path_list_item(self, prefix, item);
921+
}
922+
918923
fn visit_attribute(&mut self, attr: &ast::Attribute) {
919924
run_lints!(self, check_attribute, early_passes, attr);
920925
}

src/librustc/lint/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ pub trait LateLintPass: LintPass {
165165
// because then your lint will be called twice. Prefer check_ast_mac.
166166
fn check_mac(&mut self, _: &LateContext, _: &ast::Mac) { }
167167
fn check_path(&mut self, _: &LateContext, _: &hir::Path, _: ast::NodeId) { }
168+
fn check_path_list_item(&mut self, _: &LateContext, _: &hir::PathListItem) { }
168169
fn check_attribute(&mut self, _: &LateContext, _: &ast::Attribute) { }
169170

170171
/// Called when entering a syntax node that can have lint attributes such
@@ -211,6 +212,7 @@ pub trait EarlyLintPass: LintPass {
211212
fn check_explicit_self(&mut self, _: &EarlyContext, _: &ast::ExplicitSelf) { }
212213
fn check_mac(&mut self, _: &EarlyContext, _: &ast::Mac) { }
213214
fn check_path(&mut self, _: &EarlyContext, _: &ast::Path, _: ast::NodeId) { }
215+
fn check_path_list_item(&mut self, _: &EarlyContext, _: &ast::PathListItem) { }
214216
fn check_attribute(&mut self, _: &EarlyContext, _: &ast::Attribute) { }
215217

216218
/// Called when entering a syntax node that can have lint attributes such

src/librustc/middle/dead.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> {
279279
visit::walk_path(self, path);
280280
}
281281

282+
fn visit_path_list_item(&mut self, path: &hir::Path, item: &hir::PathListItem) {
283+
self.lookup_and_handle_definition(&item.node.id());
284+
visit::walk_path_list_item(self, path, item);
285+
}
286+
282287
fn visit_item(&mut self, _: &hir::Item) {
283288
// Do not recurse into items. These items will be added to the
284289
// worklist and recursed into manually if necessary.

src/librustc/middle/stability.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
355355
visit::walk_path(self, path)
356356
}
357357

358+
fn visit_path_list_item(&mut self, prefix: &hir::Path, item: &hir::PathListItem) {
359+
check_path_list_item(self.tcx, item,
360+
&mut |id, sp, stab| self.check(id, sp, stab));
361+
visit::walk_path_list_item(self, prefix, item)
362+
}
363+
358364
fn visit_pat(&mut self, pat: &hir::Pat) {
359365
check_pat(self.tcx, pat,
360366
&mut |id, sp, stab| self.check(id, sp, stab));
@@ -470,7 +476,17 @@ pub fn check_path(tcx: &ty::ctxt, path: &hir::Path, id: ast::NodeId,
470476
}
471477
None => {}
472478
}
479+
}
473480

481+
pub fn check_path_list_item(tcx: &ty::ctxt, item: &hir::PathListItem,
482+
cb: &mut FnMut(DefId, Span, &Option<&Stability>)) {
483+
match tcx.def_map.borrow().get(&item.node.id()).map(|d| d.full_def()) {
484+
Some(def::DefPrimTy(..)) => {}
485+
Some(def) => {
486+
maybe_do_stability_check(tcx, def.def_id(), item.span, cb);
487+
}
488+
None => {}
489+
}
474490
}
475491

476492
pub fn check_pat(tcx: &ty::ctxt, pat: &hir::Pat,

src/librustc_back/svh.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ mod svh_visitor {
423423
SawPath.hash(self.st); visit::walk_path(self, path)
424424
}
425425

426+
fn visit_path_list_item(&mut self, prefix: &Path, item: &'v PathListItem) {
427+
SawPath.hash(self.st); visit::walk_path_list_item(self, prefix, item)
428+
}
429+
426430
fn visit_block(&mut self, b: &Block) {
427431
SawBlock.hash(self.st); visit::walk_block(self, b)
428432
}

src/librustc_front/visit.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ pub trait Visitor<'v> : Sized {
121121
fn visit_path(&mut self, path: &'v Path, _id: NodeId) {
122122
walk_path(self, path)
123123
}
124+
fn visit_path_list_item(&mut self, prefix: &'v Path, item: &'v PathListItem) {
125+
walk_path_list_item(self, prefix, item)
126+
}
124127
fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) {
125128
walk_path_segment(self, path_span, path_segment)
126129
}
@@ -203,26 +206,21 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
203206
ItemExternCrate(..) => {}
204207
ItemUse(ref vp) => {
205208
match vp.node {
206-
ViewPathSimple(ident, ref path) => {
207-
visitor.visit_ident(vp.span, ident);
209+
ViewPathSimple(_ident, ref path) => {
208210
visitor.visit_path(path, item.id);
209211
}
210212
ViewPathGlob(ref path) => {
211213
visitor.visit_path(path, item.id);
212214
}
213215
ViewPathList(ref prefix, ref list) => {
214-
for id in list {
215-
match id.node {
216-
PathListIdent { name, .. } => {
217-
visitor.visit_ident(id.span, name);
218-
}
219-
PathListMod { .. } => ()
216+
if !list.is_empty() {
217+
for item in list {
218+
visitor.visit_path_list_item(prefix, item)
220219
}
220+
} else {
221+
// FIXME: uncomment this and fix the resulting ICE
222+
// visitor.visit_path(prefix, item.id);
221223
}
222-
223-
// Note that the `prefix` here is not a complete
224-
// path, so we don't use `visit_path`.
225-
walk_path(visitor, prefix);
226224
}
227225
}
228226
}
@@ -400,6 +398,17 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) {
400398
}
401399
}
402400

401+
pub fn walk_path_list_item<'v, V: Visitor<'v>>(visitor: &mut V, prefix: &'v Path,
402+
item: &'v PathListItem) {
403+
for segment in &prefix.segments {
404+
visitor.visit_path_segment(prefix.span, segment);
405+
}
406+
407+
if let PathListIdent { name, .. } = item.node {
408+
visitor.visit_ident(item.span, name);
409+
}
410+
}
411+
403412
pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V,
404413
path_span: Span,
405414
segment: &'v PathSegment) {

src/librustc_lint/builtin.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,13 @@ impl LateLintPass for Stability {
21732173
&stab.map(|s| hir_to_ast_stability(s)).as_ref()));
21742174
}
21752175

2176+
fn check_path_list_item(&mut self, cx: &LateContext, item: &hir::PathListItem) {
2177+
stability::check_path_list_item(cx.tcx, item,
2178+
&mut |id, sp, stab|
2179+
self.lint(cx, id, sp,
2180+
&stab.map(|s| hir_to_ast_stability(s)).as_ref()));
2181+
}
2182+
21762183
fn check_pat(&mut self, cx: &LateContext, pat: &hir::Pat) {
21772184
stability::check_pat(cx.tcx, pat,
21782185
&mut |id, sp, stab|

0 commit comments

Comments
 (0)