Skip to content

Commit

Permalink
Auto merge of #11173 - Alexendoo:needless-return-fn-macro, r=Manishearth
Browse files Browse the repository at this point in the history
Don't lint `needless_return` in fns across a macro boundary

Fixes #11167

changelog: none
  • Loading branch information
bors committed Jul 17, 2023
2 parents 410456d + d24f0d0 commit 3e0170b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clippy_lints/src/returns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ impl<'tcx> LateLintPass<'tcx> for Return {
sp: Span,
_: LocalDefId,
) {
if sp.from_expansion() {
return;
}

match kind {
FnKind::Closure => {
// when returning without value in closure, replace this `return`
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/let_and_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,14 @@ mod issue_5729 {
}
}

// https://github.com/rust-lang/rust-clippy/issues/11167
macro_rules! fn_in_macro {
($b:block) => {
fn f() -> usize $b
}
}
fn_in_macro!({
return 1;
});

fn main() {}

0 comments on commit 3e0170b

Please sign in to comment.