From bb4ecc3fd8d0d8c0fa490feba294e300185862e6 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 9 May 2022 17:50:39 -0700 Subject: [PATCH 1/3] rustdoc: correct path to type alias methods --- src/librustdoc/formats/cache.rs | 3 ++- src/test/rustdoc-js-std/asrawfd.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc-js-std/asrawfd.js diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 30190138750ca..862f0ecd0de02 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -293,7 +293,8 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { ItemType::Trait | ItemType::Struct | ItemType::Union - | ItemType::Enum, + | ItemType::Enum + | ItemType::Typedef, )) => Some(&fqp[..fqp.len() - 1]), Some(..) => Some(&*self.cache.stack), None => None, diff --git a/src/test/rustdoc-js-std/asrawfd.js b/src/test/rustdoc-js-std/asrawfd.js new file mode 100644 index 0000000000000..37168fc493775 --- /dev/null +++ b/src/test/rustdoc-js-std/asrawfd.js @@ -0,0 +1,14 @@ +// exact-match + +const QUERY = 'RawFd::as_raw_fd'; + +const EXPECTED = { + 'others': [ + // Reproduction test for https://github.com/rust-lang/rust/issues/78724 + // Validate that type alias methods get the correct path. + { 'path': 'std::os::unix::io::AsRawFd', 'name': 'as_raw_fd' }, + { 'path': 'std::os::wasi::io::AsRawFd', 'name': 'as_raw_fd' }, + { 'path': 'std::os::linux::process::PidFd', 'name': 'as_raw_fd' }, + { 'path': 'std::os::unix::io::RawFd', 'name': 'as_raw_fd' }, + ], +}; From 6257bd2f4ef748d9bad0c60d0df5201e824f4fde Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 10 May 2022 08:59:59 -0700 Subject: [PATCH 2/3] rustdoc: clean up method path index This removes a special case that doesn't seem to do anything any more. --- src/librustdoc/formats/cache.rs | 10 +--------- src/test/rustdoc-js/foreign-type-path.js | 9 +++++++++ src/test/rustdoc-js/foreign-type-path.rs | 13 +++++++++++++ 3 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 src/test/rustdoc-js/foreign-type-path.js create mode 100644 src/test/rustdoc-js/foreign-type-path.rs diff --git a/src/librustdoc/formats/cache.rs b/src/librustdoc/formats/cache.rs index 862f0ecd0de02..9dc30d8a18925 100644 --- a/src/librustdoc/formats/cache.rs +++ b/src/librustdoc/formats/cache.rs @@ -288,15 +288,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> { // for where the type was defined. On the other // hand, `paths` always has the right // information if present. - Some(&( - ref fqp, - ItemType::Trait - | ItemType::Struct - | ItemType::Union - | ItemType::Enum - | ItemType::Typedef, - )) => Some(&fqp[..fqp.len() - 1]), - Some(..) => Some(&*self.cache.stack), + Some(&(ref fqp, _)) => Some(&fqp[..fqp.len() - 1]), None => None, }; ((Some(*last), path), true) diff --git a/src/test/rustdoc-js/foreign-type-path.js b/src/test/rustdoc-js/foreign-type-path.js new file mode 100644 index 0000000000000..334761badcab1 --- /dev/null +++ b/src/test/rustdoc-js/foreign-type-path.js @@ -0,0 +1,9 @@ +const QUERY = 'MyForeignType::my_method'; + +const EXPECTED = { + 'others': [ + // Test case for https://github.com/rust-lang/rust/pull/96887#pullrequestreview-967154358 + // Validates that the parent path for a foreign type method is correct. + { 'path': 'foreign_type_path::aaaaaaa::MyForeignType', 'name': 'my_method' }, + ], +}; diff --git a/src/test/rustdoc-js/foreign-type-path.rs b/src/test/rustdoc-js/foreign-type-path.rs new file mode 100644 index 0000000000000..83400104ea77e --- /dev/null +++ b/src/test/rustdoc-js/foreign-type-path.rs @@ -0,0 +1,13 @@ +#![feature(extern_types)] + +pub mod aaaaaaa { + + extern { + pub type MyForeignType; + } + + impl MyForeignType { + pub fn my_method() {} + } + +} From 9dc5ac8c4bbf56bd1cae1bcb4f8af245b4b2d67e Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 10 May 2022 16:42:48 -0700 Subject: [PATCH 3/3] Ignore order This isn't an ordering test really, anyway... --- src/test/rustdoc-js-std/asrawfd.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/rustdoc-js-std/asrawfd.js b/src/test/rustdoc-js-std/asrawfd.js index 37168fc493775..fd228a59099e9 100644 --- a/src/test/rustdoc-js-std/asrawfd.js +++ b/src/test/rustdoc-js-std/asrawfd.js @@ -1,4 +1,4 @@ -// exact-match +// ignore-order const QUERY = 'RawFd::as_raw_fd';