public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] Add missing canonicalization of slices and raw pointer types Date: Wed, 8 Jun 2022 12:17:18 +0000 (GMT) [thread overview] Message-ID: <20220608121718.B3CBD380F3DC@sourceware.org> (raw) https://gcc.gnu.org/g:31413ebacfec0f8d7b8c01b1903b76563b965177 commit 31413ebacfec0f8d7b8c01b1903b76563b965177 Author: Philip Herron <philip.herron@embecosm.com> Date: Thu Mar 10 13:26:06 2022 +0000 Add missing canonicalization of slices and raw pointer types When we intercept impl blocks for slices or raw pointers we must generate the canonical path for this for name resolution this adds in the missing visitors which will generate the path. Previously this was defaulting to empty path segments and then hitting an assertion when we append the empty segment. Fixes #1005 Diff: --- gcc/rust/resolve/rust-ast-resolve-type.cc | 39 +++++++++++++++++++++++++++++++ gcc/rust/resolve/rust-ast-resolve-type.h | 4 ++++ gcc/testsuite/rust/compile/issue-1005.rs | 4 ++++ 3 files changed, 47 insertions(+) diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc index 252d1cae8aa..c27501e1a29 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.cc +++ b/gcc/rust/resolve/rust-ast-resolve-type.cc @@ -167,6 +167,45 @@ ResolveTypeToCanonicalPath::visit (AST::ReferenceType &ref) result = result.append (ident_seg); } +void +ResolveTypeToCanonicalPath::visit (AST::RawPointerType &ref) +{ + auto inner_type + = ResolveTypeToCanonicalPath::resolve (*ref.get_type_pointed_to ().get (), + include_generic_args_flag, + type_resolve_generic_args_flag); + + std::string segment_string ("*"); + switch (ref.get_pointer_type ()) + { + case AST::RawPointerType::PointerType::MUT: + segment_string += "mut "; + break; + + case AST::RawPointerType::PointerType::CONST: + segment_string += "const "; + break; + } + + segment_string += inner_type.get (); + + auto ident_seg = CanonicalPath::new_seg (ref.get_node_id (), segment_string); + result = result.append (ident_seg); +} + +void +ResolveTypeToCanonicalPath::visit (AST::SliceType &slice) +{ + auto inner_type + = ResolveTypeToCanonicalPath::resolve (*slice.get_elem_type ().get (), + include_generic_args_flag, + type_resolve_generic_args_flag); + std::string segment_string = "[" + inner_type.get () + "]"; + auto ident_seg + = CanonicalPath::new_seg (slice.get_node_id (), segment_string); + result = result.append (ident_seg); +} + void ResolveType::visit (AST::ReferenceType &type) { diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h index d835e00c77c..6dcfb4495fc 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.h +++ b/gcc/rust/resolve/rust-ast-resolve-type.h @@ -122,6 +122,10 @@ public: } } + void visit (AST::SliceType &slice) override; + + void visit (AST::RawPointerType &ptr) override; + void visit (AST::ReferenceType &ref) override; void visit (AST::TypePathSegmentGeneric &seg) override; diff --git a/gcc/testsuite/rust/compile/issue-1005.rs b/gcc/testsuite/rust/compile/issue-1005.rs new file mode 100644 index 00000000000..46c85eea91e --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-1005.rs @@ -0,0 +1,4 @@ +// { dg-additional-options "-w" } +impl<T> *const T { + fn test(self) {} +}
reply other threads:[~2022-06-08 12:17 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220608121718.B3CBD380F3DC@sourceware.org \ --to=tschwinge@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).