diff options
Diffstat (limited to 'src/test/ui/closures/2229_closure_analysis/diagnostics/multilevel-path.rs')
-rw-r--r-- | src/test/ui/closures/2229_closure_analysis/diagnostics/multilevel-path.rs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/ui/closures/2229_closure_analysis/diagnostics/multilevel-path.rs b/src/test/ui/closures/2229_closure_analysis/diagnostics/multilevel-path.rs new file mode 100644 index 000000000..fa73ff23f --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/diagnostics/multilevel-path.rs @@ -0,0 +1,28 @@ +// edition:2021 + +// Test that when a borrow checker diagnostics are emitted, it's as precise +// as the capture by the closure. + +#![allow(unused)] + +struct Point { + x: i32, + y: i32, +} +struct Wrapper { + p: Point, +} + +fn main() { + let mut w = Wrapper { p: Point { x: 10, y: 10 } }; + + let mut c = || { + w.p.x += 20; + }; + + let py = &mut w.p.x; + //~^ ERROR: cannot borrow `w.p.x` as mutable more than once at a time + c(); + + *py = 20 +} |