From 874b783748d06cdcd199df3b68777a928a8f2158 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Wed, 28 Jul 2021 21:06:54 +0100 Subject: Add type bound name resolution Resolve the type-bound to the trait. --- gcc/rust/resolve/rust-ast-resolve-type.h | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'gcc/rust') diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h index d826d68..46ebdc4 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.h +++ b/gcc/rust/resolve/rust-ast-resolve-type.h @@ -297,6 +297,42 @@ private: bool ok; }; +class ResolveTypeBound : public ResolverBase +{ + using Rust::Resolver::ResolverBase::visit; + +public: + static NodeId go (AST::TypeParamBound *type, NodeId parent, + bool canonicalize_type_with_generics = false) + { + ResolveTypeBound resolver (parent, canonicalize_type_with_generics); + type->accept_vis (resolver); + if (!resolver.ok) + rust_error_at (type->get_locus_slow (), "unresolved type bound"); + + return resolver.resolved_node; + }; + + void visit (AST::TraitBound &bound) override + { + resolved_node = ResolveType::go (&bound.get_type_path (), parent, + canonicalize_type_with_generics); + ok = resolved_node != UNKNOWN_NODEID; + } + + void visit (AST::Lifetime &bound) override { ok = true; } + +private: + ResolveTypeBound (NodeId parent, bool canonicalize_type_with_generics) + : ResolverBase (parent), + canonicalize_type_with_generics (canonicalize_type_with_generics), + ok (false) + {} + + bool canonicalize_type_with_generics; + bool ok; +}; + class ResolveGenericParam : public ResolverBase { using Rust::Resolver::ResolverBase::visit; @@ -326,6 +362,14 @@ public: if (param.has_type ()) ResolveType::go (param.get_type ().get (), param.get_node_id ()); + if (param.has_type_param_bounds ()) + { + for (auto &bound : param.get_type_param_bounds ()) + { + ResolveTypeBound::go (bound.get (), param.get_node_id ()); + } + } + // for now lets focus on handling the basics: like struct { a:T, ....} resolver->get_type_scope ().insert ( CanonicalPath::new_seg (param.get_node_id (), -- cgit v1.1