Skip to content

Commit 62ff639

Browse files
committed
Auto merge of #5008 - JohnTitor:let-on-macros, r=flip1995
Do not trigger `let_and_return` lint on macros Fixes #4997 changelog: Fix false positive in `let_and_return`
2 parents e8642c7 + 2213989 commit 62ff639

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

clippy_lints/src/returns.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::BytePos;
88
use syntax::ast;
99
use syntax::visit::FnKind;
1010

11-
use crate::utils::{match_path_ast, snippet_opt, span_lint_and_then};
11+
use crate::utils::{in_macro, match_path_ast, snippet_opt, span_lint_and_then};
1212

1313
declare_clippy_lint! {
1414
/// **What it does:** Checks for return statements at the end of a block.
@@ -205,6 +205,7 @@ impl Return {
205205
if !in_external_macro(cx.sess(), initexpr.span);
206206
if !in_external_macro(cx.sess(), retexpr.span);
207207
if !in_external_macro(cx.sess(), local.span);
208+
if !in_macro(local.span);
208209
then {
209210
span_lint_and_then(
210211
cx,

tests/ui/let_return.rs

+22
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,26 @@ fn test_nowarn_5(x: i16) -> u16 {
4545
x
4646
}
4747

48+
// False positive example
49+
trait Decode {
50+
fn decode<D: std::io::Read>(d: D) -> Result<Self, ()>
51+
where
52+
Self: Sized;
53+
}
54+
55+
macro_rules! tuple_encode {
56+
($($x:ident),*) => (
57+
impl<$($x: Decode),*> Decode for ($($x),*) {
58+
#[inline]
59+
#[allow(non_snake_case)]
60+
fn decode<D: std::io::Read>(mut d: D) -> Result<Self, ()> {
61+
// Shouldn't trigger lint
62+
Ok(($({let $x = Decode::decode(&mut d)?; $x }),*))
63+
}
64+
}
65+
);
66+
}
67+
68+
tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7);
69+
4870
fn main() {}

0 commit comments

Comments
 (0)