-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #5609 - phansch:empty-line-after-outer-attr-fix, r=flip…
…1995 Make empty_line_after_outer_attr an early lint Fixes #5567 Unfortunately I couldn't find a way to reproduce the issue without syn/quote. Considering that most real-world macros use syn and/or quote, I think it's okay to pull them in anyway. changelog: Fix false positive in [`empty_line_after_outer_attr`]
- Loading branch information
Showing
6 changed files
with
107 additions
and
40 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,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)) | ||
} |
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