Skip to content

Commit dbe59a3

Browse files
bors[bot]philberty
andauthored
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 <[email protected]>
2 parents ddd087b + 31413eb commit dbe59a3

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)