diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index eb32f4781948d..fdb6ee42127b9 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -1320,7 +1320,7 @@ impl str { core_str::StrExt::rsplitn(self, n, pat) } - /// An iterator over the matches of a pattern within the given string + /// An iterator over the disjoint matches of a pattern within the given string /// slice. /// /// The pattern can be a `&str`, [`char`], or a closure that @@ -1359,7 +1359,7 @@ impl str { core_str::StrExt::matches(self, pat) } - /// An iterator over the matches of a pattern within this string slice, + /// An iterator over the disjoint matches of a pattern within this string slice, /// yielded in reverse order. /// /// The pattern can be a `&str`, [`char`], or a closure that determines if diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 86660c28f80ad..635691dd3458d 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -459,22 +459,10 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec)> { /// rendering function with the necessary arguments for linking to a local path. fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path, print_all: bool, use_absolute: bool) -> fmt::Result { - let empty = clean::PathSegment { - name: String::new(), - params: clean::PathParameters::Parenthesized { - inputs: Vec::new(), - output: None, - } - }; - let last = path.segments.last() - .unwrap_or(&empty); - let rel_root = if path.segments.is_empty() { - None - } else { - match &*path.segments[0].name { - "self" => Some("./".to_string()), - _ => None, - } + let last = path.segments.last().unwrap(); + let rel_root = match &*path.segments[0].name { + "self" => Some("./".to_string()), + _ => None, }; if print_all { @@ -508,7 +496,7 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path, Some((_, _, fqp)) => { format!("{}::{}", fqp[..fqp.len() - 1].join("::"), - HRef::new(did, fqp.last().unwrap_or(&String::new()))) + HRef::new(did, fqp.last().unwrap())) } None => format!("{}", HRef::new(did, &last.name)), } @@ -740,10 +728,8 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: } clean::QPath { ref name, ref self_type, ref trait_ } => { let should_show_cast = match *trait_ { - box clean::ResolvedPath { .. } => { - let path = clean::Path::singleton(name.clone()); - !path.segments.is_empty() && &format!("{:#}", trait_) != "()" && - &format!("{:#}", self_type) != "Self" + box clean::ResolvedPath { ref path, .. } => { + !path.segments.is_empty() && !self_type.is_self_type() } _ => true, }; @@ -772,8 +758,18 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: // everything comes in as a fully resolved QPath (hard to // look at). box clean::ResolvedPath { did, ref typarams, .. } => { - let path = clean::Path::singleton(name.clone()); - resolved_path(f, did, &path, true, use_absolute)?; + match href(did) { + Some((ref url, _, ref path)) if !f.alternate() => { + write!(f, + "{name}", + url = url, + shortty = ItemType::AssociatedType, + name = name, + path = path.join("::"))?; + } + _ => write!(f, "{}", name)?, + } // FIXME: `typarams` are not rendered, and this seems bad? drop(typarams); diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 2b8a18eeb6805..0299e45599b80 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1334,7 +1334,7 @@ impl Context { // these modules are recursed into, but not rendered normally // (a flag on the context). if !self.render_redirect_pages { - self.render_redirect_pages = maybe_ignore_item(&item); + self.render_redirect_pages = item.is_stripped(); } if item.is_mod() { @@ -1417,7 +1417,7 @@ impl Context { // BTreeMap instead of HashMap to get a sorted output let mut map = BTreeMap::new(); for item in &m.items { - if maybe_ignore_item(item) { continue } + if item.is_stripped() { continue } let short = item.type_().css_class(); let myname = match item.name { @@ -1718,7 +1718,7 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, if let clean::DefaultImplItem(..) = items[*i].inner { return false; } - !maybe_ignore_item(&items[*i]) + !items[*i].is_stripped() }).collect::>(); // the order of item types in the listing @@ -1887,17 +1887,6 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, Ok(()) } -fn maybe_ignore_item(it: &clean::Item) -> bool { - match it.inner { - clean::StrippedItem(..) => true, - clean::ModuleItem(ref m) => { - it.doc_value().is_none() && m.items.is_empty() - && it.visibility != Some(clean::Public) - }, - _ => false, - } -} - fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec { let mut stability = vec![]; @@ -3317,7 +3306,7 @@ fn sidebar_module(fmt: &mut fmt::Formatter, _it: &clean::Item, if let clean::DefaultImplItem(..) = it.inner { false } else { - !maybe_ignore_item(it) && !it.is_stripped() && it.type_() == myty + !it.is_stripped() && it.type_() == myty } }) { let (short, name) = match myty { diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index 1cc4f9371cb68..8f6faabd157d6 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -145,20 +145,12 @@ impl<'a> fold::DocFolder for Stripper<'a> { self.fold_item_recur(i) }; - i.and_then(|i| { - match i.inner { - // emptied modules have no need to exist - clean::ModuleItem(ref m) - if m.items.is_empty() && - i.doc_value().is_none() => None, - _ => { - if self.update_retained { - self.retained.insert(i.def_id); - } - Some(i) - } + if let Some(ref i) = i { + if self.update_retained { + self.retained.insert(i.def_id); } - }) + } + i } } diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 27b40793ff64a..889ba81e77812 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -367,7 +367,7 @@ fn _remove_var(k: &OsStr) { /// An iterator that splits an environment variable into paths according to /// platform-specific conventions. /// -/// This structure is created by the [`std::env::split_paths`] function See its +/// This structure is created by the [`std::env::split_paths`] function. See its /// documentation for more. /// /// [`std::env::split_paths`]: fn.split_paths.html @@ -605,14 +605,15 @@ pub fn current_exe() -> io::Result { os_imp::current_exe() } -/// An iterator over the arguments of a process, yielding a [`String`] value -/// for each argument. +/// An iterator over the arguments of a process, yielding a [`String`] value for +/// each argument. /// -/// This structure is created through the [`std::env::args`] function. +/// This struct is created by the [`std::env::args`] function. See its +/// documentation for more. /// /// The first element is traditionally the path of the executable, but it can be -/// set to arbitrary text, and may not even exist. This means this property should -/// not be relied upon for security purposes. +/// set to arbitrary text, and may not even exist. This means this property +/// should not be relied upon for security purposes. /// /// [`String`]: ../string/struct.String.html /// [`std::env::args`]: ./fn.args.html @@ -622,11 +623,12 @@ pub struct Args { inner: ArgsOs } /// An iterator over the arguments of a process, yielding an [`OsString`] value /// for each argument. /// -/// This structure is created through the [`std::env::args_os`] function. +/// This struct is created by the [`std::env::args_os`] function. See its +/// documentation for more. /// /// The first element is traditionally the path of the executable, but it can be -/// set to arbitrary text, and may not even exist. This means this property should -/// not be relied upon for security purposes. +/// set to arbitrary text, and may not even exist. This means this property +/// should not be relied upon for security purposes. /// /// [`OsString`]: ../ffi/struct.OsString.html /// [`std::env::args_os`]: ./fn.args_os.html diff --git a/src/test/rustdoc/assoc-types.rs b/src/test/rustdoc/assoc-types.rs index e5485c356c292..d152be33f4c74 100644 --- a/src/test/rustdoc/assoc-types.rs +++ b/src/test/rustdoc/assoc-types.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-tidy-linelength + #![crate_type="lib"] // @has assoc_types/trait.Index.html @@ -18,11 +20,14 @@ pub trait Index { // @has - '//*[@id="index.v"]//code' 'fn index' // @has - '//*[@id="tymethod.index"]//code' \ // "fn index<'a>(&'a self, index: I) -> &'a Self::Output" + // @has - '//*[@id="tymethod.index"]//code//a[@href="../assoc_types/trait.Index.html#associatedtype.Output"]' \ + // "Output" fn index<'a>(&'a self, index: I) -> &'a Self::Output; } // @has assoc_types/fn.use_output.html // @has - '//*[@class="rust fn"]' '-> &T::Output' +// @has - '//*[@class="rust fn"]//a[@href="../assoc_types/trait.Index.html#associatedtype.Output"]' 'Output' pub fn use_output>(obj: &T, index: usize) -> &T::Output { obj.index(index) } @@ -33,10 +38,12 @@ pub trait Feed { // @has assoc_types/fn.use_input.html // @has - '//*[@class="rust fn"]' 'T::Input' +// @has - '//*[@class="rust fn"]//a[@href="../assoc_types/trait.Feed.html#associatedtype.Input"]' 'Input' pub fn use_input(_feed: &T, _element: T::Input) { } // @has assoc_types/fn.cmp_input.html // @has - '//*[@class="rust fn"]' 'where T::Input: PartialEq' +// @has - '//*[@class="rust fn"]//a[@href="../assoc_types/trait.Feed.html#associatedtype.Input"]' 'Input' pub fn cmp_input(a: &T::Input, b: &U::Input) -> bool where T::Input: PartialEq { diff --git a/src/test/rustdoc/empty-mod-private.rs b/src/test/rustdoc/empty-mod-private.rs new file mode 100644 index 0000000000000..6b86af62a663a --- /dev/null +++ b/src/test/rustdoc/empty-mod-private.rs @@ -0,0 +1,27 @@ +// Copyright 2017 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. + +// ignore-tidy-linelength +// compile-flags: --no-defaults --passes collapse-docs --passes unindent-comments --passes strip-priv-imports + +// @has 'empty_mod_private/index.html' '//a[@href="foo/index.html"]' 'foo' +// @has 'empty_mod_private/sidebar-items.js' 'foo' +// @matches 'empty_mod_private/foo/index.html' '//h1' 'Module empty_mod_private::foo' +mod foo {} + +// @has 'empty_mod_private/index.html' '//a[@href="bar/index.html"]' 'bar' +// @has 'empty_mod_private/sidebar-items.js' 'bar' +// @matches 'empty_mod_private/bar/index.html' '//h1' 'Module empty_mod_private::bar' +mod bar { + // @has 'empty_mod_private/bar/index.html' '//a[@href="baz/index.html"]' 'baz' + // @has 'empty_mod_private/bar/sidebar-items.js' 'baz' + // @matches 'empty_mod_private/bar/baz/index.html' '//h1' 'Module empty_mod_private::bar::baz' + mod baz {} +} diff --git a/src/test/rustdoc/empty-mod-public.rs b/src/test/rustdoc/empty-mod-public.rs new file mode 100644 index 0000000000000..413fe16142405 --- /dev/null +++ b/src/test/rustdoc/empty-mod-public.rs @@ -0,0 +1,24 @@ +// Copyright 2017 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. + +// @has 'empty_mod_public/index.html' '//a[@href="foo/index.html"]' 'foo' +// @has 'empty_mod_public/sidebar-items.js' 'foo' +// @matches 'empty_mod_public/foo/index.html' '//h1' 'Module empty_mod_public::foo' +pub mod foo {} + +// @has 'empty_mod_public/index.html' '//a[@href="bar/index.html"]' 'bar' +// @has 'empty_mod_public/sidebar-items.js' 'bar' +// @matches 'empty_mod_public/bar/index.html' '//h1' 'Module empty_mod_public::bar' +pub mod bar { + // @has 'empty_mod_public/bar/index.html' '//a[@href="baz/index.html"]' 'baz' + // @has 'empty_mod_public/bar/sidebar-items.js' 'baz' + // @matches 'empty_mod_public/bar/baz/index.html' '//h1' 'Module empty_mod_public::bar::baz' + pub mod baz {} +}