Skip to content

rustdoc: correct path to type alias methods #96887

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 3 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
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
9 changes: 1 addition & 8 deletions src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +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,
)) => Some(&fqp[..fqp.len() - 1]),
Some(..) => Some(&*self.cache.stack),
Some(&(ref fqp, _)) => Some(&fqp[..fqp.len() - 1]),
None => None,
};
((Some(*last), path), true)
Expand Down
14 changes: 14 additions & 0 deletions src/test/rustdoc-js-std/asrawfd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// ignore-order

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' },
],
};
9 changes: 9 additions & 0 deletions src/test/rustdoc-js/foreign-type-path.js
Original file line number Diff line number Diff line change
@@ -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' },
],
};
13 changes: 13 additions & 0 deletions src/test/rustdoc-js/foreign-type-path.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![feature(extern_types)]

pub mod aaaaaaa {

extern {
pub type MyForeignType;
}

impl MyForeignType {
pub fn my_method() {}
}

}