diff options
| author | bors <bors@rust-lang.org> | 2022-09-07 19:43:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-09-07 19:43:00 +0000 |
| commit | da29f8928d929309cec7ae06828659a634567d9f (patch) | |
| tree | 62fde8ec662d7ecf91f6d3ef3eefed25db0b85a5 | |
| parent | 7babd1b099ae89f3374f61beec4bcc3c2e6060f7 (diff) | |
| parent | 15859323ea424b4fb9556d9d45c8b5d374e57f9e (diff) | |
| download | rust-da29f8928d929309cec7ae06828659a634567d9f.tar.gz rust-da29f8928d929309cec7ae06828659a634567d9f.zip | |
Auto merge of #9441 - Jarcho:hang_9433, r=Alexendoo
Fix hang in `vec_init_then_push` fixes #9433 changelog: Fix infinite loop in `vec_init_then_push`
| -rw-r--r-- | clippy_lints/src/vec_init_then_push.rs | 2 | ||||
| -rw-r--r-- | tests/ui/vec_init_then_push.rs | 6 | ||||
| -rw-r--r-- | tests/ui/vec_init_then_push.stderr | 9 |
3 files changed, 15 insertions, 2 deletions
diff --git a/clippy_lints/src/vec_init_then_push.rs b/clippy_lints/src/vec_init_then_push.rs index 35db45e2b0c..d77a21d668e 100644 --- a/clippy_lints/src/vec_init_then_push.rs +++ b/clippy_lints/src/vec_init_then_push.rs @@ -86,7 +86,7 @@ impl VecPushSearcher { }, ExprKind::Unary(UnOp::Deref, _) | ExprKind::Index(..) if !needs_mut => { let mut last_place = parent; - while let Some(parent) = get_parent_expr(cx, parent) { + while let Some(parent) = get_parent_expr(cx, last_place) { if matches!(parent.kind, ExprKind::Unary(UnOp::Deref, _) | ExprKind::Field(..)) || matches!(parent.kind, ExprKind::Index(e, _) if e.hir_id == last_place.hir_id) { diff --git a/tests/ui/vec_init_then_push.rs b/tests/ui/vec_init_then_push.rs index 531745424a7..8dd098a5b54 100644 --- a/tests/ui/vec_init_then_push.rs +++ b/tests/ui/vec_init_then_push.rs @@ -104,3 +104,9 @@ fn _cond_push_with_large_start(x: bool) -> Vec<u32> { v2 } + +fn f() { + let mut v = Vec::new(); + v.push((0i32, 0i32)); + let y = v[0].0.abs(); +} diff --git a/tests/ui/vec_init_then_push.stderr b/tests/ui/vec_init_then_push.stderr index 50b029fc337..a9da1c52019 100644 --- a/tests/ui/vec_init_then_push.stderr +++ b/tests/ui/vec_init_then_push.stderr @@ -62,5 +62,12 @@ LL | | v2.push(1); LL | | v2.push(0); | |_______________^ help: consider using the `vec![]` macro: `let mut v2 = vec![..];` -error: aborting due to 7 previous errors +error: calls to `push` immediately after creation + --> $DIR/vec_init_then_push.rs:109:5 + | +LL | / let mut v = Vec::new(); +LL | | v.push((0i32, 0i32)); + | |_________________________^ help: consider using the `vec![]` macro: `let v = vec![..];` + +error: aborting due to 8 previous errors |
