Skip to content

Commit

Permalink
Move src/test/rustdoc intra-doc link tests into a subdirectory
Browse files Browse the repository at this point in the history
They were starting to get unwieldy.
  • Loading branch information
jyn514 committed Nov 29, 2020
1 parent e37f25a commit ddfb581
Show file tree
Hide file tree
Showing 64 changed files with 254 additions and 258 deletions.
18 changes: 0 additions & 18 deletions src/test/rustdoc/intra-doc-link-mod-ambiguity.rs

This file was deleted.

Expand Up @@ -3,8 +3,8 @@
/// # Anchor!
pub struct Something;

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

/// I want...
///
Expand Down
27 changes: 27 additions & 0 deletions src/test/rustdoc/intra-doc/associated-defaults.rs
@@ -0,0 +1,27 @@
// ignore-tidy-linelength
#![deny(intra_doc_link_resolution_failure)]
#![feature(associated_type_defaults)]

pub trait TraitWithDefault {
type T = usize;
fn f() -> Self::T {
0
}
}

/// 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'
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'
pub struct OverridesDefaults;
impl TraitWithDefault for OverridesDefaults {
type T = bool;
fn f() -> bool {
true
}
}
61 changes: 61 additions & 0 deletions src/test/rustdoc/intra-doc/associated-items.rs
@@ -0,0 +1,61 @@
// ignore-tidy-linelength
#![deny(intra_doc_link_resolution_failure)]

/// [`std::collections::BTreeMap::into_iter`]
/// [`String::from`] is ambiguous as to which `From` impl
/// [Vec::into_iter()] uses a disambiguator
// @has 'associated_items/fn.foo.html' '//a[@href="https://doc.rust-lang.org/nightly/alloc/collections/btree/map/struct.BTreeMap.html#method.into_iter"]' 'std::collections::BTreeMap::into_iter'
// @has 'associated_items/fn.foo.html' '//a[@href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html#method.from"]' 'String::from'
// @has 'associated_items/fn.foo.html' '//a[@href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html#method.into_iter"]' 'Vec::into_iter'
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'
pub struct MyStruct { foo: () }

impl Clone for MyStruct {
fn clone(&self) -> Self {
MyStruct
}
}

pub trait T {
type Input;
fn method(i: Self::Input);
}

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'
fn method(i: usize) {
}
}

/// Ambiguity between which trait to use
pub trait T1 {
fn ambiguous_method();
}

pub trait T2 {
fn ambiguous_method();
}

/// Link to [S::ambiguous_method]
// FIXME: there is no way to disambiguate these.
// Since we have `#[deny(intra_doc_failure)]`, we still know it was one or the other.
pub struct S;

impl T1 for S {
fn ambiguous_method() {}
}

impl T2 for S {
fn ambiguous_method() {}
}

fn main() {}
File renamed without changes.
Expand Up @@ -3,7 +3,6 @@
// compile-flags: --crate-type proc-macro

#![crate_type="proc-macro"]
#![crate_name="intra_link_proc_macro_macro"]

extern crate proc_macro;

Expand Down
@@ -1,21 +1,21 @@
// @has intra_links/index.html
// @has - '//a/@href' '../intra_links/struct.ThisType.html'
// @has - '//a/@href' '../intra_links/struct.ThisType.html#method.this_method'
// @has - '//a/@href' '../intra_links/enum.ThisEnum.html'
// @has - '//a/@href' '../intra_links/enum.ThisEnum.html#variant.ThisVariant'
// @has - '//a/@href' '../intra_links/trait.ThisTrait.html'
// @has - '//a/@href' '../intra_links/trait.ThisTrait.html#tymethod.this_associated_method'
// @has - '//a/@href' '../intra_links/trait.ThisTrait.html#associatedtype.ThisAssociatedType'
// @has - '//a/@href' '../intra_links/trait.ThisTrait.html#associatedconstant.THIS_ASSOCIATED_CONST'
// @has - '//a/@href' '../intra_links/trait.ThisTrait.html'
// @has - '//a/@href' '../intra_links/type.ThisAlias.html'
// @has - '//a/@href' '../intra_links/union.ThisUnion.html'
// @has - '//a/@href' '../intra_links/fn.this_function.html'
// @has - '//a/@href' '../intra_links/constant.THIS_CONST.html'
// @has - '//a/@href' '../intra_links/static.THIS_STATIC.html'
// @has - '//a/@href' '../intra_links/macro.this_macro.html'
// @has - '//a/@href' '../intra_links/trait.SoAmbiguous.html'
// @has - '//a/@href' '../intra_links/fn.SoAmbiguous.html'
// @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'
//! In this crate we would like to link to:
//!
//! * [`ThisType`](ThisType)
Expand Down Expand Up @@ -46,7 +46,7 @@ macro_rules! this_macro {
() => {};
}

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

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


// @has intra_links/struct.SomeOtherType.html '//a/@href' '../intra_links/struct.ThisType.html'
// @has - '//a/@href' '../intra_links/struct.ThisType.html#method.this_method'
// @has - '//a/@href' '../intra_links/enum.ThisEnum.html'
// @has - '//a/@href' '../intra_links/enum.ThisEnum.html#variant.ThisVariant'
// @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'
/// Shortcut links for:
/// * [`ThisType`]
/// * [`ThisType::this_method`]
Expand Down
@@ -1,3 +1,3 @@
// @has intra_link_builtin_macros/index.html
// @has builtin_macros/index.html
// @has - '//a/@href' 'https://doc.rust-lang.org/nightly/core/macro.cfg.html'
//! [cfg]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
51 changes: 51 additions & 0 deletions src/test/rustdoc/intra-doc/disambiguators-removed.rs
@@ -0,0 +1,51 @@
// ignore-tidy-linelength
#![deny(intra_doc_link_resolution_failure)]
// 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"
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!"
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"

// FIXME: this will turn !() into ! alone
/// [Name!()]
// @has - '//a[@href="../disambiguators_removed/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"

// 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"
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"

// 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"
macro_rules! Name {
() => ()
}
File renamed without changes.
17 changes: 17 additions & 0 deletions src/test/rustdoc/intra-doc/extern-type.rs
@@ -0,0 +1,17 @@
#![feature(extern_types)]

extern {
pub type ExternType;
}

impl ExternType {
pub fn f(&self) {

}
}

// @has 'extern_type/foreigntype.ExternType.html'
// @has 'extern_type/fn.links_to_extern_type.html' \
// 'href="../extern_type/foreigntype.ExternType.html#method.f"'
/// See also [ExternType::f]
pub fn links_to_extern_type() {}
File renamed without changes.
16 changes: 16 additions & 0 deletions src/test/rustdoc/intra-doc/mod-ambiguity.rs
@@ -0,0 +1,16 @@
#![deny(broken_intra_doc_links)]


pub fn foo() {

}

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


// @has mod_ambiguity/struct.B.html '//a/@href' '../mod_ambiguity/fn.foo.html'
/// Function is [`fn@foo`]
pub struct B;
5 changes: 5 additions & 0 deletions src/test/rustdoc/intra-doc/prim-assoc.rs
@@ -0,0 +1,5 @@
// ignore-tidy-linelength
#![deny(broken_intra_doc_links)]

//! [i32::MAX]
// @has prim_assoc/index.html '//a[@href="https://doc.rust-lang.org/nightly/std/primitive.i32.html#associatedconstant.MAX"]' "i32::MAX"
Expand Up @@ -9,7 +9,7 @@
#![no_core]
#![crate_type = "rlib"]

// @has intra_link_prim_methods_external_core/index.html
// @has prim_methods_external_core/index.html
// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html"]' 'char'
// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html#method.len_utf8"]' 'char::len_utf8'

Expand Down
Expand Up @@ -5,7 +5,7 @@

// ignore-tidy-linelength

// @has intra_link_prim_methods_local/index.html
// @has prim_methods_local/index.html
// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html"]' 'char'
// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html#method.len_utf8"]' 'char::len_utf8'

Expand Down
Expand Up @@ -2,7 +2,7 @@

// ignore-tidy-linelength

// @has intra_link_prim_methods/index.html
// @has prim_methods/index.html
// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html"]' 'char'
// @has - '//*[@id="main"]//a[@href="https://doc.rust-lang.org/nightly/std/primitive.char.html#method.len_utf8"]' 'char::len_utf8'

Expand Down
17 changes: 17 additions & 0 deletions src/test/rustdoc/intra-doc/prim-precedence.rs
@@ -0,0 +1,17 @@
// ignore-tidy-linelength
#![deny(broken_intra_doc_links)]

pub mod char {
/// [char]
// @has prim_precedence/char/struct.Inner.html '//a/@href' 'https://doc.rust-lang.org/nightly/std/primitive.char.html'
pub struct Inner;
}

/// See [prim@char]
// @has prim_precedence/struct.MyString.html '//a/@href' 'https://doc.rust-lang.org/nightly/std/primitive.char.html'
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'
pub struct MyString2;
Expand Up @@ -2,7 +2,7 @@

// ignore-tidy-linelength

// @has intra_link_primitive_non_default_impl/fn.str_methods.html
// @has primitive_non_default_impl/fn.str_methods.html
/// [`str::trim`]
// @has - '//*[@href="https://doc.rust-lang.org/nightly/std/primitive.str.html#method.trim"]' 'str::trim'
/// [`str::to_lowercase`]
Expand All @@ -13,7 +13,7 @@
// @has - '//*[@href="https://doc.rust-lang.org/nightly/std/primitive.str.html#method.replace"]' 'str::replace'
pub fn str_methods() {}

// @has intra_link_primitive_non_default_impl/fn.f32_methods.html
// @has primitive_non_default_impl/fn.f32_methods.html
/// [f32::powi]
// @has - '//*[@href="https://doc.rust-lang.org/nightly/std/primitive.f32.html#method.powi"]' 'f32::powi'
/// [f32::sqrt]
Expand All @@ -22,7 +22,7 @@ pub fn str_methods() {}
// @has - '//*[@href="https://doc.rust-lang.org/nightly/std/primitive.f32.html#method.mul_add"]' 'f32::mul_add'
pub fn f32_methods() {}

// @has intra_link_primitive_non_default_impl/fn.f64_methods.html
// @has primitive_non_default_impl/fn.f64_methods.html
/// [`f64::powi`]
// @has - '//*[@href="https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.powi"]' 'f64::powi'
/// [`f64::sqrt`]
Expand Down
File renamed without changes.
File renamed without changes.
27 changes: 27 additions & 0 deletions src/test/rustdoc/intra-doc/proc-macro.rs
@@ -0,0 +1,27 @@
// aux-build:proc-macro-macro.rs
// build-aux-docs
#![deny(broken_intra_doc_links)]

extern crate proc_macro_macro;


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' '../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'
/// Link to [deriveA](derive@DeriveA) [attr](macro@attr_a)
pub struct Bar;

// this should not cause ambiguity errors
pub trait DeriveTrait {}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -3,7 +3,7 @@

/// Link to [S::assoc_fn()]
/// Link to [Default::default()]
// @has intra_link_trait_item/struct.S.html '//*[@href="../intra_link_trait_item/struct.S.html#method.assoc_fn"]' 'S::assoc_fn()'
// @has trait_item/struct.S.html '//*[@href="../trait_item/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;

Expand Down
File renamed without changes.

0 comments on commit ddfb581

Please sign in to comment.