mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-24 14:34:23 +00:00
Don't lint implicit_return on proc macros
This commit is contained in:
parent
29cc5c691c
commit
b147b6d03d
@ -1,7 +1,7 @@
|
|||||||
use clippy_utils::diagnostics::span_lint_hir_and_then;
|
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::source::{snippet_with_applicability, snippet_with_context, walk_span_to_context};
|
||||||
use clippy_utils::visitors::for_each_expr_without_closures;
|
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 core::ops::ControlFlow;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::intravisit::FnKind;
|
use rustc_hir::intravisit::FnKind;
|
||||||
@ -245,6 +245,10 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitReturn {
|
|||||||
} else {
|
} else {
|
||||||
body.value
|
body.value
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if is_from_proc_macro(cx, expr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
lint_implicit_returns(cx, expr, expr.span.ctxt(), None);
|
lint_implicit_returns(cx, expr, expr.span.ctxt(), None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
|
//@aux-build: proc_macros.rs
|
||||||
|
|
||||||
#![feature(lint_reasons)]
|
#![feature(lint_reasons)]
|
||||||
#![warn(clippy::implicit_return)]
|
#![warn(clippy::implicit_return)]
|
||||||
#![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)]
|
#![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 {
|
fn test_end_of_fn() -> bool {
|
||||||
if true {
|
if true {
|
||||||
// no error!
|
// no error!
|
||||||
@ -137,3 +142,11 @@ fn check_expect() -> bool {
|
|||||||
#[expect(clippy::implicit_return)]
|
#[expect(clippy::implicit_return)]
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
with_span!(
|
||||||
|
span
|
||||||
|
|
||||||
|
fn dont_lint_proc_macro(x: usize) -> usize{
|
||||||
|
x
|
||||||
|
}
|
||||||
|
);
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
|
//@aux-build: proc_macros.rs
|
||||||
|
|
||||||
#![feature(lint_reasons)]
|
#![feature(lint_reasons)]
|
||||||
#![warn(clippy::implicit_return)]
|
#![warn(clippy::implicit_return)]
|
||||||
#![allow(clippy::needless_return, clippy::needless_bool, unused, clippy::never_loop)]
|
#![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 {
|
fn test_end_of_fn() -> bool {
|
||||||
if true {
|
if true {
|
||||||
// no error!
|
// no error!
|
||||||
@ -137,3 +142,11 @@ fn check_expect() -> bool {
|
|||||||
#[expect(clippy::implicit_return)]
|
#[expect(clippy::implicit_return)]
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
with_span!(
|
||||||
|
span
|
||||||
|
|
||||||
|
fn dont_lint_proc_macro(x: usize) -> usize{
|
||||||
|
x
|
||||||
|
}
|
||||||
|
);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:11:5
|
--> tests/ui/implicit_return.rs:16:5
|
||||||
|
|
|
|
||||||
LL | true
|
LL | true
|
||||||
| ^^^^ help: add `return` as shown: `return true`
|
| ^^^^ help: add `return` as shown: `return true`
|
||||||
@ -8,85 +8,85 @@ LL | true
|
|||||||
= help: to override `-D warnings` add `#[allow(clippy::implicit_return)]`
|
= help: to override `-D warnings` add `#[allow(clippy::implicit_return)]`
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:15:15
|
--> tests/ui/implicit_return.rs:20:15
|
||||||
|
|
|
|
||||||
LL | if true { true } else { false }
|
LL | if true { true } else { false }
|
||||||
| ^^^^ help: add `return` as shown: `return true`
|
| ^^^^ help: add `return` as shown: `return true`
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:15:29
|
--> tests/ui/implicit_return.rs:20:29
|
||||||
|
|
|
|
||||||
LL | if true { true } else { false }
|
LL | if true { true } else { false }
|
||||||
| ^^^^^ help: add `return` as shown: `return false`
|
| ^^^^^ help: add `return` as shown: `return false`
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:21:17
|
--> tests/ui/implicit_return.rs:26:17
|
||||||
|
|
|
|
||||||
LL | true => false,
|
LL | true => false,
|
||||||
| ^^^^^ help: add `return` as shown: `return false`
|
| ^^^^^ help: add `return` as shown: `return false`
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:22:20
|
--> tests/ui/implicit_return.rs:27:20
|
||||||
|
|
|
|
||||||
LL | false => { true },
|
LL | false => { true },
|
||||||
| ^^^^ help: add `return` as shown: `return true`
|
| ^^^^ help: add `return` as shown: `return true`
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:35:9
|
--> tests/ui/implicit_return.rs:40:9
|
||||||
|
|
|
|
||||||
LL | break true;
|
LL | break true;
|
||||||
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:42:13
|
--> tests/ui/implicit_return.rs:47:13
|
||||||
|
|
|
|
||||||
LL | break true;
|
LL | break true;
|
||||||
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:50:13
|
--> tests/ui/implicit_return.rs:55:13
|
||||||
|
|
|
|
||||||
LL | break true;
|
LL | break true;
|
||||||
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:68:18
|
--> tests/ui/implicit_return.rs:73:18
|
||||||
|
|
|
|
||||||
LL | let _ = || { true };
|
LL | let _ = || { true };
|
||||||
| ^^^^ help: add `return` as shown: `return true`
|
| ^^^^ help: add `return` as shown: `return true`
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:69:16
|
--> tests/ui/implicit_return.rs:74:16
|
||||||
|
|
|
|
||||||
LL | let _ = || true;
|
LL | let _ = || true;
|
||||||
| ^^^^ help: add `return` as shown: `return true`
|
| ^^^^ help: add `return` as shown: `return true`
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:77:5
|
--> tests/ui/implicit_return.rs:82:5
|
||||||
|
|
|
|
||||||
LL | format!("test {}", "test")
|
LL | format!("test {}", "test")
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add `return` as shown: `return format!("test {}", "test")`
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:86:5
|
--> tests/ui/implicit_return.rs:91:5
|
||||||
|
|
|
|
||||||
LL | m!(true, false)
|
LL | m!(true, false)
|
||||||
| ^^^^^^^^^^^^^^^ help: add `return` as shown: `return m!(true, false)`
|
| ^^^^^^^^^^^^^^^ help: add `return` as shown: `return m!(true, false)`
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:92:13
|
--> tests/ui/implicit_return.rs:97:13
|
||||||
|
|
|
|
||||||
LL | break true;
|
LL | break true;
|
||||||
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
| ^^^^^^^^^^ help: change `break` to `return` as shown: `return true`
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:97:17
|
--> tests/ui/implicit_return.rs:102:17
|
||||||
|
|
|
|
||||||
LL | break 'outer false;
|
LL | break 'outer false;
|
||||||
| ^^^^^^^^^^^^^^^^^^ help: change `break` to `return` as shown: `return false`
|
| ^^^^^^^^^^^^^^^^^^ help: change `break` to `return` as shown: `return false`
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:112:5
|
--> tests/ui/implicit_return.rs:117:5
|
||||||
|
|
|
|
||||||
LL | / loop {
|
LL | / loop {
|
||||||
LL | | m!(true);
|
LL | | m!(true);
|
||||||
@ -101,7 +101,7 @@ LL + }
|
|||||||
|
|
|
|
||||||
|
|
||||||
error: missing `return` statement
|
error: missing `return` statement
|
||||||
--> tests/ui/implicit_return.rs:126:5
|
--> tests/ui/implicit_return.rs:131:5
|
||||||
|
|
|
|
||||||
LL | true
|
LL | true
|
||||||
| ^^^^ help: add `return` as shown: `return true`
|
| ^^^^ help: add `return` as shown: `return true`
|
||||||
|
Loading…
Reference in New Issue
Block a user