Skip to content

Rollup of 4 pull requests #84279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Apr 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions library/std/src/net/ip.rs
Original file line number Diff line number Diff line change
@@ -334,6 +334,8 @@ impl Ipv4Addr {

/// An IPv4 address representing an unspecified address: 0.0.0.0
///
/// This corresponds to the constant `INADDR_ANY` in other languages.
///
/// # Examples
///
/// ```
@@ -342,6 +344,7 @@ impl Ipv4Addr {
/// let addr = Ipv4Addr::UNSPECIFIED;
/// assert_eq!(addr, Ipv4Addr::new(0, 0, 0, 0));
/// ```
#[doc(alias = "INADDR_ANY")]
#[stable(feature = "ip_constructors", since = "1.30.0")]
pub const UNSPECIFIED: Self = Ipv4Addr::new(0, 0, 0, 0);

33 changes: 21 additions & 12 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@ use crate::core::DocContext;
use crate::formats::cache::Cache;
use crate::formats::item_type::ItemType;
use crate::html::render::cache::ExternalLocation;
use crate::html::render::Context;

use self::FnRetTy::*;
use self::ItemKind::*;
@@ -193,19 +194,18 @@ impl Item {
self.attrs.collapsed_doc_value()
}

crate fn links(&self, cache: &Cache) -> Vec<RenderedLink> {
crate fn links(&self, cx: &Context<'_>) -> Vec<RenderedLink> {
use crate::html::format::href;
use crate::html::render::CURRENT_DEPTH;

cache
cx.cache()
.intra_doc_links
.get(&self.def_id)
.map_or(&[][..], |v| v.as_slice())
.iter()
.filter_map(|ItemLink { link: s, link_text, did, fragment }| {
.filter_map(|ItemLink { link: s, link_text, did, ref fragment }| {
match *did {
Some(did) => {
if let Some((mut href, ..)) = href(did, cache) {
if let Some((mut href, ..)) = href(did, cx) {
if let Some(ref fragment) = *fragment {
href.push('#');
href.push_str(fragment);
@@ -219,16 +219,26 @@ impl Item {
None
}
}
// FIXME(83083): using fragments as a side-channel for
// primitive names is very unfortunate
None => {
let relative_to = &cx.current;
if let Some(ref fragment) = *fragment {
let url = match cache.extern_locations.get(&self.def_id.krate) {
let url = match cx.cache().extern_locations.get(&self.def_id.krate) {
Some(&(_, _, ExternalLocation::Local)) => {
let depth = CURRENT_DEPTH.with(|l| l.get());
"../".repeat(depth)
if relative_to[0] == "std" {
let depth = relative_to.len() - 1;
"../".repeat(depth)
} else {
let depth = relative_to.len();
format!("{}std/", "../".repeat(depth))
}
}
Some(&(_, _, ExternalLocation::Remote(ref s))) => {
format!("{}/std/", s.trim_end_matches('/'))
}
Some(&(_, _, ExternalLocation::Remote(ref s))) => s.to_string(),
Some(&(_, _, ExternalLocation::Unknown)) | None => format!(
"https://doc.rust-lang.org/{}",
"https://doc.rust-lang.org/{}/std/",
crate::doc_rust_lang_org_channel(),
),
};
@@ -238,9 +248,8 @@ impl Item {
original_text: s.clone(),
new_text: link_text.clone(),
href: format!(
"{}{}std/primitive.{}.html{}",
"{}primitive.{}.html{}",
url,
if !url.ends_with('/') { "/" } else { "" },
&fragment[..tail],
&fragment[tail..]
),
457 changes: 223 additions & 234 deletions src/librustdoc/html/format.rs

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/librustdoc/html/layout.rs
Original file line number Diff line number Diff line change
@@ -113,7 +113,8 @@ crate fn render<T: Print, S: Print>(
<section class=\"footer\"></section>\
{after_content}\
<div id=\"rustdoc-vars\" data-root-path=\"{root_path}\" data-current-crate=\"{krate}\" \
data-search-js=\"{root_path}search-index{suffix}.js\"></div>
data-search-index-js=\"{root_path}search-index{suffix}.js\" \
data-search-js=\"{static_root_path}search{suffix}.js\"></div>
<script src=\"{static_root_path}main{suffix}.js\"></script>\
{extra_scripts}\
</body>\
3 changes: 3 additions & 0 deletions src/librustdoc/html/mod.rs
Original file line number Diff line number Diff line change
@@ -8,3 +8,6 @@ crate mod render;
crate mod sources;
crate mod static_files;
crate mod toc;

#[cfg(test)]
mod tests;
8 changes: 6 additions & 2 deletions src/librustdoc/html/render/context.rs
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ use crate::html::{layout, sources};
crate struct Context<'tcx> {
/// Current hierarchy of components leading down to what's currently being
/// rendered
pub(super) current: Vec<String>,
pub(crate) current: Vec<String>,
/// The current destination folder of where HTML artifacts should be placed.
/// This changes as the context descends into the module hierarchy.
pub(super) dst: PathBuf,
@@ -144,10 +144,14 @@ impl SharedContext<'_> {
}

impl<'tcx> Context<'tcx> {
pub(super) fn tcx(&self) -> TyCtxt<'tcx> {
pub(crate) fn tcx(&self) -> TyCtxt<'tcx> {
self.shared.tcx
}

pub(crate) fn cache(&self) -> &Cache {
&self.cache
}

fn sess(&self) -> &'tcx Session {
&self.shared.tcx.sess
}
145 changes: 58 additions & 87 deletions src/librustdoc/html/render/mod.rs

Large diffs are not rendered by default.

137 changes: 63 additions & 74 deletions src/librustdoc/html/render/print_item.rs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/librustdoc/html/render/write_shared.rs
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@ use crate::clean::Crate;
use crate::config::{EmitType, RenderOptions};
use crate::docfs::PathError;
use crate::error::Error;
use crate::formats::FormatRenderer;
use crate::html::{layout, static_files};

crate static FILES_UNVERSIONED: Lazy<FxHashMap<&str, &[u8]>> = Lazy::new(|| {
@@ -223,6 +222,7 @@ pub(super) fn write_shared(
&format!(" = {}", serde_json::to_string(&themes).unwrap()),
),
)?;
write_minify("search.js", static_files::SEARCH_JS)?;
write_minify("settings.js", static_files::SETTINGS_JS)?;
if cx.shared.include_sources {
write_minify("source-script.js", static_files::sidebar::SOURCE_SCRIPT)?;
@@ -410,7 +410,7 @@ pub(super) fn write_shared(
write_crate("search-index.js", &|| {
let mut v = String::from("var searchIndex = JSON.parse('{\\\n");
v.push_str(&all_indexes.join(",\\\n"));
v.push_str("\\\n}');\ninitSearch(searchIndex);");
v.push_str("\\\n}');\nif (window.initSearch) {window.initSearch(searchIndex)};");
Ok(v.into_bytes())
})?;

@@ -500,7 +500,7 @@ pub(super) fn write_shared(
None
} else {
Some(Implementor {
text: imp.inner_impl().print(cx.cache(), false, cx.tcx()).to_string(),
text: imp.inner_impl().print(false, cx).to_string(),
synthetic: imp.inner_impl().synthetic,
types: collect_paths_for_type(imp.inner_impl().for_.clone(), cx.cache()),
})
1,842 changes: 157 additions & 1,685 deletions src/librustdoc/html/static/main.js

Large diffs are not rendered by default.

1,512 changes: 1,512 additions & 0 deletions src/librustdoc/html/static/search.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/librustdoc/html/static_files.rs
Original file line number Diff line number Diff line change
@@ -24,6 +24,9 @@ crate static NORMALIZE_CSS: &str = include_str!("static/normalize.css");
/// including search behavior and docblock folding, among others.
crate static MAIN_JS: &str = include_str!("static/main.js");

/// The file contents of `search.js`, which contains the search behavior.
crate static SEARCH_JS: &str = include_str!("static/search.js");

/// The file contents of `settings.js`, which contains the JavaScript used to handle the settings
/// page.
crate static SETTINGS_JS: &str = include_str!("static/settings.js");
44 changes: 44 additions & 0 deletions src/librustdoc/html/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use crate::html::format::href_relative_parts;

fn assert_relative_path(expected: &[&str], relative_to_fqp: &[&str], fqp: &[&str]) {
let relative_to_fqp: Vec<String> = relative_to_fqp.iter().copied().map(String::from).collect();
let fqp: Vec<String> = fqp.iter().copied().map(String::from).collect();
assert_eq!(expected, href_relative_parts(&fqp, &relative_to_fqp));
}

#[test]
fn href_relative_parts_basic() {
let relative_to_fqp = &["std", "vec"];
let fqp = &["std", "iter"];
assert_relative_path(&["..", "iter"], relative_to_fqp, fqp);
}
#[test]
fn href_relative_parts_parent_module() {
let relative_to_fqp = &["std", "vec"];
let fqp = &["std"];
assert_relative_path(&[".."], relative_to_fqp, fqp);
}
#[test]
fn href_relative_parts_different_crate() {
let relative_to_fqp = &["std", "vec"];
let fqp = &["core", "iter"];
assert_relative_path(&["..", "..", "core", "iter"], relative_to_fqp, fqp);
}
#[test]
fn href_relative_parts_same_module() {
let relative_to_fqp = &["std", "vec"];
let fqp = &["std", "vec"];
assert_relative_path(&[], relative_to_fqp, fqp);
}
#[test]
fn href_relative_parts_child_module() {
let relative_to_fqp = &["std"];
let fqp = &["std", "vec"];
assert_relative_path(&["vec"], relative_to_fqp, fqp);
}
#[test]
fn href_relative_parts_root() {
let relative_to_fqp = &[];
let fqp = &["std"];
assert_relative_path(&["std"], relative_to_fqp, fqp);
}
8 changes: 7 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
@@ -289,7 +289,13 @@ fn opts() -> Vec<RustcOptGroup> {
stable("cfg", |o| o.optmulti("", "cfg", "pass a --cfg to rustc", "")),
stable("extern", |o| o.optmulti("", "extern", "pass an --extern to rustc", "NAME[=PATH]")),
unstable("extern-html-root-url", |o| {
o.optmulti("", "extern-html-root-url", "base URL to use for dependencies", "NAME=URL")
o.optmulti(
"",
"extern-html-root-url",
"base URL to use for dependencies; for example, \
\"std=/doc\" links std::vec::Vec to /doc/std/vec/struct.Vec.html",
"NAME=URL",
)
}),
stable("plugin-path", |o| o.optmulti("", "plugin-path", "removed", "DIR")),
stable("C", |o| {
24 changes: 16 additions & 8 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Original file line number Diff line number Diff line change
@@ -1957,20 +1957,28 @@ fn resolution_failure(

/// Report an anchor failure.
fn anchor_failure(cx: &DocContext<'_>, diag_info: DiagnosticInfo<'_>, failure: AnchorFailure) {
let msg = match failure {
let (msg, anchor_idx) = match failure {
AnchorFailure::MultipleAnchors => {
format!("`{}` contains multiple anchors", diag_info.ori_link)
(format!("`{}` contains multiple anchors", diag_info.ori_link), 1)
}
AnchorFailure::RustdocAnchorConflict(res) => format!(
"`{}` contains an anchor, but links to {kind}s are already anchored",
diag_info.ori_link,
kind = res.descr(),
AnchorFailure::RustdocAnchorConflict(res) => (
format!(
"`{}` contains an anchor, but links to {kind}s are already anchored",
diag_info.ori_link,
kind = res.descr(),
),
0,
),
};

report_diagnostic(cx.tcx, BROKEN_INTRA_DOC_LINKS, &msg, &diag_info, |diag, sp| {
if let Some(sp) = sp {
diag.span_label(sp, "contains invalid anchor");
if let Some(mut sp) = sp {
if let Some((fragment_offset, _)) =
diag_info.ori_link.char_indices().filter(|(_, x)| *x == '#').nth(anchor_idx)
{
sp = sp.with_lo(sp.lo() + rustc_span::BytePos(fragment_offset as _));
}
diag.span_label(sp, "invalid anchor");
}
if let AnchorFailure::RustdocAnchorConflict(Res::Primitive(_)) = failure {
diag.note("this restriction may be lifted in a future release");
20 changes: 15 additions & 5 deletions src/test/rustdoc-ui/intra-doc/anchors.stderr
Original file line number Diff line number Diff line change
@@ -2,7 +2,9 @@ error: `prim@usize#x` contains an anchor, but links to builtin types are already
--> $DIR/anchors.rs:47:6
|
LL | /// [prim@usize#x]
| ^^^^^^^^^^^^ contains invalid anchor
| ^^^^^^^^^^--
| |
| invalid anchor
|
note: the lint level is defined here
--> $DIR/anchors.rs:1:9
@@ -16,25 +18,33 @@ error: `Foo::f#hola` contains an anchor, but links to fields are already anchore
--> $DIR/anchors.rs:25:15
|
LL | /// Or maybe [Foo::f#hola].
| ^^^^^^^^^^^ contains invalid anchor
| ^^^^^^-----
| |
| invalid anchor

error: `hello#people#!` contains multiple anchors
--> $DIR/anchors.rs:31:28
|
LL | /// Another anchor error: [hello#people#!].
| ^^^^^^^^^^^^^^ contains invalid anchor
| ^^^^^^^^^^^^--
| |
| invalid anchor

error: `Enum::A#whatever` contains an anchor, but links to variants are already anchored
--> $DIR/anchors.rs:37:28
|
LL | /// Damn enum's variants: [Enum::A#whatever].
| ^^^^^^^^^^^^^^^^ contains invalid anchor
| ^^^^^^^---------
| |
| invalid anchor

error: `u32#hello` contains an anchor, but links to builtin types are already anchored
--> $DIR/anchors.rs:43:6
|
LL | /// [u32#hello]
| ^^^^^^^^^ contains invalid anchor
| ^^^------
| |
| invalid anchor
|
= note: this restriction may be lifted in a future release
= note: see https://github.com/rust-lang/rust/issues/83083 for more information
4 changes: 3 additions & 1 deletion src/test/rustdoc-ui/intra-doc/double-anchor.stderr
Original file line number Diff line number Diff line change
@@ -2,7 +2,9 @@ warning: `with#anchor#error` contains multiple anchors
--> $DIR/double-anchor.rs:5:18
|
LL | /// docs [label][with#anchor#error]
| ^^^^^^^^^^^^^^^^^ contains invalid anchor
| ^^^^^^^^^^^------
| |
| invalid anchor
|
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default

8 changes: 4 additions & 4 deletions src/test/rustdoc/assoc-types.rs
Original file line number Diff line number Diff line change
@@ -6,14 +6,14 @@ pub trait Index<I: ?Sized> {
type Output: ?Sized;
// @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"]' \
// @has - '//*[@id="tymethod.index"]//code//a[@href="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'
// @has - '//*[@class="rust fn"]//a[@href="trait.Index.html#associatedtype.Output"]' 'Output'
pub fn use_output<T: Index<usize>>(obj: &T, index: usize) -> &T::Output {
obj.index(index)
}
@@ -24,12 +24,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'
// @has - '//*[@class="rust fn"]//a[@href="trait.Feed.html#associatedtype.Input"]' 'Input'
pub fn use_input<T: Feed>(_feed: &T, _element: T::Input) { }

// @has assoc_types/fn.cmp_input.html
// @has - '//*[@class="rust fn"]' 'where T::Input: PartialEq<U::Input>'
// @has - '//*[@class="rust fn"]//a[@href="../assoc_types/trait.Feed.html#associatedtype.Input"]' 'Input'
// @has - '//*[@class="rust fn"]//a[@href="trait.Feed.html#associatedtype.Input"]' 'Input'
pub fn cmp_input<T: Feed, U: Feed>(a: &T::Input, b: &U::Input) -> bool
where T::Input: PartialEq<U::Input>
{
6 changes: 6 additions & 0 deletions src/test/rustdoc/auxiliary/primitive-doc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// compile-flags: --crate-type lib --edition 2018

#[doc(primitive = "usize")]
/// This is the built-in type `usize`.
mod usize {
}
2 changes: 1 addition & 1 deletion src/test/rustdoc/check-styled-link.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

pub struct Foo;

// @has foo/struct.Bar.html '//a[@href="../foo/struct.Foo.html"]' 'Foo'
// @has foo/struct.Bar.html '//a[@href="struct.Foo.html"]' 'Foo'

/// Code-styled reference to [`Foo`].
pub struct Bar;
9 changes: 9 additions & 0 deletions src/test/rustdoc/cross-crate-primitive-doc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// aux-build:primitive-doc.rs
// compile-flags: --extern-html-root-url=primitive_doc=../ -Z unstable-options

#![no_std]

extern crate primitive_doc;

// @has 'cross_crate_primitive_doc/fn.foo.html' '//a[@href="../primitive_doc/primitive.usize.html"]' 'usize'
pub fn foo() -> usize { 0 }
4 changes: 2 additions & 2 deletions src/test/rustdoc/default-trait-method-link.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![crate_name = "foo"]

// @has foo/trait.Foo.html '//a[@href="../foo/trait.Foo.html#tymethod.req"]' 'req'
// @has foo/trait.Foo.html '//a[@href="../foo/trait.Foo.html#method.prov"]' 'prov'
// @has foo/trait.Foo.html '//a[@href="trait.Foo.html#tymethod.req"]' 'req'
// @has foo/trait.Foo.html '//a[@href="trait.Foo.html#method.prov"]' 'prov'

/// Always make sure to implement [`req`], but you don't have to implement [`prov`].
///
4 changes: 2 additions & 2 deletions src/test/rustdoc/intra-doc-crate/self.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

extern crate cross_crate_self;

// @has self/struct.S.html '//a[@href="../self/struct.S.html#method.f"]' "Self::f"
// @has self/struct.S.html '//a[@href="../self/struct.S.html"]' "Self"
// @has self/struct.S.html '//a[@href="struct.S.html#method.f"]' "Self::f"
// @has self/struct.S.html '//a[@href="struct.S.html"]' "Self"
// @has self/struct.S.html '//a[@href="../cross_crate_self/index.html"]' "crate"
pub use cross_crate_self::S;
2 changes: 1 addition & 1 deletion src/test/rustdoc/intra-doc/anchors.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
pub struct Something;

// @has anchors/struct.SomeOtherType.html
// @has - '//a/@href' '../anchors/struct.Something.html#Anchor!'
// @has - '//a/@href' 'struct.Something.html#Anchor!'

/// I want...
///
8 changes: 4 additions & 4 deletions src/test/rustdoc/intra-doc/associated-defaults.rs
Original file line number Diff line number Diff line change
@@ -9,14 +9,14 @@ pub trait TraitWithDefault {
}

/// Link to [UsesDefaults::T] and [UsesDefaults::f]
// @has 'associated_defaults/struct.UsesDefaults.html' '//a[@href="../associated_defaults/struct.UsesDefaults.html#associatedtype.T"]' 'UsesDefaults::T'
// @has 'associated_defaults/struct.UsesDefaults.html' '//a[@href="../associated_defaults/struct.UsesDefaults.html#method.f"]' 'UsesDefaults::f'
// @has 'associated_defaults/struct.UsesDefaults.html' '//a[@href="struct.UsesDefaults.html#associatedtype.T"]' 'UsesDefaults::T'
// @has 'associated_defaults/struct.UsesDefaults.html' '//a[@href="struct.UsesDefaults.html#method.f"]' 'UsesDefaults::f'
pub struct UsesDefaults;
impl TraitWithDefault for UsesDefaults {}

/// Link to [OverridesDefaults::T] and [OverridesDefaults::f]
// @has 'associated_defaults/struct.OverridesDefaults.html' '//a[@href="../associated_defaults/struct.OverridesDefaults.html#associatedtype.T"]' 'OverridesDefaults::T'
// @has 'associated_defaults/struct.OverridesDefaults.html' '//a[@href="../associated_defaults/struct.OverridesDefaults.html#method.f"]' 'OverridesDefaults::f'
// @has 'associated_defaults/struct.OverridesDefaults.html' '//a[@href="struct.OverridesDefaults.html#associatedtype.T"]' 'OverridesDefaults::T'
// @has 'associated_defaults/struct.OverridesDefaults.html' '//a[@href="struct.OverridesDefaults.html#method.f"]' 'OverridesDefaults::f'
pub struct OverridesDefaults;
impl TraitWithDefault for OverridesDefaults {
type T = bool;
10 changes: 5 additions & 5 deletions src/test/rustdoc/intra-doc/associated-items.rs
Original file line number Diff line number Diff line change
@@ -9,10 +9,10 @@
pub fn foo() {}

/// Link to [MyStruct], [link from struct][MyStruct::method], [MyStruct::clone], [MyStruct::Input]
// @has 'associated_items/struct.MyStruct.html' '//a[@href="../associated_items/struct.MyStruct.html"]' 'MyStruct'
// @has 'associated_items/struct.MyStruct.html' '//a[@href="../associated_items/struct.MyStruct.html#method.method"]' 'link from struct'
// @has 'associated_items/struct.MyStruct.html' '//a[@href="../associated_items/struct.MyStruct.html#method.clone"]' 'MyStruct::clone'
// @has 'associated_items/struct.MyStruct.html' '//a[@href="../associated_items/struct.MyStruct.html#associatedtype.Input"]' 'MyStruct::Input'
// @has 'associated_items/struct.MyStruct.html' '//a[@href="struct.MyStruct.html"]' 'MyStruct'
// @has 'associated_items/struct.MyStruct.html' '//a[@href="struct.MyStruct.html#method.method"]' 'link from struct'
// @has 'associated_items/struct.MyStruct.html' '//a[@href="struct.MyStruct.html#method.clone"]' 'MyStruct::clone'
// @has 'associated_items/struct.MyStruct.html' '//a[@href="struct.MyStruct.html#associatedtype.Input"]' 'MyStruct::Input'
pub struct MyStruct { foo: () }

impl Clone for MyStruct {
@@ -30,7 +30,7 @@ impl T for MyStruct {
type Input = usize;

/// [link from method][MyStruct::method] on method
// @has 'associated_items/struct.MyStruct.html' '//a[@href="../associated_items/struct.MyStruct.html#method.method"]' 'link from method'
// @has 'associated_items/struct.MyStruct.html' '//a[@href="struct.MyStruct.html#method.method"]' 'link from method'
fn method(i: usize) {
}
}
44 changes: 22 additions & 22 deletions src/test/rustdoc/intra-doc/basic.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// @has basic/index.html
// @has - '//a/@href' '../basic/struct.ThisType.html'
// @has - '//a/@href' '../basic/struct.ThisType.html#method.this_method'
// @has - '//a/@href' '../basic/enum.ThisEnum.html'
// @has - '//a/@href' '../basic/enum.ThisEnum.html#variant.ThisVariant'
// @has - '//a/@href' '../basic/trait.ThisTrait.html'
// @has - '//a/@href' '../basic/trait.ThisTrait.html#tymethod.this_associated_method'
// @has - '//a/@href' '../basic/trait.ThisTrait.html#associatedtype.ThisAssociatedType'
// @has - '//a/@href' '../basic/trait.ThisTrait.html#associatedconstant.THIS_ASSOCIATED_CONST'
// @has - '//a/@href' '../basic/trait.ThisTrait.html'
// @has - '//a/@href' '../basic/type.ThisAlias.html'
// @has - '//a/@href' '../basic/union.ThisUnion.html'
// @has - '//a/@href' '../basic/fn.this_function.html'
// @has - '//a/@href' '../basic/constant.THIS_CONST.html'
// @has - '//a/@href' '../basic/static.THIS_STATIC.html'
// @has - '//a/@href' '../basic/macro.this_macro.html'
// @has - '//a/@href' '../basic/trait.SoAmbiguous.html'
// @has - '//a/@href' '../basic/fn.SoAmbiguous.html'
// @has - '//a/@href' 'struct.ThisType.html'
// @has - '//a/@href' 'struct.ThisType.html#method.this_method'
// @has - '//a/@href' 'enum.ThisEnum.html'
// @has - '//a/@href' 'enum.ThisEnum.html#variant.ThisVariant'
// @has - '//a/@href' 'trait.ThisTrait.html'
// @has - '//a/@href' 'trait.ThisTrait.html#tymethod.this_associated_method'
// @has - '//a/@href' 'trait.ThisTrait.html#associatedtype.ThisAssociatedType'
// @has - '//a/@href' 'trait.ThisTrait.html#associatedconstant.THIS_ASSOCIATED_CONST'
// @has - '//a/@href' 'trait.ThisTrait.html'
// @has - '//a/@href' 'type.ThisAlias.html'
// @has - '//a/@href' 'union.ThisUnion.html'
// @has - '//a/@href' 'fn.this_function.html'
// @has - '//a/@href' 'constant.THIS_CONST.html'
// @has - '//a/@href' 'static.THIS_STATIC.html'
// @has - '//a/@href' 'macro.this_macro.html'
// @has - '//a/@href' 'trait.SoAmbiguous.html'
// @has - '//a/@href' 'fn.SoAmbiguous.html'
//! In this crate we would like to link to:
//!
//! * [`ThisType`](ThisType)
@@ -46,7 +46,7 @@ macro_rules! this_macro {
() => {};
}

// @has basic/struct.ThisType.html '//a/@href' '../basic/macro.this_macro.html'
// @has basic/struct.ThisType.html '//a/@href' 'macro.this_macro.html'
/// another link to [`this_macro!()`]
pub struct ThisType;

@@ -72,10 +72,10 @@ pub trait SoAmbiguous {}
pub fn SoAmbiguous() {}


// @has basic/struct.SomeOtherType.html '//a/@href' '../basic/struct.ThisType.html'
// @has - '//a/@href' '../basic/struct.ThisType.html#method.this_method'
// @has - '//a/@href' '../basic/enum.ThisEnum.html'
// @has - '//a/@href' '../basic/enum.ThisEnum.html#variant.ThisVariant'
// @has basic/struct.SomeOtherType.html '//a/@href' 'struct.ThisType.html'
// @has - '//a/@href' 'struct.ThisType.html#method.this_method'
// @has - '//a/@href' 'enum.ThisEnum.html'
// @has - '//a/@href' 'enum.ThisEnum.html#variant.ThisVariant'
/// Shortcut links for:
/// * [`ThisType`]
/// * [`ThisType::this_method`]
2 changes: 1 addition & 1 deletion src/test/rustdoc/intra-doc/cross-crate/additional_doc.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

extern crate my_rand;

// @has 'additional_doc/trait.Rng.html' '//a[@href="../additional_doc/trait.Rng.html"]' 'Rng'
// @has 'additional_doc/trait.Rng.html' '//a[@href="trait.Rng.html"]' 'Rng'
// @has 'additional_doc/trait.Rng.html' '//a[@href="../my_rand/trait.RngCore.html"]' 'RngCore'
/// This is an [`Rng`].
pub use my_rand::Rng;
2 changes: 1 addition & 1 deletion src/test/rustdoc/intra-doc/cross-crate/hidden.rs
Original file line number Diff line number Diff line change
@@ -6,5 +6,5 @@

extern crate hidden_dep;

// @has 'hidden/struct.Ready.html' '//a/@href' '../hidden/fn.ready.html'
// @has 'hidden/struct.Ready.html' '//a/@href' 'fn.ready.html'
pub use hidden_dep::future::{ready, Ready};
4 changes: 2 additions & 2 deletions src/test/rustdoc/intra-doc/cross-crate/submodule-outer.rs
Original file line number Diff line number Diff line change
@@ -11,6 +11,6 @@ pub mod bar {

// NOTE: we re-exported both `Foo` and `Bar` here,
// NOTE: so they are inlined and therefore we link to the current module.
// @has 'submodule_outer/trait.Foo.html' '//a[@href="../submodule_outer/bar/trait.Bar.html"]' 'Bar'
// @has 'submodule_outer/trait.Foo.html' '//a[@href="../submodule_outer/trait.Baz.html"]' 'Baz'
// @has 'submodule_outer/trait.Foo.html' '//a[@href="bar/trait.Bar.html"]' 'Bar'
// @has 'submodule_outer/trait.Foo.html' '//a[@href="trait.Baz.html"]' 'Baz'
pub use ::bar_::{Foo, Baz};
26 changes: 13 additions & 13 deletions src/test/rustdoc/intra-doc/disambiguators-removed.rs
Original file line number Diff line number Diff line change
@@ -2,49 +2,49 @@
// first try backticks
/// Trait: [`trait@Name`], fn: [`fn@Name`], [`Name`][`macro@Name`]
// @has disambiguators_removed/struct.AtDisambiguator.html
// @has - '//a[@href="../disambiguators_removed/trait.Name.html"][code]' "Name"
// @has - '//a[@href="../disambiguators_removed/fn.Name.html"][code]' "Name"
// @has - '//a[@href="../disambiguators_removed/macro.Name.html"][code]' "Name"
// @has - '//a[@href="trait.Name.html"][code]' "Name"
// @has - '//a[@href="fn.Name.html"][code]' "Name"
// @has - '//a[@href="macro.Name.html"][code]' "Name"
pub struct AtDisambiguator;

/// fn: [`Name()`], macro: [`Name!`]
// @has disambiguators_removed/struct.SymbolDisambiguator.html
// @has - '//a[@href="../disambiguators_removed/fn.Name.html"][code]' "Name()"
// @has - '//a[@href="../disambiguators_removed/macro.Name.html"][code]' "Name!"
// @has - '//a[@href="fn.Name.html"][code]' "Name()"
// @has - '//a[@href="macro.Name.html"][code]' "Name!"
pub struct SymbolDisambiguator;

// Now make sure that backticks aren't added if they weren't already there
/// [fn@Name]
// @has disambiguators_removed/trait.Name.html
// @has - '//a[@href="../disambiguators_removed/fn.Name.html"]' "Name"
// @!has - '//a[@href="../disambiguators_removed/fn.Name.html"][code]' "Name"
// @has - '//a[@href="fn.Name.html"]' "Name"
// @!has - '//a[@href="fn.Name.html"][code]' "Name"

// FIXME: this will turn !() into ! alone
/// [Name!()]
// @has - '//a[@href="../disambiguators_removed/macro.Name.html"]' "Name!"
// @has - '//a[@href="macro.Name.html"]' "Name!"
pub trait Name {}

#[allow(non_snake_case)]

// Try collapsed reference links
/// [macro@Name][]
// @has disambiguators_removed/fn.Name.html
// @has - '//a[@href="../disambiguators_removed/macro.Name.html"]' "Name"
// @has - '//a[@href="macro.Name.html"]' "Name"

// Try links that have the same text as a generated URL
/// Weird URL aligned [../disambiguators_removed/macro.Name.html][trait@Name]
// @has - '//a[@href="../disambiguators_removed/trait.Name.html"]' "../disambiguators_removed/macro.Name.html"
/// Weird URL aligned [macro.Name.html][trait@Name]
// @has - '//a[@href="trait.Name.html"]' "macro.Name.html"
pub fn Name() {}

#[macro_export]
// Rustdoc doesn't currently handle links that have weird interspersing of inline code blocks.
/// [fn@Na`m`e]
// @has disambiguators_removed/macro.Name.html
// @has - '//a[@href="../disambiguators_removed/fn.Name.html"]' "fn@Name"
// @has - '//a[@href="fn.Name.html"]' "fn@Name"

// It also doesn't handle any case where the code block isn't the whole link text:
/// [trait@`Name`]
// @has - '//a[@href="../disambiguators_removed/trait.Name.html"]' "trait@Name"
// @has - '//a[@href="trait.Name.html"]' "trait@Name"
macro_rules! Name {
() => ()
}
2 changes: 1 addition & 1 deletion src/test/rustdoc/intra-doc/enum-struct-field.rs
Original file line number Diff line number Diff line change
@@ -11,4 +11,4 @@ pub enum Foo {
/// I want [Foo::X::y].
pub fn foo() {}

// @has foo/fn.foo.html '//a/@href' '../foo/enum.Foo.html#variant.X.field.y'
// @has foo/fn.foo.html '//a/@href' 'enum.Foo.html#variant.X.field.y'
2 changes: 1 addition & 1 deletion src/test/rustdoc/intra-doc/extern-type.rs
Original file line number Diff line number Diff line change
@@ -12,6 +12,6 @@ impl ExternType {

// @has 'extern_type/foreigntype.ExternType.html'
// @has 'extern_type/fn.links_to_extern_type.html' \
// 'href="../extern_type/foreigntype.ExternType.html#method.f"'
// 'href="foreigntype.ExternType.html#method.f"'
/// See also [ExternType::f]
pub fn links_to_extern_type() {}
2 changes: 1 addition & 1 deletion src/test/rustdoc/intra-doc/issue-82209.rs
Original file line number Diff line number Diff line change
@@ -8,4 +8,4 @@ pub enum Foo {
},
}

// @has foo/enum.Foo.html '//a/@href' '../foo/enum.Foo.html#variant.Bar.field.abc'
// @has foo/enum.Foo.html '//a/@href' 'enum.Foo.html#variant.Bar.field.abc'
4 changes: 2 additions & 2 deletions src/test/rustdoc/intra-doc/mod-ambiguity.rs
Original file line number Diff line number Diff line change
@@ -6,11 +6,11 @@ pub fn foo() {
}

pub mod foo {}
// @has mod_ambiguity/struct.A.html '//a/@href' '../mod_ambiguity/foo/index.html'
// @has mod_ambiguity/struct.A.html '//a/@href' 'foo/index.html'
/// Module is [`module@foo`]
pub struct A;


// @has mod_ambiguity/struct.B.html '//a/@href' '../mod_ambiguity/fn.foo.html'
// @has mod_ambiguity/struct.B.html '//a/@href' 'fn.foo.html'
/// Function is [`fn@foo`]
pub struct B;
4 changes: 2 additions & 2 deletions src/test/rustdoc/intra-doc/prim-precedence.rs
Original file line number Diff line number Diff line change
@@ -11,6 +11,6 @@ pub mod char {
pub struct MyString;

/// See also [crate::char] and [mod@char]
// @has prim_precedence/struct.MyString2.html '//*[@href="../prim_precedence/char/index.html"]' 'crate::char'
// @has - '//*[@href="../prim_precedence/char/index.html"]' 'mod@char'
// @has prim_precedence/struct.MyString2.html '//*[@href="char/index.html"]' 'crate::char'
// @has - '//*[@href="char/index.html"]' 'mod@char'
pub struct MyString2;
6 changes: 3 additions & 3 deletions src/test/rustdoc/intra-doc/private.rs
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@
// make sure to update `rustdoc-ui/intra-doc/private.rs` if you update this file

/// docs [DontDocMe] [DontDocMe::f] [DontDocMe::x]
// @has private/struct.DocMe.html '//*a[@href="../private/struct.DontDocMe.html"]' 'DontDocMe'
// @has private/struct.DocMe.html '//*a[@href="../private/struct.DontDocMe.html#method.f"]' 'DontDocMe::f'
// @has private/struct.DocMe.html '//*a[@href="../private/struct.DontDocMe.html#structfield.x"]' 'DontDocMe::x'
// @has private/struct.DocMe.html '//*a[@href="struct.DontDocMe.html"]' 'DontDocMe'
// @has private/struct.DocMe.html '//*a[@href="struct.DontDocMe.html#method.f"]' 'DontDocMe::f'
// @has private/struct.DocMe.html '//*a[@href="struct.DontDocMe.html#structfield.x"]' 'DontDocMe::x'
pub struct DocMe;
struct DontDocMe {
x: usize,
10 changes: 5 additions & 5 deletions src/test/rustdoc/intra-doc/proc-macro.rs
Original file line number Diff line number Diff line change
@@ -9,17 +9,17 @@ pub use proc_macro_macro::{DeriveA, attr_a};
use proc_macro_macro::{DeriveB, attr_b};

// @has proc_macro/struct.Foo.html
// @has - '//a/@href' '../proc_macro/derive.DeriveA.html'
// @has - '//a/@href' '../proc_macro/attr.attr_a.html'
// @has - '//a/@href' '../proc_macro/trait.DeriveTrait.html'
// @has - '//a/@href' 'derive.DeriveA.html'
// @has - '//a/@href' 'attr.attr_a.html'
// @has - '//a/@href' 'trait.DeriveTrait.html'
// @has - '//a/@href' '../proc_macro_macro/derive.DeriveB.html'
// @has - '//a/@href' '../proc_macro_macro/attr.attr_b.html'
/// Link to [DeriveA], [attr_a], [DeriveB], [attr_b], [DeriveTrait]
pub struct Foo;

// @has proc_macro/struct.Bar.html
// @has - '//a/@href' '../proc_macro/derive.DeriveA.html'
// @has - '//a/@href' '../proc_macro/attr.attr_a.html'
// @has - '//a/@href' 'derive.DeriveA.html'
// @has - '//a/@href' 'attr.attr_a.html'
/// Link to [deriveA](derive@DeriveA) [attr](macro@attr_a)
pub struct Bar;

2 changes: 1 addition & 1 deletion src/test/rustdoc/intra-doc/pub-use.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ extern crate inner;

// @has outer/index.html
// @ has - '//a[@href="https://doc.rust-lang.org/nightly/std/env/fn.var.html"]' "std::env"
// @ has - '//a[@href="../outer/fn.f.html"]' "g"
// @ has - '//a[@href="fn.f.html"]' "g"
pub use f as g;

// FIXME: same as above
2 changes: 1 addition & 1 deletion src/test/rustdoc/intra-doc/raw-ident-self.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ pub mod r#impl {
impl S {
/// See [Self::b].
// @has raw_ident_self/impl/struct.S.html
// @has - '//a[@href="../../raw_ident_self/impl/struct.S.html#method.b"]' 'Self::b'
// @has - '//a[@href="struct.S.html#method.b"]' 'Self::b'
pub fn a() {}

pub fn b() {}
8 changes: 4 additions & 4 deletions src/test/rustdoc/intra-doc/reexport-additional-docs.rs
Original file line number Diff line number Diff line change
@@ -3,13 +3,13 @@
#![crate_name = "foo"]
extern crate inner;

// @has foo/struct.Inner.html '//a[@href="../foo/fn.with_code.html"]' 'crate::with_code'
// @has foo/struct.Inner.html '//a[@href="fn.with_code.html"]' 'crate::with_code'
/// [crate::with_code]
// @has - '//a[@href="../foo/fn.with_code.html"]' 'different text'
// @has - '//a[@href="fn.with_code.html"]' 'different text'
/// [different text][with_code]
// @has - '//a[@href="../foo/fn.me_too.html"]' 'me_too'
// @has - '//a[@href="fn.me_too.html"]' 'me_too'
#[doc = "[me_too]"]
// @has - '//a[@href="../foo/fn.me_three.html"]' 'reference link'
// @has - '//a[@href="fn.me_three.html"]' 'reference link'
/// This [reference link]
#[doc = "has an attr in the way"]
///
28 changes: 14 additions & 14 deletions src/test/rustdoc/intra-doc/self.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#![crate_name = "foo"]


// @has foo/index.html '//a/@href' '../foo/struct.Foo.html#method.new'
// @has foo/struct.Foo.html '//a/@href' '../foo/struct.Foo.html#method.new'
// @has foo/index.html '//a/@href' 'struct.Foo.html#method.new'
// @has foo/struct.Foo.html '//a/@href' 'struct.Foo.html#method.new'

/// Use [`new`] to create a new instance.
///
@@ -15,8 +15,8 @@ impl Foo {
}
}

// @has foo/index.html '//a/@href' '../foo/struct.Bar.html#method.new2'
// @has foo/struct.Bar.html '//a/@href' '../foo/struct.Bar.html#method.new2'
// @has foo/index.html '//a/@href' 'struct.Bar.html#method.new2'
// @has foo/struct.Bar.html '//a/@href' 'struct.Bar.html#method.new2'

/// Use [`new2`] to create a new instance.
///
@@ -30,7 +30,7 @@ impl Bar {
}

pub struct MyStruct {
// @has foo/struct.MyStruct.html '//a/@href' '../foo/struct.MyStruct.html#structfield.struct_field'
// @has foo/struct.MyStruct.html '//a/@href' 'struct.MyStruct.html#structfield.struct_field'

/// [`struct_field`]
///
@@ -39,7 +39,7 @@ pub struct MyStruct {
}

pub enum MyEnum {
// @has foo/enum.MyEnum.html '//a/@href' '../foo/enum.MyEnum.html#variant.EnumVariant'
// @has foo/enum.MyEnum.html '//a/@href' 'enum.MyEnum.html#variant.EnumVariant'

/// [`EnumVariant`]
///
@@ -48,7 +48,7 @@ pub enum MyEnum {
}

pub union MyUnion {
// @has foo/union.MyUnion.html '//a/@href' '../foo/union.MyUnion.html#structfield.union_field'
// @has foo/union.MyUnion.html '//a/@href' 'union.MyUnion.html#structfield.union_field'

/// [`union_field`]
///
@@ -57,21 +57,21 @@ pub union MyUnion {
}

pub trait MyTrait {
// @has foo/trait.MyTrait.html '//a/@href' '../foo/trait.MyTrait.html#associatedtype.AssoType'
// @has foo/trait.MyTrait.html '//a/@href' 'trait.MyTrait.html#associatedtype.AssoType'

/// [`AssoType`]
///
/// [`AssoType`]: Self::AssoType
type AssoType;

// @has foo/trait.MyTrait.html '//a/@href' '../foo/trait.MyTrait.html#associatedconstant.ASSO_CONST'
// @has foo/trait.MyTrait.html '//a/@href' 'trait.MyTrait.html#associatedconstant.ASSO_CONST'

/// [`ASSO_CONST`]
///
/// [`ASSO_CONST`]: Self::ASSO_CONST
const ASSO_CONST: i32 = 1;

// @has foo/trait.MyTrait.html '//a/@href' '../foo/trait.MyTrait.html#method.asso_fn'
// @has foo/trait.MyTrait.html '//a/@href' 'trait.MyTrait.html#method.asso_fn'

/// [`asso_fn`]
///
@@ -80,7 +80,7 @@ pub trait MyTrait {
}

impl MyStruct {
// @has foo/struct.MyStruct.html '//a/@href' '../foo/struct.MyStruct.html#method.for_impl'
// @has foo/struct.MyStruct.html '//a/@href' 'struct.MyStruct.html#method.for_impl'

/// [`for_impl`]
///
@@ -91,21 +91,21 @@ impl MyStruct {
}

impl MyTrait for MyStruct {
// @has foo/struct.MyStruct.html '//a/@href' '../foo/struct.MyStruct.html#associatedtype.AssoType'
// @has foo/struct.MyStruct.html '//a/@href' 'struct.MyStruct.html#associatedtype.AssoType'

/// [`AssoType`]
///
/// [`AssoType`]: Self::AssoType
type AssoType = u32;

// @has foo/struct.MyStruct.html '//a/@href' '../foo/struct.MyStruct.html#associatedconstant.ASSO_CONST'
// @has foo/struct.MyStruct.html '//a/@href' 'struct.MyStruct.html#associatedconstant.ASSO_CONST'

/// [`ASSO_CONST`]
///
/// [`ASSO_CONST`]: Self::ASSO_CONST
const ASSO_CONST: i32 = 10;

// @has foo/struct.MyStruct.html '//a/@href' '../foo/struct.MyStruct.html#method.asso_fn'
// @has foo/struct.MyStruct.html '//a/@href' 'struct.MyStruct.html#method.asso_fn'

/// [`asso_fn`]
///
6 changes: 3 additions & 3 deletions src/test/rustdoc/intra-doc/trait-impl.rs
Original file line number Diff line number Diff line change
@@ -5,21 +5,21 @@ pub struct MyStruct;

impl MyTrait for MyStruct {

// @has foo/struct.MyStruct.html '//a/@href' '../foo/struct.MyStruct.html#associatedtype.AssoType'
// @has foo/struct.MyStruct.html '//a/@href' 'struct.MyStruct.html#associatedtype.AssoType'

/// [`AssoType`]
///
/// [`AssoType`]: MyStruct::AssoType
type AssoType = u32;

// @has foo/struct.MyStruct.html '//a/@href' '../foo/struct.MyStruct.html#associatedconstant.ASSO_CONST'
// @has foo/struct.MyStruct.html '//a/@href' 'struct.MyStruct.html#associatedconstant.ASSO_CONST'

/// [`ASSO_CONST`]
///
/// [`ASSO_CONST`]: MyStruct::ASSO_CONST
const ASSO_CONST: i32 = 10;

// @has foo/struct.MyStruct.html '//a/@href' '../foo/struct.MyStruct.html#method.trait_fn'
// @has foo/struct.MyStruct.html '//a/@href' 'struct.MyStruct.html#method.trait_fn'

/// [`trait_fn`]
///
2 changes: 1 addition & 1 deletion src/test/rustdoc/intra-doc/trait-item.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

/// Link to [S::assoc_fn()]
/// Link to [Default::default()]
// @has trait_item/struct.S.html '//*[@href="../trait_item/struct.S.html#method.assoc_fn"]' 'S::assoc_fn()'
// @has trait_item/struct.S.html '//*[@href="struct.S.html#method.assoc_fn"]' 'S::assoc_fn()'
// @has - '//*[@href="https://doc.rust-lang.org/nightly/core/default/trait.Default.html#tymethod.default"]' 'Default::default()'
pub struct S;

4 changes: 2 additions & 2 deletions src/test/rustdoc/intra-link-self-cache.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![crate_name = "foo"]
// @has foo/enum.E1.html '//a/@href' '../foo/enum.E1.html#variant.A'
// @has foo/enum.E1.html '//a/@href' 'enum.E1.html#variant.A'

/// [Self::A::b]
pub enum E1 {
A { b: usize }
}

// @has foo/enum.E2.html '//a/@href' '../foo/enum.E2.html#variant.A'
// @has foo/enum.E2.html '//a/@href' 'enum.E2.html#variant.A'

/// [Self::A::b]
pub enum E2 {
8 changes: 4 additions & 4 deletions src/test/rustdoc/issue-28478.rs
Original file line number Diff line number Diff line change
@@ -23,9 +23,9 @@ impl Foo {
}

impl Bar for Foo {
// @has - '//*[@href="../issue_28478/trait.Bar.html#associatedtype.Bar"]' 'Bar'
// @has - '//*[@href="../issue_28478/trait.Bar.html#associatedconstant.Baz"]' 'Baz'
// @has - '//*[@href="../issue_28478/trait.Bar.html#tymethod.bar"]' 'bar'
// @has - '//*[@href="trait.Bar.html#associatedtype.Bar"]' 'Bar'
// @has - '//*[@href="trait.Bar.html#associatedconstant.Baz"]' 'Baz'
// @has - '//*[@href="trait.Bar.html#tymethod.bar"]' 'bar'
fn bar() {}
// @has - '//*[@href="../issue_28478/trait.Bar.html#method.baz"]' 'baz'
// @has - '//*[@href="trait.Bar.html#method.baz"]' 'baz'
}
28 changes: 14 additions & 14 deletions src/test/rustdoc/issue-55364.rs
Original file line number Diff line number Diff line change
@@ -2,19 +2,19 @@

// @has issue_55364/subone/index.html
// These foo/bar links in the module's documentation should refer inside `subone`
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../../issue_55364/subone/fn.foo.html"]' 'foo'
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../../issue_55364/subone/fn.bar.html"]' 'bar'
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="fn.foo.html"]' 'foo'
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="fn.bar.html"]' 'bar'
pub mod subone {
//! See either [foo] or [bar].
// This should refer to subone's `bar`
// @has issue_55364/subone/fn.foo.html
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../../issue_55364/subone/fn.bar.html"]' 'bar'
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="fn.bar.html"]' 'bar'
/// See [bar]
pub fn foo() {}
// This should refer to subone's `foo`
// @has issue_55364/subone/fn.bar.html
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../../issue_55364/subone/fn.foo.html"]' 'foo'
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="fn.foo.html"]' 'foo'
/// See [foo]
pub fn bar() {}
}
@@ -23,11 +23,11 @@ pub mod subone {

// @has issue_55364/subtwo/index.html
// These foo/bar links in the module's documentation should not reference inside `subtwo`
// @!has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../../issue_55364/subtwo/fn.foo.html"]' 'foo'
// @!has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../../issue_55364/subtwo/fn.bar.html"]' 'bar'
// @!has - '//section[@id="main"]/div[@class="docblock"]//a[@href="fn.foo.html"]' 'foo'
// @!has - '//section[@id="main"]/div[@class="docblock"]//a[@href="fn.bar.html"]' 'bar'
// Instead it should be referencing the top level functions
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../../issue_55364/fn.foo.html"]' 'foo'
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../../issue_55364/fn.bar.html"]' 'bar'
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../fn.foo.html"]' 'foo'
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../fn.bar.html"]' 'bar'
// Though there should be such links later
// @has - '//section[@id="main"]/table//tr[@class="module-item"]/td/a[@class="fn"][@href="fn.foo.html"]' 'foo'
// @has - '//section[@id="main"]/table//tr[@class="module-item"]/td/a[@class="fn"][@href="fn.bar.html"]' 'bar'
@@ -37,13 +37,13 @@ pub mod subtwo {
// Despite the module's docs referring to the top level foo/bar,
// this should refer to subtwo's `bar`
// @has issue_55364/subtwo/fn.foo.html
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../../issue_55364/subtwo/fn.bar.html"]' 'bar'
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="fn.bar.html"]' 'bar'
/// See [bar]
pub fn foo() {}
// Despite the module's docs referring to the top level foo/bar,
// this should refer to subtwo's `foo`
// @has issue_55364/subtwo/fn.bar.html
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../../issue_55364/subtwo/fn.foo.html"]' 'foo'
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="fn.foo.html"]' 'foo'
/// See [foo]
pub fn bar() {}
}
@@ -59,17 +59,17 @@ pub fn bar() {}

// @has issue_55364/subthree/index.html
// This module should also refer to the top level foo/bar
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../../issue_55364/fn.foo.html"]' 'foo'
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../../issue_55364/fn.bar.html"]' 'bar'
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../fn.foo.html"]' 'foo'
// @has - '//section[@id="main"]/div[@class="docblock"]//a[@href="../fn.bar.html"]' 'bar'
pub mod subthree {
//! See either [foo][super::foo] or [bar][super::bar]
}

// Next we go *deeper* - In order to ensure it's not just "this or parent"
// we test `crate::` and a `super::super::...` chain
// @has issue_55364/subfour/subfive/subsix/subseven/subeight/index.html
// @has - '//section[@id="main"]/table//tr[@class="module-item"]/td[@class="docblock-short"]//a[@href="../../../../../../issue_55364/subone/fn.foo.html"]' 'other foo'
// @has - '//section[@id="main"]/table//tr[@class="module-item"]/td[@class="docblock-short"]//a[@href="../../../../../../issue_55364/subtwo/fn.bar.html"]' 'other bar'
// @has - '//section[@id="main"]/table//tr[@class="module-item"]/td[@class="docblock-short"]//a[@href="../../../../../subone/fn.foo.html"]' 'other foo'
// @has - '//section[@id="main"]/table//tr[@class="module-item"]/td[@class="docblock-short"]//a[@href="../../../../../subtwo/fn.bar.html"]' 'other bar'
pub mod subfour {
pub mod subfive {
pub mod subsix {
2 changes: 1 addition & 1 deletion src/test/rustdoc/issue-72340.rs
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ impl Body {
}

impl Default for Body {
// @has foo/struct.Body.html '//a/@href' '../foo/struct.Body.html#method.empty'
// @has foo/struct.Body.html '//a/@href' 'struct.Body.html#method.empty'

/// Returns [`Body::empty()`](Body::empty).
fn default() -> Body {
4 changes: 2 additions & 2 deletions src/test/rustdoc/link-assoc-const.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![crate_name = "foo"]

// @has foo/index.html '//a[@href="../foo/foo/constant.FIRSTCONST.html"]' 'foo::FIRSTCONST'
// @has foo/index.html '//a[@href="../foo/struct.Bar.html#associatedconstant.CONST"]' 'Bar::CONST'
// @has foo/index.html '//a[@href="foo/constant.FIRSTCONST.html"]' 'foo::FIRSTCONST'
// @has foo/index.html '//a[@href="struct.Bar.html#associatedconstant.CONST"]' 'Bar::CONST'

//! We have here [`foo::FIRSTCONST`] and [`Bar::CONST`].
6 changes: 3 additions & 3 deletions src/test/rustdoc/proc-macro.rs
Original file line number Diff line number Diff line change
@@ -61,12 +61,12 @@ pub fn some_derive(_item: TokenStream) -> TokenStream {
// @has some_macros/foo/index.html
mod foo {
// @has - '//code' 'pub use some_proc_macro;'
// @has - '//a/@href' '../../some_macros/macro.some_proc_macro.html'
// @has - '//a/@href' '../macro.some_proc_macro.html'
pub use some_proc_macro;
// @has - '//code' 'pub use some_proc_attr;'
// @has - '//a/@href' '../../some_macros/attr.some_proc_attr.html'
// @has - '//a/@href' '../attr.some_proc_attr.html'
pub use some_proc_attr;
// @has - '//code' 'pub use some_derive;'
// @has - '//a/@href' '../../some_macros/derive.SomeDerive.html'
// @has - '//a/@href' '../derive.SomeDerive.html'
pub use some_derive;
}
6 changes: 3 additions & 3 deletions src/test/rustdoc/raw-ident-eliminate-r-hashtag.rs
Original file line number Diff line number Diff line change
@@ -8,13 +8,13 @@ pub mod internal {
///
/// [name]: mod
/// [other name]: crate::internal::mod
// @has 'raw_ident_eliminate_r_hashtag/internal/struct.B.html' '//*a[@href="../../raw_ident_eliminate_r_hashtag/internal/struct.mod.html"]' 'name'
// @has 'raw_ident_eliminate_r_hashtag/internal/struct.B.html' '//*a[@href="../../raw_ident_eliminate_r_hashtag/internal/struct.mod.html"]' 'other name'
// @has 'raw_ident_eliminate_r_hashtag/internal/struct.B.html' '//*a[@href="struct.mod.html"]' 'name'
// @has 'raw_ident_eliminate_r_hashtag/internal/struct.B.html' '//*a[@href="struct.mod.html"]' 'other name'
pub struct B;
}

/// See [name].
///
/// [name]: internal::mod
// @has 'raw_ident_eliminate_r_hashtag/struct.A.html' '//*a[@href="../raw_ident_eliminate_r_hashtag/internal/struct.mod.html"]' 'name'
// @has 'raw_ident_eliminate_r_hashtag/struct.A.html' '//*a[@href="internal/struct.mod.html"]' 'name'
pub struct A;
6 changes: 3 additions & 3 deletions src/test/rustdoc/struct-field.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#![crate_name = "foo"]


// @has foo/index.html '//*[@class="docblock"]/p/a[@href="../foo/struct.Foo.html#structfield.bar"]' 'Foo::bar'
// @has foo/index.html '//*[@class="docblock"]/p/a[@href="../foo/union.Bar.html#structfield.foo"]' 'Bar::foo'
// @has foo/index.html '//*[@class="docblock"]/p/a[@href="../foo/enum.Uniooon.html#variant.X"]' 'Uniooon::X'
// @has foo/index.html '//*[@class="docblock"]/p/a[@href="struct.Foo.html#structfield.bar"]' 'Foo::bar'
// @has foo/index.html '//*[@class="docblock"]/p/a[@href="union.Bar.html#structfield.foo"]' 'Bar::foo'
// @has foo/index.html '//*[@class="docblock"]/p/a[@href="enum.Uniooon.html#variant.X"]' 'Uniooon::X'

//! Test with [Foo::bar], [Bar::foo], [Uniooon::X]
10 changes: 5 additions & 5 deletions src/test/rustdoc/trait-impl-items-links-and-anchors.rs
Original file line number Diff line number Diff line change
@@ -40,25 +40,25 @@ impl MyTrait for Vec<u8> {
impl MyTrait for MyStruct {
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//h4[@id="associatedtype.Assoc-3"]//a[@class="type"]/@href' #associatedtype.Assoc
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//h4[@id="associatedtype.Assoc-3"]//a[@class="anchor"]/@href' #associatedtype.Assoc-3
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="associatedtype.Assoc"]//a[@class="type"]/@href' ../trait_impl_items_links_and_anchors/trait.MyTrait.html#associatedtype.Assoc
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="associatedtype.Assoc"]//a[@class="type"]/@href' trait.MyTrait.html#associatedtype.Assoc
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="associatedtype.Assoc"]//a[@class="anchor"]/@href' #associatedtype.Assoc
type Assoc = bool;
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//h4[@id="associatedconstant.VALUE-3"]//a[@class="constant"]/@href' #associatedconstant.VALUE
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//h4[@id="associatedconstant.VALUE-3"]//a[@class="anchor"]/@href' #associatedconstant.VALUE-3
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="associatedconstant.VALUE"]//a[@class="constant"]/@href' ../trait_impl_items_links_and_anchors/trait.MyTrait.html#associatedconstant.VALUE
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="associatedconstant.VALUE"]//a[@class="constant"]/@href' trait.MyTrait.html#associatedconstant.VALUE
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="associatedconstant.VALUE"]//a[@class="anchor"]/@href' #associatedconstant.VALUE
const VALUE: u32 = 20;
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//h4[@id="method.trait_function-2"]//a[@class="fnname"]/@href' #tymethod.trait_function
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//h4[@id="method.trait_function-2"]//a[@class="anchor"]/@href' #method.trait_function-2
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="method.trait_function"]//a[@class="fnname"]/@href' ../trait_impl_items_links_and_anchors/trait.MyTrait.html#tymethod.trait_function
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="method.trait_function"]//a[@class="fnname"]/@href' trait.MyTrait.html#tymethod.trait_function
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="method.trait_function"]//a[@class="anchor"]/@href' #method.trait_function
fn trait_function(&self) {}
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//h4[@id="method.defaulted_override-3"]//a[@class="fnname"]/@href' #method.defaulted_override
// @has trait_impl_items_links_and_anchors/trait.MyTrait.html '//h4[@id="method.defaulted_override-3"]//a[@class="anchor"]/@href' #method.defaulted_override-3
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="method.defaulted_override"]//a[@class="fnname"]/@href' ../trait_impl_items_links_and_anchors/trait.MyTrait.html#method.defaulted_override
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="method.defaulted_override"]//a[@class="fnname"]/@href' trait.MyTrait.html#method.defaulted_override
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="method.defaulted_override"]//a[@class="anchor"]/@href' #method.defaulted_override
fn defaulted_override(&self) {}
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="method.defaulted"]//a[@class="fnname"]/@href' ../trait_impl_items_links_and_anchors/trait.MyTrait.html#method.defaulted
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="method.defaulted"]//a[@class="fnname"]/@href' trait.MyTrait.html#method.defaulted
// @has trait_impl_items_links_and_anchors/struct.MyStruct.html '//h4[@id="method.defaulted"]//a[@class="anchor"]/@href' #method.defaulted
}

2 changes: 1 addition & 1 deletion src/test/rustdoc/trait-self-link.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @has trait_self_link/trait.Foo.html //a/@href ../trait_self_link/trait.Foo.html
// @has trait_self_link/trait.Foo.html //a/@href trait.Foo.html
pub trait Foo {}

pub struct Bar;
12 changes: 6 additions & 6 deletions src/tools/rustdoc-js/tester.js
Original file line number Diff line number Diff line change
@@ -246,7 +246,7 @@ function lookForEntry(entry, data) {
return null;
}

function loadMainJsAndIndex(mainJs, searchIndex, storageJs, crate) {
function loadSearchJsAndIndex(searchJs, searchIndex, storageJs, crate) {
if (searchIndex[searchIndex.length - 1].length === 0) {
searchIndex.pop();
}
@@ -270,9 +270,9 @@ function loadMainJsAndIndex(mainJs, searchIndex, storageJs, crate) {
ALIASES = {};
finalJS += 'window = { "currentCrate": "' + crate + '", rootPath: "../" };\n';
finalJS += loadThings(["hasOwnProperty", "onEach"], 'function', extractFunction, storageJs);
finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, mainJs);
finalJS += loadThings(variablesToLoad, 'variable', extractVariable, mainJs);
finalJS += loadThings(functionsToLoad, 'function', extractFunction, mainJs);
finalJS += loadThings(arraysToLoad, 'array', extractArrayVariable, searchJs);
finalJS += loadThings(variablesToLoad, 'variable', extractVariable, searchJs);
finalJS += loadThings(functionsToLoad, 'function', extractFunction, searchJs);

var loaded = loadContent(finalJS);
var index = loaded.buildIndex(searchIndex.rawSearchIndex);
@@ -382,12 +382,12 @@ function runChecks(testFile, loaded, index) {
}

function load_files(doc_folder, resource_suffix, crate) {
var mainJs = readFile(path.join(doc_folder, "main" + resource_suffix + ".js"));
var searchJs = readFile(path.join(doc_folder, "search" + resource_suffix + ".js"));
var storageJs = readFile(path.join(doc_folder, "storage" + resource_suffix + ".js"));
var searchIndex = readFile(
path.join(doc_folder, "search-index" + resource_suffix + ".js")).split("\n");

return loadMainJsAndIndex(mainJs, searchIndex, storageJs, crate);
return loadSearchJsAndIndex(searchJs, searchIndex, storageJs, crate);
}

function showHelp() {