mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-28 07:30:57 +00:00
Auto merge of #7772 - Manishearth:doc-markdown-intra, r=camsteffen
Handle intra-doc links in doc_markdown Fixes #7758 changelog: Handle intra-doc links in [`doc_markdown`]
This commit is contained in:
commit
11492c75a3
2 changed files with 18 additions and 1 deletions
|
@ -406,6 +406,15 @@ struct DocHeaders {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &'a [Attribute]) -> DocHeaders {
|
fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &'a [Attribute]) -> DocHeaders {
|
||||||
|
use pulldown_cmark::{BrokenLink, CowStr, Options};
|
||||||
|
/// We don't want the parser to choke on intra doc links. Since we don't
|
||||||
|
/// actually care about rendering them, just pretend that all broken links are
|
||||||
|
/// point to a fake address.
|
||||||
|
#[allow(clippy::unnecessary_wraps)] // we're following a type signature
|
||||||
|
fn fake_broken_link_callback<'a>(_: BrokenLink<'_>) -> Option<(CowStr<'a>, CowStr<'a>)> {
|
||||||
|
Some(("fake".into(), "fake".into()))
|
||||||
|
}
|
||||||
|
|
||||||
let mut doc = String::new();
|
let mut doc = String::new();
|
||||||
let mut spans = vec![];
|
let mut spans = vec![];
|
||||||
|
|
||||||
|
@ -440,7 +449,10 @@ fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let parser = pulldown_cmark::Parser::new(&doc).into_offset_iter();
|
let mut cb = fake_broken_link_callback;
|
||||||
|
|
||||||
|
let parser =
|
||||||
|
pulldown_cmark::Parser::new_with_broken_link_callback(&doc, Options::empty(), Some(&mut cb)).into_offset_iter();
|
||||||
// Iterate over all `Events` and combine consecutive events into one
|
// Iterate over all `Events` and combine consecutive events into one
|
||||||
let events = parser.coalesce(|previous, current| {
|
let events = parser.coalesce(|previous, current| {
|
||||||
use pulldown_cmark::Event::Text;
|
use pulldown_cmark::Event::Text;
|
||||||
|
|
|
@ -203,6 +203,11 @@ fn issue_2343() {}
|
||||||
/// __|_ _|__||_|
|
/// __|_ _|__||_|
|
||||||
fn pulldown_cmark_crash() {}
|
fn pulldown_cmark_crash() {}
|
||||||
|
|
||||||
|
/// This should not lint
|
||||||
|
/// (regression test for #7758)
|
||||||
|
/// [plain text][path::to::item]
|
||||||
|
fn intra_doc_link() {}
|
||||||
|
|
||||||
// issue #7033 - generic_const_exprs ICE
|
// issue #7033 - generic_const_exprs ICE
|
||||||
struct S<T, const N: usize>
|
struct S<T, const N: usize>
|
||||||
where [(); N.checked_next_power_of_two().unwrap()]: {
|
where [(); N.checked_next_power_of_two().unwrap()]: {
|
||||||
|
|
Loading…
Reference in a new issue