Skip to content

Commit 994e9d9

Browse files
committed
Add more tests and ignore AnonConst
1 parent 50f61ba commit 994e9d9

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

clippy_lints/src/let_and_return.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use if_chain::if_chain;
22
use rustc_errors::Applicability;
33
use rustc_hir::{
4-
AnonConst, Block, Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind, Node, PatKind, StmtKind, TraitFn,
5-
TraitItem, TraitItemKind,
4+
Block, Expr, ExprKind, HirId, ImplItem, ImplItemKind, Item, ItemKind, Node, PatKind, StmtKind, TraitFn, TraitItem,
5+
TraitItemKind,
66
};
77
use rustc_lint::{LateContext, LateLintPass, LintContext};
88
use rustc_middle::lint::in_external_macro;
@@ -109,8 +109,8 @@ fn last_statement_borrows_locals(cx: &LateContext<'_, '_>, block: &'_ Block<'_>)
109109
| Node::TraitItem(TraitItem {
110110
kind: TraitItemKind::Fn(.., TraitFn::Provided(_)) | TraitItemKind::Const(.., Some(_)),
111111
..
112-
})
113-
| Node::AnonConst(AnonConst { .. }) => {
112+
}) => {
113+
// NOTE: AnonConst is omitted because the problem can't be reproduced without implementing Drop.
114114
return Some(hir_id);
115115
},
116116
_ => {},

tests/ui/let_return.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,33 @@ mod issue_3792 {
123123
let line = stdin.lock().lines().next().unwrap().unwrap();
124124
line
125125
}
126+
127+
// Test that it works with other fn-likes; none of these should be linted
128+
129+
struct S {}
130+
impl S {
131+
fn test() -> String {
132+
let stdin = io::stdin();
133+
let line = stdin.lock().lines().next().unwrap().unwrap();
134+
line
135+
}
136+
}
137+
138+
trait T {
139+
fn test() -> String {
140+
let stdin = io::stdin();
141+
let line = stdin.lock().lines().next().unwrap().unwrap();
142+
line
143+
}
144+
}
145+
146+
fn in_closure() {
147+
let _ = || {
148+
let stdin = io::stdin();
149+
let line = stdin.lock().lines().next().unwrap().unwrap();
150+
line
151+
};
152+
}
126153
}
127154

128155
fn main() {}

0 commit comments

Comments
 (0)