diff options
| author | bors <bors@rust-lang.org> | 2025-05-06 06:37:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-05-06 06:37:30 +0000 |
| commit | 651e9cf327358b28db7e37a2ae61727f4a2ef232 (patch) | |
| tree | 9e08a2741b303e04c0f4b98a180efd01d8716f1d /tests/rustdoc/jump-to-def | |
| parent | 7295b08a17d1107155acd4b552069e3705b0ab1f (diff) | |
| parent | 546c1c2dd48ba6eded56a9ee74d78cab8e7ad204 (diff) | |
| download | rust-651e9cf327358b28db7e37a2ae61727f4a2ef232.tar.gz rust-651e9cf327358b28db7e37a2ae61727f4a2ef232.zip | |
Auto merge of #140695 - Zalathar:rollup-i32gzbo, r=Zalathar
Rollup of 12 pull requests Successful merges: - #139550 (Fix `-Zremap-path-scope` rmeta handling) - #139764 (Consistent trait bounds for ExtractIf Debug impls) - #139773 (Implement `Iterator::last` for `vec::IntoIter`) - #140035 (Implement RFC 3503: frontmatters) - #140251 (coverage-dump: Resolve global file IDs to filenames) - #140393 (std: get rid of `sys_common::process`) - #140532 (Fix RustAnalyzer discovery of rustc's `stable_mir` crate) - #140598 (Steer docs to `utf8_chunks` and `Iterator::take`) - #140634 (Use more accurate ELF flags on MIPS) - #140673 (Clean rustdoc tests folder) - #140678 (Be a bit more relaxed about not yet constrained infer vars in closure upvar analysis) - #140687 (Update mdbook to 0.4.49) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'tests/rustdoc/jump-to-def')
7 files changed, 222 insertions, 0 deletions
diff --git a/tests/rustdoc/jump-to-def/auxiliary/jump-to-def-macro.rs b/tests/rustdoc/jump-to-def/auxiliary/jump-to-def-macro.rs new file mode 100644 index 00000000000..f442b9461e8 --- /dev/null +++ b/tests/rustdoc/jump-to-def/auxiliary/jump-to-def-macro.rs @@ -0,0 +1,6 @@ +#[macro_export] +macro_rules! symbols { + ($name:ident = $value:expr) => { + pub const $name: isize = $value; + } +} diff --git a/tests/rustdoc/jump-to-def/jump-to-def-doc-links-calls.rs b/tests/rustdoc/jump-to-def/jump-to-def-doc-links-calls.rs new file mode 100644 index 00000000000..61856978773 --- /dev/null +++ b/tests/rustdoc/jump-to-def/jump-to-def-doc-links-calls.rs @@ -0,0 +1,27 @@ +//@ compile-flags: -Zunstable-options --generate-link-to-definition + +#![crate_name = "foo"] + +//@ has 'src/foo/jump-to-def-doc-links-calls.rs.html' + +//@ has - '//a[@href="../../foo/struct.Bar.html"]' 'Bar' +pub struct Bar; + +impl std::default::Default for Bar { + //@ has - '//a[@href="#20-22"]' 'Self::new' + fn default() -> Self { + Self::new() + } +} + +//@ has - '//a[@href="#8"]' 'Bar' +impl Bar { + //@ has - '//a[@href="#24-26"]' 'Self::bar' + pub fn new()-> Self { + Self::bar() + } + + pub fn bar() -> Self { + Self + } +} diff --git a/tests/rustdoc/jump-to-def/jump-to-def-doc-links.rs b/tests/rustdoc/jump-to-def/jump-to-def-doc-links.rs new file mode 100644 index 00000000000..2abb52e0a00 --- /dev/null +++ b/tests/rustdoc/jump-to-def/jump-to-def-doc-links.rs @@ -0,0 +1,51 @@ +//@ compile-flags: -Zunstable-options --generate-link-to-definition + +#![crate_name = "foo"] + +//@ has 'src/foo/jump-to-def-doc-links.rs.html' + +//@ has - '//a[@href="../../foo/struct.Bar.html"]' 'Bar' +//@ has - '//a[@href="../../foo/struct.Foo.html"]' 'Foo' +pub struct Bar; pub struct Foo; + +//@ has - '//a[@href="../../foo/enum.Enum.html"]' 'Enum' +pub enum Enum { + Variant1(String), + Variant2(u8), +} + +//@ has - '//a[@href="../../foo/struct.Struct.html"]' 'Struct' +pub struct Struct { + pub a: u8, + b: Foo, +} + +impl Struct { + pub fn foo() {} + pub fn foo2(&self) {} + fn bar() {} + fn bar(&self) {} +} + +//@ has - '//a[@href="../../foo/trait.Trait.html"]' 'Trait' +pub trait Trait { + fn foo(); +} + +impl Trait for Struct { + fn foo() {} +} + +//@ has - '//a[@href="../../foo/union.Union.html"]' 'Union' +pub union Union { + pub a: u16, + pub f: u32, +} + +//@ has - '//a[@href="../../foo/fn.bar.html"]' 'bar' +pub fn bar(b: Bar) { + let x = Foo; +} + +//@ has - '//a[@href="../../foo/bar/index.html"]' 'bar' +pub mod bar {} diff --git a/tests/rustdoc/jump-to-def/jump-to-def-macro.rs b/tests/rustdoc/jump-to-def/jump-to-def-macro.rs new file mode 100644 index 00000000000..680477937c6 --- /dev/null +++ b/tests/rustdoc/jump-to-def/jump-to-def-macro.rs @@ -0,0 +1,15 @@ +//@ aux-build:jump-to-def-macro.rs +//@ build-aux-docs +//@ compile-flags: -Zunstable-options --generate-link-to-definition + +#![crate_name = "foo"] + +//@ has 'src/foo/jump-to-def-macro.rs.html' + +#[macro_use] +extern crate jump_to_def_macro; + +//@ has - '//a[@href="../../jump_to_def_macro/macro.symbols.html"]' 'symbols!' +symbols! { + A = 12 +} diff --git a/tests/rustdoc/jump-to-def/jump-to-def-pats.rs b/tests/rustdoc/jump-to-def/jump-to-def-pats.rs new file mode 100644 index 00000000000..147902b44cf --- /dev/null +++ b/tests/rustdoc/jump-to-def/jump-to-def-pats.rs @@ -0,0 +1,52 @@ +// This test ensures that patterns also get a link generated. + +//@ compile-flags: -Zunstable-options --generate-link-to-definition + +#![crate_name = "foo"] + +//@ has 'src/foo/jump-to-def-pats.rs.html' + +use std::fmt; + +pub enum MyEnum<T, E> { + Ok(T), + Err(E), + Some(T), + None, +} + +pub enum X { + A, +} + +pub fn foo() -> Result<(), ()> { + // FIXME: would be nice to be able to check both the class and the href at the same time so + // we could check the text as well... + //@ has - '//a[@class="prelude-val"]/@href' '{{channel}}/core/result/enum.Result.html#variant.Ok' + //@ has - '//a[@href="{{channel}}/core/result/enum.Result.html#variant.Ok"]' 'Ok' + Ok(()) +} + +impl<T, E> fmt::Display for MyEnum<T, E> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + //@ has - '//a[@href="#12"]' 'Self::Ok' + Self::Ok(_) => f.write_str("MyEnum::Ok"), + //@ has - '//a[@href="#13"]' 'MyEnum::Err' + MyEnum::Err(_) => f.write_str("MyEnum::Err"), + //@ has - '//a[@href="#14"]' 'Self::Some' + Self::Some(_) => f.write_str("MyEnum::Some"), + //@ has - '//a[@href="#15"]' 'Self::None' + Self::None => f.write_str("MyEnum::None"), + } + } +} + +impl X { + fn p(&self) -> &str { + match self { + //@ has - '//a[@href="#19"]' 'Self::A' + Self::A => "X::A", + } + } +} diff --git a/tests/rustdoc/jump-to-def/jump-to-def-prelude-types.rs b/tests/rustdoc/jump-to-def/jump-to-def-prelude-types.rs new file mode 100644 index 00000000000..43617b1bc9d --- /dev/null +++ b/tests/rustdoc/jump-to-def/jump-to-def-prelude-types.rs @@ -0,0 +1,23 @@ +// This test checks that prelude types like `Result` and `Option` still get a link generated. + +//@ compile-flags: -Zunstable-options --generate-link-to-definition + +#![crate_name = "foo"] + +//@ has 'src/foo/jump-to-def-prelude-types.rs.html' +// FIXME: would be nice to be able to check both the class and the href at the same time so +// we could check the text as well... +//@ has - '//a[@class="prelude-ty"]/@href' '{{channel}}/core/result/enum.Result.html' +//@ has - '//a[@class="prelude-ty"]/@href' '{{channel}}/core/option/enum.Option.html' +pub fn foo() -> Result<Option<()>, ()> { Err(()) } + +// This part is to ensure that they are not linking to the actual prelude ty. +pub mod bar { + struct Result; + struct Option; + + //@ has - '//a[@href="#16"]' 'Result' + pub fn bar() -> Result { Result } + //@ has - '//a[@href="#17"]' 'Option' + pub fn bar2() -> Option { Option } +} diff --git a/tests/rustdoc/jump-to-def/jump-to-non-local-method.rs b/tests/rustdoc/jump-to-def/jump-to-non-local-method.rs new file mode 100644 index 00000000000..e2f530425f0 --- /dev/null +++ b/tests/rustdoc/jump-to-def/jump-to-non-local-method.rs @@ -0,0 +1,48 @@ +//@ compile-flags: -Zunstable-options --generate-link-to-definition + +#![crate_name = "foo"] + +//@ has 'src/foo/jump-to-non-local-method.rs.html' + +//@ has - '//a[@href="{{channel}}/core/sync/atomic/struct.AtomicIsize.html"]' 'std::sync::atomic::AtomicIsize' +use std::sync::atomic::AtomicIsize; +//@ has - '//a[@href="{{channel}}/std/io/trait.Read.html"]' 'std::io::Read' +use std::io::Read; +//@ has - '//a[@href="{{channel}}/std/io/index.html"]' 'std::io' +use std::io; +//@ has - '//a[@href="{{channel}}/std/process/fn.exit.html"]' 'std::process::exit' +use std::process::exit; +use std::cmp::Ordering; +use std::marker::PhantomData; + +pub fn bar2<T: Read>(readable: T) { + //@ has - '//a[@href="{{channel}}/std/io/trait.Read.html#tymethod.read"]' 'read' + let _ = readable.read(&mut []); +} + +pub fn bar() { + //@ has - '//a[@href="{{channel}}/core/sync/atomic/struct.AtomicIsize.html#method.new"]' 'AtomicIsize::new' + let _ = AtomicIsize::new(0); + //@ has - '//a[@href="#48"]' 'local_private' + local_private(); +} + +pub fn extern_call() { + //@ has - '//a[@href="{{channel}}/std/process/fn.exit.html"]' 'exit' + exit(0); +} + +pub fn macro_call() -> Result<(), ()> { + //@ has - '//a[@href="{{channel}}/core/macro.try.html"]' 'try!' + try!(Err(())); + Ok(()) +} + +pub fn variant() { + //@ has - '//a[@href="{{channel}}/core/cmp/enum.Ordering.html#variant.Less"]' 'Ordering::Less' + let _ = Ordering::Less; + //@ has - '//a[@href="{{channel}}/core/marker/struct.PhantomData.html"]' 'PhantomData' + let _: PhantomData::<usize> = PhantomData; +} + +fn local_private() {} |
