Skip to content
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

Correctly get complete intra-doc link data #123162

Merged
merged 2 commits into from
Mar 28, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/librustdoc/passes/lint/redundant_explicit_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fn check_redundant_explicit_link<'md>(
) -> Option<()> {
let mut broken_line_callback = |link: BrokenLink<'md>| Some((link.reference, "".into()));
let mut offset_iter = Parser::new_with_broken_link_callback(
&doc,
doc,
main_body_opts(),
Some(&mut broken_line_callback),
)
Expand Down Expand Up @@ -264,6 +264,7 @@ fn collect_link_data(offset_iter: &mut OffsetIter<'_, '_>) -> LinkData {
let mut resolvable_link = None;
let mut resolvable_link_range = None;
let mut display_link = String::new();
let mut is_resolvable = true;

while let Some((event, range)) = offset_iter.next() {
match event {
Expand All @@ -281,13 +282,23 @@ fn collect_link_data(offset_iter: &mut OffsetIter<'_, '_>) -> LinkData {
resolvable_link = Some(code);
resolvable_link_range = Some(range);
}
Event::Start(_) => {
// If there is anything besides backticks, it's not considered as an intra-doc link
// so we ignore it.
is_resolvable = false;
}
Event::End(_) => {
break;
}
_ => {}
}
}

if !is_resolvable {
resolvable_link_range = None;
resolvable_link = None;
}

LinkData { resolvable_link, resolvable_link_range, display_link }
}

Expand Down
8 changes: 8 additions & 0 deletions tests/rustdoc-ui/invalid-redundant-explicit-link.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@ check-pass

// Regression test for <https://github.com/rust-lang/rust/issues/123158>. It
// should not emit any warning.

//! [**`SomeTrait`**](SomeTrait):

pub trait SomeTrait {}