Skip to content

Commit 6a3c45e

Browse files
committed
Auto merge of rust-lang#131368 - GuillaumeGomez:rustdoc-dead-code, r=notriddle
[rustdoc] Remove intra-doc links dead code While working on rust-lang#130278, I wondered what `resolve_display_text` was doing. I removed it and ran all rustdoc tests, and nothing failed. Are some intra-doc links tests missing or is it really dead code? Couldn't figure it out. r? `@notriddle`
2 parents cf24c73 + 126cb9b commit 6a3c45e

File tree

2 files changed

+1
-115
lines changed

2 files changed

+1
-115
lines changed

Diff for: src/librustdoc/html/markdown.rs

+1-48
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ use std::str::{self, CharIndices};
3535
use std::sync::OnceLock;
3636

3737
use pulldown_cmark::{
38-
BrokenLink, BrokenLinkCallback, CodeBlockKind, CowStr, Event, LinkType, OffsetIter, Options,
39-
Parser, Tag, TagEnd, html,
38+
BrokenLink, CodeBlockKind, CowStr, Event, LinkType, Options, Parser, Tag, TagEnd, html,
4039
};
4140
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
4241
use rustc_errors::{Diag, DiagMessage};
@@ -1686,7 +1685,6 @@ pub(crate) fn html_text_from_events<'a>(
16861685
pub(crate) struct MarkdownLink {
16871686
pub kind: LinkType,
16881687
pub link: String,
1689-
pub display_text: Option<String>,
16901688
pub range: MarkdownLinkRange,
16911689
}
16921690

@@ -1848,23 +1846,9 @@ pub(crate) fn markdown_links<'md, R>(
18481846
LinkType::Autolink | LinkType::Email => unreachable!(),
18491847
};
18501848

1851-
let display_text = if matches!(
1852-
link_type,
1853-
LinkType::Inline
1854-
| LinkType::ReferenceUnknown
1855-
| LinkType::Reference
1856-
| LinkType::Shortcut
1857-
| LinkType::ShortcutUnknown
1858-
) {
1859-
collect_link_data(&mut event_iter)
1860-
} else {
1861-
None
1862-
};
1863-
18641849
if let Some(link) = preprocess_link(MarkdownLink {
18651850
kind: link_type,
18661851
link: dest_url.into_string(),
1867-
display_text,
18681852
range,
18691853
}) {
18701854
links.push(link);
@@ -1877,37 +1861,6 @@ pub(crate) fn markdown_links<'md, R>(
18771861
links
18781862
}
18791863

1880-
/// Collects additional data of link.
1881-
fn collect_link_data<'input, F: BrokenLinkCallback<'input>>(
1882-
event_iter: &mut OffsetIter<'input, F>,
1883-
) -> Option<String> {
1884-
let mut display_text: Option<String> = None;
1885-
let mut append_text = |text: CowStr<'_>| {
1886-
if let Some(display_text) = &mut display_text {
1887-
display_text.push_str(&text);
1888-
} else {
1889-
display_text = Some(text.to_string());
1890-
}
1891-
};
1892-
1893-
while let Some((event, _span)) = event_iter.next() {
1894-
match event {
1895-
Event::Text(text) => {
1896-
append_text(text);
1897-
}
1898-
Event::Code(code) => {
1899-
append_text(code);
1900-
}
1901-
Event::End(_) => {
1902-
break;
1903-
}
1904-
_ => {}
1905-
}
1906-
}
1907-
1908-
display_text
1909-
}
1910-
19111864
#[derive(Debug)]
19121865
pub(crate) struct RustCodeBlock {
19131866
/// The range in the markdown that the code block occupies. Note that this includes the fences

Diff for: src/librustdoc/passes/collect_intra_doc_links.rs

-67
Original file line numberDiff line numberDiff line change
@@ -1040,21 +1040,6 @@ impl LinkCollector<'_, '_> {
10401040
false,
10411041
)?;
10421042

1043-
if ori_link.display_text.is_some() {
1044-
self.resolve_display_text(
1045-
path_str,
1046-
ResolutionInfo {
1047-
item_id,
1048-
module_id,
1049-
dis: disambiguator,
1050-
path_str: ori_link.display_text.clone()?.into_boxed_str(),
1051-
extra_fragment: extra_fragment.clone(),
1052-
},
1053-
&ori_link,
1054-
&diag_info,
1055-
);
1056-
}
1057-
10581043
// Check for a primitive which might conflict with a module
10591044
// Report the ambiguity and require that the user specify which one they meant.
10601045
// FIXME: could there ever be a primitive not in the type namespace?
@@ -1398,58 +1383,6 @@ impl LinkCollector<'_, '_> {
13981383
}
13991384
}
14001385
}
1401-
1402-
/// Resolve display text if the provided link has separated parts of links.
1403-
///
1404-
/// For example:
1405-
/// Inline link `[display_text](dest_link)` and reference link `[display_text][reference_link]` has
1406-
/// separated parts of links.
1407-
fn resolve_display_text(
1408-
&mut self,
1409-
explicit_link: &Box<str>,
1410-
display_res_info: ResolutionInfo,
1411-
ori_link: &MarkdownLink,
1412-
diag_info: &DiagnosticInfo<'_>,
1413-
) {
1414-
// Check if explicit resolution's path is same as resolution of original link's display text path, see
1415-
// tests/rustdoc-ui/lint/redundant_explicit_links.rs for more cases.
1416-
//
1417-
// To avoid disambiguator from panicking, we check if display text path is possible to be disambiguated
1418-
// into explicit path.
1419-
if !matches!(
1420-
ori_link.kind,
1421-
LinkType::Inline | LinkType::Reference | LinkType::ReferenceUnknown
1422-
) {
1423-
return;
1424-
}
1425-
1426-
// Algorithm to check if display text could possibly be the explicit link:
1427-
//
1428-
// Consider 2 links which are display text and explicit link, pick the shorter
1429-
// one as symbol and longer one as full qualified path, and tries to match symbol
1430-
// to the full qualified path's last symbol.
1431-
//
1432-
// Otherwise, check if 2 links are same, if so, skip the resolve process.
1433-
//
1434-
// Notice that this algorithm is passive, might possibly miss actual redundant cases.
1435-
let explicit_link = explicit_link.to_string();
1436-
let display_text = ori_link.display_text.as_ref().unwrap();
1437-
1438-
if display_text.len() == explicit_link.len() {
1439-
// Whether they are same or not, skip the resolve process.
1440-
return;
1441-
}
1442-
1443-
if explicit_link.ends_with(&display_text[..]) || display_text.ends_with(&explicit_link[..])
1444-
{
1445-
self.resolve_with_disambiguator_cached(
1446-
display_res_info,
1447-
diag_info.clone(), // this struct should really be Copy, but Range is not :(
1448-
false,
1449-
true,
1450-
);
1451-
}
1452-
}
14531386
}
14541387

14551388
/// Get the section of a link between the backticks,

0 commit comments

Comments
 (0)