Rollup merge of #72280 - nbdd0121:typeck, r=nikomatsakis

Fix up autoderef when reborrowing

Currently `(f)()` and `f.call_mut()` behaves differently if expression `f` contains autoderef in it. This causes a weird error in #72225.

When `f` is type checked, `Deref` is used (this is expected as we can't yet determine if we should use `Fn` or `FnMut`). When subsequently we determine the actual trait to be used, when using the `f.call_mut()` syntax the `Deref` is patched to `DerefMut`, while for the `(f)()` syntax case it is not.

This PR replicates the fixup for the first case.

Fixes #72225
Fixes #68590
This commit is contained in:
Ralf Jung 2020-06-19 14:29:16 +02:00 committed by GitHub
commit 70622db43d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 467 additions and 392 deletions

View file

@ -0,0 +1,25 @@
// check-pass
// rust-lang/rust#68590: confusing diagnostics when reborrowing through DerefMut.
use std::cell::RefCell;
struct A;
struct S<'a> {
a: &'a mut A,
}
fn take_a(_: &mut A) {}
fn test<'a>(s: &RefCell<S<'a>>) {
let mut guard = s.borrow_mut();
take_a(guard.a);
let _s2 = S { a: guard.a };
}
fn main() {
let a = &mut A;
let s = RefCell::new(S { a });
test(&s);
}

View file

@ -0,0 +1,21 @@
// check-pass
// rust-lang/rust#72225: confusing diagnostics when calling FnMut through DerefMut.
use std::cell::RefCell;
struct S {
f: Box<dyn FnMut()>
}
fn test(s: &RefCell<S>) {
let mut guard = s.borrow_mut();
(guard.f)();
}
fn main() {
let s = RefCell::new(S {
f: Box::new(|| ())
});
test(&s);
}