From 994e9d9e3d1eeb14e3bad4daed1c91b1765ba9dc Mon Sep 17 00:00:00 2001 From: Eduardo Broto Date: Wed, 3 Jun 2020 09:33:18 +0200 Subject: [PATCH] Add more tests and ignore AnonConst --- clippy_lints/src/let_and_return.rs | 8 ++++---- tests/ui/let_return.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/let_and_return.rs b/clippy_lints/src/let_and_return.rs index 3fc918aa1f7d..bbe64015317a 100644 --- a/clippy_lints/src/let_and_return.rs +++ b/clippy_lints/src/let_and_return.rs @@ -1,8 +1,8 @@ use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::{ - AnonConst, Block, Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind, Node, PatKind, StmtKind, TraitFn, - TraitItem, TraitItemKind, + Block, Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind, Node, PatKind, StmtKind, TraitFn, TraitItem, + TraitItemKind, }; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; @@ -109,8 +109,8 @@ fn last_statement_borrows_locals(cx: &LateContext<'_, '_>, block: &'_ Block<'_>) | Node::TraitItem(TraitItem { kind: TraitItemKind::Fn(.., TraitFn::Provided(_)) | TraitItemKind::Const(.., Some(_)), .. - }) - | Node::AnonConst(AnonConst { .. }) => { + }) => { + // NOTE: AnonConst is omitted because the problem can't be reproduced without implementing Drop. return Some(hir_id); }, _ => {}, diff --git a/tests/ui/let_return.rs b/tests/ui/let_return.rs index 3c30a45689a8..11adff4301e5 100644 --- a/tests/ui/let_return.rs +++ b/tests/ui/let_return.rs @@ -123,6 +123,33 @@ mod issue_3792 { let line = stdin.lock().lines().next().unwrap().unwrap(); line } + + // Test that it works with other fn-likes; none of these should be linted + + struct S {} + impl S { + fn test() -> String { + let stdin = io::stdin(); + let line = stdin.lock().lines().next().unwrap().unwrap(); + line + } + } + + trait T { + fn test() -> String { + let stdin = io::stdin(); + let line = stdin.lock().lines().next().unwrap().unwrap(); + line + } + } + + fn in_closure() { + let _ = || { + let stdin = io::stdin(); + let line = stdin.lock().lines().next().unwrap().unwrap(); + line + }; + } } fn main() {}