From 4710f85882c08594a900b09c13fbe51ca207daec Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Mon, 15 Jun 2020 00:59:03 +0100 Subject: [PATCH] Add ui tests for issue 68590 and 72225 --- .../issue-68590-reborrow-through-derefmut.rs | 25 +++++++++++++++++++ ...issue-72225-call-fnmut-through-derefmut.rs | 21 ++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/test/ui/typeck/issue-68590-reborrow-through-derefmut.rs create mode 100644 src/test/ui/typeck/issue-72225-call-fnmut-through-derefmut.rs diff --git a/src/test/ui/typeck/issue-68590-reborrow-through-derefmut.rs b/src/test/ui/typeck/issue-68590-reborrow-through-derefmut.rs new file mode 100644 index 00000000000..e4436260e70 --- /dev/null +++ b/src/test/ui/typeck/issue-68590-reborrow-through-derefmut.rs @@ -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>) { + 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); +} diff --git a/src/test/ui/typeck/issue-72225-call-fnmut-through-derefmut.rs b/src/test/ui/typeck/issue-72225-call-fnmut-through-derefmut.rs new file mode 100644 index 00000000000..3ea05389f04 --- /dev/null +++ b/src/test/ui/typeck/issue-72225-call-fnmut-through-derefmut.rs @@ -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 +} + +fn test(s: &RefCell) { + let mut guard = s.borrow_mut(); + (guard.f)(); +} + +fn main() { + let s = RefCell::new(S { + f: Box::new(|| ()) + }); + test(&s); +}