syntax: ViewItemUse no longer contains multiple view paths.

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.
This commit is contained in:
Kang Seonghoon 2014-04-26 22:33:45 +09:00
parent eea4909a87
commit b03547bac1
15 changed files with 185 additions and 208 deletions

View File

@ -130,8 +130,7 @@ impl<'a> Visitor<()> for Context<'a> {
fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) { fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
match i.node { match i.node {
ast::ViewItemUse(ref paths) => { ast::ViewItemUse(ref path) => {
for path in paths.iter() {
match path.node { match path.node {
ast::ViewPathGlob(..) => { ast::ViewPathGlob(..) => {
self.gate_feature("globs", path.span, self.gate_feature("globs", path.span,
@ -141,7 +140,6 @@ impl<'a> Visitor<()> for Context<'a> {
_ => {} _ => {}
} }
} }
}
ast::ViewItemExternCrate(..) => { ast::ViewItemExternCrate(..) => {
for attr in i.attrs.iter() { for attr in i.attrs.iter() {
if attr.name().get() == "phase"{ if attr.name().get() == "phase"{

View File

@ -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 vp = @codemap::dummy_spanned(ast::ViewPathGlob(prelude_path, ast::DUMMY_NODE_ID));
let vi2 = ast::ViewItem { let vi2 = ast::ViewItem {
node: ast::ViewItemUse(vec!(vp)), node: ast::ViewItemUse(vp),
attrs: Vec::new(), attrs: Vec::new(),
vis: ast::Inherited, vis: ast::Inherited,
span: DUMMY_SP, span: DUMMY_SP,

View File

@ -299,9 +299,9 @@ fn mk_std(cx: &TestCtxt) -> ast::ViewItem {
let id_test = token::str_to_ident("test"); let id_test = token::str_to_ident("test");
let (vi, vis) = if cx.is_test_crate { let (vi, vis) = if cx.is_test_crate {
(ast::ViewItemUse( (ast::ViewItemUse(
vec!(@nospan(ast::ViewPathSimple(id_test, @nospan(ast::ViewPathSimple(id_test,
path_node(vec!(id_test)), path_node(vec!(id_test)),
ast::DUMMY_NODE_ID)))), ast::DUMMY_NODE_ID))),
ast::Public) ast::Public)
} else { } else {
(ast::ViewItemExternCrate(id_test, (ast::ViewItemExternCrate(id_test,

View File

@ -872,8 +872,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
fn visit_view_item(&mut self, a: &ast::ViewItem, _: ()) { fn visit_view_item(&mut self, a: &ast::ViewItem, _: ()) {
match a.node { match a.node {
ast::ViewItemExternCrate(..) => {} ast::ViewItemExternCrate(..) => {}
ast::ViewItemUse(ref uses) => { ast::ViewItemUse(ref vpath) => {
for vpath in uses.iter() {
match vpath.node { match vpath.node {
ast::ViewPathSimple(..) | ast::ViewPathGlob(..) => {} ast::ViewPathSimple(..) | ast::ViewPathGlob(..) => {}
ast::ViewPathList(_, ref list, _) => { ast::ViewPathList(_, ref list, _) => {
@ -896,7 +895,6 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> {
} }
} }
} }
}
visit::walk_view_item(self, a, ()); visit::walk_view_item(self, a, ());
} }

View File

@ -1417,8 +1417,7 @@ impl<'a> Resolver<'a> {
fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem, fn build_reduced_graph_for_view_item(&mut self, view_item: &ViewItem,
parent: ReducedGraphParent) { parent: ReducedGraphParent) {
match view_item.node { match view_item.node {
ViewItemUse(ref view_paths) => { ViewItemUse(ref view_path) => {
for view_path in view_paths.iter() {
// Extract and intern the module part of the path. For // Extract and intern the module part of the path. For
// globs and lists, the path is found directly in the AST; // globs and lists, the path is found directly in the AST;
// for simple paths we have to munge the path a little. // for simple paths we have to munge the path a little.
@ -1484,7 +1483,6 @@ impl<'a> Resolver<'a> {
} }
} }
} }
}
ViewItemExternCrate(name, _, node_id) => { ViewItemExternCrate(name, _, node_id) => {
// n.b. we don't need to look at the path option here, because cstore already did // n.b. we don't need to look at the path option here, because cstore already did
@ -5226,8 +5224,7 @@ impl<'a> Resolver<'a> {
match vi.node { match vi.node {
ViewItemExternCrate(..) => {} // ignore ViewItemExternCrate(..) => {} // ignore
ViewItemUse(ref path) => { ViewItemUse(ref p) => {
for p in path.iter() {
match p.node { match p.node {
ViewPathSimple(_, _, id) => self.finalize_import(id, p.span), ViewPathSimple(_, _, id) => self.finalize_import(id, p.span),
ViewPathList(_, ref list, _) => { ViewPathList(_, ref list, _) => {
@ -5246,7 +5243,6 @@ impl<'a> Resolver<'a> {
} }
} }
} }
}
// We have information about whether `use` (import) directives are actually used now. // We have information about whether `use` (import) directives are actually used now.
// If an import is not used at all, we signal a lint error. If an import is only used // If an import is not used at all, we signal a lint error. If an import is only used

View File

@ -1085,7 +1085,7 @@ impl Clean<Item> for ast::ViewItem {
#[deriving(Clone, Encodable, Decodable)] #[deriving(Clone, Encodable, Decodable)]
pub enum ViewItemInner { pub enum ViewItemInner {
ExternCrate(~str, Option<~str>, ast::NodeId), ExternCrate(~str, Option<~str>, ast::NodeId),
Import(Vec<ViewPath>) Import(ViewPath)
} }
impl Clean<ViewItemInner> for ast::ViewItem_ { impl Clean<ViewItemInner> for ast::ViewItem_ {
@ -1099,7 +1099,7 @@ impl Clean<ViewItemInner> for ast::ViewItem_ {
ExternCrate(i.clean(), string, *id) ExternCrate(i.clean(), string, *id)
} }
&ast::ViewItemUse(ref vp) => { &ast::ViewItemUse(ref vp) => {
Import(vp.clean().move_iter().collect()) Import(vp.clean())
} }
} }
} }

View File

@ -1165,14 +1165,12 @@ fn item_module(w: &mut Writer, cx: &Context,
try!(write!(w, ";</code></td></tr>")); try!(write!(w, ";</code></td></tr>"));
} }
clean::Import(ref imports) => { clean::Import(ref import) => {
for import in imports.iter() {
try!(write!(w, "<tr><td><code>{}{}</code></td></tr>", try!(write!(w, "<tr><td><code>{}{}</code></td></tr>",
VisSpace(myitem.visibility), VisSpace(myitem.visibility),
*import)); *import));
} }
} }
}
} }

View File

@ -133,14 +133,12 @@ impl<'a> RustdocVisitor<'a> {
return om.view_items.push(item.clone()); return om.view_items.push(item.clone());
} }
let item = match item.node { let item = match item.node {
ast::ViewItemUse(ref paths) => { ast::ViewItemUse(ref vpath) => {
// rustc no longer supports "use foo, bar;" match self.visit_view_path(*vpath, om) {
assert_eq!(paths.len(), 1);
match self.visit_view_path(*paths.get(0), om) {
None => return, None => return,
Some(path) => { Some(path) => {
ast::ViewItem { ast::ViewItem {
node: ast::ViewItemUse(vec!(path)), node: ast::ViewItemUse(path),
.. item.clone() .. item.clone()
} }
} }

View File

@ -1003,7 +1003,7 @@ pub enum ViewItem_ {
// (containing arbitrary characters) from which to fetch the crate sources // (containing arbitrary characters) from which to fetch the crate sources
// For example, extern crate whatever = "github.com/mozilla/rust" // For example, extern crate whatever = "github.com/mozilla/rust"
ViewItemExternCrate(Ident, Option<(InternedString,StrStyle)>, NodeId), ViewItemExternCrate(Ident, Option<(InternedString,StrStyle)>, NodeId),
ViewItemUse(Vec<@ViewPath> ), ViewItemUse(@ViewPath),
} }
// Meta-data associated with an item // Meta-data associated with an item

View File

@ -407,8 +407,7 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
ViewItemExternCrate(_, _, node_id) => { ViewItemExternCrate(_, _, node_id) => {
self.operation.visit_id(node_id) self.operation.visit_id(node_id)
} }
ViewItemUse(ref view_paths) => { ViewItemUse(ref view_path) => {
for view_path in view_paths.iter() {
match view_path.node { match view_path.node {
ViewPathSimple(_, _, node_id) | ViewPathSimple(_, _, node_id) |
ViewPathGlob(_, node_id) => { ViewPathGlob(_, node_id) => {
@ -423,7 +422,6 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> {
} }
} }
} }
}
visit::walk_view_item(self, view_item, env); visit::walk_view_item(self, view_item, env);
self.visited_outermost = false; self.visited_outermost = false;
} }

View File

@ -246,7 +246,7 @@ pub trait AstBuilder {
-> @ast::MetaItem; -> @ast::MetaItem;
fn view_use(&self, sp: Span, fn view_use(&self, sp: Span,
vis: ast::Visibility, vp: Vec<@ast::ViewPath> ) -> ast::ViewItem; vis: ast::Visibility, vp: @ast::ViewPath) -> ast::ViewItem;
fn view_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> ast::ViewItem; fn view_use_simple(&self, sp: Span, vis: ast::Visibility, path: ast::Path) -> ast::ViewItem;
fn view_use_simple_(&self, sp: Span, vis: ast::Visibility, fn view_use_simple_(&self, sp: Span, vis: ast::Visibility,
ident: ast::Ident, path: ast::Path) -> ast::ViewItem; ident: ast::Ident, path: ast::Path) -> ast::ViewItem;
@ -949,7 +949,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
} }
fn view_use(&self, sp: Span, fn view_use(&self, sp: Span,
vis: ast::Visibility, vp: Vec<@ast::ViewPath> ) -> ast::ViewItem { vis: ast::Visibility, vp: @ast::ViewPath) -> ast::ViewItem {
ast::ViewItem { ast::ViewItem {
node: ast::ViewItemUse(vp), node: ast::ViewItemUse(vp),
attrs: Vec::new(), attrs: Vec::new(),
@ -966,10 +966,10 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
fn view_use_simple_(&self, sp: Span, vis: ast::Visibility, fn view_use_simple_(&self, sp: Span, vis: ast::Visibility,
ident: ast::Ident, path: ast::Path) -> ast::ViewItem { ident: ast::Ident, path: ast::Path) -> ast::ViewItem {
self.view_use(sp, vis, self.view_use(sp, vis,
vec!(@respan(sp, @respan(sp,
ast::ViewPathSimple(ident, ast::ViewPathSimple(ident,
path, path,
ast::DUMMY_NODE_ID)))) ast::DUMMY_NODE_ID)))
} }
fn view_use_list(&self, sp: Span, vis: ast::Visibility, fn view_use_list(&self, sp: Span, vis: ast::Visibility,
@ -979,17 +979,17 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
}).collect(); }).collect();
self.view_use(sp, vis, self.view_use(sp, vis,
vec!(@respan(sp, @respan(sp,
ast::ViewPathList(self.path(sp, path), ast::ViewPathList(self.path(sp, path),
imports, imports,
ast::DUMMY_NODE_ID)))) ast::DUMMY_NODE_ID)))
} }
fn view_use_glob(&self, sp: Span, fn view_use_glob(&self, sp: Span,
vis: ast::Visibility, path: Vec<ast::Ident> ) -> ast::ViewItem { vis: ast::Visibility, path: Vec<ast::Ident> ) -> ast::ViewItem {
self.view_use(sp, vis, self.view_use(sp, vis,
vec!(@respan(sp, @respan(sp,
ast::ViewPathGlob(self.path(sp, path), ast::DUMMY_NODE_ID)))) ast::ViewPathGlob(self.path(sp, path), ast::DUMMY_NODE_ID)))
} }
} }

View File

@ -28,8 +28,7 @@ pub trait Folder {
meta_items.iter().map(|x| fold_meta_item_(*x, self)).collect() meta_items.iter().map(|x| fold_meta_item_(*x, self)).collect()
} }
fn fold_view_paths(&mut self, view_paths: &[@ViewPath]) -> Vec<@ViewPath> { fn fold_view_path(&mut self, view_path: @ViewPath) -> @ViewPath {
view_paths.iter().map(|view_path| {
let inner_view_path = match view_path.node { let inner_view_path = match view_path.node {
ViewPathSimple(ref ident, ref path, node_id) => { ViewPathSimple(ref ident, ref path, node_id) => {
let id = self.new_id(node_id); let id = self.new_id(node_id);
@ -65,7 +64,6 @@ pub trait Folder {
node: inner_view_path, node: inner_view_path,
span: self.new_span(view_path.span), span: self.new_span(view_path.span),
} }
}).collect()
} }
fn fold_view_item(&mut self, vi: &ViewItem) -> ViewItem { fn fold_view_item(&mut self, vi: &ViewItem) -> ViewItem {
@ -557,8 +555,8 @@ pub fn noop_fold_view_item<T: Folder>(vi: &ViewItem, folder: &mut T)
(*string).clone(), (*string).clone(),
folder.new_id(node_id)) folder.new_id(node_id))
} }
ViewItemUse(ref view_paths) => { ViewItemUse(ref view_path) => {
ViewItemUse(folder.fold_view_paths(view_paths.as_slice())) ViewItemUse(folder.fold_view_path(*view_path))
} }
}; };
ViewItem { ViewItem {

View File

@ -4918,12 +4918,12 @@ impl<'a> Parser<'a> {
} }
// matches view_paths = view_path | view_path , view_paths // matches view_paths = view_path | view_path , view_paths
fn parse_view_paths(&mut self) -> Vec<@ViewPath> { fn parse_view_paths(&mut self) -> @ViewPath {
let mut vp = vec!(self.parse_view_path()); let vp = self.parse_view_path();
while self.token == token::COMMA { while self.token == token::COMMA {
self.bump(); self.bump();
self.obsolete(self.last_span, ObsoleteMultipleImport); self.obsolete(self.last_span, ObsoleteMultipleImport);
vp.push(self.parse_view_path()); let _ = self.parse_view_path();
} }
return vp; return vp;
} }

View File

@ -1995,11 +1995,6 @@ impl<'a> State<'a> {
} }
} }
pub fn print_view_paths(&mut self,
vps: &[@ast::ViewPath]) -> IoResult<()> {
self.commasep(Inconsistent, vps, |s, &vp| s.print_view_path(vp))
}
pub fn print_view_item(&mut self, item: &ast::ViewItem) -> IoResult<()> { pub fn print_view_item(&mut self, item: &ast::ViewItem) -> IoResult<()> {
try!(self.hardbreak_if_not_bol()); try!(self.hardbreak_if_not_bol());
try!(self.maybe_print_comment(item.span.lo)); try!(self.maybe_print_comment(item.span.lo));
@ -2017,9 +2012,9 @@ impl<'a> State<'a> {
} }
} }
ast::ViewItemUse(ref vps) => { ast::ViewItemUse(ref vp) => {
try!(self.head("use")); try!(self.head("use"));
try!(self.print_view_paths(vps.as_slice())); try!(self.print_view_path(*vp));
} }
} }
try!(word(&mut self.s, ";")); try!(word(&mut self.s, ";"));

View File

@ -150,8 +150,7 @@ pub fn walk_view_item<E: Clone, V: Visitor<E>>(visitor: &mut V, vi: &ViewItem, e
ViewItemExternCrate(name, _, _) => { ViewItemExternCrate(name, _, _) => {
visitor.visit_ident(vi.span, name, env) visitor.visit_ident(vi.span, name, env)
} }
ViewItemUse(ref paths) => { ViewItemUse(ref vp) => {
for vp in paths.iter() {
match vp.node { match vp.node {
ViewPathSimple(ident, ref path, id) => { ViewPathSimple(ident, ref path, id) => {
visitor.visit_ident(vp.span, ident, env.clone()); visitor.visit_ident(vp.span, ident, env.clone());
@ -169,7 +168,6 @@ pub fn walk_view_item<E: Clone, V: Visitor<E>>(visitor: &mut V, vi: &ViewItem, e
} }
} }
} }
}
} }
pub fn walk_local<E: Clone, V: Visitor<E>>(visitor: &mut V, local: &Local, env: E) { pub fn walk_local<E: Clone, V: Visitor<E>>(visitor: &mut V, local: &Local, env: E) {