Skip to content

Commit 3e0170b

Browse files
committed
Auto merge of rust-lang#11173 - Alexendoo:needless-return-fn-macro, r=Manishearth
Don't lint `needless_return` in fns across a macro boundary Fixes rust-lang#11167 changelog: none
2 parents 410456d + d24f0d0 commit 3e0170b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

clippy_lints/src/returns.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ impl<'tcx> LateLintPass<'tcx> for Return {
174174
sp: Span,
175175
_: LocalDefId,
176176
) {
177+
if sp.from_expansion() {
178+
return;
179+
}
180+
177181
match kind {
178182
FnKind::Closure => {
179183
// when returning without value in closure, replace this `return`

tests/ui/let_and_return.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,14 @@ mod issue_5729 {
169169
}
170170
}
171171

172+
// https://github.com/rust-lang/rust-clippy/issues/11167
173+
macro_rules! fn_in_macro {
174+
($b:block) => {
175+
fn f() -> usize $b
176+
}
177+
}
178+
fn_in_macro!({
179+
return 1;
180+
});
181+
172182
fn main() {}

0 commit comments

Comments
 (0)