mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 20:46:07 +03:00
Make empty_line_after_outer_attr an early lint
This commit is contained in:
@@ -38,7 +38,7 @@ fn clippy_driver_path() -> PathBuf {
|
||||
// as what we manually pass to `cargo` invocation
|
||||
fn third_party_crates() -> String {
|
||||
use std::collections::HashMap;
|
||||
static CRATES: &[&str] = &["serde", "serde_derive", "regex", "clippy_lints"];
|
||||
static CRATES: &[&str] = &["serde", "serde_derive", "regex", "clippy_lints", "syn", "quote"];
|
||||
let dep_dir = cargo::TARGET_LIB.join("deps");
|
||||
let mut crates: HashMap<&str, PathBuf> = HashMap::with_capacity(CRATES.len());
|
||||
for entry in fs::read_dir(dep_dir).unwrap() {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![crate_type = "proc-macro"]
|
||||
#![feature(repr128, proc_macro_hygiene, proc_macro_quote)]
|
||||
#![allow(clippy::useless_conversion)]
|
||||
|
||||
extern crate proc_macro;
|
||||
extern crate quote;
|
||||
extern crate syn;
|
||||
|
||||
use proc_macro::TokenStream;
|
||||
use quote::{quote, quote_spanned};
|
||||
use syn::parse_macro_input;
|
||||
use syn::{parse_quote, ItemTrait, TraitItem};
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn fake_async_trait(_args: TokenStream, input: TokenStream) -> TokenStream {
|
||||
let mut item = parse_macro_input!(input as ItemTrait);
|
||||
for inner in &mut item.items {
|
||||
if let TraitItem::Method(method) = inner {
|
||||
let sig = &method.sig;
|
||||
let block = &mut method.default;
|
||||
if let Some(block) = block {
|
||||
let brace = block.brace_token;
|
||||
|
||||
let my_block = quote_spanned!( brace.span => {
|
||||
// Should not trigger `empty_line_after_outer_attr`
|
||||
#[crate_type = "lib"]
|
||||
#sig #block
|
||||
Vec::new()
|
||||
});
|
||||
*block = parse_quote!(#my_block);
|
||||
}
|
||||
}
|
||||
}
|
||||
TokenStream::from(quote!(#item))
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
// aux-build:proc_macro_attr.rs
|
||||
#![warn(clippy::empty_line_after_outer_attr)]
|
||||
#![allow(clippy::assertions_on_constants)]
|
||||
#![feature(custom_inner_attributes)]
|
||||
#![rustfmt::skip]
|
||||
|
||||
#[macro_use]
|
||||
extern crate proc_macro_attr;
|
||||
|
||||
// This should produce a warning
|
||||
#[crate_type = "lib"]
|
||||
|
||||
@@ -93,4 +97,17 @@ pub enum FooFighter {
|
||||
/* test */
|
||||
pub struct T;
|
||||
|
||||
fn main() { }
|
||||
// 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![]
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error: Found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute?
|
||||
--> $DIR/empty_line_after_outer_attribute.rs:7:1
|
||||
--> $DIR/empty_line_after_outer_attribute.rs:11:1
|
||||
|
|
||||
LL | / #[crate_type = "lib"]
|
||||
LL | |
|
||||
@@ -10,7 +10,7 @@ LL | | fn with_one_newline_and_comment() { assert!(true) }
|
||||
= note: `-D clippy::empty-line-after-outer-attr` implied by `-D warnings`
|
||||
|
||||
error: Found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute?
|
||||
--> $DIR/empty_line_after_outer_attribute.rs:19:1
|
||||
--> $DIR/empty_line_after_outer_attribute.rs:23:1
|
||||
|
|
||||
LL | / #[crate_type = "lib"]
|
||||
LL | |
|
||||
@@ -18,7 +18,7 @@ LL | | fn with_one_newline() { assert!(true) }
|
||||
| |_
|
||||
|
||||
error: Found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute?
|
||||
--> $DIR/empty_line_after_outer_attribute.rs:24:1
|
||||
--> $DIR/empty_line_after_outer_attribute.rs:28:1
|
||||
|
|
||||
LL | / #[crate_type = "lib"]
|
||||
LL | |
|
||||
@@ -27,7 +27,7 @@ LL | | fn with_two_newlines() { assert!(true) }
|
||||
| |_
|
||||
|
||||
error: Found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute?
|
||||
--> $DIR/empty_line_after_outer_attribute.rs:31:1
|
||||
--> $DIR/empty_line_after_outer_attribute.rs:35:1
|
||||
|
|
||||
LL | / #[crate_type = "lib"]
|
||||
LL | |
|
||||
@@ -35,7 +35,7 @@ LL | | enum Baz {
|
||||
| |_
|
||||
|
||||
error: Found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute?
|
||||
--> $DIR/empty_line_after_outer_attribute.rs:39:1
|
||||
--> $DIR/empty_line_after_outer_attribute.rs:43:1
|
||||
|
|
||||
LL | / #[crate_type = "lib"]
|
||||
LL | |
|
||||
@@ -43,7 +43,7 @@ LL | | struct Foo {
|
||||
| |_
|
||||
|
||||
error: Found an empty line after an outer attribute. Perhaps you forgot to add a `!` to make it an inner attribute?
|
||||
--> $DIR/empty_line_after_outer_attribute.rs:47:1
|
||||
--> $DIR/empty_line_after_outer_attribute.rs:51:1
|
||||
|
|
||||
LL | / #[crate_type = "lib"]
|
||||
LL | |
|
||||
|
||||
Reference in New Issue
Block a user