Skip to content

Commit

Permalink
add proc macro check to needless_return
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Sep 26, 2024
1 parent 8ab744e commit c8725f7
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 55 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/returns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ fn check_final_expr<'tcx>(
}
}

if ret_span.from_expansion() {
if ret_span.from_expansion() || is_from_proc_macro(cx, expr) {
return;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/ui/needless_return.fixed
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@aux-build:proc_macros.rs
#![feature(yeet_expr)]
#![allow(unused)]
#![allow(
Expand All @@ -9,6 +10,9 @@
)]
#![warn(clippy::needless_return)]

extern crate proc_macros;
use proc_macros::with_span;

use std::cell::RefCell;

macro_rules! the_answer {
Expand Down Expand Up @@ -359,4 +363,8 @@ fn issue12907() -> String {
"".split("").next().unwrap().to_string()
}

fn issue13458() {
with_span!(span return);
}

fn main() {}
8 changes: 8 additions & 0 deletions tests/ui/needless_return.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@aux-build:proc_macros.rs
#![feature(yeet_expr)]
#![allow(unused)]
#![allow(
Expand All @@ -9,6 +10,9 @@
)]
#![warn(clippy::needless_return)]

extern crate proc_macros;
use proc_macros::with_span;

use std::cell::RefCell;

macro_rules! the_answer {
Expand Down Expand Up @@ -369,4 +373,8 @@ fn issue12907() -> String {
return "".split("").next().unwrap().to_string();
}

fn issue13458() {
with_span!(span return);
}

fn main() {}
Loading

0 comments on commit c8725f7

Please sign in to comment.