mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-11 08:05:12 +00:00
finally came up with some repro code
This commit is contained in:
parent
ecb0311fcc
commit
9fe7c6a7ec
@ -11,8 +11,8 @@ use quote::{quote, quote_spanned};
|
||||
use syn::spanned::Spanned;
|
||||
use syn::token::Star;
|
||||
use syn::{
|
||||
parse_macro_input, parse_quote, FnArg, ImplItem, ItemImpl, ItemTrait, Lifetime, Pat, PatIdent, PatType, Signature,
|
||||
TraitItem, Type,
|
||||
parse_macro_input, parse_quote, FnArg, ImplItem, ItemFn, ItemImpl, ItemTrait, Lifetime, Pat, PatIdent, PatType,
|
||||
Signature, TraitItem, Type,
|
||||
};
|
||||
|
||||
#[proc_macro_attribute]
|
||||
@ -95,3 +95,33 @@ pub fn rename_my_lifetimes(_args: TokenStream, input: TokenStream) -> TokenStrea
|
||||
|
||||
TokenStream::from(quote!(#item))
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn fake_main(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let mut item = parse_macro_input!(item as ItemFn);
|
||||
let span = item.block.brace_token.span;
|
||||
|
||||
if item.sig.asyncness.is_some() {
|
||||
item.sig.asyncness = None;
|
||||
}
|
||||
|
||||
let crate_name = quote! { fake_crate };
|
||||
let block = item.block;
|
||||
item.block = syn::parse_quote_spanned! {
|
||||
span =>
|
||||
{
|
||||
#crate_name::block_on(async {
|
||||
#block
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
quote! {
|
||||
mod #crate_name {
|
||||
pub fn block_on<F: ::std::future::Future>(_fut: F) {}
|
||||
}
|
||||
|
||||
#item
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
@ -1,6 +1,11 @@
|
||||
//@aux-build:proc_macro_attr.rs
|
||||
|
||||
#![warn(clippy::semicolon_if_nothing_returned)]
|
||||
#![allow(clippy::redundant_closure, clippy::uninlined_format_args, clippy::needless_late_init)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate proc_macro_attr;
|
||||
|
||||
fn get_unit() {}
|
||||
|
||||
// the functions below trigger the lint
|
||||
@ -120,3 +125,25 @@ fn let_else_stmts() {
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
mod issue12123 {
|
||||
#[rustfmt::skip]
|
||||
mod this_triggers {
|
||||
#[fake_main];
|
||||
async fn main() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
mod and_this {
|
||||
#[fake_main];
|
||||
async fn main() {
|
||||
println!("hello");
|
||||
}
|
||||
}
|
||||
|
||||
mod but_this_does_not {
|
||||
#[fake_main]
|
||||
async fn main() {}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,11 @@
|
||||
//@aux-build:proc_macro_attr.rs
|
||||
|
||||
#![warn(clippy::semicolon_if_nothing_returned)]
|
||||
#![allow(clippy::redundant_closure, clippy::uninlined_format_args, clippy::needless_late_init)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate proc_macro_attr;
|
||||
|
||||
fn get_unit() {}
|
||||
|
||||
// the functions below trigger the lint
|
||||
@ -120,3 +125,25 @@ fn let_else_stmts() {
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
mod issue12123 {
|
||||
#[rustfmt::skip]
|
||||
mod this_triggers {
|
||||
#[fake_main]
|
||||
async fn main() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
mod and_this {
|
||||
#[fake_main]
|
||||
async fn main() {
|
||||
println!("hello");
|
||||
}
|
||||
}
|
||||
|
||||
mod but_this_does_not {
|
||||
#[fake_main]
|
||||
async fn main() {}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: consider adding a `;` to the last statement for consistent formatting
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:8:5
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:13:5
|
||||
|
|
||||
LL | println!("Hello")
|
||||
| ^^^^^^^^^^^^^^^^^ help: add a `;` here: `println!("Hello");`
|
||||
@ -8,28 +8,40 @@ LL | println!("Hello")
|
||||
= help: to override `-D warnings` add `#[allow(clippy::semicolon_if_nothing_returned)]`
|
||||
|
||||
error: consider adding a `;` to the last statement for consistent formatting
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:12:5
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:17:5
|
||||
|
|
||||
LL | get_unit()
|
||||
| ^^^^^^^^^^ help: add a `;` here: `get_unit();`
|
||||
|
||||
error: consider adding a `;` to the last statement for consistent formatting
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:17:5
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:22:5
|
||||
|
|
||||
LL | y = x + 1
|
||||
| ^^^^^^^^^ help: add a `;` here: `y = x + 1;`
|
||||
|
||||
error: consider adding a `;` to the last statement for consistent formatting
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:23:9
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:28:9
|
||||
|
|
||||
LL | hello()
|
||||
| ^^^^^^^ help: add a `;` here: `hello();`
|
||||
|
||||
error: consider adding a `;` to the last statement for consistent formatting
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:34:9
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:39:9
|
||||
|
|
||||
LL | ptr::drop_in_place(s.as_mut_ptr())
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `ptr::drop_in_place(s.as_mut_ptr());`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
error: consider adding a `;` to the last statement for consistent formatting
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:132:9
|
||||
|
|
||||
LL | #[fake_main]
|
||||
| ^^^^^^^^^^^^ help: add a `;` here: `#[fake_main];`
|
||||
|
||||
error: consider adding a `;` to the last statement for consistent formatting
|
||||
--> $DIR/semicolon_if_nothing_returned.rs:139:9
|
||||
|
|
||||
LL | #[fake_main]
|
||||
| ^^^^^^^^^^^^ help: add a `;` here: `#[fake_main];`
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user