diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /src/test/ui/closures/2229_closure_analysis/diagnostics/box.rs | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/closures/2229_closure_analysis/diagnostics/box.rs')
-rw-r--r-- | src/test/ui/closures/2229_closure_analysis/diagnostics/box.rs | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/box.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/box.rs deleted file mode 100644 index a110fa4e2..000000000 --- a/src/test/ui/closures/2229_closure_analysis/diagnostics/box.rs +++ /dev/null @@ -1,64 +0,0 @@ -// edition:2021 - -// Test borrow checker when we precise capture when using boxes - -struct MetaData { x: String, name: String } -struct Data { m: MetaData } -struct BoxedData(Box<Data>); -struct EvenMoreBoxedData(Box<BoxedData>); - -// Check diagnostics when the same path is mutated both inside and outside the closure -fn box_1() { - let m = MetaData { x: format!("x"), name: format!("name") }; - let d = Data { m }; - let b = BoxedData(Box::new(d)); - let mut e = EvenMoreBoxedData(Box::new(b)); - - let mut c = || { - e.0.0.m.x = format!("not-x"); - }; - - e.0.0.m.x = format!("not-x"); - //~^ ERROR: cannot assign to `e.0.0.m.x` because it is borrowed - c(); -} - -// Check diagnostics when a path is mutated inside a closure while attempting to read it outside -// the closure. -fn box_2() { - let m = MetaData { x: format!("x"), name: format!("name") }; - let d = Data { m }; - let b = BoxedData(Box::new(d)); - let mut e = EvenMoreBoxedData(Box::new(b)); - - let mut c = || { - e.0.0.m.x = format!("not-x"); - }; - - println!("{}", e.0.0.m.x); - //~^ ERROR: cannot borrow `e.0.0.m.x` as immutable because it is also borrowed as mutable - c(); -} - -// Check diagnostics when a path is read inside a closure while attempting to mutate it outside -// the closure. -fn box_3() { - let m = MetaData { x: format!("x"), name: format!("name") }; - let d = Data { m }; - let b = BoxedData(Box::new(d)); - let mut e = EvenMoreBoxedData(Box::new(b)); - - let c = || { - println!("{}", e.0.0.m.x); - }; - - e.0.0.m.x = format!("not-x"); - //~^ ERROR: cannot assign to `e.0.0.m.x` because it is borrowed - c(); -} - -fn main() { - box_1(); - box_2(); - box_3(); -} |