diff options
author | Raiki Tamura <tamaron1203@gmail.com> | 2023-09-20 13:42:02 +0900 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-01-16 19:04:37 +0100 |
commit | 1e1e3814ffb0cdd865593d3d42cbf5cbb6f9fa57 (patch) | |
tree | 6c9367e45a3e0633a6ce0eb49b6842c5d7c2c8f9 /gcc | |
parent | b9a046cf4cdee115c30d8d0b667ec56ca4c1fd64 (diff) | |
download | gcc-1e1e3814ffb0cdd865593d3d42cbf5cbb6f9fa57.zip gcc-1e1e3814ffb0cdd865593d3d42cbf5cbb6f9fa57.tar.gz gcc-1e1e3814ffb0cdd865593d3d42cbf5cbb6f9fa57.tar.bz2 |
gccrs: Fix CanonicalPath for inherent impl
gcc/rust/ChangeLog:
* util/rust-canonical-path.h: Add new segment kind for inherent impl.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Use it.
* resolve/rust-ast-resolve-toplevel.h: Use it.
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.cc | 7 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-toplevel.h | 8 | ||||
-rw-r--r-- | gcc/rust/util/rust-canonical-path.h | 6 |
3 files changed, 17 insertions, 4 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 1dee98a..48682f00 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -565,6 +565,7 @@ ResolveItem::visit (AST::InherentImpl &impl_block) // FIXME this needs to be protected behind nominal type-checks see: // rustc --explain E0118 + // issue #2634 ResolveType::go (impl_block.get_type ().get ()); // Setup paths @@ -576,13 +577,15 @@ ResolveItem::visit (AST::InherentImpl &impl_block) self_cpath.get ().c_str ()); CanonicalPath impl_type = self_cpath; - CanonicalPath impl_prefix = prefix.append (impl_type); + CanonicalPath impl_type_seg + = CanonicalPath::inherent_impl_seg (impl_block.get_node_id (), impl_type); + CanonicalPath impl_prefix = prefix.append (impl_type_seg); // see https://godbolt.org/z/a3vMbsT6W CanonicalPath cpath = CanonicalPath::create_empty (); if (canonical_prefix.size () <= 1) { - cpath = self_cpath; + cpath = impl_prefix; } else { diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h index 88d034b..73b4d29 100644 --- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h +++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h @@ -344,10 +344,14 @@ public: void visit (AST::InherentImpl &impl_block) override { std::string raw_impl_type_path = impl_block.get_type ()->as_string (); - CanonicalPath impl_type + CanonicalPath impl_type_seg = CanonicalPath::new_seg (impl_block.get_type ()->get_node_id (), raw_impl_type_path); - CanonicalPath impl_prefix = prefix.append (impl_type); + + CanonicalPath impl_type + = CanonicalPath::inherent_impl_seg (impl_block.get_node_id (), + impl_type_seg); + CanonicalPath impl_prefix = prefix.append (impl_type_seg); for (auto &impl_item : impl_block.get_impl_items ()) ResolveToplevelImplItem::go (impl_item.get (), impl_prefix); diff --git a/gcc/rust/util/rust-canonical-path.h b/gcc/rust/util/rust-canonical-path.h index a524fea..f2865eb 100644 --- a/gcc/rust/util/rust-canonical-path.h +++ b/gcc/rust/util/rust-canonical-path.h @@ -69,6 +69,12 @@ public: + trait_seg.get () + ">"); } + static CanonicalPath inherent_impl_seg (NodeId id, + const CanonicalPath &impl_type_seg) + { + return CanonicalPath::new_seg (id, "<" + impl_type_seg.get () + ">"); + } + std::string get () const { std::string buf; |