Skip to content

Commit f577d71

Browse files
committed
Fix duplicated diagnostics
1 parent ed3f85f commit f577d71

File tree

2 files changed

+13
-37
lines changed

2 files changed

+13
-37
lines changed

clippy_lints/src/doc/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,20 +818,27 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
818818
// We don't want the parser to choke on intra doc links. Since we don't
819819
// actually care about rendering them, just pretend that all broken links
820820
// point to a fake address.
821+
// NOTE: use this full cb version only for the check_doc function.
822+
// Otherwise, using it as callback for more functions will cause,
823+
// duplicated diagnostics for the broken link checker.
824+
// Use the light cb version for the other cases.
821825
#[expect(clippy::unnecessary_wraps)] // we're following a type signature
822-
let fake_broken_link_callback = |bl: BrokenLink<'_>| -> Option<(CowStr<'_>, CowStr<'_>)> {
826+
let mut full_fake_broken_link_callback = |bl: BrokenLink<'_>| -> Option<(CowStr<'_>, CowStr<'_>)> {
823827
broken_link::check(cx, &bl, &doc, &fragments);
824828
Some(("fake".into(), "fake".into()))
825829
};
826830

827-
let mut cb = fake_broken_link_callback;
831+
#[expect(clippy::unnecessary_wraps)] // we're following a type signature
832+
fn light_fake_broken_link_callback<'a>(_: BrokenLink<'_>) -> Option<(CowStr<'a>, CowStr<'a>)> {
833+
Some(("fake".into(), "fake".into()))
834+
}
828835

829836
check_for_code_clusters(
830837
cx,
831838
pulldown_cmark::Parser::new_with_broken_link_callback(
832839
&doc,
833840
main_body_opts() - Options::ENABLE_SMART_PUNCTUATION,
834-
Some(&mut cb),
841+
Some(&mut light_fake_broken_link_callback),
835842
)
836843
.into_offset_iter(),
837844
&doc,
@@ -843,7 +850,8 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
843850

844851
// disable smart punctuation to pick up ['link'] more easily
845852
let opts = main_body_opts() - Options::ENABLE_SMART_PUNCTUATION;
846-
let parser = pulldown_cmark::Parser::new_with_broken_link_callback(&doc, opts, Some(&mut cb));
853+
let parser =
854+
pulldown_cmark::Parser::new_with_broken_link_callback(&doc, opts, Some(&mut full_fake_broken_link_callback));
847855

848856
Some(check_doc(
849857
cx,

tests/ui/doc_broken_link.stderr

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,55 +7,23 @@ LL | /// [doc invalid link broken url scheme part](https://
77
= note: `-D clippy::doc-broken-link` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::doc_broken_link)]`
99

10-
error: possible broken doc link: broken across multiple lines
11-
--> tests/ui/doc_broken_link.rs:53:5
12-
|
13-
LL | /// [doc invalid link broken url scheme part part](https://
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15-
|
16-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
17-
1810
error: possible broken doc link: broken across multiple lines
1911
--> tests/ui/doc_broken_link.rs:59:5
2012
|
2113
LL | /// [doc invalid link broken url host part](https://test
2214
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2315

24-
error: possible broken doc link: broken across multiple lines
25-
--> tests/ui/doc_broken_link.rs:59:5
26-
|
27-
LL | /// [doc invalid link broken url host part](https://test
28-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29-
|
30-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
31-
32-
error: possible broken doc link: broken across multiple lines
33-
--> tests/ui/doc_broken_link.rs:65:16
34-
|
35-
LL | /// There is a [fist link - invalid](https://test
36-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
37-
38-
error: possible broken doc link: broken across multiple lines
39-
--> tests/ui/doc_broken_link.rs:68:80
40-
|
41-
LL | /// with a [second link - valid](https://test.fake/doc_valid_link) and another [third link - invalid](https://test
42-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
43-
4416
error: possible broken doc link: broken across multiple lines
4517
--> tests/ui/doc_broken_link.rs:65:16
4618
|
4719
LL | /// There is a [fist link - invalid](https://test
4820
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49-
|
50-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
5121

5222
error: possible broken doc link: broken across multiple lines
5323
--> tests/ui/doc_broken_link.rs:68:80
5424
|
5525
LL | /// with a [second link - valid](https://test.fake/doc_valid_link) and another [third link - invalid](https://test
5626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
57-
|
58-
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
5927

60-
error: aborting due to 8 previous errors
28+
error: aborting due to 4 previous errors
6129

0 commit comments

Comments
 (0)