diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/front/feature_gate.rs | 2 | ||||
| -rw-r--r-- | src/librustc/front/std_inject.rs | 6 | ||||
| -rw-r--r-- | src/librustc/front/test.rs | 2 | ||||
| -rw-r--r-- | src/librustc/metadata/creader.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/privacy.rs | 4 | ||||
| -rw-r--r-- | src/librustc/middle/resolve.rs | 4 | ||||
| -rw-r--r-- | src/librustc/util/nodemap.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/clean.rs | 6 | ||||
| -rw-r--r-- | src/librustdoc/html/render.rs | 67 | ||||
| -rw-r--r-- | src/librustdoc/visit_ast.rs | 2 | ||||
| -rw-r--r-- | src/libstd/macros.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/ast.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 2 |
18 files changed, 86 insertions, 43 deletions
diff --git a/src/librustc/front/feature_gate.rs b/src/librustc/front/feature_gate.rs index b0a901f30be..fb58b3f4b7b 100644 --- a/src/librustc/front/feature_gate.rs +++ b/src/librustc/front/feature_gate.rs @@ -134,7 +134,7 @@ impl Visitor<()> for Context { } } } - ast::ViewItemExternMod(..) => { + ast::ViewItemExternCrate(..) => { for attr in i.attrs.iter() { if attr.name().get() == "phase"{ self.gate_feature("phase", attr.span, diff --git a/src/librustc/front/std_inject.rs b/src/librustc/front/std_inject.rs index eec44cc31b1..564d6a717ff 100644 --- a/src/librustc/front/std_inject.rs +++ b/src/librustc/front/std_inject.rs @@ -74,7 +74,7 @@ pub fn with_version(krate: &str) -> Option<(InternedString, ast::StrStyle)> { impl fold::Folder for StandardLibraryInjector { fn fold_crate(&mut self, krate: ast::Crate) -> ast::Crate { let mut vis = vec!(ast::ViewItem { - node: ast::ViewItemExternMod(token::str_to_ident("std"), + node: ast::ViewItemExternCrate(token::str_to_ident("std"), with_version("std"), ast::DUMMY_NODE_ID), attrs: vec!( @@ -90,7 +90,7 @@ impl fold::Folder for StandardLibraryInjector { if use_uv(&krate) && !self.sess.building_library.get() { vis.push(ast::ViewItem { - node: ast::ViewItemExternMod(token::str_to_ident("green"), + node: ast::ViewItemExternCrate(token::str_to_ident("green"), with_version("green"), ast::DUMMY_NODE_ID), attrs: Vec::new(), @@ -98,7 +98,7 @@ impl fold::Folder for StandardLibraryInjector { span: DUMMY_SP }); vis.push(ast::ViewItem { - node: ast::ViewItemExternMod(token::str_to_ident("rustuv"), + node: ast::ViewItemExternCrate(token::str_to_ident("rustuv"), with_version("rustuv"), ast::DUMMY_NODE_ID), attrs: Vec::new(), diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index ecbb704684b..9c2ebb4fb5d 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -306,7 +306,7 @@ fn mk_std(cx: &TestCtxt) -> ast::ViewItem { path_node(~[id_test]), ast::DUMMY_NODE_ID)))) } else { - ast::ViewItemExternMod(id_test, + ast::ViewItemExternCrate(id_test, with_version("test"), ast::DUMMY_NODE_ID) }; diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 58268d1169b..7289155291a 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -167,7 +167,7 @@ struct CrateInfo { fn extract_crate_info(e: &Env, i: &ast::ViewItem) -> Option<CrateInfo> { match i.node { - ast::ViewItemExternMod(ident, ref path_opt, id) => { + ast::ViewItemExternCrate(ident, ref path_opt, id) => { let ident = token::get_ident(ident); debug!("resolving extern crate stmt. ident: {:?} path_opt: {:?}", ident, path_opt); diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 182a52817b2..0a0bcc4ae0e 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -845,7 +845,7 @@ impl<'a> Visitor<()> for PrivacyVisitor<'a> { fn visit_view_item(&mut self, a: &ast::ViewItem, _: ()) { match a.node { - ast::ViewItemExternMod(..) => {} + ast::ViewItemExternCrate(..) => {} ast::ViewItemUse(ref uses) => { for vpath in uses.iter() { match vpath.node { @@ -976,7 +976,7 @@ impl Visitor<()> for SanePrivacyVisitor { reachable"); } else { match i.node { - ast::ViewItemExternMod(..) => { + ast::ViewItemExternCrate(..) => { self.tcx.sess.span_err(i.span, "`pub` visibility \ is not allowed"); } diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 46faf5b040f..7e333818912 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1516,7 +1516,7 @@ impl Resolver { } } - ViewItemExternMod(name, _, node_id) => { + ViewItemExternCrate(name, _, node_id) => { // n.b. we don't need to look at the path option here, because cstore already did match self.session.cstore.find_extern_mod_stmt_cnum(node_id) { Some(crate_id) => { @@ -5415,7 +5415,7 @@ impl Resolver { if vi.span == DUMMY_SP { return } match vi.node { - ViewItemExternMod(..) => {} // ignore + ViewItemExternCrate(..) => {} // ignore ViewItemUse(ref path) => { for p in path.iter() { match p.node { diff --git a/src/librustc/util/nodemap.rs b/src/librustc/util/nodemap.rs index fe24733aba2..05b3b105981 100644 --- a/src/librustc/util/nodemap.rs +++ b/src/librustc/util/nodemap.rs @@ -118,8 +118,8 @@ impl Writer for FnvState { fn write(&mut self, bytes: &[u8]) -> io::IoResult<()> { let FnvState(mut hash) = *self; for byte in bytes.iter() { - hash = hash * 0x100000001b3; hash = hash ^ (*byte as u64); + hash = hash * 0x100000001b3; } *self = FnvState(hash); Ok(()) diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index fd958844abd..efd0f046dc8 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -1066,19 +1066,19 @@ impl Clean<Item> for ast::ViewItem { #[deriving(Clone, Encodable, Decodable)] pub enum ViewItemInner { - ExternMod(~str, Option<~str>, ast::NodeId), + ExternCrate(~str, Option<~str>, ast::NodeId), Import(~[ViewPath]) } impl Clean<ViewItemInner> for ast::ViewItem_ { fn clean(&self) -> ViewItemInner { match self { - &ast::ViewItemExternMod(ref i, ref p, ref id) => { + &ast::ViewItemExternCrate(ref i, ref p, ref id) => { let string = match *p { None => None, Some((ref x, _)) => Some(x.get().to_owned()), }; - ExternMod(i.clean(), string, *id) + ExternCrate(i.clean(), string, *id) } &ast::ViewItemUse(ref vp) => { Import(vp.clean().move_iter().collect()) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 1029cc7444d..e985de4d2f5 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -39,6 +39,7 @@ use std::io; use std::io::{fs, File, BufferedWriter}; use std::str; use std::vec; +use std::vec_ng::Vec; use collections::{HashMap, HashSet}; use sync::Arc; @@ -160,6 +161,13 @@ pub struct Cache { priv search_index: ~[IndexItem], priv privmod: bool, priv public_items: NodeSet, + + // In rare case where a structure is defined in one module but implemented + // in another, if the implementing module is parsed before defining module, + // then the fully qualified name of the structure isn't presented in `paths` + // yet when its implementation methods are being indexed. Caches such methods + // and their parent id here and indexes them at the end of crate parsing. + priv orphan_methods: Vec<(ast::NodeId, clean::Item)>, } /// Helper struct to render all source code to HTML pages @@ -249,10 +257,31 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> { extern_locations: HashMap::new(), privmod: false, public_items: public_items, + orphan_methods: Vec::new(), } }); cache.stack.push(krate.name.clone()); krate = cache.fold_crate(krate); + { + // Attach all orphan methods to the type's definition if the type + // has since been learned. + let Cache { search_index: ref mut index, + orphan_methods: ref meths, paths: ref paths, ..} = cache; + for &(ref pid, ref item) in meths.iter() { + match paths.find(pid) { + Some(&(ref fqp, _)) => { + index.push(IndexItem { + ty: shortty(item), + name: item.name.clone().unwrap(), + path: fqp.slice_to(fqp.len() - 1).connect("::"), + desc: shorter(item.doc_value()).to_owned(), + parent: Some(*pid), + }); + }, + None => {} + } + }; + } // Add all the static files let mut dst = cx.dst.join(krate.name.as_slice()); @@ -527,26 +556,33 @@ impl DocFolder for Cache { clean::TyMethodItem(..) | clean::StructFieldItem(..) | clean::VariantItem(..) => { - Some((Some(*self.parent_stack.last().unwrap()), - self.stack.slice_to(self.stack.len() - 1))) + (Some(*self.parent_stack.last().unwrap()), + Some(self.stack.slice_to(self.stack.len() - 1))) } clean::MethodItem(..) => { if self.parent_stack.len() == 0 { - None + (None, None) } else { let last = self.parent_stack.last().unwrap(); - let amt = match self.paths.find(last) { - Some(&(_, "trait")) => self.stack.len() - 1, - Some(..) | None => self.stack.len(), + let path = match self.paths.find(last) { + Some(&(_, "trait")) => + Some(self.stack.slice_to(self.stack.len() - 1)), + // The current stack not necessarily has correlation for + // where the type was defined. On the other hand, + // `paths` always has the right information if present. + Some(&(ref fqp, "struct")) | Some(&(ref fqp, "enum")) => + Some(fqp.slice_to(fqp.len() - 1)), + Some(..) => Some(self.stack.as_slice()), + None => None }; - Some((Some(*last), self.stack.slice_to(amt))) + (Some(*last), path) } } - _ => Some((None, self.stack.as_slice())) + _ => (None, Some(self.stack.as_slice())) }; match parent { - Some((parent, path)) if !self.privmod => { + (parent, Some(path)) if !self.privmod => { self.search_index.push(IndexItem { ty: shortty(&item), name: s.to_owned(), @@ -555,7 +591,12 @@ impl DocFolder for Cache { parent: parent, }); } - Some(..) | None => {} + (Some(parent), None) if !self.privmod => { + // We have a parent, but we don't know where they're + // defined yet. Wait for later to index this item. + self.orphan_methods.push((parent, item.clone())) + } + _ => {} } } None => {} @@ -960,8 +1001,8 @@ fn item_module(w: &mut Writer, cx: &Context, match (&i1.inner, &i2.inner) { (&clean::ViewItemItem(ref a), &clean::ViewItemItem(ref b)) => { match (&a.inner, &b.inner) { - (&clean::ExternMod(..), _) => Less, - (_, &clean::ExternMod(..)) => Greater, + (&clean::ExternCrate(..), _) => Less, + (_, &clean::ExternCrate(..)) => Greater, _ => idx1.cmp(&idx2), } } @@ -1056,7 +1097,7 @@ fn item_module(w: &mut Writer, cx: &Context, clean::ViewItemItem(ref item) => { match item.inner { - clean::ExternMod(ref name, ref src, _) => { + clean::ExternCrate(ref name, ref src, _) => { try!(write!(w, "<tr><td><code>extern crate {}", name.as_slice())); match *src { diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index dc15b7f73a9..5ac623af37a 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -147,7 +147,7 @@ impl<'a> RustdocVisitor<'a> { } } } - ast::ViewItemExternMod(..) => item.clone() + ast::ViewItemExternCrate(..) => item.clone() }; om.view_items.push(item); } diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index ba72e1f2549..f0ea90a4aed 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -366,12 +366,14 @@ macro_rules! try( ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) }) ) +/// Create a `std::vec_ng::Vec` containing the arguments. #[macro_export] macro_rules! vec( ($($e:expr),*) => ({ - let mut temp = ::std::vec_ng::Vec::new(); - $(temp.push($e);)* - temp + // leading _ to allow empty construction without a warning. + let mut _temp = ::std::vec_ng::Vec::new(); + $(_temp.push($e);)* + _temp }) ) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 544d9f2d669..a8480b6cfeb 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1019,7 +1019,7 @@ pub enum ViewItem_ { // optional (InternedString,StrStyle): if present, this is a location // (containing arbitrary characters) from which to fetch the crate sources // For example, extern crate whatever = "github.com/mozilla/rust" - ViewItemExternMod(Ident, Option<(InternedString,StrStyle)>, NodeId), + ViewItemExternCrate(Ident, Option<(InternedString,StrStyle)>, NodeId), ViewItemUse(Vec<@ViewPath> ), } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 3899731b250..a6e3111fe3f 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -375,7 +375,7 @@ impl<'a, O: IdVisitingOperation> Visitor<()> for IdVisitor<'a, O> { fn visit_view_item(&mut self, view_item: &ViewItem, env: ()) { match view_item.node { - ViewItemExternMod(_, _, node_id) => { + ViewItemExternCrate(_, _, node_id) => { self.operation.visit_id(node_id) } ViewItemUse(ref view_paths) => { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 12eaa759ede..30b04b7f377 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -424,7 +424,7 @@ pub fn expand_view_item(vi: &ast::ViewItem, fld: &mut MacroExpander) -> ast::ViewItem { match vi.node { - ast::ViewItemExternMod(..) => { + ast::ViewItemExternCrate(..) => { let should_load = vi.attrs.iter().any(|attr| { attr.name().get() == "phase" && attr.meta_item_list().map_or(false, |phases| { @@ -446,7 +446,7 @@ fn load_extern_macros(krate: &ast::ViewItem, fld: &mut MacroExpander) { let MacroCrate { lib, cnum } = fld.cx.ecfg.loader.load_crate(krate); let crate_name = match krate.node { - ast::ViewItemExternMod(name, _, _) => name, + ast::ViewItemExternCrate(name, _, _) => name, _ => unreachable!() }; let name = format!("<{} macros>", token::get_ident(crate_name)); diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index e5b90393e0a..df6b06c5804 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -514,8 +514,8 @@ fn fold_variant_arg_<T: Folder>(va: &VariantArg, folder: &mut T) -> VariantArg { pub fn noop_fold_view_item<T: Folder>(vi: &ViewItem, folder: &mut T) -> ViewItem{ let inner_view_item = match vi.node { - ViewItemExternMod(ref ident, ref string, node_id) => { - ViewItemExternMod(ident.clone(), + ViewItemExternCrate(ref ident, ref string, node_id) => { + ViewItemExternCrate(ident.clone(), (*string).clone(), folder.new_id(node_id)) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 341151117f0..6fbf5f071ad 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -55,7 +55,7 @@ use ast::{TyInfer, TypeMethod}; use ast::{TyNil, TyParam, TyParamBound, TyPath, TyPtr, TyRptr}; use ast::{TyTup, TyU32, TyUniq, TyVec, UnUniq}; use ast::{UnnamedField, UnsafeBlock, UnsafeFn, ViewItem}; -use ast::{ViewItem_, ViewItemExternMod, ViewItemUse}; +use ast::{ViewItem_, ViewItemExternCrate, ViewItemUse}; use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple}; use ast::Visibility; use ast; @@ -4361,7 +4361,7 @@ impl Parser { }; IoviViewItem(ast::ViewItem { - node: ViewItemExternMod(ident, maybe_path, ast::DUMMY_NODE_ID), + node: ViewItemExternCrate(ident, maybe_path, ast::DUMMY_NODE_ID), attrs: attrs, vis: visibility, span: mk_sp(lo, self.last_span.hi) @@ -5017,11 +5017,11 @@ impl Parser { // `extern crate` must precede `use`. extern_mod_allowed = false; } - ViewItemExternMod(..) if !extern_mod_allowed => { + ViewItemExternCrate(..) if !extern_mod_allowed => { self.span_err(view_item.span, "\"extern crate\" declarations are not allowed here"); } - ViewItemExternMod(..) => {} + ViewItemExternCrate(..) => {} } view_items.push(view_item); } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index e8c32d07c74..aafda9d687d 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -2065,7 +2065,7 @@ pub fn print_view_item(s: &mut State, item: &ast::ViewItem) -> io::IoResult<()> try!(print_outer_attributes(s, item.attrs.as_slice())); try!(print_visibility(s, item.vis)); match item.node { - ast::ViewItemExternMod(id, ref optional_path, _) => { + ast::ViewItemExternCrate(id, ref optional_path, _) => { try!(head(s, "extern crate")); try!(print_ident(s, id)); for &(ref p, style) in optional_path.iter() { diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index d25d1a8cc35..f8a07599420 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -148,7 +148,7 @@ pub fn walk_mod<E: Clone, V: Visitor<E>>(visitor: &mut V, module: &Mod, env: E) pub fn walk_view_item<E: Clone, V: Visitor<E>>(visitor: &mut V, vi: &ViewItem, env: E) { match vi.node { - ViewItemExternMod(name, _, _) => { + ViewItemExternCrate(name, _, _) => { visitor.visit_ident(vi.span, name, env) } ViewItemUse(ref paths) => { |
