From 50e42ea9f70361ccd71682070c01ea808891f0ce Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 12 Sep 2015 16:10:12 +0300 Subject: [PATCH 1/5] Correctly walk import lists in AST visitors --- src/liballoc/lib.rs | 2 +- src/libcollections/lib.rs | 4 +++ src/libcollections/str.rs | 1 + src/librustc/lint/context.rs | 5 +++ src/librustc/lint/mod.rs | 2 ++ src/librustc/middle/dead.rs | 5 +++ src/librustc/middle/stability.rs | 16 +++++++++ src/librustc_back/svh.rs | 4 +++ src/librustc_front/visit.rs | 33 ++++++++++------- src/librustc_lint/builtin.rs | 7 ++++ src/librustc_privacy/lib.rs | 27 ++++++-------- src/libstd/lib.rs | 1 + src/libsyntax/visit.rs | 40 +++++++++++---------- src/test/compile-fail/issue-28075.rs | 22 ++++++++++++ src/test/compile-fail/lint-output-format.rs | 3 +- 15 files changed, 122 insertions(+), 50 deletions(-) create mode 100644 src/test/compile-fail/issue-28075.rs diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 1beb015364d9e..66de5d7bea84e 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -100,7 +100,7 @@ #![cfg_attr(stage0, feature(alloc_system))] #![cfg_attr(not(stage0), feature(needs_allocator))] -#![cfg_attr(test, feature(test, rustc_private))] +#![cfg_attr(test, feature(test, rustc_private, box_heap))] #[cfg(stage0)] extern crate alloc_system; diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index fe06e3fb2093e..34bd1345fcb3b 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -38,6 +38,8 @@ #![feature(core_intrinsics)] #![feature(core_slice_ext)] #![feature(core_str_ext)] +#![feature(fmt_internals)] +#![feature(fmt_radix)] #![feature(heap_api)] #![feature(iter_order)] #![feature(iter_arith)] @@ -47,6 +49,8 @@ #![feature(oom)] #![feature(pattern)] #![feature(ptr_as_ref)] +#![feature(ref_slice)] +#![feature(slice_bytes)] #![feature(slice_patterns)] #![feature(staged_api)] #![feature(step_by)] diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index fbb6c279bbcd8..23c21a732b520 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -38,6 +38,7 @@ use slice::SliceConcatExt; use boxed::Box; pub use core::str::{FromStr, Utf8Error}; +#[allow(deprecated)] pub use core::str::{Lines, LinesAny, CharRange}; pub use core::str::{Split, RSplit}; pub use core::str::{SplitN, RSplitN}; diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 9a736747d5291..138acde64764d 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -915,6 +915,11 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> { ast_visit::walk_path(self, p); } + fn visit_path_list_item(&mut self, prefix: &hir::Path, item: &hir::PathListItem) { + run_lints!(self, check_path_list_item, item); + visit::walk_path_list_item(self, prefix, item); + } + fn visit_attribute(&mut self, attr: &ast::Attribute) { run_lints!(self, check_attribute, early_passes, attr); } diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index e52b6e91f68cd..a1e7ffd3c7b14 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -165,6 +165,7 @@ pub trait LateLintPass: LintPass { // because then your lint will be called twice. Prefer check_ast_mac. fn check_mac(&mut self, _: &LateContext, _: &ast::Mac) { } fn check_path(&mut self, _: &LateContext, _: &hir::Path, _: ast::NodeId) { } + fn check_path_list_item(&mut self, _: &LateContext, _: &hir::PathListItem) { } fn check_attribute(&mut self, _: &LateContext, _: &ast::Attribute) { } /// Called when entering a syntax node that can have lint attributes such @@ -211,6 +212,7 @@ pub trait EarlyLintPass: LintPass { fn check_explicit_self(&mut self, _: &EarlyContext, _: &ast::ExplicitSelf) { } fn check_mac(&mut self, _: &EarlyContext, _: &ast::Mac) { } fn check_path(&mut self, _: &EarlyContext, _: &ast::Path, _: ast::NodeId) { } + fn check_path_list_item(&mut self, _: &EarlyContext, _: &ast::PathListItem) { } fn check_attribute(&mut self, _: &EarlyContext, _: &ast::Attribute) { } /// Called when entering a syntax node that can have lint attributes such diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 182bc067a7fc1..e077d6d35c74f 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -279,6 +279,11 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MarkSymbolVisitor<'a, 'tcx> { visit::walk_path(self, path); } + fn visit_path_list_item(&mut self, path: &hir::Path, item: &hir::PathListItem) { + self.lookup_and_handle_definition(&item.node.id()); + visit::walk_path_list_item(self, path, item); + } + fn visit_item(&mut self, _: &hir::Item) { // Do not recurse into items. These items will be added to the // worklist and recursed into manually if necessary. diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index e29d432707104..c8ed90ec5d11b 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -355,6 +355,12 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> { visit::walk_path(self, path) } + fn visit_path_list_item(&mut self, prefix: &hir::Path, item: &hir::PathListItem) { + check_path_list_item(self.tcx, item, + &mut |id, sp, stab| self.check(id, sp, stab)); + visit::walk_path_list_item(self, prefix, item) + } + fn visit_pat(&mut self, pat: &hir::Pat) { check_pat(self.tcx, pat, &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, } None => {} } +} +pub fn check_path_list_item(tcx: &ty::ctxt, item: &hir::PathListItem, + cb: &mut FnMut(DefId, Span, &Option<&Stability>)) { + match tcx.def_map.borrow().get(&item.node.id()).map(|d| d.full_def()) { + Some(def::DefPrimTy(..)) => {} + Some(def) => { + maybe_do_stability_check(tcx, def.def_id(), item.span, cb); + } + None => {} + } } pub fn check_pat(tcx: &ty::ctxt, pat: &hir::Pat, diff --git a/src/librustc_back/svh.rs b/src/librustc_back/svh.rs index 7134066d08ce7..27d63d8a539af 100644 --- a/src/librustc_back/svh.rs +++ b/src/librustc_back/svh.rs @@ -423,6 +423,10 @@ mod svh_visitor { SawPath.hash(self.st); visit::walk_path(self, path) } + fn visit_path_list_item(&mut self, prefix: &Path, item: &'v PathListItem) { + SawPath.hash(self.st); visit::walk_path_list_item(self, prefix, item) + } + fn visit_block(&mut self, b: &Block) { SawBlock.hash(self.st); visit::walk_block(self, b) } diff --git a/src/librustc_front/visit.rs b/src/librustc_front/visit.rs index d9b4f37411420..89c9818efbf01 100644 --- a/src/librustc_front/visit.rs +++ b/src/librustc_front/visit.rs @@ -121,6 +121,9 @@ pub trait Visitor<'v> : Sized { fn visit_path(&mut self, path: &'v Path, _id: NodeId) { walk_path(self, path) } + fn visit_path_list_item(&mut self, prefix: &'v Path, item: &'v PathListItem) { + walk_path_list_item(self, prefix, item) + } fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) { walk_path_segment(self, path_span, path_segment) } @@ -203,26 +206,21 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { ItemExternCrate(..) => {} ItemUse(ref vp) => { match vp.node { - ViewPathSimple(ident, ref path) => { - visitor.visit_ident(vp.span, ident); + ViewPathSimple(_ident, ref path) => { visitor.visit_path(path, item.id); } ViewPathGlob(ref path) => { visitor.visit_path(path, item.id); } ViewPathList(ref prefix, ref list) => { - for id in list { - match id.node { - PathListIdent { name, .. } => { - visitor.visit_ident(id.span, name); - } - PathListMod { .. } => () + if !list.is_empty() { + for item in list { + visitor.visit_path_list_item(prefix, item) } + } else { + // FIXME: uncomment this and fix the resulting ICE + // visitor.visit_path(prefix, item.id); } - - // Note that the `prefix` here is not a complete - // path, so we don't use `visit_path`. - walk_path(visitor, prefix); } } } @@ -400,6 +398,17 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) { } } +pub fn walk_path_list_item<'v, V: Visitor<'v>>(visitor: &mut V, prefix: &'v Path, + item: &'v PathListItem) { + for segment in &prefix.segments { + visitor.visit_path_segment(prefix.span, segment); + } + + if let PathListIdent { name, .. } = item.node { + visitor.visit_ident(item.span, name); + } +} + pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, path_span: Span, segment: &'v PathSegment) { diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 394bd2abc08c7..dc7de6b285331 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -2173,6 +2173,13 @@ impl LateLintPass for Stability { &stab.map(|s| hir_to_ast_stability(s)).as_ref())); } + fn check_path_list_item(&mut self, cx: &LateContext, item: &hir::PathListItem) { + stability::check_path_list_item(cx.tcx, item, + &mut |id, sp, stab| + self.lint(cx, id, sp, + &stab.map(|s| hir_to_ast_stability(s)).as_ref())); + } + fn check_pat(&mut self, cx: &LateContext, pat: &hir::Pat) { stability::check_pat(cx.tcx, pat, &mut |id, sp, stab| diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 48efd34e21220..1a07877066e69 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -859,23 +859,6 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> { impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { fn visit_item(&mut self, item: &hir::Item) { - if let hir::ItemUse(ref vpath) = item.node { - if let hir::ViewPathList(ref prefix, ref list) = vpath.node { - for pid in list { - match pid.node { - hir::PathListIdent { id, name, .. } => { - debug!("privacy - ident item {}", id); - self.check_path(pid.span, id, name.name); - } - hir::PathListMod { id, .. } => { - debug!("privacy - mod item {}", id); - let name = prefix.segments.last().unwrap().identifier.name; - self.check_path(pid.span, id, name); - } - } - } - } - } let orig_curitem = replace(&mut self.curitem, item.id); visit::walk_item(self, item); self.curitem = orig_curitem; @@ -1000,6 +983,16 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { self.check_path(path.span, id, path.segments.last().unwrap().identifier.name); visit::walk_path(self, path); } + + fn visit_path_list_item(&mut self, prefix: &hir::Path, item: &hir::PathListItem) { + let name = if let hir::PathListIdent { name, .. } = item.node { + name.name + } else { + prefix.segments.last().unwrap().identifier.name + }; + self.check_path(item.span, item.node.id(), name); + visit::walk_path_list_item(self, prefix, item); + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 774d13966bd6b..6eabf5d69a2cd 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -201,6 +201,7 @@ #![feature(alloc)] #![feature(allow_internal_unstable)] +#![feature(arc_weak)] #![feature(associated_consts)] #![feature(borrow_state)] #![feature(box_syntax)] diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 8365a7375c68d..2a2f5c0f2c16e 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -127,6 +127,9 @@ pub trait Visitor<'v> : Sized { fn visit_path(&mut self, path: &'v Path, _id: ast::NodeId) { walk_path(self, path) } + fn visit_path_list_item(&mut self, prefix: &'v Path, item: &'v PathListItem) { + walk_path_list_item(self, prefix, item) + } fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) { walk_path_segment(self, path_span, path_segment) } @@ -209,33 +212,21 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { ItemExternCrate(..) => {} ItemUse(ref vp) => { match vp.node { - ViewPathSimple(ident, ref path) => { - visitor.visit_ident(vp.span, ident); + ViewPathSimple(_ident, ref path) => { visitor.visit_path(path, item.id); } ViewPathGlob(ref path) => { visitor.visit_path(path, item.id); } ViewPathList(ref prefix, ref list) => { - for id in list { - match id.node { - PathListIdent { name, rename, .. } => { - visitor.visit_ident(id.span, name); - if let Some(ident) = rename { - visitor.visit_ident(id.span, ident); - } - } - PathListMod { rename, .. } => { - if let Some(ident) = rename { - visitor.visit_ident(id.span, ident); - } - } + if !list.is_empty() { + for item in list { + visitor.visit_path_list_item(prefix, item) } + } else { + // FIXME: uncomment this and fix the resulting ICE + // visitor.visit_path(prefix, item.id); } - - // Note that the `prefix` here is not a complete - // path, so we don't use `visit_path`. - walk_path(visitor, prefix); } } } @@ -417,6 +408,17 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) { } } +pub fn walk_path_list_item<'v, V: Visitor<'v>>(visitor: &mut V, prefix: &'v Path, + item: &'v PathListItem) { + for segment in &prefix.segments { + visitor.visit_path_segment(prefix.span, segment); + } + + if let PathListIdent { name, .. } = item.node { + visitor.visit_ident(item.span, name); + } +} + pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, path_span: Span, segment: &'v PathSegment) { diff --git a/src/test/compile-fail/issue-28075.rs b/src/test/compile-fail/issue-28075.rs new file mode 100644 index 0000000000000..74a241e819f31 --- /dev/null +++ b/src/test/compile-fail/issue-28075.rs @@ -0,0 +1,22 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Unstable entities should be caught in import lists + +#![allow(unused_imports)] + +use std::thread::{catch_panic, sleep}; //~ ERROR use of unstable library feature 'catch_panic' +//~^ ERROR use of unstable library feature 'thread_sleep' + +use std::rt::{self}; //~ ERROR use of unstable library feature 'rt' +use std::rt::{}; + +fn main() { +} diff --git a/src/test/compile-fail/lint-output-format.rs b/src/test/compile-fail/lint-output-format.rs index d95ed7f10bd17..3febacca73f25 100644 --- a/src/test/compile-fail/lint-output-format.rs +++ b/src/test/compile-fail/lint-output-format.rs @@ -14,7 +14,8 @@ #![feature(foo)] //~ ERROR unused or unknown feature extern crate lint_output_format; //~ ERROR use of unstable library feature -use lint_output_format::{foo, bar}; +use lint_output_format::{foo, bar}; //~ ERROR use of unstable library feature +//~^ WARNING use of deprecated item, fn main() { let _x = foo(); //~ WARNING #[warn(deprecated)] on by default From 357982fae4ac7be0f6e0065399606f2d78618aaf Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 14 Sep 2015 01:24:27 +0300 Subject: [PATCH 2/5] Workaround for imports with empty braces --- src/librustc_front/visit.rs | 4 ++-- src/librustc_privacy/lib.rs | 10 +++++++--- src/libstd/lib.rs | 1 - src/libsyntax/visit.rs | 4 ++-- src/test/compile-fail/issue-28075.rs | 5 ++--- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/librustc_front/visit.rs b/src/librustc_front/visit.rs index 89c9818efbf01..12a20a8d21f49 100644 --- a/src/librustc_front/visit.rs +++ b/src/librustc_front/visit.rs @@ -218,8 +218,8 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_path_list_item(prefix, item) } } else { - // FIXME: uncomment this and fix the resulting ICE - // visitor.visit_path(prefix, item.id); + // FIXME(#28388) visit_path should be used instead of walk_path + walk_path(visitor, prefix); } } } diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 1a07877066e69..817fd98470899 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -980,15 +980,19 @@ impl<'a, 'tcx, 'v> Visitor<'v> for PrivacyVisitor<'a, 'tcx> { } fn visit_path(&mut self, path: &hir::Path, id: ast::NodeId) { - self.check_path(path.span, id, path.segments.last().unwrap().identifier.name); - visit::walk_path(self, path); + if !path.segments.is_empty() { + self.check_path(path.span, id, path.segments.last().unwrap().identifier.name); + visit::walk_path(self, path); + } } fn visit_path_list_item(&mut self, prefix: &hir::Path, item: &hir::PathListItem) { let name = if let hir::PathListIdent { name, .. } = item.node { name.name - } else { + } else if !prefix.segments.is_empty() { prefix.segments.last().unwrap().identifier.name + } else { + self.tcx.sess.bug("`self` import in an import list with empty prefix"); }; self.check_path(item.span, item.node.id(), name); visit::walk_path_list_item(self, prefix, item); diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 6eabf5d69a2cd..774d13966bd6b 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -201,7 +201,6 @@ #![feature(alloc)] #![feature(allow_internal_unstable)] -#![feature(arc_weak)] #![feature(associated_consts)] #![feature(borrow_state)] #![feature(box_syntax)] diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 2a2f5c0f2c16e..cda750c5cda7e 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -224,8 +224,8 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_path_list_item(prefix, item) } } else { - // FIXME: uncomment this and fix the resulting ICE - // visitor.visit_path(prefix, item.id); + // FIXME(#28388) visit_path should be used instead of walk_path + walk_path(visitor, prefix); } } } diff --git a/src/test/compile-fail/issue-28075.rs b/src/test/compile-fail/issue-28075.rs index 74a241e819f31..7e9dfcf3ccb8f 100644 --- a/src/test/compile-fail/issue-28075.rs +++ b/src/test/compile-fail/issue-28075.rs @@ -12,11 +12,10 @@ #![allow(unused_imports)] -use std::thread::{catch_panic, sleep}; //~ ERROR use of unstable library feature 'catch_panic' -//~^ ERROR use of unstable library feature 'thread_sleep' +use std::thread::{catch_panic, ScopedKey}; //~ ERROR use of unstable library feature 'catch_panic' +//~^ ERROR use of unstable library feature 'scoped_tls' use std::rt::{self}; //~ ERROR use of unstable library feature 'rt' -use std::rt::{}; fn main() { } From c3f53d1b12dfe5e08f98b19e9e3980da116e31ee Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 16 Sep 2015 00:50:50 +0300 Subject: [PATCH 3/5] Resolve prefix in imports with empty braces --- src/librustc_front/visit.rs | 3 +-- src/librustc_resolve/lib.rs | 28 ++++++++++++++++++++------ src/libsyntax/visit.rs | 3 +-- src/test/compile-fail/issue-28388-1.rs | 15 ++++++++++++++ src/test/compile-fail/issue-28388-2.rs | 19 +++++++++++++++++ src/test/compile-fail/issue-28388-3.rs | 16 +++++++++++++++ 6 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 src/test/compile-fail/issue-28388-1.rs create mode 100644 src/test/compile-fail/issue-28388-2.rs create mode 100644 src/test/compile-fail/issue-28388-3.rs diff --git a/src/librustc_front/visit.rs b/src/librustc_front/visit.rs index 12a20a8d21f49..8f5208d3ef119 100644 --- a/src/librustc_front/visit.rs +++ b/src/librustc_front/visit.rs @@ -218,8 +218,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_path_list_item(prefix, item) } } else { - // FIXME(#28388) visit_path should be used instead of walk_path - walk_path(visitor, prefix); + visitor.visit_path(prefix, item.id); } } } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 8e34118957ebd..6159ba5b79e0e 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2210,10 +2210,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { ItemUse(ref view_path) => { // check for imports shadowing primitive types - let check_rename = |id, ident: Ident| { - match self.def_map.borrow().get(&id).map(|d| d.full_def()) { + let check_rename = |this: &Self, id, ident: Ident| { + match this.def_map.borrow().get(&id).map(|d| d.full_def()) { Some(DefTy(..)) | Some(DefStruct(..)) | Some(DefTrait(..)) | None => { - self.check_if_primitive_type_name(ident.name, item.span); + this.check_if_primitive_type_name(ident.name, item.span); } _ => {} } @@ -2221,12 +2221,28 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { match view_path.node { hir::ViewPathSimple(ident, _) => { - check_rename(item.id, ident); + check_rename(self, item.id, ident); } - hir::ViewPathList(_, ref items) => { + hir::ViewPathList(ref prefix, ref items) => { for item in items { if let Some(ident) = item.node.rename() { - check_rename(item.node.id(), ident); + check_rename(self, item.node.id(), ident); + } + } + + // Resolve prefix of an import with empty braces (issue #28388) + if items.is_empty() && !prefix.segments.is_empty() { + match self.resolve_crate_relative_path(prefix.span, + &prefix.segments, + TypeNS) { + Some((def, lp)) => self.record_def(item.id, + PathResolution::new(def, lp, 0)), + None => { + resolve_error(self, + prefix.span, + ResolutionError::FailedToResolve( + &path_names_to_string(prefix, 0))); + } } } } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index cda750c5cda7e..f4f4c9dfc24fb 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -224,8 +224,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_path_list_item(prefix, item) } } else { - // FIXME(#28388) visit_path should be used instead of walk_path - walk_path(visitor, prefix); + visitor.visit_path(prefix, item.id); } } } diff --git a/src/test/compile-fail/issue-28388-1.rs b/src/test/compile-fail/issue-28388-1.rs new file mode 100644 index 0000000000000..ef97b400b00a5 --- /dev/null +++ b/src/test/compile-fail/issue-28388-1.rs @@ -0,0 +1,15 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Prefix in imports with empty braces should be resolved and checked privacy, stability, etc. + +use foo::{}; //~ ERROR failed to resolve. foo + +fn main() {} diff --git a/src/test/compile-fail/issue-28388-2.rs b/src/test/compile-fail/issue-28388-2.rs new file mode 100644 index 0000000000000..837dc67c804eb --- /dev/null +++ b/src/test/compile-fail/issue-28388-2.rs @@ -0,0 +1,19 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Prefix in imports with empty braces should be resolved and checked privacy, stability, etc. + +mod m { + mod n {} +} + +use m::n::{}; //~ ERROR module `n` is private + +fn main() {} diff --git a/src/test/compile-fail/issue-28388-3.rs b/src/test/compile-fail/issue-28388-3.rs new file mode 100644 index 0000000000000..59756be55bd62 --- /dev/null +++ b/src/test/compile-fail/issue-28388-3.rs @@ -0,0 +1,16 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Prefix in imports with empty braces should be resolved and checked privacy, stability, etc. + +use std::rt::{}; //~ ERROR use of unstable library feature 'rt' +use std::{}; // OK + +fn main() {} From 1599c1675fbb30c1f03fe8d292f7e37c4a1e98ac Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 17 Sep 2015 15:19:24 +0300 Subject: [PATCH 4/5] Fix code broken by rebase --- src/librustc/lint/context.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 138acde64764d..d3392c02b6f3b 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -767,6 +767,11 @@ impl<'a, 'tcx, 'v> hir_visit::Visitor<'v> for LateContext<'a, 'tcx> { hir_visit::walk_path(self, p); } + fn visit_path_list_item(&mut self, prefix: &hir::Path, item: &hir::PathListItem) { + run_lints!(self, check_path_list_item, late_passes, item); + hir_visit::walk_path_list_item(self, prefix, item); + } + fn visit_attribute(&mut self, attr: &ast::Attribute) { run_lints!(self, check_attribute, late_passes, attr); } @@ -915,9 +920,9 @@ impl<'a, 'v> ast_visit::Visitor<'v> for EarlyContext<'a> { ast_visit::walk_path(self, p); } - fn visit_path_list_item(&mut self, prefix: &hir::Path, item: &hir::PathListItem) { - run_lints!(self, check_path_list_item, item); - visit::walk_path_list_item(self, prefix, item); + fn visit_path_list_item(&mut self, prefix: &ast::Path, item: &ast::PathListItem) { + run_lints!(self, check_path_list_item, early_passes, item); + ast_visit::walk_path_list_item(self, prefix, item); } fn visit_attribute(&mut self, attr: &ast::Attribute) { From b44cb01bd73b32ffe046b4dcfa549a954d139ab2 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 19 Sep 2015 12:16:30 +0300 Subject: [PATCH 5/5] Don't use std in stability tests --- src/test/compile-fail/issue-28075.rs | 10 +++++++--- src/test/compile-fail/issue-28388-3.rs | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/test/compile-fail/issue-28075.rs b/src/test/compile-fail/issue-28075.rs index 7e9dfcf3ccb8f..d75f5f606a01a 100644 --- a/src/test/compile-fail/issue-28075.rs +++ b/src/test/compile-fail/issue-28075.rs @@ -10,12 +10,16 @@ // Unstable entities should be caught in import lists +// aux-build:lint_stability.rs + #![allow(unused_imports)] -use std::thread::{catch_panic, ScopedKey}; //~ ERROR use of unstable library feature 'catch_panic' -//~^ ERROR use of unstable library feature 'scoped_tls' +extern crate lint_stability; + +use lint_stability::{unstable, deprecated}; //~ ERROR use of unstable library feature 'test_feature' +//~^ WARNING use of deprecated item -use std::rt::{self}; //~ ERROR use of unstable library feature 'rt' +use lint_stability::unstable::{self as u}; //~ ERROR use of unstable library feature 'test_feature' fn main() { } diff --git a/src/test/compile-fail/issue-28388-3.rs b/src/test/compile-fail/issue-28388-3.rs index 59756be55bd62..0cb669f5f8fb4 100644 --- a/src/test/compile-fail/issue-28388-3.rs +++ b/src/test/compile-fail/issue-28388-3.rs @@ -10,7 +10,11 @@ // Prefix in imports with empty braces should be resolved and checked privacy, stability, etc. -use std::rt::{}; //~ ERROR use of unstable library feature 'rt' -use std::{}; // OK +// aux-build:lint_stability.rs + +extern crate lint_stability; + +use lint_stability::UnstableStruct::{}; //~ ERROR use of unstable library feature 'test_feature' +use lint_stability::StableStruct::{}; // OK fn main() {}