diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/borrowck/mutability-errors.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/borrowck/mutability-errors.rs')
-rw-r--r-- | src/test/ui/borrowck/mutability-errors.rs | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/test/ui/borrowck/mutability-errors.rs b/src/test/ui/borrowck/mutability-errors.rs new file mode 100644 index 000000000..5be0df137 --- /dev/null +++ b/src/test/ui/borrowck/mutability-errors.rs @@ -0,0 +1,82 @@ +// All the possible mutability error cases. + +#![allow(unused)] + +type MakeRef = fn() -> &'static (i32,); +type MakePtr = fn() -> *const (i32,); + +fn named_ref(x: &(i32,)) { + *x = (1,); //~ ERROR + x.0 = 1; //~ ERROR + &mut *x; //~ ERROR + &mut x.0; //~ ERROR +} + +fn unnamed_ref(f: MakeRef) { + *f() = (1,); //~ ERROR + f().0 = 1; //~ ERROR + &mut *f(); //~ ERROR + &mut f().0; //~ ERROR +} + +unsafe fn named_ptr(x: *const (i32,)) { + *x = (1,); //~ ERROR + (*x).0 = 1; //~ ERROR + &mut *x; //~ ERROR + &mut (*x).0; //~ ERROR +} + +unsafe fn unnamed_ptr(f: MakePtr) { + *f() = (1,); //~ ERROR + (*f()).0 = 1; //~ ERROR + &mut *f(); //~ ERROR + &mut (*f()).0; //~ ERROR +} + +fn fn_ref<F: Fn()>(f: F) -> F { f } + +fn ref_closure(mut x: (i32,)) { + fn_ref(|| { + x = (1,); //~ ERROR + x.0 = 1; //~ ERROR + &mut x; //~ ERROR + &mut x.0; //~ ERROR + }); + fn_ref(move || { + x = (1,); //~ ERROR + x.0 = 1; //~ ERROR + &mut x; //~ ERROR + &mut x.0; //~ ERROR + }); +} + +fn imm_local(x: (i32,)) { + &mut x; //~ ERROR + &mut x.0; //~ ERROR +} + +fn imm_capture(x: (i32,)) { + || { + x = (1,); //~ ERROR + x.0 = 1; //~ ERROR + &mut x; //~ ERROR + &mut x.0; //~ ERROR + }; + move || { + x = (1,); //~ ERROR + x.0 = 1; //~ ERROR + &mut x; //~ ERROR + &mut x.0; //~ ERROR + }; +} + +static X: (i32,) = (0,); + +fn imm_static() { + X = (1,); //~ ERROR + X.0 = 1; //~ ERROR + &mut X; //~ ERROR + &mut X.0; //~ ERROR +} + +fn main() {} |