Skip to content

Commit ebcd6bc

Browse files
committed
Auto merge of rust-lang#13091 - Alexendoo:empty-line-after-rewrite, r=dswij
Rewrite `empty_line_after_doc_comments` and `empty_line_after_outer_attr`, move them from `nursery` to `suspicious` changelog: [`empty_line_after_doc_comments`], [`empty_line_after_outer_attr`]: rewrite and move them from `nursery` to `suspicious` They now lint when there's a comment between the last attr/doc comment and the empty line, to cover the case: ```rust /// Docs for `old_code // fn old_code() {} fn new_code() {} ``` When these lints or `suspicious_doc_comments` trigger we no longer trigger any other doc lint as a broad fix for rust-lang#12917, reverts some of rust-lang#13002 as the empty line lints cover it I ended up not doing rust-lang/rust-clippy#12917 (comment) as I don't think it's needed
2 parents 083e20a + 3474df6 commit ebcd6bc

File tree

73 files changed

+1563
-872
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1563
-872
lines changed

clippy_lints/src/attrs/empty_line_after.rs

-52
This file was deleted.

clippy_lints/src/attrs/mod.rs

-95
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ mod blanket_clippy_restriction_lints;
44
mod deprecated_cfg_attr;
55
mod deprecated_semver;
66
mod duplicated_attributes;
7-
mod empty_line_after;
87
mod inline_always;
98
mod mixed_attributes_style;
109
mod non_minimal_cfg;
@@ -126,94 +125,6 @@ declare_clippy_lint! {
126125
"use of `#[deprecated(since = \"x\")]` where x is not semver"
127126
}
128127

129-
declare_clippy_lint! {
130-
/// ### What it does
131-
/// Checks for empty lines after outer attributes
132-
///
133-
/// ### Why is this bad?
134-
/// Most likely the attribute was meant to be an inner attribute using a '!'.
135-
/// If it was meant to be an outer attribute, then the following item
136-
/// should not be separated by empty lines.
137-
///
138-
/// ### Known problems
139-
/// Can cause false positives.
140-
///
141-
/// From the clippy side it's difficult to detect empty lines between an attributes and the
142-
/// following item because empty lines and comments are not part of the AST. The parsing
143-
/// currently works for basic cases but is not perfect.
144-
///
145-
/// ### Example
146-
/// ```no_run
147-
/// #[allow(dead_code)]
148-
///
149-
/// fn not_quite_good_code() { }
150-
/// ```
151-
///
152-
/// Use instead:
153-
/// ```no_run
154-
/// // Good (as inner attribute)
155-
/// #![allow(dead_code)]
156-
///
157-
/// fn this_is_fine() { }
158-
///
159-
/// // or
160-
///
161-
/// // Good (as outer attribute)
162-
/// #[allow(dead_code)]
163-
/// fn this_is_fine_too() { }
164-
/// ```
165-
#[clippy::version = "pre 1.29.0"]
166-
pub EMPTY_LINE_AFTER_OUTER_ATTR,
167-
nursery,
168-
"empty line after outer attribute"
169-
}
170-
171-
declare_clippy_lint! {
172-
/// ### What it does
173-
/// Checks for empty lines after documentation comments.
174-
///
175-
/// ### Why is this bad?
176-
/// The documentation comment was most likely meant to be an inner attribute or regular comment.
177-
/// If it was intended to be a documentation comment, then the empty line should be removed to
178-
/// be more idiomatic.
179-
///
180-
/// ### Known problems
181-
/// Only detects empty lines immediately following the documentation. If the doc comment is followed
182-
/// by an attribute and then an empty line, this lint will not trigger. Use `empty_line_after_outer_attr`
183-
/// in combination with this lint to detect both cases.
184-
///
185-
/// Does not detect empty lines after doc attributes (e.g. `#[doc = ""]`).
186-
///
187-
/// ### Example
188-
/// ```no_run
189-
/// /// Some doc comment with a blank line after it.
190-
///
191-
/// fn not_quite_good_code() { }
192-
/// ```
193-
///
194-
/// Use instead:
195-
/// ```no_run
196-
/// /// Good (no blank line)
197-
/// fn this_is_fine() { }
198-
/// ```
199-
///
200-
/// ```no_run
201-
/// // Good (convert to a regular comment)
202-
///
203-
/// fn this_is_fine_too() { }
204-
/// ```
205-
///
206-
/// ```no_run
207-
/// //! Good (convert to a comment on an inner attribute)
208-
///
209-
/// fn this_is_fine_as_well() { }
210-
/// ```
211-
#[clippy::version = "1.70.0"]
212-
pub EMPTY_LINE_AFTER_DOC_COMMENTS,
213-
nursery,
214-
"empty line after documentation comments"
215-
}
216-
217128
declare_clippy_lint! {
218129
/// ### What it does
219130
/// Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category.
@@ -601,18 +512,12 @@ impl EarlyAttributes {
601512

602513
impl_lint_pass!(EarlyAttributes => [
603514
DEPRECATED_CFG_ATTR,
604-
EMPTY_LINE_AFTER_OUTER_ATTR,
605-
EMPTY_LINE_AFTER_DOC_COMMENTS,
606515
NON_MINIMAL_CFG,
607516
DEPRECATED_CLIPPY_CFG_ATTR,
608517
UNNECESSARY_CLIPPY_CFG,
609518
]);
610519

611520
impl EarlyLintPass for EarlyAttributes {
612-
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &rustc_ast::Item) {
613-
empty_line_after::check(cx, item);
614-
}
615-
616521
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
617522
deprecated_cfg_attr::check(cx, attr, &self.msrv);
618523
deprecated_cfg_attr::check_clippy(cx, attr);

clippy_lints/src/declared_lints.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ pub static LINTS: &[&crate::LintInfo] = &[
4949
crate::attrs::DEPRECATED_CLIPPY_CFG_ATTR_INFO,
5050
crate::attrs::DEPRECATED_SEMVER_INFO,
5151
crate::attrs::DUPLICATED_ATTRIBUTES_INFO,
52-
crate::attrs::EMPTY_LINE_AFTER_DOC_COMMENTS_INFO,
53-
crate::attrs::EMPTY_LINE_AFTER_OUTER_ATTR_INFO,
5452
crate::attrs::INLINE_ALWAYS_INFO,
5553
crate::attrs::MIXED_ATTRIBUTES_STYLE_INFO,
5654
crate::attrs::NON_MINIMAL_CFG_INFO,
@@ -138,6 +136,8 @@ pub static LINTS: &[&crate::LintInfo] = &[
138136
crate::doc::DOC_LINK_WITH_QUOTES_INFO,
139137
crate::doc::DOC_MARKDOWN_INFO,
140138
crate::doc::EMPTY_DOCS_INFO,
139+
crate::doc::EMPTY_LINE_AFTER_DOC_COMMENTS_INFO,
140+
crate::doc::EMPTY_LINE_AFTER_OUTER_ATTR_INFO,
141141
crate::doc::MISSING_ERRORS_DOC_INFO,
142142
crate::doc::MISSING_PANICS_DOC_INFO,
143143
crate::doc::MISSING_SAFETY_DOC_INFO,

0 commit comments

Comments
 (0)