Skip to content

Commit 96b31a5

Browse files
committed
Fix FP when coercion kicks in
1 parent aa7ffa5 commit 96b31a5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clippy_lints/src/loops.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,8 @@ fn detect_same_item_push<'tcx>(
11401140
walk_expr(&mut same_item_push_visitor, body);
11411141
if same_item_push_visitor.should_lint {
11421142
if let Some((vec, pushed_item)) = same_item_push_visitor.vec_push {
1143-
let ty = cx.typeck_results().expr_ty(pushed_item);
1143+
let vec_ty = cx.typeck_results().expr_ty(vec);
1144+
let ty = vec_ty.walk().nth(1).unwrap().expect_ty();
11441145
if cx
11451146
.tcx
11461147
.lang_items()

tests/ui/same_item_push.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,15 @@ fn main() {
100100
for _ in 0..10 {
101101
vec14.push(std::fs::File::open("foobar").unwrap());
102102
}
103+
// Fix #5979
104+
#[derive(Clone)]
105+
struct S {}
106+
107+
trait T {}
108+
impl T for S {}
109+
110+
let mut vec15: Vec<Box<dyn T>> = Vec::new();
111+
for _ in 0..10 {
112+
vec15.push(Box::new(S {}));
113+
}
103114
}

0 commit comments

Comments
 (0)