Skip to content

Commit 7cda242

Browse files
authored
don't emit suggestion inside macro in manual_async_fn (#14142)
fixes #12407 I think it is meaningful to emit a warning even if the span is in a macro. changelog: [`manual_async_fn`]: don't emit suggestion inside macro
2 parents 20b2461 + 60f9445 commit 7cda242

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

clippy_lints/src/manual_async_fn.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
6262
&& let Some(closure_body) = desugared_async_block(cx, block)
6363
&& let Node::Item(Item {vis_span, ..}) | Node::ImplItem(ImplItem {vis_span, ..}) =
6464
cx.tcx.hir_node_by_def_id(fn_def_id)
65+
&& !span.from_expansion()
6566
{
6667
let header_span = span.with_hi(ret_ty.span.hi());
6768

tests/ui/manual_async_fn.fixed

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,30 @@ pub(crate) async fn issue_10450_2() -> i32 { 42 }
113113

114114
pub(self) async fn issue_10450_3() -> i32 { 42 }
115115

116+
macro_rules! issue_12407 {
117+
(
118+
$(
119+
$(#[$m:meta])*
120+
$v:vis $(override($($overrides:tt),* $(,)?))? fn $name:ident $([$($params:tt)*])? (
121+
$($arg_name:ident: $arg_typ:ty),* $(,)?
122+
) $(-> $ret_ty:ty)? = $e:expr;
123+
)*
124+
) => {
125+
$(
126+
$(#[$m])*
127+
$v $($($overrides)*)? fn $name$(<$($params)*>)?(
128+
$($arg_name: $arg_typ),*
129+
) $(-> $ret_ty)? {
130+
$e
131+
}
132+
)*
133+
};
134+
}
135+
136+
issue_12407! {
137+
fn _hello() -> impl Future<Output = ()> = async {};
138+
fn non_async() = println!("hello");
139+
fn foo() = non_async();
140+
}
141+
116142
fn main() {}

tests/ui/manual_async_fn.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,30 @@ pub(self) fn issue_10450_3() -> impl Future<Output = i32> {
139139
async { 42 }
140140
}
141141

142+
macro_rules! issue_12407 {
143+
(
144+
$(
145+
$(#[$m:meta])*
146+
$v:vis $(override($($overrides:tt),* $(,)?))? fn $name:ident $([$($params:tt)*])? (
147+
$($arg_name:ident: $arg_typ:ty),* $(,)?
148+
) $(-> $ret_ty:ty)? = $e:expr;
149+
)*
150+
) => {
151+
$(
152+
$(#[$m])*
153+
$v $($($overrides)*)? fn $name$(<$($params)*>)?(
154+
$($arg_name: $arg_typ),*
155+
) $(-> $ret_ty)? {
156+
$e
157+
}
158+
)*
159+
};
160+
}
161+
162+
issue_12407! {
163+
fn _hello() -> impl Future<Output = ()> = async {};
164+
fn non_async() = println!("hello");
165+
fn foo() = non_async();
166+
}
167+
142168
fn main() {}

0 commit comments

Comments
 (0)