From 2213989a0150b85c180466e31f67846e64590dc0 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 7 Jan 2020 05:26:20 +0900 Subject: [PATCH] Do not trigger `let_and_return` lint on macros --- clippy_lints/src/returns.rs | 3 ++- tests/ui/let_return.rs | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 96e9fb2c409b..6c2d2103ef4b 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -8,7 +8,7 @@ use rustc_span::BytePos; use syntax::ast; use syntax::visit::FnKind; -use crate::utils::{match_path_ast, snippet_opt, span_lint_and_then}; +use crate::utils::{in_macro, match_path_ast, snippet_opt, span_lint_and_then}; declare_clippy_lint! { /// **What it does:** Checks for return statements at the end of a block. @@ -205,6 +205,7 @@ impl Return { if !in_external_macro(cx.sess(), initexpr.span); if !in_external_macro(cx.sess(), retexpr.span); if !in_external_macro(cx.sess(), local.span); + if !in_macro(local.span); then { span_lint_and_then( cx, diff --git a/tests/ui/let_return.rs b/tests/ui/let_return.rs index 40052f86dd53..23645d48fe79 100644 --- a/tests/ui/let_return.rs +++ b/tests/ui/let_return.rs @@ -45,4 +45,26 @@ fn test_nowarn_5(x: i16) -> u16 { x } +// False positive example +trait Decode { + fn decode(d: D) -> Result + where + Self: Sized; +} + +macro_rules! tuple_encode { + ($($x:ident),*) => ( + impl<$($x: Decode),*> Decode for ($($x),*) { + #[inline] + #[allow(non_snake_case)] + fn decode(mut d: D) -> Result { + // Shouldn't trigger lint + Ok(($({let $x = Decode::decode(&mut d)?; $x }),*)) + } + } + ); +} + +tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7); + fn main() {}