Skip to content

Commit 11492c7

Browse files
committed
Auto merge of rust-lang#7772 - Manishearth:doc-markdown-intra, r=camsteffen
Handle intra-doc links in doc_markdown Fixes rust-lang#7758 changelog: Handle intra-doc links in [`doc_markdown`]
2 parents b9d753e + 2a8d7bd commit 11492c7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

clippy_lints/src/doc.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,15 @@ struct DocHeaders {
406406
}
407407

408408
fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &'a [Attribute]) -> DocHeaders {
409+
use pulldown_cmark::{BrokenLink, CowStr, Options};
410+
/// We don't want the parser to choke on intra doc links. Since we don't
411+
/// actually care about rendering them, just pretend that all broken links are
412+
/// point to a fake address.
413+
#[allow(clippy::unnecessary_wraps)] // we're following a type signature
414+
fn fake_broken_link_callback<'a>(_: BrokenLink<'_>) -> Option<(CowStr<'a>, CowStr<'a>)> {
415+
Some(("fake".into(), "fake".into()))
416+
}
417+
409418
let mut doc = String::new();
410419
let mut spans = vec![];
411420

@@ -440,7 +449,10 @@ fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs
440449
};
441450
}
442451

443-
let parser = pulldown_cmark::Parser::new(&doc).into_offset_iter();
452+
let mut cb = fake_broken_link_callback;
453+
454+
let parser =
455+
pulldown_cmark::Parser::new_with_broken_link_callback(&doc, Options::empty(), Some(&mut cb)).into_offset_iter();
444456
// Iterate over all `Events` and combine consecutive events into one
445457
let events = parser.coalesce(|previous, current| {
446458
use pulldown_cmark::Event::Text;

tests/ui/doc/doc.rs

+5
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ fn issue_2343() {}
203203
/// __|_ _|__||_|
204204
fn pulldown_cmark_crash() {}
205205

206+
/// This should not lint
207+
/// (regression test for #7758)
208+
/// [plain text][path::to::item]
209+
fn intra_doc_link() {}
210+
206211
// issue #7033 - generic_const_exprs ICE
207212
struct S<T, const N: usize>
208213
where [(); N.checked_next_power_of_two().unwrap()]: {

0 commit comments

Comments
 (0)