mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-07 12:33:14 +00:00
Fix while_let_on_iterator
When the iterator is one field within a local correctly check for usages of the field
This commit is contained in:
parent
fe75faa6ee
commit
205aa88921
@ -146,7 +146,7 @@ fn is_expr_same_child_or_parent_field(cx: &LateContext<'_>, expr: &Expr<'_>, fie
|
|||||||
match expr.kind {
|
match expr.kind {
|
||||||
ExprKind::Field(base, name) => {
|
ExprKind::Field(base, name) => {
|
||||||
if let Some((head_field, tail_fields)) = fields.split_first() {
|
if let Some((head_field, tail_fields)) = fields.split_first() {
|
||||||
if name.name == *head_field && is_expr_same_field(cx, base, fields, path_res) {
|
if name.name == *head_field && is_expr_same_field(cx, base, tail_fields, path_res) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Check if the expression is a parent field
|
// Check if the expression is a parent field
|
||||||
|
@ -357,6 +357,15 @@ fn issue7510() {
|
|||||||
println!("{}", it.0.next().unwrap());
|
println!("{}", it.0.next().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn exact_match_with_single_field() {
|
||||||
|
struct S<T>(T);
|
||||||
|
let mut s = S(0..10);
|
||||||
|
// Don't lint. `s.0` is used inside the loop.
|
||||||
|
while let Some(_) = s.0.next() {
|
||||||
|
let _ = &mut s.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut it = 0..20;
|
let mut it = 0..20;
|
||||||
for _ in it {
|
for _ in it {
|
||||||
|
@ -357,6 +357,15 @@ fn issue7510() {
|
|||||||
println!("{}", it.0.next().unwrap());
|
println!("{}", it.0.next().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn exact_match_with_single_field() {
|
||||||
|
struct S<T>(T);
|
||||||
|
let mut s = S(0..10);
|
||||||
|
// Don't lint. `s.0` is used inside the loop.
|
||||||
|
while let Some(_) = s.0.next() {
|
||||||
|
let _ = &mut s.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut it = 0..20;
|
let mut it = 0..20;
|
||||||
while let Some(..) = it.next() {
|
while let Some(..) = it.next() {
|
||||||
|
@ -123,7 +123,7 @@ LL | while let Some(x) = it.0.next() {
|
|||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in &mut *it.0`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for x in &mut *it.0`
|
||||||
|
|
||||||
error: this loop could be written as a `for` loop
|
error: this loop could be written as a `for` loop
|
||||||
--> $DIR/while_let_on_iterator.rs:362:5
|
--> $DIR/while_let_on_iterator.rs:371:5
|
||||||
|
|
|
|
||||||
LL | while let Some(..) = it.next() {
|
LL | while let Some(..) = it.next() {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in it`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `for _ in it`
|
||||||
|
Loading…
Reference in New Issue
Block a user