aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust/compile
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2024-12-16 14:51:17 +0000
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-21 12:56:56 +0100
commit770ca551cf9c591ba195e6c12c8a24948d5b289b (patch)
tree91e55b4d1a85f822ce72749920c7a9d9a8b895ba /gcc/testsuite/rust/compile
parent76565cabf2842b7dff20f4a3cbe2808fec7d15da (diff)
downloadgcc-770ca551cf9c591ba195e6c12c8a24948d5b289b.zip
gcc-770ca551cf9c591ba195e6c12c8a24948d5b289b.tar.gz
gcc-770ca551cf9c591ba195e6c12c8a24948d5b289b.tar.bz2
gccrs: improve mutability checks
This ensures that we handle var decls readonly checks much better Addresses: Rust-GCC#807 Rust-GCC#3287 gcc/rust/ChangeLog: * checks/errors/rust-readonly-check.cc (check_decl): improve mut check (emit_error): helper (check_modify_expr): likewise (readonly_walk_fn): reuse helper (ReadonlyCheck::Lint): cleanup context each run gcc/testsuite/ChangeLog: * rust/execute/torture/builtin_macro_include_bytes.rs: needs mut * rust/compile/mutability_checks1.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/testsuite/rust/compile')
-rw-r--r--gcc/testsuite/rust/compile/mutability_checks1.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/gcc/testsuite/rust/compile/mutability_checks1.rs b/gcc/testsuite/rust/compile/mutability_checks1.rs
new file mode 100644
index 0000000..4affae0
--- /dev/null
+++ b/gcc/testsuite/rust/compile/mutability_checks1.rs
@@ -0,0 +1,15 @@
+pub fn test() {
+ let a;
+ a = 1;
+ a = 2 + 1;
+ // { dg-error "assignment of read-only variable" "" { target *-*-* } .-1 }
+
+ struct Foo(i32);
+ let a = Foo(1);
+ a.0 = 2;
+ // { dg-error "assignment of read-only variable" "" { target *-*-* } .-1 }
+
+ let a = [1, 2, 3, 4];
+ a[0] = 1 + 2;
+ // { dg-error "assignment of read-only variable" "" { target *-*-* } .-1 }
+}