Auto merge of #5949 - rail-rain:fix_fp_borrow_interior_mutable_const, r=oli-obk

Fix fp in `borrow_interior_mutable_const`

fixes #5796

changelog: fix false positive in `borrow_interior_mutable_const` when referencing a field behind a pointer.
This commit is contained in:
bors 2020-08-26 11:06:37 +00:00
commit 9ef44799bf
3 changed files with 64 additions and 18 deletions

View file

@ -211,8 +211,21 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
needs_check_adjustment = false;
},
ExprKind::Field(..) => {
dereferenced_expr = parent_expr;
needs_check_adjustment = true;
// Check whether implicit dereferences happened;
// if so, no need to go further up
// because of the same reason as the `ExprKind::Unary` case.
if cx
.typeck_results()
.expr_adjustments(dereferenced_expr)
.iter()
.any(|adj| matches!(adj.kind, Adjust::Deref(_)))
{
break;
}
dereferenced_expr = parent_expr;
},
ExprKind::Index(e, _) if ptr::eq(&**e, cur_expr) => {
// `e[i]` => desugared to `*Index::index(&e, i)`,