mirror of
https://gcc.gnu.org/git/gcc.git
synced 2026-02-22 20:01:22 -05:00
gccrs: Check for mutable references in const functions
Use StackedContext instead. Fix error string Signed-off-by: Dave Evans <dave@dmetwo.org> (Squashed commits) Check for mutable references in const functions using StackedContext gcc/rust/ChangeLog: * checks/errors/rust-const-checker.cc (ConstChecker::visit): Use StackedContext class. gcc/testsuite/ChangeLog: * rust/compile/const10.rs: New test. Signed-off-by: Dave Evans <dave@dmetwo.org>
This commit is contained in:
@@ -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)
|
||||
|
||||
3
gcc/testsuite/rust/compile/const10.rs
Normal file
3
gcc/testsuite/rust/compile/const10.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
const fn foo (a: &mut i32) { // { dg-error "mutable references are not allowed in constant functions" }
|
||||
*a = 1;
|
||||
}
|
||||
Reference in New Issue
Block a user