Skip to content

Commit

Permalink
Auto merge of rust-lang#5008 - JohnTitor:let-on-macros, r=flip1995
Browse files Browse the repository at this point in the history
Do not trigger `let_and_return` lint on macros

Fixes rust-lang#4997

changelog: Fix false positive in `let_and_return`
  • Loading branch information
bors committed Jan 6, 2020
2 parents e8642c7 + 2213989 commit 62ff639
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clippy_lints/src/returns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions tests/ui/let_return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,26 @@ fn test_nowarn_5(x: i16) -> u16 {
x
}

// False positive example
trait Decode {
fn decode<D: std::io::Read>(d: D) -> Result<Self, ()>
where
Self: Sized;
}

macro_rules! tuple_encode {
($($x:ident),*) => (
impl<$($x: Decode),*> Decode for ($($x),*) {
#[inline]
#[allow(non_snake_case)]
fn decode<D: std::io::Read>(mut d: D) -> Result<Self, ()> {
// Shouldn't trigger lint
Ok(($({let $x = Decode::decode(&mut d)?; $x }),*))
}
}
);
}

tuple_encode!(T0, T1, T2, T3, T4, T5, T6, T7);

fn main() {}

0 comments on commit 62ff639

Please sign in to comment.