Skip to content

Commit 1585932

Browse files
committed
Fix hang in vec_init_then_push
1 parent 7babd1b commit 1585932

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

clippy_lints/src/vec_init_then_push.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl VecPushSearcher {
8686
},
8787
ExprKind::Unary(UnOp::Deref, _) | ExprKind::Index(..) if !needs_mut => {
8888
let mut last_place = parent;
89-
while let Some(parent) = get_parent_expr(cx, parent) {
89+
while let Some(parent) = get_parent_expr(cx, last_place) {
9090
if matches!(parent.kind, ExprKind::Unary(UnOp::Deref, _) | ExprKind::Field(..))
9191
|| matches!(parent.kind, ExprKind::Index(e, _) if e.hir_id == last_place.hir_id)
9292
{

tests/ui/vec_init_then_push.rs

+6
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,9 @@ fn _cond_push_with_large_start(x: bool) -> Vec<u32> {
104104

105105
v2
106106
}
107+
108+
fn f() {
109+
let mut v = Vec::new();
110+
v.push((0i32, 0i32));
111+
let y = v[0].0.abs();
112+
}

tests/ui/vec_init_then_push.stderr

+8-1
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,12 @@ LL | | v2.push(1);
6262
LL | | v2.push(0);
6363
| |_______________^ help: consider using the `vec![]` macro: `let mut v2 = vec![..];`
6464

65-
error: aborting due to 7 previous errors
65+
error: calls to `push` immediately after creation
66+
--> $DIR/vec_init_then_push.rs:109:5
67+
|
68+
LL | / let mut v = Vec::new();
69+
LL | | v.push((0i32, 0i32));
70+
| |_________________________^ help: consider using the `vec![]` macro: `let v = vec![..];`
71+
72+
error: aborting due to 8 previous errors
6673

0 commit comments

Comments
 (0)