Skip to content

Commit 31413eb

Browse files
committed
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
1 parent 77a4950 commit 31413eb

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

gcc/rust/resolve/rust-ast-resolve-type.cc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,45 @@ ResolveTypeToCanonicalPath::visit (AST::ReferenceType &ref)
167167
result = result.append (ident_seg);
168168
}
169169

170+
void
171+
ResolveTypeToCanonicalPath::visit (AST::RawPointerType &ref)
172+
{
173+
auto inner_type
174+
= ResolveTypeToCanonicalPath::resolve (*ref.get_type_pointed_to ().get (),
175+
include_generic_args_flag,
176+
type_resolve_generic_args_flag);
177+
178+
std::string segment_string ("*");
179+
switch (ref.get_pointer_type ())
180+
{
181+
case AST::RawPointerType::PointerType::MUT:
182+
segment_string += "mut ";
183+
break;
184+
185+
case AST::RawPointerType::PointerType::CONST:
186+
segment_string += "const ";
187+
break;
188+
}
189+
190+
segment_string += inner_type.get ();
191+
192+
auto ident_seg = CanonicalPath::new_seg (ref.get_node_id (), segment_string);
193+
result = result.append (ident_seg);
194+
}
195+
196+
void
197+
ResolveTypeToCanonicalPath::visit (AST::SliceType &slice)
198+
{
199+
auto inner_type
200+
= ResolveTypeToCanonicalPath::resolve (*slice.get_elem_type ().get (),
201+
include_generic_args_flag,
202+
type_resolve_generic_args_flag);
203+
std::string segment_string = "[" + inner_type.get () + "]";
204+
auto ident_seg
205+
= CanonicalPath::new_seg (slice.get_node_id (), segment_string);
206+
result = result.append (ident_seg);
207+
}
208+
170209
void
171210
ResolveType::visit (AST::ReferenceType &type)
172211
{

gcc/rust/resolve/rust-ast-resolve-type.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ class ResolveTypeToCanonicalPath : public ResolverBase
122122
}
123123
}
124124

125+
void visit (AST::SliceType &slice) override;
126+
127+
void visit (AST::RawPointerType &ptr) override;
128+
125129
void visit (AST::ReferenceType &ref) override;
126130

127131
void visit (AST::TypePathSegmentGeneric &seg) override;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// { dg-additional-options "-w" }
2+
impl<T> *const T {
3+
fn test(self) {}
4+
}

0 commit comments

Comments
 (0)