diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2023-01-05 08:36:42 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-05 08:36:42 +0000 |
commit | fc72441e83fb9a0fafbcfe23060964f2cf3eee9f (patch) | |
tree | 94c413486df42172df582f342e4186ebc2a7e748 /gcc | |
parent | 8742e54052355beaa18fef9242a87fe84de51adb (diff) | |
parent | 5918059fd3a28915546c08e0d3adbc62b9ca3977 (diff) | |
download | gcc-fc72441e83fb9a0fafbcfe23060964f2cf3eee9f.zip gcc-fc72441e83fb9a0fafbcfe23060964f2cf3eee9f.tar.gz gcc-fc72441e83fb9a0fafbcfe23060964f2cf3eee9f.tar.bz2 |
Merge #1709
1709: Check const functions for mutable references r=CohenArthur a=dme2
Fixes #1552
Co-authored-by: Dave <dme2223@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/checks/errors/rust-const-checker.cc | 8 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/const10.rs | 3 |
2 files changed, 9 insertions, 2 deletions
diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc index 3de27ec..5f20437 100644 --- a/gcc/rust/checks/errors/rust-const-checker.cc +++ b/gcc/rust/checks/errors/rust-const-checker.cc @@ -898,8 +898,12 @@ ConstChecker::visit (RawPointerType &) {} void -ConstChecker::visit (ReferenceType &) -{} +ConstChecker::visit (ReferenceType &type) +{ + if (const_context.is_in_context () && type.is_mut ()) + rust_error_at (type.get_locus (), + "mutable references are not allowed in constant functions"); +} void ConstChecker::visit (ArrayType &type) diff --git a/gcc/testsuite/rust/compile/const10.rs b/gcc/testsuite/rust/compile/const10.rs new file mode 100644 index 0000000..9ab8274 --- /dev/null +++ b/gcc/testsuite/rust/compile/const10.rs @@ -0,0 +1,3 @@ +const fn foo (a: &mut i32) { // { dg-error "mutable references are not allowed in constant functions" } + *a = 1; +} |