From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/borrowck/borrowck-loan-vec-content.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/ui/borrowck/borrowck-loan-vec-content.rs (limited to 'tests/ui/borrowck/borrowck-loan-vec-content.rs') diff --git a/tests/ui/borrowck/borrowck-loan-vec-content.rs b/tests/ui/borrowck/borrowck-loan-vec-content.rs new file mode 100644 index 000000000..300ec88c5 --- /dev/null +++ b/tests/ui/borrowck/borrowck-loan-vec-content.rs @@ -0,0 +1,24 @@ +// Here we check that it is allowed to lend out an element of a +// (locally rooted) mutable, unique vector, and that we then prevent +// modifications to the contents. + +fn takes_imm_elt(_v: &isize, f: F) where F: FnOnce() { + f(); +} + +fn has_mut_vec_and_does_not_try_to_change_it() { + let mut v: Vec = vec![1, 2, 3]; + takes_imm_elt(&v[0], || {}) +} + +fn has_mut_vec_but_tries_to_change_it() { + let mut v: Vec = vec![1, 2, 3]; + takes_imm_elt( + &v[0], + || { //~ ERROR cannot borrow `v` as mutable + v[1] = 4; + }) +} + +fn main() { +} -- cgit v1.2.3