aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-03-11 10:10:58 +0000
committerGitHub <noreply@github.com>2022-03-11 10:10:58 +0000
commitdbe59a3198495c760c019369c9a272fb63059e51 (patch)
treea1943727e046a2fd8e9ff73b2b7d83207e72d463 /gcc
parentddd087b0efa734cd166231b5812a201f30a4fd2b (diff)
parent31413ebacfec0f8d7b8c01b1903b76563b965177 (diff)
downloadgcc-dbe59a3198495c760c019369c9a272fb63059e51.zip
gcc-dbe59a3198495c760c019369c9a272fb63059e51.tar.gz
gcc-dbe59a3198495c760c019369c9a272fb63059e51.tar.bz2
Merge #1007
1007: Add missing canonicalization of slices and raw pointer types r=philberty a=philberty This is part of my patch series for slices. This adds the missing visitors for name canonicalization. More information in the patch, once we get slice support in we need to start taking advantage of `@dkm's` HIR visitor refactoring to avoid these issues with missing visitors making simple bugs hard to track down. Fixes #1005 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-type.cc39
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-type.h4
-rw-r--r--gcc/testsuite/rust/compile/issue-1005.rs4
3 files changed, 47 insertions, 0 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc
index fd5c056..29b5edf 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -168,6 +168,45 @@ ResolveTypeToCanonicalPath::visit (AST::ReferenceType &ref)
}
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)
{
type.get_type_referenced ()->accept_vis (*this);
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h
index e534423..4920e2b 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 0000000..46c85ee
--- /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) {}
+}