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>
{}
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)
--- /dev/null
+const fn foo (a: &mut i32) { // { dg-error "mutable references are not allowed in constant functions" }
+ *a = 1;
+}