Skip to content

Commit

Permalink
syntax: ViewItemUse no longer contains multiple view paths.
Browse files Browse the repository at this point in the history
it reflected the obsolete syntax `use a, b, c;` and did not make
past the parser (though it was a non-fatal error so we can continue).
this legacy affected many portions of rustc and rustdoc as well,
so this commit cleans them up altogether.
  • Loading branch information
lifthrasiir committed Apr 26, 2014
1 parent eea4909 commit b03547b
Show file tree
Hide file tree
Showing 15 changed files with 187 additions and 210 deletions.
16 changes: 7 additions & 9 deletions src/librustc/front/feature_gate.rs
Expand Up @@ -130,16 +130,14 @@ impl<'a> Visitor<()> for Context<'a> {

fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
match i.node {
ast::ViewItemUse(ref paths) => {
for path in paths.iter() {
match path.node {
ast::ViewPathGlob(..) => {
self.gate_feature("globs", path.span,
"glob import statements are \
experimental and possibly buggy");
}
_ => {}
ast::ViewItemUse(ref path) => {
match path.node {
ast::ViewPathGlob(..) => {
self.gate_feature("globs", path.span,
"glob import statements are \
experimental and possibly buggy");
}
_ => {}
}
}
ast::ViewItemExternCrate(..) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/front/std_inject.rs
Expand Up @@ -166,7 +166,7 @@ impl<'a> fold::Folder for PreludeInjector<'a> {

let vp = @codemap::dummy_spanned(ast::ViewPathGlob(prelude_path, ast::DUMMY_NODE_ID));
let vi2 = ast::ViewItem {
node: ast::ViewItemUse(vec!(vp)),
node: ast::ViewItemUse(vp),
attrs: Vec::new(),
vis: ast::Inherited,
span: DUMMY_SP,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/front/test.rs
Expand Up @@ -299,9 +299,9 @@ fn mk_std(cx: &TestCtxt) -> ast::ViewItem {
let id_test = token::str_to_ident("test");
let (vi, vis) = if cx.is_test_crate {
(ast::ViewItemUse(
vec!(@nospan(ast::ViewPathSimple(id_test,
path_node(vec!(id_test)),
ast::DUMMY_NODE_ID)))),
@nospan(ast::ViewPathSimple(id_test,
path_node(vec!(id_test)),
ast::DUMMY_NODE_ID))),
ast::Public)
} else {
(ast::ViewItemExternCrate(id_test,
Expand Down
38 changes: 18 additions & 20 deletions src/librustc/middle/privacy.rs
Expand Up @@ -872,26 +872,24 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
fn visit_view_item(&mut self, a: &ast::ViewItem, _: ()) {
match a.node {
ast::ViewItemExternCrate(..) => {}
ast::ViewItemUse(ref uses) => {
for vpath in uses.iter() {
match vpath.node {
ast::ViewPathSimple(..) | ast::ViewPathGlob(..) => {}
ast::ViewPathList(_, ref list, _) => {
for pid in list.iter() {
debug!("privacy - list {}", pid.node.id);
let seg = ast::PathSegment {
identifier: pid.node.name,
lifetimes: Vec::new(),
types: OwnedSlice::empty(),
};
let segs = vec!(seg);
let path = ast::Path {
global: false,
span: pid.span,
segments: segs,
};
self.check_path(pid.span, pid.node.id, &path);
}
ast::ViewItemUse(ref vpath) => {
match vpath.node {
ast::ViewPathSimple(..) | ast::ViewPathGlob(..) => {}
ast::ViewPathList(_, ref list, _) => {
for pid in list.iter() {
debug!("privacy - list {}", pid.node.id);
let seg = ast::PathSegment {
identifier: pid.node.name,
lifetimes: Vec::new(),
types: OwnedSlice::empty(),
};
let segs = vec!(seg);
let path = ast::Path {
global: false,
span: pid.span,
segments: segs,
};
self.check_path(pid.span, pid.node.id, &path);
}
}
}
Expand Down
146 changes: 71 additions & 75 deletions src/librustc/middle/resolve.rs
Expand Up @@ -1417,72 +1417,70 @@ impl<'a> Resolver<'a> {
fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem,
parent: ReducedGraphParent) {
match view_item.node {
ViewItemUse(ref view_paths) => {
for view_path in view_paths.iter() {
// Extract and intern the module part of the path. For
// globs and lists, the path is found directly in the AST;
// for simple paths we have to munge the path a little.

let mut module_path = Vec::new();
match view_path.node {
ViewPathSimple(_, ref full_path, _) => {
let path_len = full_path.segments.len();
assert!(path_len != 0);

for (i, segment) in full_path.segments
.iter()
.enumerate() {
if i != path_len - 1 {
module_path.push(segment.identifier)
}
}
}

ViewPathGlob(ref module_ident_path, _) |
ViewPathList(ref module_ident_path, _, _) => {
for segment in module_ident_path.segments.iter() {
ViewItemUse(ref view_path) => {
// Extract and intern the module part of the path. For
// globs and lists, the path is found directly in the AST;
// for simple paths we have to munge the path a little.

let mut module_path = Vec::new();
match view_path.node {
ViewPathSimple(_, ref full_path, _) => {
let path_len = full_path.segments.len();
assert!(path_len != 0);

for (i, segment) in full_path.segments
.iter()
.enumerate() {
if i != path_len - 1 {
module_path.push(segment.identifier)
}
}
}

// Build up the import directives.
let module_ = parent.module();
let is_public = view_item.vis == ast::Public;
match view_path.node {
ViewPathSimple(binding, ref full_path, id) => {
let source_ident =
full_path.segments.last().unwrap().identifier;
let subclass = SingleImport(binding,
source_ident);
self.build_import_directive(&*module_,
module_path,
subclass,
view_path.span,
id,
is_public);
ViewPathGlob(ref module_ident_path, _) |
ViewPathList(ref module_ident_path, _, _) => {
for segment in module_ident_path.segments.iter() {
module_path.push(segment.identifier)
}
ViewPathList(_, ref source_idents, _) => {
for source_ident in source_idents.iter() {
let name = source_ident.node.name;
self.build_import_directive(
&*module_,
module_path.clone(),
SingleImport(name, name),
source_ident.span,
source_ident.node.id,
is_public);
}
}
ViewPathGlob(_, id) => {
self.build_import_directive(&*module_,
module_path,
GlobImport,
view_path.span,
id,
is_public);
}
}

// Build up the import directives.
let module_ = parent.module();
let is_public = view_item.vis == ast::Public;
match view_path.node {
ViewPathSimple(binding, ref full_path, id) => {
let source_ident =
full_path.segments.last().unwrap().identifier;
let subclass = SingleImport(binding,
source_ident);
self.build_import_directive(&*module_,
module_path,
subclass,
view_path.span,
id,
is_public);
}
ViewPathList(_, ref source_idents, _) => {
for source_ident in source_idents.iter() {
let name = source_ident.node.name;
self.build_import_directive(
&*module_,
module_path.clone(),
SingleImport(name, name),
source_ident.span,
source_ident.node.id,
is_public);
}
}
ViewPathGlob(_, id) => {
self.build_import_directive(&*module_,
module_path,
GlobImport,
view_path.span,
id,
is_public);
}
}
}

Expand Down Expand Up @@ -5226,23 +5224,21 @@ impl<'a> Resolver<'a> {

match vi.node {
ViewItemExternCrate(..) => {} // ignore
ViewItemUse(ref path) => {
for p in path.iter() {
match p.node {
ViewPathSimple(_, _, id) => self.finalize_import(id, p.span),
ViewPathList(_, ref list, _) => {
for i in list.iter() {
self.finalize_import(i.node.id, i.span);
}
},
ViewPathGlob(_, id) => {
if !self.used_imports.contains(&(id, TypeNS)) &&
!self.used_imports.contains(&(id, ValueNS)) {
self.session.add_lint(UnusedImports, id, p.span,
"unused import".to_owned());
}
},
}
ViewItemUse(ref p) => {
match p.node {
ViewPathSimple(_, _, id) => self.finalize_import(id, p.span),
ViewPathList(_, ref list, _) => {
for i in list.iter() {
self.finalize_import(i.node.id, i.span);
}
},
ViewPathGlob(_, id) => {
if !self.used_imports.contains(&(id, TypeNS)) &&
!self.used_imports.contains(&(id, ValueNS)) {
self.session.add_lint(UnusedImports, id, p.span,
"unused import".to_owned());
}
},
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean.rs
Expand Up @@ -1085,7 +1085,7 @@ impl Clean<Item> for ast::ViewItem {
#[deriving(Clone, Encodable, Decodable)]
pub enum ViewItemInner {
ExternCrate(~str, Option<~str>, ast::NodeId),
Import(Vec<ViewPath>)
Import(ViewPath)
}

impl Clean<ViewItemInner> for ast::ViewItem_ {
Expand All @@ -1099,7 +1099,7 @@ impl Clean<ViewItemInner> for ast::ViewItem_ {
ExternCrate(i.clean(), string, *id)
}
&ast::ViewItemUse(ref vp) => {
Import(vp.clean().move_iter().collect())
Import(vp.clean())
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/librustdoc/html/render.rs
Expand Up @@ -1165,12 +1165,10 @@ fn item_module(w: &mut Writer, cx: &Context,
try!(write!(w, ";</code></td></tr>"));
}

clean::Import(ref imports) => {
for import in imports.iter() {
try!(write!(w, "<tr><td><code>{}{}</code></td></tr>",
VisSpace(myitem.visibility),
*import));
}
clean::Import(ref import) => {
try!(write!(w, "<tr><td><code>{}{}</code></td></tr>",
VisSpace(myitem.visibility),
*import));
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/librustdoc/visit_ast.rs
Expand Up @@ -133,14 +133,12 @@ impl<'a> RustdocVisitor<'a> {
return om.view_items.push(item.clone());
}
let item = match item.node {
ast::ViewItemUse(ref paths) => {
// rustc no longer supports "use foo, bar;"
assert_eq!(paths.len(), 1);
match self.visit_view_path(*paths.get(0), om) {
ast::ViewItemUse(ref vpath) => {
match self.visit_view_path(*vpath, om) {
None => return,
Some(path) => {
ast::ViewItem {
node: ast::ViewItemUse(vec!(path)),
node: ast::ViewItemUse(path),
.. item.clone()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Expand Up @@ -1003,7 +1003,7 @@ pub enum ViewItem_ {
// (containing arbitrary characters) from which to fetch the crate sources
// For example, extern crate whatever = "github.com/mozilla/rust"
ViewItemExternCrate(Ident, Option<(InternedString,StrStyle)>, NodeId),
ViewItemUse(Vec<@ViewPath> ),
ViewItemUse(@ViewPath),
}

// Meta-data associated with an item
Expand Down
22 changes: 10 additions & 12 deletions src/libsyntax/ast_util.rs
Expand Up @@ -407,18 +407,16 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
ViewItemExternCrate(_, _, node_id) => {
self.operation.visit_id(node_id)
}
ViewItemUse(ref view_paths) => {
for view_path in view_paths.iter() {
match view_path.node {
ViewPathSimple(_, _, node_id) |
ViewPathGlob(_, node_id) => {
self.operation.visit_id(node_id)
}
ViewPathList(_, ref paths, node_id) => {
self.operation.visit_id(node_id);
for path in paths.iter() {
self.operation.visit_id(path.node.id)
}
ViewItemUse(ref view_path) => {
match view_path.node {
ViewPathSimple(_, _, node_id) |
ViewPathGlob(_, node_id) => {
self.operation.visit_id(node_id)
}
ViewPathList(_, ref paths, node_id) => {
self.operation.visit_id(node_id);
for path in paths.iter() {
self.operation.visit_id(path.node.id)
}
}
}
Expand Down

0 comments on commit b03547b

Please sign in to comment.