Skip to content

Commit

Permalink
Merge #1007
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bors[bot] and philberty authored Mar 11, 2022
2 parents ddd087b + 31413eb commit dbe59a3
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
39 changes: 39 additions & 0 deletions gcc/rust/resolve/rust-ast-resolve-type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
4 changes: 4 additions & 0 deletions gcc/rust/resolve/rust-ast-resolve-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ class ResolveTypeToCanonicalPath : public ResolverBase
}
}

void visit (AST::SliceType &slice) override;

void visit (AST::RawPointerType &ptr) override;

void visit (AST::ReferenceType &ref) override;

void visit (AST::TypePathSegmentGeneric &seg) override;
Expand Down
4 changes: 4 additions & 0 deletions gcc/testsuite/rust/compile/issue-1005.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// { dg-additional-options "-w" }
impl<T> *const T {
fn test(self) {}
}

0 comments on commit dbe59a3

Please sign in to comment.