mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-02-17 06:28:42 +00:00
Fix get_enclosing_block
This commit is contained in:
parent
d5bac82837
commit
3a4ea45821
3 changed files with 41 additions and 0 deletions
|
@ -518,6 +518,9 @@ pub fn get_enclosing_block<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, node: NodeI
|
|||
Node::NodeItem(&Item {
|
||||
node: ItemFn(_, _, _, _, _, eid),
|
||||
..
|
||||
}) | Node::NodeImplItem(&ImplItem {
|
||||
node: ImplItemKind::Method(_, eid),
|
||||
..
|
||||
}) => match cx.tcx.hir.body(eid).value.node {
|
||||
ExprBlock(ref block) => Some(block),
|
||||
_ => None,
|
||||
|
|
24
tests/ui/issue_2356.rs
Normal file
24
tests/ui/issue_2356.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
#![deny(while_let_on_iterator)]
|
||||
|
||||
use std::iter::Iterator;
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl Foo {
|
||||
fn foo1<I: Iterator<Item = usize>>(mut it: I) {
|
||||
while let Some(_) = it.next() {
|
||||
println!("{:?}", it.size_hint());
|
||||
}
|
||||
}
|
||||
|
||||
fn foo2<I: Iterator<Item = usize>>(mut it: I) {
|
||||
while let Some(e) = it.next() {
|
||||
println!("{:?}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
Foo::foo1(vec![].into_iter());
|
||||
Foo::foo2(vec![].into_iter());
|
||||
}
|
14
tests/ui/issue_2356.stderr
Normal file
14
tests/ui/issue_2356.stderr
Normal file
|
@ -0,0 +1,14 @@
|
|||
error: this loop could be written as a `for` loop
|
||||
--> $DIR/issue_2356.rs:15:29
|
||||
|
|
||||
15 | while let Some(e) = it.next() {
|
||||
| ^^^^^^^^^ help: try: `for e in it { .. }`
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/issue_2356.rs:1:9
|
||||
|
|
||||
1 | #![deny(while_let_on_iterator)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Add table
Reference in a new issue