Skip to content

Commit f55d66a

Browse files
committed
auto merge of #13777 : lifthrasiir/rust/no-multi-viewitemuse, r=alexcrichton
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 PR cleans them up altogether. As a side effect of cleanup, we now have `SCHEMA_VERSION` in `rustdoc::clean` (instead of the crate root), so it has a better chance to be updated when `rustdoc::clean` gets updated.
2 parents ade02bb + bec77eb commit f55d66a

File tree

16 files changed

+194
-212
lines changed

16 files changed

+194
-212
lines changed

src/librustc/front/feature_gate.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,14 @@ impl<'a> Visitor<()> for Context<'a> {
130130

131131
fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
132132
match i.node {
133-
ast::ViewItemUse(ref paths) => {
134-
for path in paths.iter() {
135-
match path.node {
136-
ast::ViewPathGlob(..) => {
137-
self.gate_feature("globs", path.span,
138-
"glob import statements are \
139-
experimental and possibly buggy");
140-
}
141-
_ => {}
133+
ast::ViewItemUse(ref path) => {
134+
match path.node {
135+
ast::ViewPathGlob(..) => {
136+
self.gate_feature("globs", path.span,
137+
"glob import statements are \
138+
experimental and possibly buggy");
142139
}
140+
_ => {}
143141
}
144142
}
145143
ast::ViewItemExternCrate(..) => {

src/librustc/front/std_inject.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ impl<'a> fold::Folder for PreludeInjector<'a> {
166166

167167
let vp = @codemap::dummy_spanned(ast::ViewPathGlob(prelude_path, ast::DUMMY_NODE_ID));
168168
let vi2 = ast::ViewItem {
169-
node: ast::ViewItemUse(vec!(vp)),
169+
node: ast::ViewItemUse(vp),
170170
attrs: Vec::new(),
171171
vis: ast::Inherited,
172172
span: DUMMY_SP,

src/librustc/front/test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,9 @@ fn mk_std(cx: &TestCtxt) -> ast::ViewItem {
299299
let id_test = token::str_to_ident("test");
300300
let (vi, vis) = if cx.is_test_crate {
301301
(ast::ViewItemUse(
302-
vec!(@nospan(ast::ViewPathSimple(id_test,
303-
path_node(vec!(id_test)),
304-
ast::DUMMY_NODE_ID)))),
302+
@nospan(ast::ViewPathSimple(id_test,
303+
path_node(vec!(id_test)),
304+
ast::DUMMY_NODE_ID))),
305305
ast::Public)
306306
} else {
307307
(ast::ViewItemExternCrate(id_test,

src/librustc/middle/privacy.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -872,26 +872,24 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
872872
fn visit_view_item(&mut self, a: &ast::ViewItem, _: ()) {
873873
match a.node {
874874
ast::ViewItemExternCrate(..) => {}
875-
ast::ViewItemUse(ref uses) => {
876-
for vpath in uses.iter() {
877-
match vpath.node {
878-
ast::ViewPathSimple(..) | ast::ViewPathGlob(..) => {}
879-
ast::ViewPathList(_, ref list, _) => {
880-
for pid in list.iter() {
881-
debug!("privacy - list {}", pid.node.id);
882-
let seg = ast::PathSegment {
883-
identifier: pid.node.name,
884-
lifetimes: Vec::new(),
885-
types: OwnedSlice::empty(),
886-
};
887-
let segs = vec!(seg);
888-
let path = ast::Path {
889-
global: false,
890-
span: pid.span,
891-
segments: segs,
892-
};
893-
self.check_path(pid.span, pid.node.id, &path);
894-
}
875+
ast::ViewItemUse(ref vpath) => {
876+
match vpath.node {
877+
ast::ViewPathSimple(..) | ast::ViewPathGlob(..) => {}
878+
ast::ViewPathList(_, ref list, _) => {
879+
for pid in list.iter() {
880+
debug!("privacy - list {}", pid.node.id);
881+
let seg = ast::PathSegment {
882+
identifier: pid.node.name,
883+
lifetimes: Vec::new(),
884+
types: OwnedSlice::empty(),
885+
};
886+
let segs = vec!(seg);
887+
let path = ast::Path {
888+
global: false,
889+
span: pid.span,
890+
segments: segs,
891+
};
892+
self.check_path(pid.span, pid.node.id, &path);
895893
}
896894
}
897895
}

src/librustc/middle/resolve.rs

+71-75
Original file line numberDiff line numberDiff line change
@@ -1417,72 +1417,70 @@ impl<'a> Resolver<'a> {
14171417
fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem,
14181418
parent: ReducedGraphParent) {
14191419
match view_item.node {
1420-
ViewItemUse(ref view_paths) => {
1421-
for view_path in view_paths.iter() {
1422-
// Extract and intern the module part of the path. For
1423-
// globs and lists, the path is found directly in the AST;
1424-
// for simple paths we have to munge the path a little.
1425-
1426-
let mut module_path = Vec::new();
1427-
match view_path.node {
1428-
ViewPathSimple(_, ref full_path, _) => {
1429-
let path_len = full_path.segments.len();
1430-
assert!(path_len != 0);
1431-
1432-
for (i, segment) in full_path.segments
1433-
.iter()
1434-
.enumerate() {
1435-
if i != path_len - 1 {
1436-
module_path.push(segment.identifier)
1437-
}
1438-
}
1439-
}
1440-
1441-
ViewPathGlob(ref module_ident_path, _) |
1442-
ViewPathList(ref module_ident_path, _, _) => {
1443-
for segment in module_ident_path.segments.iter() {
1420+
ViewItemUse(ref view_path) => {
1421+
// Extract and intern the module part of the path. For
1422+
// globs and lists, the path is found directly in the AST;
1423+
// for simple paths we have to munge the path a little.
1424+
1425+
let mut module_path = Vec::new();
1426+
match view_path.node {
1427+
ViewPathSimple(_, ref full_path, _) => {
1428+
let path_len = full_path.segments.len();
1429+
assert!(path_len != 0);
1430+
1431+
for (i, segment) in full_path.segments
1432+
.iter()
1433+
.enumerate() {
1434+
if i != path_len - 1 {
14441435
module_path.push(segment.identifier)
14451436
}
14461437
}
14471438
}
14481439

1449-
// Build up the import directives.
1450-
let module_ = parent.module();
1451-
let is_public = view_item.vis == ast::Public;
1452-
match view_path.node {
1453-
ViewPathSimple(binding, ref full_path, id) => {
1454-
let source_ident =
1455-
full_path.segments.last().unwrap().identifier;
1456-
let subclass = SingleImport(binding,
1457-
source_ident);
1458-
self.build_import_directive(&*module_,
1459-
module_path,
1460-
subclass,
1461-
view_path.span,
1462-
id,
1463-
is_public);
1440+
ViewPathGlob(ref module_ident_path, _) |
1441+
ViewPathList(ref module_ident_path, _, _) => {
1442+
for segment in module_ident_path.segments.iter() {
1443+
module_path.push(segment.identifier)
14641444
}
1465-
ViewPathList(_, ref source_idents, _) => {
1466-
for source_ident in source_idents.iter() {
1467-
let name = source_ident.node.name;
1468-
self.build_import_directive(
1469-
&*module_,
1470-
module_path.clone(),
1471-
SingleImport(name, name),
1472-
source_ident.span,
1473-
source_ident.node.id,
1474-
is_public);
1475-
}
1476-
}
1477-
ViewPathGlob(_, id) => {
1478-
self.build_import_directive(&*module_,
1479-
module_path,
1480-
GlobImport,
1481-
view_path.span,
1482-
id,
1483-
is_public);
1445+
}
1446+
}
1447+
1448+
// Build up the import directives.
1449+
let module_ = parent.module();
1450+
let is_public = view_item.vis == ast::Public;
1451+
match view_path.node {
1452+
ViewPathSimple(binding, ref full_path, id) => {
1453+
let source_ident =
1454+
full_path.segments.last().unwrap().identifier;
1455+
let subclass = SingleImport(binding,
1456+
source_ident);
1457+
self.build_import_directive(&*module_,
1458+
module_path,
1459+
subclass,
1460+
view_path.span,
1461+
id,
1462+
is_public);
1463+
}
1464+
ViewPathList(_, ref source_idents, _) => {
1465+
for source_ident in source_idents.iter() {
1466+
let name = source_ident.node.name;
1467+
self.build_import_directive(
1468+
&*module_,
1469+
module_path.clone(),
1470+
SingleImport(name, name),
1471+
source_ident.span,
1472+
source_ident.node.id,
1473+
is_public);
14841474
}
14851475
}
1476+
ViewPathGlob(_, id) => {
1477+
self.build_import_directive(&*module_,
1478+
module_path,
1479+
GlobImport,
1480+
view_path.span,
1481+
id,
1482+
is_public);
1483+
}
14861484
}
14871485
}
14881486

@@ -5226,23 +5224,21 @@ impl<'a> Resolver<'a> {
52265224

52275225
match vi.node {
52285226
ViewItemExternCrate(..) => {} // ignore
5229-
ViewItemUse(ref path) => {
5230-
for p in path.iter() {
5231-
match p.node {
5232-
ViewPathSimple(_, _, id) => self.finalize_import(id, p.span),
5233-
ViewPathList(_, ref list, _) => {
5234-
for i in list.iter() {
5235-
self.finalize_import(i.node.id, i.span);
5236-
}
5237-
},
5238-
ViewPathGlob(_, id) => {
5239-
if !self.used_imports.contains(&(id, TypeNS)) &&
5240-
!self.used_imports.contains(&(id, ValueNS)) {
5241-
self.session.add_lint(UnusedImports, id, p.span,
5242-
"unused import".to_owned());
5243-
}
5244-
},
5245-
}
5227+
ViewItemUse(ref p) => {
5228+
match p.node {
5229+
ViewPathSimple(_, _, id) => self.finalize_import(id, p.span),
5230+
ViewPathList(_, ref list, _) => {
5231+
for i in list.iter() {
5232+
self.finalize_import(i.node.id, i.span);
5233+
}
5234+
},
5235+
ViewPathGlob(_, id) => {
5236+
if !self.used_imports.contains(&(id, TypeNS)) &&
5237+
!self.used_imports.contains(&(id, ValueNS)) {
5238+
self.session.add_lint(UnusedImports, id, p.span,
5239+
"unused import".to_owned());
5240+
}
5241+
},
52465242
}
52475243
}
52485244
}

src/librustdoc/clean.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ use core;
3232
use doctree;
3333
use visit_ast;
3434

35+
/// A stable identifier to the particular version of JSON output.
36+
/// Increment this when the `Crate` and related structures change.
37+
pub static SCHEMA_VERSION: &'static str = "0.8.2";
38+
3539
pub trait Clean<T> {
3640
fn clean(&self) -> T;
3741
}
@@ -1085,7 +1089,7 @@ impl Clean<Item> for ast::ViewItem {
10851089
#[deriving(Clone, Encodable, Decodable)]
10861090
pub enum ViewItemInner {
10871091
ExternCrate(~str, Option<~str>, ast::NodeId),
1088-
Import(Vec<ViewPath>)
1092+
Import(ViewPath)
10891093
}
10901094

10911095
impl Clean<ViewItemInner> for ast::ViewItem_ {
@@ -1099,7 +1103,7 @@ impl Clean<ViewItemInner> for ast::ViewItem_ {
10991103
ExternCrate(i.clean(), string, *id)
11001104
}
11011105
&ast::ViewItemUse(ref vp) => {
1102-
Import(vp.clean().move_iter().collect())
1106+
Import(vp.clean())
11031107
}
11041108
}
11051109
}

src/librustdoc/html/render.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1167,12 +1167,10 @@ fn item_module(w: &mut Writer, cx: &Context,
11671167
try!(write!(w, ";</code></td></tr>"));
11681168
}
11691169

1170-
clean::Import(ref imports) => {
1171-
for import in imports.iter() {
1172-
try!(write!(w, "<tr><td><code>{}{}</code></td></tr>",
1173-
VisSpace(myitem.visibility),
1174-
*import));
1175-
}
1170+
clean::Import(ref import) => {
1171+
try!(write!(w, "<tr><td><code>{}{}</code></td></tr>",
1172+
VisSpace(myitem.visibility),
1173+
*import));
11761174
}
11771175
}
11781176

src/librustdoc/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ use std::io::{File, MemWriter};
3434
use std::str;
3535
use serialize::{json, Decodable, Encodable};
3636

37+
// reexported from `clean` so it can be easily updated with the mod itself
38+
pub use clean::SCHEMA_VERSION;
39+
3740
pub mod clean;
3841
pub mod core;
3942
pub mod doctree;
@@ -55,8 +58,6 @@ pub mod visit_ast;
5558
pub mod test;
5659
mod flock;
5760

58-
pub static SCHEMA_VERSION: &'static str = "0.8.1";
59-
6061
type Pass = (&'static str, // name
6162
fn(clean::Crate) -> plugins::PluginResult, // fn
6263
&'static str); // description

src/librustdoc/visit_ast.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,12 @@ impl<'a> RustdocVisitor<'a> {
133133
return om.view_items.push(item.clone());
134134
}
135135
let item = match item.node {
136-
ast::ViewItemUse(ref paths) => {
137-
// rustc no longer supports "use foo, bar;"
138-
assert_eq!(paths.len(), 1);
139-
match self.visit_view_path(*paths.get(0), om) {
136+
ast::ViewItemUse(ref vpath) => {
137+
match self.visit_view_path(*vpath, om) {
140138
None => return,
141139
Some(path) => {
142140
ast::ViewItem {
143-
node: ast::ViewItemUse(vec!(path)),
141+
node: ast::ViewItemUse(path),
144142
.. item.clone()
145143
}
146144
}

src/libsyntax/ast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ pub enum ViewItem_ {
10031003
// (containing arbitrary characters) from which to fetch the crate sources
10041004
// For example, extern crate whatever = "github.com/mozilla/rust"
10051005
ViewItemExternCrate(Ident, Option<(InternedString,StrStyle)>, NodeId),
1006-
ViewItemUse(Vec<@ViewPath> ),
1006+
ViewItemUse(@ViewPath),
10071007
}
10081008

10091009
// Meta-data associated with an item

src/libsyntax/ast_util.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -407,18 +407,16 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
407407
ViewItemExternCrate(_, _, node_id) => {
408408
self.operation.visit_id(node_id)
409409
}
410-
ViewItemUse(ref view_paths) => {
411-
for view_path in view_paths.iter() {
412-
match view_path.node {
413-
ViewPathSimple(_, _, node_id) |
414-
ViewPathGlob(_, node_id) => {
415-
self.operation.visit_id(node_id)
416-
}
417-
ViewPathList(_, ref paths, node_id) => {
418-
self.operation.visit_id(node_id);
419-
for path in paths.iter() {
420-
self.operation.visit_id(path.node.id)
421-
}
410+
ViewItemUse(ref view_path) => {
411+
match view_path.node {
412+
ViewPathSimple(_, _, node_id) |
413+
ViewPathGlob(_, node_id) => {
414+
self.operation.visit_id(node_id)
415+
}
416+
ViewPathList(_, ref paths, node_id) => {
417+
self.operation.visit_id(node_id);
418+
for path in paths.iter() {
419+
self.operation.visit_id(path.node.id)
422420
}
423421
}
424422
}

0 commit comments

Comments
 (0)