Skip to content

Commit fd62036

Browse files
Correctly handle if a link starts with a whitespace
1 parent 9a7cc6c commit fd62036

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

compiler/rustc_resolve/src/rustdoc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ pub fn inner_docs(attrs: &[ast::Attribute]) -> bool {
340340
fn preprocess_link(link: &str) -> String {
341341
let link = link.replace('`', "");
342342
let link = link.split('#').next().unwrap();
343+
let link = link.trim();
343344
let link = link.rsplit('@').next().unwrap();
344345
let link = link.strip_suffix("()").unwrap_or(link);
345346
let link = link.strip_suffix("{}").unwrap_or(link);

src/librustdoc/passes/collect_intra_doc_links.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,8 @@ fn preprocess_link(
884884
let mut parts = stripped.split('#');
885885

886886
let link = parts.next().unwrap();
887-
if link.trim().is_empty() {
887+
let link = link.trim();
888+
if link.is_empty() {
888889
// This is an anchor to an element of the current page, nothing to do in here!
889890
return None;
890891
}
@@ -897,7 +898,7 @@ fn preprocess_link(
897898
// Parse and strip the disambiguator from the link, if present.
898899
let (disambiguator, path_str, link_text) = match Disambiguator::from_str(link) {
899900
Ok(Some((d, path, link_text))) => (Some(d), path.trim(), link_text.trim()),
900-
Ok(None) => (None, link.trim(), link.trim()),
901+
Ok(None) => (None, link, link),
901902
Err((err_msg, relative_range)) => {
902903
// Only report error if we would not have ignored this link. See issue #83859.
903904
if !should_ignore_link_with_disambiguators(link) {

0 commit comments

Comments
 (0)