Skip to content

Commit 2fd51b8

Browse files
JacherrxFrednet
authored andcommitted
doc_comment_double_space_linebreaks: lint per line instead of by block
remove additional lint call fix fix lint defs
1 parent f94f64f commit 2fd51b8

File tree

5 files changed

+49
-83
lines changed

5 files changed

+49
-83
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5570,8 +5570,8 @@ Released 2018-09-13
55705570
[`disallowed_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_type
55715571
[`disallowed_types`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types
55725572
[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
5573-
[`doc_include_without_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_include_without_cfg
55745573
[`doc_comment_double_space_linebreak`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_comment_double_space_linebreak
5574+
[`doc_include_without_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_include_without_cfg
55755575
[`doc_lazy_continuation`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation
55765576
[`doc_link_code`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_code
55775577
[`doc_link_with_quotes`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes

clippy_lints/src/declared_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ pub static LINTS: &[&crate::LintInfo] = &[
137137
crate::disallowed_names::DISALLOWED_NAMES_INFO,
138138
crate::disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS_INFO,
139139
crate::disallowed_types::DISALLOWED_TYPES_INFO,
140-
crate::doc::DOC_INCLUDE_WITHOUT_CFG_INFO,
141140
crate::doc::DOC_COMMENT_DOUBLE_SPACE_LINEBREAK_INFO,
141+
crate::doc::DOC_INCLUDE_WITHOUT_CFG_INFO,
142142
crate::doc::DOC_LAZY_CONTINUATION_INFO,
143143
crate::doc::DOC_LINK_CODE_INFO,
144144
crate::doc::DOC_LINK_WITH_QUOTES_INFO,
Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,20 @@
1-
use clippy_utils::diagnostics::span_lint_and_then;
2-
use clippy_utils::source::snippet_opt;
1+
use clippy_utils::diagnostics::span_lint_and_sugg;
32
use rustc_errors::Applicability;
43
use rustc_lint::LateContext;
5-
use rustc_span::Span;
4+
use rustc_span::{BytePos, Span};
65

76
use super::DOC_COMMENT_DOUBLE_SPACE_LINEBREAK;
87

98
pub fn check(cx: &LateContext<'_>, collected_breaks: &[Span]) {
10-
let replacements: Vec<_> = collect_doc_replacements(cx, collected_breaks);
11-
12-
if let Some((&(lo_span, _), &(hi_span, _))) = replacements.first().zip(replacements.last()) {
13-
span_lint_and_then(
9+
for r_span in collected_breaks {
10+
span_lint_and_sugg(
1411
cx,
1512
DOC_COMMENT_DOUBLE_SPACE_LINEBREAK,
16-
lo_span.to(hi_span),
13+
r_span.with_hi(r_span.lo() + BytePos(2)),
1714
"doc comment uses two spaces for a hard line break",
18-
|diag| {
19-
diag.multipart_suggestion(
20-
"replace this double space with a backslash",
21-
replacements,
22-
Applicability::MachineApplicable,
23-
);
24-
},
15+
"replace this double space with a backslash",
16+
"\\".to_owned(),
17+
Applicability::MachineApplicable,
2518
);
2619
}
2720
}
28-
29-
fn collect_doc_replacements(cx: &LateContext<'_>, spans: &[Span]) -> Vec<(Span, String)> {
30-
spans
31-
.iter()
32-
.map(|span| {
33-
// we already made sure the snippet exists when collecting spans
34-
let s = snippet_opt(cx, *span).expect("snippet was already validated to exist");
35-
let after_newline = s.trim_start_matches(' ');
36-
37-
let new_comment = format!("\\{after_newline}");
38-
(*span, new_comment)
39-
})
40-
.collect()
41-
}

clippy_lints/src/doc/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,6 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
772772
return None;
773773
}
774774

775-
suspicious_doc_comments::check(cx, attrs);
776-
777775
let (fragments, _) = attrs_to_doc_fragments(
778776
attrs.iter().filter_map(|attr| {
779777
if attr.doc_str_and_comment_kind().is_none() || attr.span().in_external_macro(cx.sess().source_map()) {
Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,65 @@
11
error: doc comment uses two spaces for a hard line break
22
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:7:43
33
|
4-
LL | //! Should warn on double space linebreaks
5-
| ___________________________________________^
6-
LL | | //! in file/module doc comment
7-
| |____^
4+
LL | //! Should warn on double space linebreaks
5+
| ^^ help: replace this double space with a backslash: `\`
86
|
97
= note: `-D clippy::doc-comment-double-space-linebreak` implied by `-D warnings`
108
= help: to override `-D warnings` add `#[allow(clippy::doc_comment_double_space_linebreak)]`
11-
help: replace this double space with a backslash
12-
|
13-
LL ~ //! Should warn on double space linebreaks\
14-
LL ~ //! in file/module doc comment
15-
|
169

1710
error: doc comment uses two spaces for a hard line break
1811
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:35:51
1912
|
20-
LL | /// Should warn when doc comment uses double space
21-
| ___________________________________________________^
22-
LL | | /// as a line-break, even when there are multiple
23-
LL | | /// in a row
24-
| |____^
25-
|
26-
help: replace this double space with a backslash
27-
|
28-
LL ~ /// Should warn when doc comment uses double space\
29-
LL ~ /// as a line-break, even when there are multiple\
30-
LL ~ /// in a row
13+
LL | /// Should warn when doc comment uses double space
14+
| ^^ help: replace this double space with a backslash: `\`
15+
16+
error: doc comment uses two spaces for a hard line break
17+
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:36:50
3118
|
19+
LL | /// as a line-break, even when there are multiple
20+
| ^^ help: replace this double space with a backslash: `\`
3221

3322
error: doc comment uses two spaces for a hard line break
3423
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:44:12
3524
|
36-
LL | /// 🌹 are 🟥
37-
| ______________^
38-
LL | | /// 🌷 are 🟦
39-
LL | | /// 📎 is 😎
40-
LL | | /// and so are 🫵
41-
LL | | /// (hopefully no formatting weirdness linting this)
42-
| |____^
25+
LL | /// 🌹 are 🟥
26+
| ^^ help: replace this double space with a backslash: `\`
27+
28+
error: doc comment uses two spaces for a hard line break
29+
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:45:12
4330
|
44-
help: replace this double space with a backslash
31+
LL | /// 🌷 are 🟦
32+
| ^^ help: replace this double space with a backslash: `\`
33+
34+
error: doc comment uses two spaces for a hard line break
35+
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:46:11
4536
|
46-
LL ~ /// 🌹 are 🟥\
47-
LL ~ /// 🌷 are 🟦\
48-
LL ~ /// 📎 is 😎\
49-
LL ~ /// and so are 🫵\
50-
LL ~ /// (hopefully no formatting weirdness linting this)
37+
LL | /// 📎 is 😎
38+
| ^^ help: replace this double space with a backslash: `\`
39+
40+
error: doc comment uses two spaces for a hard line break
41+
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:47:17
5142
|
43+
LL | /// and so are 🫵
44+
| ^^ help: replace this double space with a backslash: `\`
5245

5346
error: doc comment uses two spaces for a hard line break
5447
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:86:16
5548
|
56-
LL | /// here we mix
57-
| ________________^
58-
LL | | /// double spaces\
59-
LL | | /// and also
60-
LL | | /// adding backslash\
61-
LL | | /// to some of them
62-
LL | | /// to see how that looks
63-
| |____^
64-
|
65-
help: replace this double space with a backslash
49+
LL | /// here we mix
50+
| ^^ help: replace this double space with a backslash: `\`
51+
52+
error: doc comment uses two spaces for a hard line break
53+
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:88:13
6654
|
67-
LL ~ /// here we mix\
68-
LL ~ /// double spaces\
69-
LL ~ /// and also\
70-
LL ~ /// adding backslash\
71-
LL ~ /// to some of them\
72-
LL ~ /// to see how that looks
55+
LL | /// and also
56+
| ^^ help: replace this double space with a backslash: `\`
57+
58+
error: doc comment uses two spaces for a hard line break
59+
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:90:20
7360
|
61+
LL | /// to some of them
62+
| ^^ help: replace this double space with a backslash: `\`
7463

75-
error: aborting due to 4 previous errors
64+
error: aborting due to 10 previous errors
7665

0 commit comments

Comments
 (0)