Fix intra-doc links to Self
and crate
This commit is contained in:
parent
c8915eebea
commit
0acaa5af6b
3 changed files with 22 additions and 6 deletions
|
@ -1024,12 +1024,18 @@ impl LinkCollector<'_, '_> {
|
||||||
|
|
||||||
let resolved_self;
|
let resolved_self;
|
||||||
// replace `Self` with suitable item's parent name
|
// replace `Self` with suitable item's parent name
|
||||||
if path_str.starts_with("Self::") {
|
let is_lone_self = path_str == "Self";
|
||||||
|
let is_lone_crate = path_str == "crate";
|
||||||
|
if path_str.starts_with("Self::") || is_lone_self {
|
||||||
if let Some(ref name) = self_name {
|
if let Some(ref name) = self_name {
|
||||||
|
if is_lone_self {
|
||||||
|
path_str = name;
|
||||||
|
} else {
|
||||||
resolved_self = format!("{}::{}", name, &path_str[6..]);
|
resolved_self = format!("{}::{}", name, &path_str[6..]);
|
||||||
path_str = &resolved_self;
|
path_str = &resolved_self;
|
||||||
}
|
}
|
||||||
} else if path_str.starts_with("crate::") {
|
}
|
||||||
|
} else if path_str.starts_with("crate::") || is_lone_crate {
|
||||||
use rustc_span::def_id::CRATE_DEF_INDEX;
|
use rustc_span::def_id::CRATE_DEF_INDEX;
|
||||||
|
|
||||||
// HACK(jynelson): rustc_resolve thinks that `crate` is the crate currently being documented.
|
// HACK(jynelson): rustc_resolve thinks that `crate` is the crate currently being documented.
|
||||||
|
@ -1038,8 +1044,12 @@ impl LinkCollector<'_, '_> {
|
||||||
// HACK(jynelson)(2): If we just strip `crate::` then suddenly primitives become ambiguous
|
// HACK(jynelson)(2): If we just strip `crate::` then suddenly primitives become ambiguous
|
||||||
// (consider `crate::char`). Instead, change it to `self::`. This works because 'self' is now the crate root.
|
// (consider `crate::char`). Instead, change it to `self::`. This works because 'self' is now the crate root.
|
||||||
// FIXME(#78696): This doesn't always work.
|
// FIXME(#78696): This doesn't always work.
|
||||||
|
if is_lone_crate {
|
||||||
|
path_str = "self";
|
||||||
|
} else {
|
||||||
resolved_self = format!("self::{}", &path_str["crate::".len()..]);
|
resolved_self = format!("self::{}", &path_str["crate::".len()..]);
|
||||||
path_str = &resolved_self;
|
path_str = &resolved_self;
|
||||||
|
}
|
||||||
module_id = DefId { krate, index: CRATE_DEF_INDEX };
|
module_id = DefId { krate, index: CRATE_DEF_INDEX };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
#![crate_name = "cross_crate_self"]
|
#![crate_name = "cross_crate_self"]
|
||||||
|
|
||||||
|
/// Link to [Self]
|
||||||
|
/// Link to [crate]
|
||||||
pub struct S;
|
pub struct S;
|
||||||
|
|
||||||
impl S {
|
impl S {
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
// aux-build:self.rs
|
// aux-build:self.rs
|
||||||
|
// build-aux-docs
|
||||||
|
|
||||||
extern crate cross_crate_self;
|
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#method.f"]' "Self::f"
|
||||||
|
// @has self/struct.S.html '//a[@href="../self/struct.S.html"]' "Self"
|
||||||
|
// @has self/struct.S.html '//a[@href="../cross_crate_self/index.html"]' "crate"
|
||||||
pub use cross_crate_self::S;
|
pub use cross_crate_self::S;
|
||||||
|
|
Loading…
Reference in a new issue