Skip to content

Commit 9ecc9b7

Browse files
bors[bot]Veykril
andauthored
Merge #10597
10597: fix: Fix standard library doclinks not going to the correct page r=Veykril a=Veykril Fixes #10082 bors r+ Co-authored-by: Lukas Wirth <[email protected]>
2 parents c73aa7a + 0ba95c6 commit 9ecc9b7

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

crates/base_db/src/input.rs

+9
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,15 @@ pub struct CrateDisplayName {
120120
canonical_name: String,
121121
}
122122

123+
impl CrateDisplayName {
124+
pub fn canonical_name(&self) -> &str {
125+
&self.canonical_name
126+
}
127+
pub fn crate_name(&self) -> &CrateName {
128+
&self.crate_name
129+
}
130+
}
131+
123132
impl From<CrateName> for CrateDisplayName {
124133
fn from(crate_name: CrateName) -> CrateDisplayName {
125134
let canonical_name = crate_name.to_string();

crates/ide/src/doc_links.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -467,17 +467,24 @@ fn map_links<'e>(
467467
/// ```
468468
fn get_doc_base_url(db: &RootDatabase, krate: &Crate) -> Option<Url> {
469469
let display_name = krate.display_name(db)?;
470-
krate
471-
.get_html_root_url(db)
472-
.or_else(|| {
473-
// Fallback to docs.rs. This uses `display_name` and can never be
474-
// correct, but that's what fallbacks are about.
475-
//
476-
// FIXME: clicking on the link should just open the file in the editor,
477-
// instead of falling back to external urls.
478-
Some(format!("https://docs.rs/{krate}/*/", krate = display_name))
479-
})
480-
.and_then(|s| Url::parse(&s).ok()?.join(&format!("{}/", display_name)).ok())
470+
let base = match &**display_name.crate_name() {
471+
// std and co do not specify `html_root_url` any longer so we gotta handwrite this ourself.
472+
// FIXME: Use the toolchains channel instead of nightly
473+
name @ ("core" | "std" | "alloc" | "proc_macro" | "test") => {
474+
format!("https://doc.rust-lang.org/nightly/{}", name)
475+
}
476+
_ => {
477+
krate.get_html_root_url(db).or_else(|| {
478+
// Fallback to docs.rs. This uses `display_name` and can never be
479+
// correct, but that's what fallbacks are about.
480+
//
481+
// FIXME: clicking on the link should just open the file in the editor,
482+
// instead of falling back to external urls.
483+
Some(format!("https://docs.rs/{krate}/*/", krate = display_name))
484+
})?
485+
}
486+
};
487+
Url::parse(&base).ok()?.join(&format!("{}/", display_name)).ok()
481488
}
482489

483490
/// Get the filename and extension generated for a symbol by rustdoc.

0 commit comments

Comments
 (0)