From f56781662f82dcbe1780cbe3e7eb4ac17f8156d0 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Mon, 19 Jul 2021 19:32:41 +0100 Subject: Assignments are a coercion site in rust This implements the reference mutability coercion rules, where the base types must be compatible and the base can turn a mutable reference into a constant one. Address #434 Fixes #576 --- gcc/rust/backend/rust-compile-context.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gcc/rust/backend/rust-compile-context.h') diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index d822937..efca267 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -537,6 +537,10 @@ public: Btype *base_compiled_type = TyTyResolveCompile::compile (ctx, type.get_base ()); translated = ctx->get_backend ()->reference_type (base_compiled_type); + if (!type.is_mutable ()) + { + translated = ctx->get_backend ()->immutable_type (translated); + } } void visit (TyTy::StrType &type) override -- cgit v1.1