aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-03-17 22:46:37 +0000
committerPhilip Herron <philip.herron@embecosm.com>2023-03-20 21:47:57 +0000
commita8662e89f84e91466acc09e28b4a289d298498ee (patch)
tree33cfd871de61c050019fdb3434a3bb6faed8ec36 /gcc/rust/hir
parent70b83a23f508d3694aa08cda793bab118a9be768 (diff)
downloadgcc-a8662e89f84e91466acc09e28b4a289d298498ee.zip
gcc-a8662e89f84e91466acc09e28b4a289d298498ee.tar.gz
gcc-a8662e89f84e91466acc09e28b4a289d298498ee.tar.bz2
gccrs: support use declaration to write the type into the correct namespace
This builds upon the previous path resolution fixes so that it returns the resolved_node_id or UNKNOWN_NODEID on failure to resolve the use-path. It then exports the name to the current module namespace so it can be used. Fixes #850 #855 gcc/rust/ChangeLog: * ast/rust-ast.h: add const get_final_segment helper * hir/rust-ast-lower-enumitem.h: dont add an item mapping for enumitems * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): add enum to enum-items mappings * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): likewise * hir/tree/rust-hir-item.h: add non const helper to get variants * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): resolve the use declaration * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): handle self * resolve/rust-ast-resolve-toplevel.h: add enum item mappings to module mappings * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): ensure variant (TypeCheckExpr::resolve_segments): likewise * typecheck/rust-type-util.cc (query_type): lookup enum's * util/rust-hir-map.cc (Mappings::insert_hir_enumitem): enum item mappings (Mappings::lookup_hir_enumitem): likewise * util/rust-hir-map.h: likewise gcc/testsuite/ChangeLog: * rust/compile/issue-850.rs: New test. * rust/compile/issue-855.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Diffstat (limited to 'gcc/rust/hir')
-rw-r--r--gcc/rust/hir/rust-ast-lower-enumitem.h1
-rw-r--r--gcc/rust/hir/rust-ast-lower-item.cc15
-rw-r--r--gcc/rust/hir/rust-ast-lower-stmt.cc15
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h2
4 files changed, 22 insertions, 11 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-enumitem.h b/gcc/rust/hir/rust-ast-lower-enumitem.h
index cc3e9e5..a8aa45a 100644
--- a/gcc/rust/hir/rust-ast-lower-enumitem.h
+++ b/gcc/rust/hir/rust-ast-lower-enumitem.h
@@ -46,7 +46,6 @@ public:
auto defid = resolver.translated->get_mappings ().get_defid ();
resolver.mappings->insert_defid_mapping (defid, resolver.translated);
- resolver.mappings->insert_hir_item (resolver.translated);
resolver.mappings->insert_location (hirid,
resolver.translated->get_locus ());
diff --git a/gcc/rust/hir/rust-ast-lower-item.cc b/gcc/rust/hir/rust-ast-lower-item.cc
index 0ad4a84..eade1bc 100644
--- a/gcc/rust/hir/rust-ast-lower-item.cc
+++ b/gcc/rust/hir/rust-ast-lower-item.cc
@@ -274,11 +274,16 @@ ASTLoweringItem::visit (AST::Enum &enum_decl)
mappings->get_next_hir_id (crate_num),
mappings->get_next_localdef_id (crate_num));
- translated = new HIR::Enum (mapping, enum_decl.get_identifier (), vis,
- std::move (generic_params),
- std::move (where_clause), /* is_unit, */
- std::move (items), enum_decl.get_outer_attrs (),
- enum_decl.get_locus ());
+ HIR::Enum *hir_enum
+ = new HIR::Enum (mapping, enum_decl.get_identifier (), vis,
+ std::move (generic_params), std::move (where_clause),
+ std::move (items), enum_decl.get_outer_attrs (),
+ enum_decl.get_locus ());
+ translated = hir_enum;
+ for (auto &variant : hir_enum->get_variants ())
+ {
+ mappings->insert_hir_enumitem (hir_enum, variant.get ());
+ }
}
void
diff --git a/gcc/rust/hir/rust-ast-lower-stmt.cc b/gcc/rust/hir/rust-ast-lower-stmt.cc
index dbff8ad..5ba8db0 100644
--- a/gcc/rust/hir/rust-ast-lower-stmt.cc
+++ b/gcc/rust/hir/rust-ast-lower-stmt.cc
@@ -301,11 +301,16 @@ ASTLoweringStmt::visit (AST::Enum &enum_decl)
mappings->get_next_hir_id (crate_num),
mappings->get_next_localdef_id (crate_num));
- translated = new HIR::Enum (mapping, enum_decl.get_identifier (), vis,
- std::move (generic_params),
- std::move (where_clause), /* is_unit, */
- std::move (items), enum_decl.get_outer_attrs (),
- enum_decl.get_locus ());
+ HIR::Enum *hir_enum
+ = new HIR::Enum (mapping, enum_decl.get_identifier (), vis,
+ std::move (generic_params), std::move (where_clause),
+ std::move (items), enum_decl.get_outer_attrs (),
+ enum_decl.get_locus ());
+ translated = hir_enum;
+ for (auto &variant : hir_enum->get_variants ())
+ {
+ mappings->insert_hir_enumitem (hir_enum, variant.get ());
+ }
}
void
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index 7a2a39f..9ff9732 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -1966,6 +1966,8 @@ public:
return items;
}
+ std::vector<std::unique_ptr<EnumItem>> &get_variants () { return items; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */