about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-06-19 19:01:28 +0000
committerbors <bors@rust-lang.org>2024-06-19 19:01:28 +0000
commit4aee08f999767307f82d8d33fee6ee1af7ad5a00 (patch)
tree11b40768e570444d71f7a264c3fe5dc5b693a3b4
parent29cc5c691c574b54b2fcfed51c22f8bb51110919 (diff)
parentb147b6d03de918bfdf9bf9207a4a36379e917a1d (diff)
downloadrust-4aee08f999767307f82d8d33fee6ee1af7ad5a00.tar.gz
rust-4aee08f999767307f82d8d33fee6ee1af7ad5a00.zip
Auto merge of #12963 - lochetti:fix_12874, r=Centri3
Don't lint `implicit_return` on proc macros

This pr fixes https://github.com/rust-lang/rust-clippy/issues/12872

changelog: [`implicit_return`]: Don't lint on procedural macros.
-rw-r--r--clippy_lints/src/implicit_return.rs6
-rw-r--r--tests/ui/implicit_return.fixed13
-rw-r--r--tests/ui/implicit_return.rs13
-rw-r--r--tests/ui/implicit_return.stderr32
4 files changed, 47 insertions, 17 deletions
diff --git a/clippy_lints/src/implicit_return.rs b/clippy_lints/src/implicit_return.rs
index 2f543781c44..a102b434cfa 100644
--- a/clippy_lints/src/implicit_return.rs
+++ b/clippy_lints/src/implicit_return.rs
@@ -1,7 +1,7 @@
 use clippy_utils::diagnostics::span_lint_hir_and_then;
 use clippy_utils::source::{snippet_with_applicability, snippet_with_context, walk_span_to_context};
 use clippy_utils::visitors::for_each_expr_without_closures;
-use clippy_utils::{get_async_fn_body, is_async_fn};
+use clippy_utils::{get_async_fn_body, is_async_fn, is_from_proc_macro};
 use core::ops::ControlFlow;
 use rustc_errors::Applicability;
 use rustc_hir::intravisit::FnKind;
@@ -245,6 +245,10 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitReturn {
         } else {
             body.value
         };
+
+        if is_from_proc_macro(cx, expr) {
+            return;
+        }
         lint_implicit_returns(cx, expr, expr.span.ctxt(), None);
     }
 }
diff --git a/tests/ui/implicit_return.fixed b/tests/ui/implicit_return.fixed
index 897f1b76616..a6aac351e32 100644
--- a/tests/ui/implicit_return.fixed
+++ b/tests/ui/implicit_return.fixed
@@ -1,7 +1,12 @@
+//@aux-build: proc_macros.rs
+
 #![feature(lint_reasons)]
 #![warn(clippy::implicit_return)]
 #![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)]
 
+extern crate proc_macros;
+use proc_macros::with_span;
+
 fn test_end_of_fn() -> bool {
     if true {
         // no error!
@@ -137,3 +142,11 @@ fn check_expect() -> bool {
     #[expect(clippy::implicit_return)]
     true
 }
+
+with_span!(
+    span
+
+    fn dont_lint_proc_macro(x: usize) -> usize{
+        x
+    }
+);
diff --git a/tests/ui/implicit_return.rs b/tests/ui/implicit_return.rs
index fcff67b5807..757c49f5e1c 100644
--- a/tests/ui/implicit_return.rs
+++ b/tests/ui/implicit_return.rs
@@ -1,7 +1,12 @@
+//@aux-build: proc_macros.rs
+
 #![feature(lint_reasons)]
 #![warn(clippy::implicit_return)]
 #![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)]
 
+extern crate proc_macros;
+use proc_macros::with_span;
+
 fn test_end_of_fn() -> bool {
     if true {
         // no error!
@@ -137,3 +142,11 @@ fn check_expect() -> bool {
     #[expect(clippy::implicit_return)]
     true
 }
+
+with_span!(
+    span
+
+    fn dont_lint_proc_macro(x: usize) -> usize{
+        x
+    }
+);
diff --git a/tests/ui/implicit_return.stderr b/tests/ui/implicit_return.stderr
index 3ffed273e0f..3d7bd408cb6 100644
--- a/tests/ui/implicit_return.stderr
+++ b/tests/ui/implicit_return.stderr
@@ -1,5 +1,5 @@
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:11:5
+  --> tests/ui/implicit_return.rs:16:5
    |
 LL |     true
    |     ^^^^ help: add `return` as shown: `return true`
@@ -8,85 +8,85 @@ LL |     true
    = help: to override `-D warnings` add `#[allow(clippy::implicit_return)]`
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:15:15
+  --> tests/ui/implicit_return.rs:20:15
    |
 LL |     if true { true } else { false }
    |               ^^^^ help: add `return` as shown: `return true`
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:15:29
+  --> tests/ui/implicit_return.rs:20:29
    |
 LL |     if true { true } else { false }
    |                             ^^^^^ help: add `return` as shown: `return false`
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:21:17
+  --> tests/ui/implicit_return.rs:26:17
    |
 LL |         true => false,
    |                 ^^^^^ help: add `return` as shown: `return false`
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:22:20
+  --> tests/ui/implicit_return.rs:27:20
    |
 LL |         false => { true },
    |                    ^^^^ help: add `return` as shown: `return true`
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:35:9
+  --> tests/ui/implicit_return.rs:40:9
    |
 LL |         break true;
    |         ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:42:13
+  --> tests/ui/implicit_return.rs:47:13
    |
 LL |             break true;
    |             ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:50:13
+  --> tests/ui/implicit_return.rs:55:13
    |
 LL |             break true;
    |             ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:68:18
+  --> tests/ui/implicit_return.rs:73:18
    |
 LL |     let _ = || { true };
    |                  ^^^^ help: add `return` as shown: `return true`
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:69:16
+  --> tests/ui/implicit_return.rs:74:16
    |
 LL |     let _ = || true;
    |                ^^^^ help: add `return` as shown: `return true`
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:77:5
+  --> tests/ui/implicit_return.rs:82:5
    |
 LL |     format!("test {}", "test")
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")`
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:86:5
+  --> tests/ui/implicit_return.rs:91:5
    |
 LL |     m!(true, false)
    |     ^^^^^^^^^^^^^^^ help: add `return` as shown: `return m!(true, false)`
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:92:13
+  --> tests/ui/implicit_return.rs:97:13
    |
 LL |             break true;
    |             ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:97:17
+  --> tests/ui/implicit_return.rs:102:17
    |
 LL |                 break 'outer false;
    |                 ^^^^^^^^^^^^^^^^^^ help: change `break` to `return` as shown: `return false`
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:112:5
+  --> tests/ui/implicit_return.rs:117:5
    |
 LL | /     loop {
 LL | |         m!(true);
@@ -101,7 +101,7 @@ LL +     }
    |
 
 error: missing `return` statement
-  --> tests/ui/implicit_return.rs:126:5
+  --> tests/ui/implicit_return.rs:131:5
    |
 LL |     true
    |     ^^^^ help: add `return` as shown: `return true`