diff options
Diffstat (limited to 'tests/ui/issues/issue-40288.rs')
-rw-r--r-- | tests/ui/issues/issue-40288.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/ui/issues/issue-40288.rs b/tests/ui/issues/issue-40288.rs new file mode 100644 index 000000000..60204c117 --- /dev/null +++ b/tests/ui/issues/issue-40288.rs @@ -0,0 +1,20 @@ +fn save_ref<'a>(refr: &'a i32, to: &mut [&'a i32]) { + for val in &mut *to { + *val = refr; + } +} + +fn main() { + let ref init = 0i32; + let ref mut refr = 1i32; + + let mut out = [init]; + + save_ref(&*refr, &mut out); + + // This shouldn't be allowed as `refr` is borrowed + *refr = 3; //~ ERROR cannot assign to `*refr` because it is borrowed + + // Prints 3?! + println!("{:?}", out[0]); +} |