about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJason Newcomb <jsnewcomb@pm.me>2025-02-06 20:38:46 +0000
committerGitHub <noreply@github.com>2025-02-06 20:38:46 +0000
commit7cda242e3ce3eaf59223f3921e7eb53b15c9e2a5 (patch)
tree2085802d31d8adb737b87c15467874142c1b77da
parent20b2461938caff4975bb29d28d3b26cb81cfa6d2 (diff)
parent60f94459002db4d8674008877fabd98782617104 (diff)
downloadrust-7cda242e3ce3eaf59223f3921e7eb53b15c9e2a5.tar.gz
rust-7cda242e3ce3eaf59223f3921e7eb53b15c9e2a5.zip
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
-rw-r--r--clippy_lints/src/manual_async_fn.rs1
-rw-r--r--tests/ui/manual_async_fn.fixed26
-rw-r--r--tests/ui/manual_async_fn.rs26
3 files changed, 53 insertions, 0 deletions
diff --git a/clippy_lints/src/manual_async_fn.rs b/clippy_lints/src/manual_async_fn.rs
index 9f3b0957eab..ba63f980316 100644
--- a/clippy_lints/src/manual_async_fn.rs
+++ b/clippy_lints/src/manual_async_fn.rs
@@ -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());
 
diff --git a/tests/ui/manual_async_fn.fixed b/tests/ui/manual_async_fn.fixed
index dc1cb8e11fc..ad0266d39e9 100644
--- a/tests/ui/manual_async_fn.fixed
+++ b/tests/ui/manual_async_fn.fixed
@@ -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() {}
diff --git a/tests/ui/manual_async_fn.rs b/tests/ui/manual_async_fn.rs
index 9ca7654a368..87973222c0b 100644
--- a/tests/ui/manual_async_fn.rs
+++ b/tests/ui/manual_async_fn.rs
@@ -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() {}