From 81b35d197b7e14149cf6cfc02ed4087f273d6915 Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Thu, 11 May 2017 16:32:06 +0200 Subject: [PATCH] Fixes #1735 --- clippy_lints/src/returns.rs | 2 ++ tests/ui/let_return.rs | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 16f582c77c9..96b1e4e9185 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -111,6 +111,8 @@ impl ReturnPass { let ast::StmtKind::Expr(ref retexpr) = retexpr.node, let Some(stmt) = it.next_back(), let ast::StmtKind::Local(ref local) = stmt.node, + // don't lint in the presence of type inference + local.ty.is_none(), !local.attrs.iter().any(attr_is_cfg), let Some(ref initexpr) = local.init, let ast::PatKind::Ident(_, Spanned { node: id, .. }, _) = local.pat.node, diff --git a/tests/ui/let_return.rs b/tests/ui/let_return.rs index de0bb9b3cc1..71cdf88c887 100644 --- a/tests/ui/let_return.rs +++ b/tests/ui/let_return.rs @@ -36,5 +36,11 @@ fn test_nowarn_3() -> (i32, i32) { (x, y) } +fn test_nowarn_4() -> i32 { + // this should technically warn, but not b/c of let_and_return, but b/c of useless type + let x: i32 = 5; + x +} + fn main() { }