From: Pierre-Emmanuel Patry <[email protected]>
The rust syntax allows unsafe module even if those are rejected at a
later stage.
gcc/rust/ChangeLog:
* ast/rust-item.h: Add safety status to Modules in the AST.
* parse/rust-parse-impl.h (Parser::parse_module): Adapt constructors.
Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
gcc/rust/ast/rust-item.h | 13 ++++++++-----
gcc/rust/parse/rust-parse-impl.h | 8 +++++---
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 3480d126bc0..6c3715e1eeb 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -736,6 +736,7 @@ private:
Identifier module_name;
location_t locus;
ModuleKind kind;
+ Unsafety safety;
// Name of the file including the module
std::string outer_filename;
@@ -766,11 +767,12 @@ public:
// Unloaded module constructor
Module (Identifier module_name, Visibility visibility,
- std::vector<Attribute> outer_attrs, location_t locus,
+ std::vector<Attribute> outer_attrs, location_t locus, Unsafety safety,
std::string outer_filename, std::vector<std::string> module_scope)
: VisItem (std::move (visibility), std::move (outer_attrs)),
module_name (module_name), locus (locus), kind (ModuleKind::UNLOADED),
- outer_filename (outer_filename), inner_attrs (std::vector<Attribute> ()),
+ safety (safety), outer_filename (outer_filename),
+ inner_attrs (std::vector<Attribute> ()),
items (std::vector<std::unique_ptr<Item>> ()),
module_scope (std::move (module_scope))
{}
@@ -779,18 +781,19 @@ public:
Module (Identifier name, location_t locus,
std::vector<std::unique_ptr<Item>> items,
Visibility visibility = Visibility::create_error (),
+ Unsafety safety = Unsafety::Normal,
std::vector<Attribute> inner_attrs = std::vector<Attribute> (),
std::vector<Attribute> outer_attrs = std::vector<Attribute> ())
: VisItem (std::move (visibility), std::move (outer_attrs)),
module_name (name), locus (locus), kind (ModuleKind::LOADED),
- outer_filename (std::string ()), inner_attrs (std::move (inner_attrs)),
- items (std::move (items))
+ safety (safety), outer_filename (std::string ()),
+ inner_attrs (std::move (inner_attrs)), items (std::move (items))
{}
// Copy constructor with vector clone
Module (Module const &other)
: VisItem (other), module_name (other.module_name), locus (other.locus),
- kind (other.kind), inner_attrs (other.inner_attrs),
+ kind (other.kind), safety (other.safety), inner_attrs
(other.inner_attrs),
module_scope (other.module_scope)
{
// We need to check whether we are copying a loaded module or an unloaded
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 53b3839db37..2e24a66123b 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -22,6 +22,7 @@
/* DO NOT INCLUDE ANYWHERE - this is automatically included with rust-parse.h
* This is also the reason why there are no include guards. */
+#include "rust-common.h"
#include "rust-item.h"
#include "rust-token.h"
#define INCLUDE_ALGORITHM
@@ -2446,8 +2447,8 @@ Parser<ManagedTokenSource>::parse_module (AST::Visibility
vis,
// Construct an external module
return std::unique_ptr<AST::Module> (
new AST::Module (std::move (name), std::move (vis),
- std::move (outer_attrs), locus, lexer.get_filename (),
- inline_module_stack));
+ std::move (outer_attrs), locus, Unsafety::Normal,
+ lexer.get_filename (), inline_module_stack));
case LEFT_CURLY: {
lexer.skip_token ();
@@ -2503,7 +2504,8 @@ Parser<ManagedTokenSource>::parse_module (AST::Visibility
vis,
return std::unique_ptr<AST::Module> (
new AST::Module (std::move (name), locus, std::move (items),
- std::move (vis), std::move (inner_attrs),
+ std::move (vis), Unsafety::Normal,
+ std::move (inner_attrs),
std::move (outer_attrs))); // module name?
}
default:
--
2.42.1