diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2024-05-21 10:38:16 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-17 16:35:33 +0100 |
commit | a2a66257457d368c999319b8d31e4d11367f8755 (patch) | |
tree | 367faf88d89c36002a42d56d862a4fc873026d40 /gcc | |
parent | a0f4c30e52aebcb5c71ea5eba98fb20dbbc56858 (diff) | |
download | gcc-a2a66257457d368c999319b8d31e4d11367f8755.zip gcc-a2a66257457d368c999319b8d31e4d11367f8755.tar.gz gcc-a2a66257457d368c999319b8d31e4d11367f8755.tar.bz2 |
gccrs: Prevent raw reference from being lowered silently
We do not handle those kind of references yet, we shall not let them
pass as a regular reference.
gcc/rust/ChangeLog:
* ast/rust-expr.h: Add a getter for mutability.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Panic when a
raw reference is met.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 2 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-expr.cc | 13 |
2 files changed, 9 insertions, 6 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 6609ad8..a5afbff 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -398,6 +398,8 @@ public: bool get_is_mut () const { return mutability == Mutability::Mut; } + Mutability get_mutability () const { return mutability; } + bool get_is_double_borrow () const { return double_borrow; } bool is_raw_borrow () const { return raw_borrow; } diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc b/gcc/rust/hir/rust-ast-lower-expr.cc index 515d36a..a0eb5e3 100644 --- a/gcc/rust/hir/rust-ast-lower-expr.cc +++ b/gcc/rust/hir/rust-ast-lower-expr.cc @@ -628,6 +628,9 @@ ASTLoweringExpr::visit (AST::ContinueExpr &expr) void ASTLoweringExpr::visit (AST::BorrowExpr &expr) { + if (expr.is_raw_borrow ()) + rust_unreachable (); + HIR::Expr *borrow_lvalue = ASTLoweringExpr::translate (expr.get_borrowed_expr ()); @@ -638,9 +641,8 @@ ASTLoweringExpr::visit (AST::BorrowExpr &expr) auto *borrow_expr = new HIR::BorrowExpr (mapping, std::unique_ptr<HIR::Expr> (borrow_lvalue), - expr.get_is_mut () ? Mutability::Mut - : Mutability::Imm, - expr.get_outer_attrs (), expr.get_locus ()); + expr.get_mutability (), expr.get_outer_attrs (), + expr.get_locus ()); if (expr.get_is_double_borrow ()) { @@ -652,9 +654,8 @@ ASTLoweringExpr::visit (AST::BorrowExpr &expr) borrow_expr = new HIR::BorrowExpr (mapping, std::unique_ptr<HIR::Expr> (borrow_expr), - expr.get_is_mut () ? Mutability::Mut - : Mutability::Imm, - expr.get_outer_attrs (), expr.get_locus ()); + expr.get_mutability (), expr.get_outer_attrs (), + expr.get_locus ()); } translated = borrow_expr; |