Skip to content

Commit 9fe7c6a

Browse files
committed
finally came up with some repro code
1 parent ecb0311 commit 9fe7c6a

File tree

4 files changed

+104
-8
lines changed

4 files changed

+104
-8
lines changed

tests/ui/auxiliary/proc_macro_attr.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use quote::{quote, quote_spanned};
1111
use syn::spanned::Spanned;
1212
use syn::token::Star;
1313
use syn::{
14-
parse_macro_input, parse_quote, FnArg, ImplItem, ItemImpl, ItemTrait, Lifetime, Pat, PatIdent, PatType, Signature,
15-
TraitItem, Type,
14+
parse_macro_input, parse_quote, FnArg, ImplItem, ItemFn, ItemImpl, ItemTrait, Lifetime, Pat, PatIdent, PatType,
15+
Signature, TraitItem, Type,
1616
};
1717

1818
#[proc_macro_attribute]
@@ -95,3 +95,33 @@ pub fn rename_my_lifetimes(_args: TokenStream, input: TokenStream) -> TokenStrea
9595

9696
TokenStream::from(quote!(#item))
9797
}
98+
99+
#[proc_macro_attribute]
100+
pub fn fake_main(_attr: TokenStream, item: TokenStream) -> TokenStream {
101+
let mut item = parse_macro_input!(item as ItemFn);
102+
let span = item.block.brace_token.span;
103+
104+
if item.sig.asyncness.is_some() {
105+
item.sig.asyncness = None;
106+
}
107+
108+
let crate_name = quote! { fake_crate };
109+
let block = item.block;
110+
item.block = syn::parse_quote_spanned! {
111+
span =>
112+
{
113+
#crate_name::block_on(async {
114+
#block
115+
})
116+
}
117+
};
118+
119+
quote! {
120+
mod #crate_name {
121+
pub fn block_on<F: ::std::future::Future>(_fut: F) {}
122+
}
123+
124+
#item
125+
}
126+
.into()
127+
}

tests/ui/semicolon_if_nothing_returned.fixed

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
//@aux-build:proc_macro_attr.rs
2+
13
#![warn(clippy::semicolon_if_nothing_returned)]
24
#![allow(clippy::redundant_closure, clippy::uninlined_format_args, clippy::needless_late_init)]
35

6+
#[macro_use]
7+
extern crate proc_macro_attr;
8+
49
fn get_unit() {}
510

611
// the functions below trigger the lint
@@ -120,3 +125,25 @@ fn let_else_stmts() {
120125
return;
121126
};
122127
}
128+
129+
mod issue12123 {
130+
#[rustfmt::skip]
131+
mod this_triggers {
132+
#[fake_main];
133+
async fn main() {
134+
135+
}
136+
}
137+
138+
mod and_this {
139+
#[fake_main];
140+
async fn main() {
141+
println!("hello");
142+
}
143+
}
144+
145+
mod but_this_does_not {
146+
#[fake_main]
147+
async fn main() {}
148+
}
149+
}

tests/ui/semicolon_if_nothing_returned.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
//@aux-build:proc_macro_attr.rs
2+
13
#![warn(clippy::semicolon_if_nothing_returned)]
24
#![allow(clippy::redundant_closure, clippy::uninlined_format_args, clippy::needless_late_init)]
35

6+
#[macro_use]
7+
extern crate proc_macro_attr;
8+
49
fn get_unit() {}
510

611
// the functions below trigger the lint
@@ -120,3 +125,25 @@ fn let_else_stmts() {
120125
return;
121126
};
122127
}
128+
129+
mod issue12123 {
130+
#[rustfmt::skip]
131+
mod this_triggers {
132+
#[fake_main]
133+
async fn main() {
134+
135+
}
136+
}
137+
138+
mod and_this {
139+
#[fake_main]
140+
async fn main() {
141+
println!("hello");
142+
}
143+
}
144+
145+
mod but_this_does_not {
146+
#[fake_main]
147+
async fn main() {}
148+
}
149+
}
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: consider adding a `;` to the last statement for consistent formatting
2-
--> $DIR/semicolon_if_nothing_returned.rs:8:5
2+
--> $DIR/semicolon_if_nothing_returned.rs:13:5
33
|
44
LL | println!("Hello")
55
| ^^^^^^^^^^^^^^^^^ help: add a `;` here: `println!("Hello");`
@@ -8,28 +8,40 @@ LL | println!("Hello")
88
= help: to override `-D warnings` add `#[allow(clippy::semicolon_if_nothing_returned)]`
99

1010
error: consider adding a `;` to the last statement for consistent formatting
11-
--> $DIR/semicolon_if_nothing_returned.rs:12:5
11+
--> $DIR/semicolon_if_nothing_returned.rs:17:5
1212
|
1313
LL | get_unit()
1414
| ^^^^^^^^^^ help: add a `;` here: `get_unit();`
1515

1616
error: consider adding a `;` to the last statement for consistent formatting
17-
--> $DIR/semicolon_if_nothing_returned.rs:17:5
17+
--> $DIR/semicolon_if_nothing_returned.rs:22:5
1818
|
1919
LL | y = x + 1
2020
| ^^^^^^^^^ help: add a `;` here: `y = x + 1;`
2121

2222
error: consider adding a `;` to the last statement for consistent formatting
23-
--> $DIR/semicolon_if_nothing_returned.rs:23:9
23+
--> $DIR/semicolon_if_nothing_returned.rs:28:9
2424
|
2525
LL | hello()
2626
| ^^^^^^^ help: add a `;` here: `hello();`
2727

2828
error: consider adding a `;` to the last statement for consistent formatting
29-
--> $DIR/semicolon_if_nothing_returned.rs:34:9
29+
--> $DIR/semicolon_if_nothing_returned.rs:39:9
3030
|
3131
LL | ptr::drop_in_place(s.as_mut_ptr())
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add a `;` here: `ptr::drop_in_place(s.as_mut_ptr());`
3333

34-
error: aborting due to 5 previous errors
34+
error: consider adding a `;` to the last statement for consistent formatting
35+
--> $DIR/semicolon_if_nothing_returned.rs:132:9
36+
|
37+
LL | #[fake_main]
38+
| ^^^^^^^^^^^^ help: add a `;` here: `#[fake_main];`
39+
40+
error: consider adding a `;` to the last statement for consistent formatting
41+
--> $DIR/semicolon_if_nothing_returned.rs:139:9
42+
|
43+
LL | #[fake_main]
44+
| ^^^^^^^^^^^^ help: add a `;` here: `#[fake_main];`
45+
46+
error: aborting due to 7 previous errors
3547

0 commit comments

Comments
 (0)