From 6dea70e1dafa603b2327bfb936d26fac95f46069 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Mon, 22 Aug 2022 12:22:54 +0100 Subject: Cleanup canonical path usage on impl blocks --- gcc/rust/resolve/rust-ast-resolve-item.cc | 40 ++++++++++++++----------------- 1 file changed, 18 insertions(+), 22 deletions(-) (limited to 'gcc/rust/resolve') diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 75bd2e1..0c38f28 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -534,25 +534,17 @@ ResolveItem::visit (AST::InherentImpl &impl_block) // FIXME this needs to be protected behind nominal type-checks see: // rustc --explain E0118 - - NodeId resolved_node = ResolveType::go (impl_block.get_type ().get ()); - if (resolved_node == UNKNOWN_NODEID) - { - resolver->get_type_scope ().pop (); - resolver->get_name_scope ().pop (); - return; - } + ResolveType::go (impl_block.get_type ().get ()); // Setup paths CanonicalPath self_cpath = CanonicalPath::create_empty (); bool ok = ResolveTypeToCanonicalPath::go (impl_block.get_type ().get (), self_cpath); rust_assert (ok); + rust_debug ("AST::InherentImpl resolve Self: {%s}", + self_cpath.get ().c_str ()); - std::string raw_impl_type_path = impl_block.get_type ()->as_string (); - CanonicalPath impl_type - = CanonicalPath::new_seg (impl_block.get_type ()->get_node_id (), - raw_impl_type_path); + CanonicalPath impl_type = self_cpath; CanonicalPath impl_prefix = prefix.append (impl_type); // see https://godbolt.org/z/a3vMbsT6W @@ -580,6 +572,9 @@ ResolveItem::visit (AST::InherentImpl &impl_block) for (auto &impl_item : impl_block.get_impl_items ()) { + rust_debug ( + "AST::InherentImpl resolve_impl_item: impl_prefix={%s} cpath={%s}", + impl_prefix.get ().c_str (), cpath.get ().c_str ()); resolve_impl_item (impl_item.get (), impl_prefix, cpath); } @@ -703,22 +698,20 @@ ResolveItem::visit (AST::TraitImpl &impl_block) canonical_trait_type); rust_assert (ok); + rust_debug ("AST::TraitImpl resolve trait type: {%s}", + canonical_trait_type.get ().c_str ()); + CanonicalPath canonical_impl_type = CanonicalPath::create_empty (); ok = ResolveTypeToCanonicalPath::go (impl_block.get_type ().get (), canonical_impl_type); rust_assert (ok); - // raw paths - std::string raw_impl_type_path = impl_block.get_type ()->as_string (); - CanonicalPath impl_type_seg - = CanonicalPath::new_seg (impl_block.get_type ()->get_node_id (), - raw_impl_type_path); - - std::string raw_trait_type_path = impl_block.get_trait_path ().as_string (); - CanonicalPath trait_type_seg - = CanonicalPath::new_seg (impl_block.get_trait_path ().get_node_id (), - raw_trait_type_path); + rust_debug ("AST::TraitImpl resolve self: {%s}", + canonical_impl_type.get ().c_str ()); + // raw paths + CanonicalPath impl_type_seg = canonical_impl_type; + CanonicalPath trait_type_seg = canonical_trait_type; CanonicalPath projection = CanonicalPath::trait_impl_projection_seg (impl_block.get_node_id (), trait_type_seg, impl_type_seg); @@ -756,6 +749,9 @@ ResolveItem::visit (AST::TraitImpl &impl_block) for (auto &impl_item : impl_block.get_impl_items ()) { + rust_debug ( + "AST::TraitImpl resolve_impl_item: impl_prefix={%s} cpath={%s}", + impl_prefix.get ().c_str (), cpath.get ().c_str ()); resolve_impl_item (impl_item.get (), impl_prefix, cpath); } -- cgit v1.1 From 56f503b88a240f1d77c8d6564656bc22269b4842 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Mon, 22 Aug 2022 12:43:53 +0100 Subject: Qualified paths can have an optional as clause Qualified paths can look like ::bla with an associated impl block for dynamic trait objects. If we implement similar fine grained visitors that we use in the HIR this will help solve issues like this where we have missing visitors. Fixes #1249 --- gcc/rust/resolve/rust-ast-resolve-path.cc | 3 ++- gcc/rust/resolve/rust-ast-resolve-type.cc | 21 +++++++++++++++++++++ gcc/rust/resolve/rust-ast-resolve-type.h | 4 ++++ 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'gcc/rust/resolve') diff --git a/gcc/rust/resolve/rust-ast-resolve-path.cc b/gcc/rust/resolve/rust-ast-resolve-path.cc index 27f32aa..b139c6a 100644 --- a/gcc/rust/resolve/rust-ast-resolve-path.cc +++ b/gcc/rust/resolve/rust-ast-resolve-path.cc @@ -242,8 +242,9 @@ void ResolvePath::resolve_path (AST::QualifiedPathInExpression *expr) { AST::QualifiedPathType &root_segment = expr->get_qualified_path_type (); - ResolveType::go (&root_segment.get_as_type_path ()); ResolveType::go (root_segment.get_type ().get ()); + if (root_segment.has_as_clause ()) + ResolveType::go (&root_segment.get_as_type_path ()); for (auto &segment : expr->get_segments ()) { diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc index a8931ce..6b08613 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.cc +++ b/gcc/rust/resolve/rust-ast-resolve-type.cc @@ -477,6 +477,27 @@ ResolveTypeToCanonicalPath::visit (AST::SliceType &type) } } +void +ResolveTypeToCanonicalPath::visit (AST::TraitObjectTypeOneBound &type) +{ + CanonicalPath path = CanonicalPath::create_empty (); + bool ok + = ResolveTypeToCanonicalPath::go (&type.get_trait_bound ().get_type_path (), + path); + if (ok) + { + std::string slice_path = ""; + result = CanonicalPath::new_seg (type.get_node_id (), slice_path); + } +} + +void +ResolveTypeToCanonicalPath::visit (AST::TraitObjectType &type) +{ + // FIXME is this actually allowed? dyn A+B + gcc_unreachable (); +} + ResolveTypeToCanonicalPath::ResolveTypeToCanonicalPath () : ResolverBase (), result (CanonicalPath::create_empty ()) {} diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h index b57b513..5a71268 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.h +++ b/gcc/rust/resolve/rust-ast-resolve-type.h @@ -242,6 +242,10 @@ public: void visit (AST::SliceType &type) override; + void visit (AST::TraitObjectTypeOneBound &type) override; + + void visit (AST::TraitObjectType &type) override; + private: ResolveTypeToCanonicalPath (); -- cgit v1.1