Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}