From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/borrowck/borrowck-loan-rcvr.rs | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/test/ui/borrowck/borrowck-loan-rcvr.rs (limited to 'src/test/ui/borrowck/borrowck-loan-rcvr.rs') diff --git a/src/test/ui/borrowck/borrowck-loan-rcvr.rs b/src/test/ui/borrowck/borrowck-loan-rcvr.rs new file mode 100644 index 000000000..d2234e17a --- /dev/null +++ b/src/test/ui/borrowck/borrowck-loan-rcvr.rs @@ -0,0 +1,40 @@ +struct Point { x: isize, y: isize } + +trait Methods { + fn impurem(&self); + fn blockm(&self, f: F) where F: FnOnce(); +} + +impl Methods for Point { + fn impurem(&self) { + } + + fn blockm(&self, f: F) where F: FnOnce() { f() } +} + +fn a() { + let mut p = Point {x: 3, y: 4}; + + // Here: it's ok to call even though receiver is mutable, because we + // can loan it out. + p.impurem(); + + // But in this case we do not honor the loan: + p.blockm(|| { //~ ERROR cannot borrow `p` as mutable + p.x = 10; + }) +} + +fn b() { + let mut p = Point {x: 3, y: 4}; + + // Here I create an outstanding loan and check that we get conflicts: + + let l = &mut p; + p.impurem(); //~ ERROR cannot borrow + + l.x += 1; +} + +fn main() { +} -- cgit v1.2.3