Skip to content

Commit

Permalink
ast-collector: Adapt to lang item type path segments
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): Fix collector to better
	handle lang item type path segments.
  • Loading branch information
CohenArthur committed Jan 16, 2025
1 parent 72f469e commit 5c04d4e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions gcc/rust/ast/rust-ast-collector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,14 @@ TokenCollector::visit (TypePathSegment &segment)
{
// Syntax:
// PathIdentSegment
auto ident_segment = segment.get_ident_segment ();
auto id = ident_segment.as_string ();
push (
Rust::Token::make_identifier (ident_segment.get_locus (), std::move (id)));

auto locus = segment.is_lang_item ()
? segment.get_locus ()
: segment.get_ident_segment ().get_locus ();
auto segment_string = segment.is_lang_item ()
? LangItem::PrettyString (segment.get_lang_item ())
: segment.get_ident_segment ().as_string ();
push (Rust::Token::make_identifier (locus, std::move (segment_string)));
}

void
Expand All @@ -558,10 +562,13 @@ TokenCollector::visit (TypePathSegmentGeneric &segment)
// `<` `>`
// | `<` ( GenericArg `,` )* GenericArg `,`? `>`

auto ident_segment = segment.get_ident_segment ();
auto id = ident_segment.as_string ();
push (
Rust::Token::make_identifier (ident_segment.get_locus (), std::move (id)));
auto locus = segment.is_lang_item ()
? segment.get_locus ()
: segment.get_ident_segment ().get_locus ();
auto segment_string = segment.is_lang_item ()
? LangItem::PrettyString (segment.get_lang_item ())
: segment.get_ident_segment ().as_string ();
push (Rust::Token::make_identifier (locus, std::move (segment_string)));

if (segment.get_separating_scope_resolution ())
push (Rust::Token::make (SCOPE_RESOLUTION, UNDEF_LOCATION));
Expand Down

0 comments on commit 5c04d4e

Please sign in to comment.