forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: warn on empty line outer AttrKind::DocComment
changelog: [`empty_line_after_doc_comments`]: add lint for checking empty lines after rustdoc comments. Fixes: rust-lang#10395
- Loading branch information
Showing
5 changed files
with
251 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
//@aux-build:proc_macro_attr.rs | ||
#![warn(clippy::empty_line_after_doc_comments)] | ||
#![allow(clippy::assertions_on_constants)] | ||
#![feature(custom_inner_attributes)] | ||
#![rustfmt::skip] | ||
|
||
#[macro_use] | ||
extern crate proc_macro_attr; | ||
|
||
mod some_mod { | ||
//! This doc comment should *NOT* produce a warning | ||
mod some_inner_mod { | ||
fn some_noop() {} | ||
} | ||
} | ||
|
||
/// This should produce a warning | ||
fn with_doc_and_newline() { assert!(true)} | ||
|
||
// This should *NOT* produce a warning | ||
#[crate_type = "lib"] | ||
|
||
/// some comment | ||
fn with_one_newline_and_comment() { assert!(true) } | ||
|
||
// This should *NOT* produce a warning | ||
#[crate_type = "lib"] | ||
/// some comment | ||
fn with_no_newline_and_comment() { assert!(true) } | ||
|
||
|
||
// This should *NOT* produce a warning | ||
#[crate_type = "lib"] | ||
|
||
fn with_one_newline() { assert!(true) } | ||
|
||
// This should *NOT* produce a warning | ||
#[crate_type = "lib"] | ||
|
||
|
||
fn with_two_newlines() { assert!(true) } | ||
|
||
|
||
// This should *NOT* produce a warning | ||
#[crate_type = "lib"] | ||
|
||
enum Baz { | ||
One, | ||
Two | ||
} | ||
|
||
// This should *NOT* produce a warning | ||
#[crate_type = "lib"] | ||
|
||
struct Foo { | ||
one: isize, | ||
two: isize | ||
} | ||
|
||
// This should *NOT* produce a warning | ||
#[crate_type = "lib"] | ||
|
||
mod foo { | ||
} | ||
|
||
/// This doc comment should produce a warning | ||
/** This is also a doc comment and should produce a warning | ||
*/ | ||
|
||
// This should *NOT* produce a warning | ||
#[allow(non_camel_case_types)] | ||
#[allow(missing_docs)] | ||
#[allow(missing_docs)] | ||
fn three_attributes() { assert!(true) } | ||
|
||
// This should *NOT* produce a warning | ||
#[doc = " | ||
Returns the escaped value of the textual representation of | ||
"] | ||
pub fn function() -> bool { | ||
true | ||
} | ||
|
||
// This should *NOT* produce a warning | ||
#[derive(Clone, Copy)] | ||
pub enum FooFighter { | ||
Bar1, | ||
|
||
Bar2, | ||
|
||
Bar3, | ||
|
||
Bar4 | ||
} | ||
|
||
// This should *NOT* produce a warning because the empty line is inside a block comment | ||
#[crate_type = "lib"] | ||
/* | ||
*/ | ||
pub struct S; | ||
|
||
// This should *NOT* produce a warning | ||
#[crate_type = "lib"] | ||
/* test */ | ||
pub struct T; | ||
|
||
// This should *NOT* produce a warning | ||
// See https://github.com/rust-lang/rust-clippy/issues/5567 | ||
#[fake_async_trait] | ||
pub trait Bazz { | ||
fn foo() -> Vec<u8> { | ||
let _i = ""; | ||
|
||
|
||
|
||
vec![] | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy)] | ||
#[dummy(string = "first line | ||
second line | ||
")] | ||
pub struct Args; | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
error: found an empty line after a doc comment. Perhaps you need to use `//!` to make a comment on a module, remove the empty line, or make a regular comment with `//`? | ||
--> $DIR/empty_line_after_doc_comments.rs:18:1 | ||
| | ||
LL | / /// This should produce a warning | ||
LL | | | ||
LL | | fn with_doc_and_newline() { assert!(true)} | ||
| |_ | ||
| | ||
= note: `-D clippy::empty-line-after-doc-comments` implied by `-D warnings` | ||
|
||
error: found an empty line after a doc comment. Perhaps you need to use `//!` to make a comment on a module, remove the empty line, or make a regular comment with `//`? | ||
--> $DIR/empty_line_after_doc_comments.rs:68:1 | ||
| | ||
LL | / /// This doc comment should produce a warning | ||
LL | | | ||
LL | | /** This is also a doc comment and should produce a warning | ||
LL | | */ | ||
... | | ||
LL | | #[allow(missing_docs)] | ||
LL | | fn three_attributes() { assert!(true) } | ||
| |_ | ||
|
||
error: found an empty line after a doc comment. Perhaps you need to use `//!` to make a comment on a module, remove the empty line, or make a regular comment with `//`? | ||
--> $DIR/empty_line_after_doc_comments.rs:70:1 | ||
| | ||
LL | / /** This is also a doc comment and should produce a warning | ||
LL | | */ | ||
LL | | | ||
LL | | // This should *NOT* produce a warning | ||
... | | ||
LL | | #[allow(missing_docs)] | ||
LL | | fn three_attributes() { assert!(true) } | ||
| |_ | ||
|
||
error: aborting due to 3 previous errors | ||
|