diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-07-05 16:36:54 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-07-10 21:26:17 +0100 |
commit | bb51a9de35e35ac4e411a323c1fde806fb54d142 (patch) | |
tree | b2120cdfd5781be08e7aa78a54f256f969b5b387 /gcc | |
parent | c5ce98cbb8db8d33774c50e229daedf99a71bb5a (diff) | |
download | gcc-bb51a9de35e35ac4e411a323c1fde806fb54d142.zip gcc-bb51a9de35e35ac4e411a323c1fde806fb54d142.tar.gz gcc-bb51a9de35e35ac4e411a323c1fde806fb54d142.tar.bz2 |
Add toplevel resolution for type alias
TypeAliases can be contained within ImplBlocks and need their full
canonical path to be resolved.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-implitem.h | 15 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.h | 18 |
2 files changed, 30 insertions, 3 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h index 576cd3e..9b71dad 100644 --- a/gcc/rust/resolve/rust-ast-resolve-implitem.h +++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h @@ -43,6 +43,21 @@ public: item->accept_vis (resolver); } + void visit (AST::TypeAlias &type) override + { + auto path = prefix.append (CanonicalPath (type.get_new_type_name ())); + resolver->get_type_scope ().insert ( + path, type.get_node_id (), type.get_locus (), false, + [&] (const CanonicalPath &, NodeId, Location locus) -> void { + RichLocation r (type.get_locus ()); + r.add_range (locus); + rust_error_at (r, "redefined multiple times"); + }); + resolver->insert_new_definition (type.get_node_id (), + Definition{type.get_node_id (), + type.get_node_id ()}); + } + void visit (AST::ConstantItem &constant) override { auto path diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h index fafd27e..09d6430 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.h +++ b/gcc/rust/resolve/rust-ast-resolve-item.h @@ -433,10 +433,22 @@ public: resolver->get_label_scope ().pop (); } - // TODO - void visit (AST::TraitItemConst &) override { gcc_unreachable (); } + void visit (AST::TraitItemConst &constant) override + { + ResolveType::go (constant.get_type ().get (), constant.get_node_id ()); + ResolveExpr::go (constant.get_expr ().get (), constant.get_node_id ()); + + // the mutability checker needs to verify for immutable decls the number + // of assignments are <1. This marks an implicit assignment + resolver->mark_decl_mutability (constant.get_node_id (), false); + resolver->mark_assignment_to_decl (constant.get_node_id (), + constant.get_node_id ()); + } - void visit (AST::TraitItemType &) override { gcc_unreachable (); } + void visit (AST::TraitItemType &alias) override + { + // nothing to do here until we start supporting Type Bounds + } private: ResolveItem () : ResolverBase (UNKNOWN_NODEID) {} |