Fix FP when coercion kicks in

This commit is contained in:
Takayuki Nakata 2020-09-06 00:02:35 +09:00
parent aa7ffa5257
commit 96b31a5b36
2 changed files with 13 additions and 1 deletions

View File

@ -1140,7 +1140,8 @@ fn detect_same_item_push<'tcx>(
walk_expr(&mut same_item_push_visitor, body);
if same_item_push_visitor.should_lint {
if let Some((vec, pushed_item)) = same_item_push_visitor.vec_push {
let ty = cx.typeck_results().expr_ty(pushed_item);
let vec_ty = cx.typeck_results().expr_ty(vec);
let ty = vec_ty.walk().nth(1).unwrap().expect_ty();
if cx
.tcx
.lang_items()

View File

@ -100,4 +100,15 @@ fn main() {
for _ in 0..10 {
vec14.push(std::fs::File::open("foobar").unwrap());
}
// Fix #5979
#[derive(Clone)]
struct S {}
trait T {}
impl T for S {}
let mut vec15: Vec<Box<dyn T>> = Vec::new();
for _ in 0..10 {
vec15.push(Box::new(S {}));
}
}