Skip to content

Commit

Permalink
don't emit suggestion inside macro in manual_async_fn (#14142)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Jarcho authored Feb 6, 2025
2 parents 20b2461 + 60f9445 commit 7cda242
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions clippy_lints/src/manual_async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
&& let Some(closure_body) = desugared_async_block(cx, block)
&& let Node::Item(Item {vis_span, ..}) | Node::ImplItem(ImplItem {vis_span, ..}) =
cx.tcx.hir_node_by_def_id(fn_def_id)
&& !span.from_expansion()
{
let header_span = span.with_hi(ret_ty.span.hi());

Expand Down
26 changes: 26 additions & 0 deletions tests/ui/manual_async_fn.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,30 @@ pub(crate) async fn issue_10450_2() -> i32 { 42 }

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

macro_rules! issue_12407 {
(
$(
$(#[$m:meta])*
$v:vis $(override($($overrides:tt),* $(,)?))? fn $name:ident $([$($params:tt)*])? (
$($arg_name:ident: $arg_typ:ty),* $(,)?
) $(-> $ret_ty:ty)? = $e:expr;
)*
) => {
$(
$(#[$m])*
$v $($($overrides)*)? fn $name$(<$($params)*>)?(
$($arg_name: $arg_typ),*
) $(-> $ret_ty)? {
$e
}
)*
};
}

issue_12407! {
fn _hello() -> impl Future<Output = ()> = async {};
fn non_async() = println!("hello");
fn foo() = non_async();
}

fn main() {}
26 changes: 26 additions & 0 deletions tests/ui/manual_async_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,30 @@ pub(self) fn issue_10450_3() -> impl Future<Output = i32> {
async { 42 }
}

macro_rules! issue_12407 {
(
$(
$(#[$m:meta])*
$v:vis $(override($($overrides:tt),* $(,)?))? fn $name:ident $([$($params:tt)*])? (
$($arg_name:ident: $arg_typ:ty),* $(,)?
) $(-> $ret_ty:ty)? = $e:expr;
)*
) => {
$(
$(#[$m])*
$v $($($overrides)*)? fn $name$(<$($params)*>)?(
$($arg_name: $arg_typ),*
) $(-> $ret_ty)? {
$e
}
)*
};
}

issue_12407! {
fn _hello() -> impl Future<Output = ()> = async {};
fn non_async() = println!("hello");
fn foo() = non_async();
}

fn main() {}

0 comments on commit 7cda242

Please sign in to comment.