public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7701] gccrs: ast: Change Identifier definition
@ 2024-01-16 17:55 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 17:55 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:fcb228d1232820a1fbf63f9f366630067a13a432

commit r14-7701-gfcb228d1232820a1fbf63f9f366630067a13a432
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Tue Jun 27 11:22:00 2023 +0200

    gccrs: ast: Change Identifier definition
    
    Change Identifier type definition from a simple typedef to a whole class
    with it's own node id.
    
    gcc/rust/ChangeLog:
    
            * ast/rust-ast-collector.cc (TokenCollector::visit): Change with
            call to getter.
            * ast/rust-ast.cc (Module::as_string): Likewise.
            (StaticItem::as_string): Likewise.
            (TupleStruct::as_string): Likewise.
            (Method::as_string): Likewise.
            (StructStruct::as_string): Likewise.
            (UseTreeRebind::as_string): Likewise.
            (Enum::as_string): Likewise.
            (Trait::as_string): Likewise.
            (Union::as_string): Likewise.
            (Function::as_string): Likewise.
            (TypeAlias::as_string): Likewise.
            (MacroRulesDefinition::as_string): Likewise.
            (FieldAccessExpr::as_string): Likewise.
            (MacroMatchFragment::as_string): Likewise.
            (TypeParam::as_string): Likewise.
            (StructExprFieldIdentifierValue::as_string): Likewise.
            (EnumItem::as_string): Likewise.
            (StructField::as_string): Likewise.
            (ExternalTypeItem::as_string): Likewise.
            (ExternalStaticItem::as_string): Likewise.
            (ExternalFunctionItem::as_string): Likewise.
            (TraitFunctionDecl::as_string): Likewise.
            (TraitMethodDecl::as_string): Likewise.
            (TraitItemConst::as_string): Likewise.
            (TraitItemType::as_string): Likewise.
            (MaybeNamedParam::as_string): Likewise.
            (MetaListPaths::as_string): Likewise.
            (MetaListNameValueStr::as_string): Likewise.
            (Module::process_file_path): Likewise.
            (MetaListNameValueStr::check_cfg_predicate): Likewise.
            (MetaListPaths::check_cfg_predicate): Likewise.
            (MetaWord::check_cfg_predicate): Likewise.
            (MetaNameValueStr::check_cfg_predicate): Likewise.
            (MetaNameValueStr::to_attribute): Likewise.
            (MetaWord::to_attribute): Likewise.
            (MetaListPaths::to_attribute): Likewise.
            (MetaListNameValueStr::to_attribute): Likewise.
            (operator<<): Change Identifier class <<
            operator overload for standard output stream.
            * ast/rust-ast.h (class Identifier): Change typedef to proper
            class definition.
            (operator<<): Add prototype for operator overload.
            (class Token): Change getter identifier.
            (class MetaListNameValueStr): Likewise.
            (class PathExpr): Likewise.
            * ast/rust-expr.h: Likewise.
            * ast/rust-item.h: Likewise.
            * ast/rust-macro.h: Likewise.
            * ast/rust-path.cc (GenericArg::disambiguate_to_type): Likewise.
            (GenericArgsBinding::as_string): Likewise.
            (ConstGenericParam::as_string): Likewise.
            * ast/rust-path.h: Likewise.
            * ast/rust-pattern.cc (IdentifierPattern::as_string): Likewise.
            (StructPatternFieldIdentPat::as_string): Likewise.
            (StructPatternFieldIdent::as_string): Likewise.
            * ast/rust-type.h: Likewise.
            * backend/rust-compile-base.cc: Likewise.
            * backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
            * backend/rust-compile-extern.h: Likewise.
            * backend/rust-compile-fnparam.cc (CompileFnParam::visit):
            Likewise.
            * backend/rust-compile-implitem.cc (CompileTraitItem::visit):
            Likewise.
            * backend/rust-compile-item.cc (CompileItem::visit): Likewise.
            * backend/rust-compile-pattern.cc (CompilePatternBindings::visit): Likewise.
            * backend/rust-compile-struct-field-expr.cc (CompileStructExprField::visit):
            Likewise.
            * backend/rust-compile-var-decl.h: Likewise.
            * backend/rust-compile.cc: Likewise.
            * checks/errors/rust-unsafe-checker.cc (check_extern_call):
            Likewise.
            * checks/lints/rust-lint-marklive.cc (MarkLive::visit):
            Likewise.
            * checks/lints/rust-lint-scan-deadcode.h: Likewise.
            * expand/rust-derive-clone.cc (DeriveClone::clone_fn): Likewise.
            (DeriveClone::visit_tuple): Likewise.
            (DeriveClone::visit_struct): Likewise.
            (DeriveClone::visit_union): Likewise.
            * expand/rust-derive-copy.cc (DeriveCopy::visit_struct):
            Likewise.
            (DeriveCopy::visit_tuple): Likewise.
            (DeriveCopy::visit_enum): Likewise.
            (DeriveCopy::visit_union): Likewise.
            * expand/rust-macro-expand.cc (MacroExpander::match_matcher):
            Likewise.
            (MacroExpander::match_n_matches): Likewise.
            (MacroExpander::match_repetition): Likewise.
            (MacroExpander::match_repetition_skipped_metavars): Likewise.
            * hir/rust-ast-lower-base.cc (struct_field_name_exists):
            Likewise.
            * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
            * hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit):
            Likewise.
            * hir/rust-hir-dump.cc (Dump::visit): Likewise.
            * hir/tree/rust-hir-expr.h: Likewise.
            * hir/tree/rust-hir-item.h: Likewise.
            * hir/tree/rust-hir-path.h: Likewise.
            * hir/tree/rust-hir-type.h: Likewise.
            * hir/tree/rust-hir.cc (Module::as_string): Likewise.
            (StaticItem::as_string): Likewise.
            (TupleStruct::as_string): Likewise.
            (ConstantItem::as_string): Likewise.
            (StructStruct::as_string): Likewise.
            (UseTreeRebind::as_string): Likewise.
            (Enum::as_string): Likewise.
            (Trait::as_string): Likewise.
            (Union::as_string): Likewise.
            (Function::as_string): Likewise.
            (TypeAlias::as_string): Likewise.
            (FieldAccessExpr::as_string): Likewise.
            (TypeParam::as_string): Likewise.
            (GenericArgsBinding::as_string): Likewise.
            (StructPatternFieldIdent::as_string): Likewise.
            (StructPatternFieldIdentPat::as_string): Likewise.
            (IdentifierPattern::as_string): Likewise.
            (StructExprFieldIdentifierValue::as_string): Likewise.
            (EnumItem::as_string): Likewise.
            (StructField::as_string): Likewise.
            (ExternalStaticItem::as_string): Likewise.
            (ExternalFunctionItem::as_string): Likewise.
            (NamedFunctionParam::as_string): Likewise.
            (TraitFunctionDecl::as_string): Likewise.
            (TraitItemConst::as_string): Likewise.
            (TraitItemType::as_string): Likewise.
            (MaybeNamedParam::as_string): Likewise.
            * hir/tree/rust-hir.h: Likewise.
            * parse/rust-parse-impl.h (Parser::parse_macro_match_fragment):
            Likewise.
            (Parser::parse_module): Likewise.
            (Parser::parse_use_tree): Likewise.
            (Parser::parse_maybe_named_param): Likewise.
            * resolve/rust-ast-resolve-implitem.h: Likewise.
            * resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit):
            Likewise.
            (ResolveItem::visit): Likewise.
            (flatten_rebind): Likewise.
            (ResolveExternItem::visit): Likewise.
            (rust_flatten_rebind): Likewise.
            (rust_flatten_rebind_nested): Likewise.
            * resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::go):
            Likewise.
            (PatternDeclaration::visit): Likewise.
            (PatternDeclaration::add_new_binding): Likewise.
            * resolve/rust-ast-resolve-stmt.h: Likewise.
            * resolve/rust-ast-resolve-toplevel.h: Likewise.
            * resolve/rust-ast-resolve-type.h: Likewise.
            * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise.
            * typecheck/rust-autoderef.cc: Likewise.
            * typecheck/rust-hir-dot-operator.cc (MethodResolver::select):
            Likewise.
            * typecheck/rust-hir-path-probe.cc (PathProbeType::visit):
            Likewise.
            * typecheck/rust-hir-trait-reference.cc (TraitReference::get_name): Likewise.
            * typecheck/rust-hir-trait-resolve.cc (ResolveTraitItemToRef::visit): Likewise.
            (TraitResolver::resolve_trait): Likewise.
            (TraitItemReference::resolve_item): Likewise.
            (AssociatedImplTrait::setup_raw_associated_types): Likewise.
            * typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit): Likewise.
            * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
            Likewise.
            * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): Likewise.
            (TypeCheckImplItem::visit): Likewise.
            (TypeCheckImplItemWithTrait::visit): Likewise.
            * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
            Likewise.
            * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise.
            * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::visit): Likewise.
            * typecheck/rust-hir-type-check-type.cc (TypeResolveGenericParam::visit): Likewise.
            * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise.
            * typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args): Likewise.
            * util/rust-attributes.cc (check_doc_attribute): Likewise.
            * util/rust-hir-map.cc (Mappings::insert_macro_def): Likewise.
    
    Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>

Diff:
---
 gcc/rust/ast/rust-ast-collector.cc                 |  78 ++++-----
 gcc/rust/ast/rust-ast.cc                           | 114 +++++++------
 gcc/rust/ast/rust-ast.h                            | 115 ++++++++-----
 gcc/rust/ast/rust-expr.h                           |   4 +-
 gcc/rust/ast/rust-item.h                           |  22 +--
 gcc/rust/ast/rust-macro.h                          |   6 +-
 gcc/rust/ast/rust-path.cc                          |   6 +-
 gcc/rust/ast/rust-path.h                           |  13 +-
 gcc/rust/ast/rust-pattern.cc                       |   6 +-
 gcc/rust/ast/rust-type.h                           |   2 +-
 gcc/rust/backend/rust-compile-base.cc              |   6 +-
 gcc/rust/backend/rust-compile-expr.cc              |   8 +-
 gcc/rust/backend/rust-compile-extern.h             |   6 +-
 gcc/rust/backend/rust-compile-fnparam.cc           |   6 +-
 gcc/rust/backend/rust-compile-implitem.cc          |   4 +-
 gcc/rust/backend/rust-compile-item.cc              |   2 +-
 gcc/rust/backend/rust-compile-pattern.cc           |   4 +-
 gcc/rust/backend/rust-compile-struct-field-expr.cc |   2 +-
 gcc/rust/backend/rust-compile-var-decl.h           |   7 +-
 gcc/rust/backend/rust-compile.cc                   |   3 +-
 gcc/rust/checks/errors/rust-unsafe-checker.cc      |   2 +-
 gcc/rust/checks/lints/rust-lint-marklive.cc        |   5 +-
 gcc/rust/checks/lints/rust-lint-scan-deadcode.h    |  22 +--
 gcc/rust/expand/rust-derive-clone.cc               |  25 +--
 gcc/rust/expand/rust-derive-copy.cc                |   8 +-
 gcc/rust/expand/rust-macro-expand.cc               |  14 +-
 gcc/rust/hir/rust-ast-lower-base.cc                |   6 +-
 gcc/rust/hir/rust-ast-lower-expr.cc                |   2 +-
 gcc/rust/hir/rust-ast-lower-type.cc                |   2 +-
 gcc/rust/hir/rust-hir-dump.cc                      |   4 +-
 gcc/rust/hir/tree/rust-hir-expr.h                  |   2 +-
 gcc/rust/hir/tree/rust-hir-item.h                  |  27 ++-
 gcc/rust/hir/tree/rust-hir-path.h                  |   2 +-
 gcc/rust/hir/tree/rust-hir-type.h                  |   2 +-
 gcc/rust/hir/tree/rust-hir.cc                      |  55 +++---
 gcc/rust/hir/tree/rust-hir.h                       |   1 -
 gcc/rust/parse/rust-parse-impl.h                   |  14 +-
 gcc/rust/resolve/rust-ast-resolve-implitem.h       |  34 ++--
 gcc/rust/resolve/rust-ast-resolve-item.cc          |  84 +++++-----
 gcc/rust/resolve/rust-ast-resolve-pattern.cc       |  16 +-
 gcc/rust/resolve/rust-ast-resolve-stmt.h           |  37 +++--
 gcc/rust/resolve/rust-ast-resolve-toplevel.h       |  58 ++++---
 gcc/rust/resolve/rust-ast-resolve-type.h           |   5 +-
 gcc/rust/resolve/rust-early-name-resolver.cc       |   4 +-
 gcc/rust/typecheck/rust-autoderef.cc               |   4 +-
 gcc/rust/typecheck/rust-hir-dot-operator.cc        | 184 +++++++++++----------
 gcc/rust/typecheck/rust-hir-path-probe.cc          |   6 +-
 gcc/rust/typecheck/rust-hir-trait-reference.cc     |   2 +-
 gcc/rust/typecheck/rust-hir-trait-resolve.cc       |  21 ++-
 gcc/rust/typecheck/rust-hir-type-check-enumitem.cc |  13 +-
 gcc/rust/typecheck/rust-hir-type-check-expr.cc     |   9 +-
 gcc/rust/typecheck/rust-hir-type-check-implitem.cc |  54 +++---
 gcc/rust/typecheck/rust-hir-type-check-item.cc     |  52 +++---
 gcc/rust/typecheck/rust-hir-type-check-pattern.cc  |  16 +-
 gcc/rust/typecheck/rust-hir-type-check-struct.cc   |  17 +-
 gcc/rust/typecheck/rust-hir-type-check-type.cc     |  10 +-
 gcc/rust/typecheck/rust-hir-type-check.cc          |  12 +-
 gcc/rust/typecheck/rust-tyty-subst.cc              |  13 +-
 gcc/rust/util/rust-attributes.cc                   |   2 +-
 gcc/rust/util/rust-hir-map.cc                      |   9 +-
 60 files changed, 689 insertions(+), 580 deletions(-)

diff --git a/gcc/rust/ast/rust-ast-collector.cc b/gcc/rust/ast/rust-ast-collector.cc
index e2618497980..d851066373e 100644
--- a/gcc/rust/ast/rust-ast-collector.cc
+++ b/gcc/rust/ast/rust-ast-collector.cc
@@ -296,7 +296,7 @@ TokenCollector::visit (StructField &field)
       visit (attr);
     }
   visit (field.get_visibility ());
-  auto name = field.get_field_name ();
+  auto name = field.get_field_name ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (field.get_locus (), std::move (name)));
   tokens.push_back (Rust::Token::make (COLON, Location ()));
@@ -358,7 +358,7 @@ TokenCollector::visit (MaybeNamedParam &param)
     {
       visit (attr);
     }
-  auto param_name = param.get_name ();
+  auto param_name = param.get_name ().as_string ();
   switch (param.get_param_kind ())
     {
     case MaybeNamedParam::UNNAMED:
@@ -458,7 +458,7 @@ TokenCollector::visit (AttrInputMetaItemContainer &container)
 void
 TokenCollector::visit (IdentifierExpr &ident_expr)
 {
-  auto ident = ident_expr.get_ident ();
+  auto ident = ident_expr.get_ident ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (ident_expr.get_locus (), std::move (ident)));
 }
@@ -520,7 +520,7 @@ TokenCollector::visit (ConstGenericParam &param)
   // const IDENTIFIER : Type ( = Block | IDENTIFIER | -?LITERAL )?
 
   tokens.push_back (Rust::Token::make (CONST, param.get_locus ()));
-  auto id = param.get_name ();
+  auto id = param.get_name ().as_string ();
   tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
   tokens.push_back (Rust::Token::make (COLON, Location ()));
   visit (param.get_type ());
@@ -632,7 +632,7 @@ TokenCollector::visit (GenericArgsBinding &binding)
 {
   // Syntax:
   //    IDENTIFIER `=` Type
-  auto identifier = binding.get_identifier ();
+  auto identifier = binding.get_identifier ().as_string ();
   tokens.push_back (Rust::Token::make_identifier (binding.get_locus (),
 						  std::move (identifier)));
 
@@ -1128,7 +1128,7 @@ TokenCollector::visit (StructExprFieldIdentifier &expr)
 {
   // TODO: Add attributes
   // visit_items_as_lines (expr.get_attrs ());
-  auto id = expr.get_field_name ();
+  auto id = expr.get_field_name ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (expr.get_locus (), std::move (id)));
 }
@@ -1217,7 +1217,7 @@ TokenCollector::visit (FieldAccessExpr &expr)
 {
   visit (expr.get_receiver_expr ());
   tokens.push_back (Rust::Token::make (DOT, expr.get_locus ()));
-  auto field_name = expr.get_field_name ();
+  auto field_name = expr.get_field_name ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (Location (), std::move (field_name)));
 }
@@ -1524,7 +1524,7 @@ TokenCollector::visit (TypeParam &param)
   // TypeParamBounds :
   //    TypeParamBound ( + TypeParamBound )* +?
 
-  auto id = param.get_type_representation ();
+  auto id = param.get_type_representation ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (param.get_locus (), std::move (id)));
   if (param.has_type_param_bounds ())
@@ -1591,7 +1591,7 @@ void
 TokenCollector::visit (Method &method)
 {
   visit (method.get_visibility ());
-  auto method_name = method.get_method_name ();
+  auto method_name = method.get_method_name ().as_string ();
   tokens.push_back (Rust::Token::make (FN_TOK, method.get_locus ()));
   tokens.push_back (
     Rust::Token::make_identifier (Location (), std::move (method_name)));
@@ -1632,7 +1632,7 @@ TokenCollector::visit (Module &module)
 
   visit_items_as_lines (module.get_outer_attrs ());
   visit (module.get_visibility ());
-  auto name = module.get_name ();
+  auto name = module.get_name ().as_string ();
   tokens.push_back (Rust::Token::make (MOD, module.get_locus ()));
   tokens.push_back (
     Rust::Token::make_identifier (Location (), std::move (name)));
@@ -1733,7 +1733,7 @@ TokenCollector::visit (UseTreeRebind &use_tree)
     {
       case UseTreeRebind::NewBindType::IDENTIFIER: {
 	tokens.push_back (Rust::Token::make (AS, Location ()));
-	auto id = use_tree.get_identifier ();
+	auto id = use_tree.get_identifier ().as_string ();
 	tokens.push_back (
 	  Rust::Token::make_identifier (use_tree.get_locus (), std::move (id)));
       }
@@ -1770,7 +1770,7 @@ TokenCollector::visit (Function &function)
   visit (function.get_visibility ());
 
   tokens.push_back (Rust::Token::make (FN_TOK, function.get_locus ()));
-  auto name = function.get_function_name ();
+  auto name = function.get_function_name ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (Location (), std::move (name)));
   if (function.has_generics ())
@@ -1808,7 +1808,7 @@ TokenCollector::visit (TypeAlias &type_alias)
   visit_items_as_lines (type_alias.get_outer_attrs ());
   if (type_alias.has_visibility ())
     visit (type_alias.get_visibility ());
-  auto alias_name = type_alias.get_new_type_name ();
+  auto alias_name = type_alias.get_new_type_name ().as_string ();
   tokens.push_back (Rust::Token::make (TYPE, type_alias.get_locus ()));
   tokens.push_back (
     Rust::Token::make_identifier (Location (), std::move (alias_name)));
@@ -1827,7 +1827,7 @@ TokenCollector::visit (StructStruct &struct_item)
   visit_items_as_lines (struct_item.get_outer_attrs ());
   if (struct_item.has_visibility ())
     visit (struct_item.get_visibility ());
-  auto struct_name = struct_item.get_identifier ();
+  auto struct_name = struct_item.get_identifier ().as_string ();
   tokens.push_back (Rust::Token::make (STRUCT_TOK, struct_item.get_locus ()));
   tokens.push_back (
     Rust::Token::make_identifier (Location (), std::move (struct_name)));
@@ -1850,7 +1850,7 @@ void
 TokenCollector::visit (TupleStruct &tuple_struct)
 {
   visit_items_as_lines (tuple_struct.get_outer_attrs ());
-  auto struct_name = tuple_struct.get_identifier ();
+  auto struct_name = tuple_struct.get_identifier ().as_string ();
   tokens.push_back (Rust::Token::make (STRUCT_TOK, tuple_struct.get_locus ()));
   tokens.push_back (
     Rust::Token::make_identifier (Location (), std::move (struct_name)));
@@ -1870,7 +1870,7 @@ void
 TokenCollector::visit (EnumItem &item)
 {
   visit_items_as_lines (item.get_outer_attrs ());
-  auto id = item.get_identifier ();
+  auto id = item.get_identifier ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (item.get_locus (), std::move (id)));
 }
@@ -1878,7 +1878,7 @@ TokenCollector::visit (EnumItem &item)
 void
 TokenCollector::visit (EnumItemTuple &item)
 {
-  auto id = item.get_identifier ();
+  auto id = item.get_identifier ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (item.get_locus (), std::move (id)));
   tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ()));
@@ -1889,7 +1889,7 @@ TokenCollector::visit (EnumItemTuple &item)
 void
 TokenCollector::visit (EnumItemStruct &item)
 {
-  auto id = item.get_identifier ();
+  auto id = item.get_identifier ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (item.get_locus (), std::move (id)));
   visit_items_as_block (item.get_struct_fields (),
@@ -1899,7 +1899,7 @@ TokenCollector::visit (EnumItemStruct &item)
 void
 TokenCollector::visit (EnumItemDiscriminant &item)
 {
-  auto id = item.get_identifier ();
+  auto id = item.get_identifier ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (item.get_locus (), std::move (id)));
   tokens.push_back (Rust::Token::make (EQUAL, Location ()));
@@ -1913,7 +1913,7 @@ TokenCollector::visit (Enum &enumeration)
   if (enumeration.has_visibility ())
     visit (enumeration.get_visibility ());
   tokens.push_back (Rust::Token::make (ENUM_TOK, enumeration.get_locus ()));
-  auto id = enumeration.get_identifier ();
+  auto id = enumeration.get_identifier ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (enumeration.get_locus (), std::move (id)));
   if (enumeration.has_generics ())
@@ -1929,7 +1929,7 @@ void
 TokenCollector::visit (Union &union_item)
 {
   visit_items_as_lines (union_item.get_outer_attrs ());
-  auto id = union_item.get_identifier ();
+  auto id = union_item.get_identifier ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (union_item.get_locus (), "union"));
   tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
@@ -1974,7 +1974,7 @@ TokenCollector::visit (StaticItem &item)
   tokens.push_back (Rust::Token::make (STATIC_TOK, item.get_locus ()));
   if (item.is_mutable ())
     tokens.push_back (Rust::Token::make (MUT, Location ()));
-  auto id = item.get_identifier ();
+  auto id = item.get_identifier ().as_string ();
   tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
   tokens.push_back (Rust::Token::make (COLON, Location ()));
   visit (item.get_type ());
@@ -2012,7 +2012,7 @@ void
 TokenCollector::visit (TraitItemFunc &item)
 {
   auto func = item.get_trait_function_decl ();
-  auto id = func.get_identifier ();
+  auto id = func.get_identifier ().as_string ();
   tokens.push_back (Rust::Token::make (FN_TOK, item.get_locus ()));
   tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
   tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ()));
@@ -2049,7 +2049,7 @@ void
 TokenCollector::visit (TraitItemMethod &item)
 {
   auto method = item.get_trait_method_decl ();
-  auto id = method.get_identifier ();
+  auto id = method.get_identifier ().as_string ();
 
   tokens.push_back (Rust::Token::make (FN_TOK, item.get_locus ()));
   tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
@@ -2071,7 +2071,7 @@ TokenCollector::visit (TraitItemMethod &item)
 void
 TokenCollector::visit (TraitItemConst &item)
 {
-  auto id = item.get_identifier ();
+  auto id = item.get_identifier ().as_string ();
   indentation ();
   tokens.push_back (Rust::Token::make (CONST, item.get_locus ()));
   tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
@@ -2084,7 +2084,7 @@ TokenCollector::visit (TraitItemConst &item)
 void
 TokenCollector::visit (TraitItemType &item)
 {
-  auto id = item.get_identifier ();
+  auto id = item.get_identifier ().as_string ();
   indentation ();
   tokens.push_back (Rust::Token::make (TYPE, item.get_locus ()));
   tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
@@ -2104,7 +2104,7 @@ TokenCollector::visit (Trait &trait)
 
   visit (trait.get_visibility ());
 
-  auto id = trait.get_identifier ();
+  auto id = trait.get_identifier ().as_string ();
   tokens.push_back (Rust::Token::make (TRAIT, trait.get_locus ()));
   tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
 
@@ -2168,7 +2168,7 @@ TokenCollector::visit (ExternalTypeItem &type)
 {
   visit (type.get_visibility ());
 
-  auto id = type.get_identifier ();
+  auto id = type.get_identifier ().as_string ();
   tokens.push_back (Rust::Token::make (TYPE, Location ()));
   tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
   tokens.push_back (Rust::Token::make (SEMICOLON, Location ()));
@@ -2177,7 +2177,7 @@ TokenCollector::visit (ExternalTypeItem &type)
 void
 TokenCollector::visit (ExternalStaticItem &item)
 {
-  auto id = item.get_identifier ();
+  auto id = item.get_identifier ().as_string ();
   visit_items_as_lines (item.get_outer_attrs ());
   if (item.has_visibility ())
     visit (item.get_visibility ());
@@ -2197,7 +2197,7 @@ TokenCollector::visit (ExternalFunctionItem &function)
 {
   visit (function.get_visibility ());
 
-  auto id = function.get_identifier ();
+  auto id = function.get_identifier ().as_string ();
   tokens.push_back (Rust::Token::make (FN_TOK, function.get_locus ()));
   tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
   tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ()));
@@ -2247,7 +2247,7 @@ get_delimiters (DelimType delim)
 void
 TokenCollector::visit (MacroMatchFragment &match)
 {
-  auto id = match.get_ident ();
+  auto id = match.get_ident ().as_string ();
   auto frag_spec = match.get_frag_spec ().as_string ();
   tokens.push_back (Rust::Token::make (DOLLAR_SIGN, Location ()));
   tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
@@ -2318,7 +2318,7 @@ TokenCollector::visit (MacroRulesDefinition &rules_def)
   for (auto &outer_attr : rules_def.get_outer_attrs ())
     visit (outer_attr);
 
-  auto rule_name = rules_def.get_rule_name ();
+  auto rule_name = rules_def.get_rule_name ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (rules_def.get_locus (), "macro_rules"));
   tokens.push_back (Rust::Token::make (EXCLAM, Location ()));
@@ -2361,7 +2361,7 @@ TokenCollector::visit (MetaItemSeq &item)
 void
 TokenCollector::visit (MetaWord &word)
 {
-  auto id = word.get_ident ();
+  auto id = word.get_ident ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (word.get_locus (), std::move (id)));
 }
@@ -2370,7 +2370,7 @@ void
 TokenCollector::visit (MetaNameValueStr &name)
 {
   auto pair = name.get_name_value_pair ();
-  auto id = std::get<0> (pair);
+  auto id = std::get<0> (pair).as_string ();
   auto value = std::get<1> (pair);
   tokens.push_back (
     Rust::Token::make_identifier (name.get_locus (), std::move (id)));
@@ -2384,7 +2384,7 @@ TokenCollector::visit (MetaNameValueStr &name)
 void
 TokenCollector::visit (MetaListPaths &list)
 {
-  auto id = list.get_ident ();
+  auto id = list.get_ident ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (list.get_locus (), std::move (id)));
   tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ()));
@@ -2395,7 +2395,7 @@ TokenCollector::visit (MetaListPaths &list)
 void
 TokenCollector::visit (MetaListNameValueStr &list)
 {
-  auto id = list.get_ident ();
+  auto id = list.get_ident ().as_string ();
   tokens.push_back (
     Rust::Token::make_identifier (list.get_locus (), std::move (id)));
   tokens.push_back (Rust::Token::make (LEFT_PAREN, Location ()));
@@ -2421,7 +2421,7 @@ TokenCollector::visit (IdentifierPattern &pattern)
     {
       tokens.push_back (Rust::Token::make (MUT, Location ()));
     }
-  auto id = pattern.get_ident ();
+  auto id = pattern.get_ident ().as_string ();
   tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
   if (pattern.has_pattern_to_bind ())
     {
@@ -2528,7 +2528,7 @@ void
 TokenCollector::visit (StructPatternFieldIdentPat &pattern)
 {
   visit_items_as_lines (pattern.get_outer_attrs ());
-  auto id = pattern.get_identifier ();
+  auto id = pattern.get_identifier ().as_string ();
   tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
   tokens.push_back (Rust::Token::make (COLON, pattern.get_locus ()));
   visit (pattern.get_ident_pattern ());
@@ -2543,7 +2543,7 @@ TokenCollector::visit (StructPatternFieldIdent &pattern)
   if (pattern.is_mut ())
     tokens.push_back (Rust::Token::make (MUT, Location ()));
 
-  auto id = pattern.get_identifier ();
+  auto id = pattern.get_identifier ().as_string ();
   tokens.push_back (Rust::Token::make_identifier (Location (), std::move (id)));
 }
 
diff --git a/gcc/rust/ast/rust-ast.cc b/gcc/rust/ast/rust-ast.cc
index 14ad3a05620..24e719c1e4a 100644
--- a/gcc/rust/ast/rust-ast.cc
+++ b/gcc/rust/ast/rust-ast.cc
@@ -251,7 +251,7 @@ VisItem::as_string () const
 std::string
 Module::as_string () const
 {
-  std::string str = VisItem::as_string () + "mod " + module_name;
+  std::string str = VisItem::as_string () + "mod " + module_name.as_string ();
 
   // Return early if we're dealing with an unloaded module as their body resides
   // in a different file
@@ -298,7 +298,7 @@ StaticItem::as_string () const
   if (has_mut)
     str += " mut";
 
-  str += " " + name;
+  str += " " + name.as_string ();
 
   // DEBUG: null pointer check
   if (type == nullptr)
@@ -339,7 +339,7 @@ TupleStruct::as_string () const
 {
   std::string str = VisItem::as_string ();
 
-  str += "struct " + struct_name;
+  str += "struct " + struct_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -476,7 +476,7 @@ Method::as_string () const
 
   str += vis.as_string () + " " + qualifiers.as_string ();
 
-  str += " fn " + method_name;
+  str += " fn " + method_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -537,7 +537,7 @@ StructStruct::as_string () const
 {
   std::string str = VisItem::as_string ();
 
-  str += "struct " + struct_name;
+  str += "struct " + struct_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -686,7 +686,7 @@ UseTreeRebind::as_string () const
       // nothing to add, just path
       break;
     case IDENTIFIER:
-      path_str += " as " + identifier;
+      path_str += " as " + identifier.as_string ();
       break;
     case WILDCARD:
       path_str += " as _";
@@ -703,7 +703,7 @@ std::string
 Enum::as_string () const
 {
   std::string str = VisItem::as_string ();
-  str += enum_name;
+  str += enum_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -768,7 +768,7 @@ Trait::as_string () const
   if (has_unsafe)
     str += "unsafe ";
 
-  str += "trait " + name;
+  str += "trait " + name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -851,7 +851,7 @@ Union::as_string () const
 {
   std::string str = VisItem::as_string ();
 
-  str += "union " + union_name;
+  str += "union " + union_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -923,7 +923,7 @@ Function::as_string () const
       str += "void ";
     }
 
-  str += function_name;
+  str += function_name.as_string ();
 
   if (has_generics ())
     {
@@ -1110,7 +1110,7 @@ TypeAlias::as_string () const
 {
   std::string str = VisItem::as_string ();
 
-  str += " " + new_type_name;
+  str += " " + new_type_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -1192,7 +1192,7 @@ MacroRulesDefinition::as_string () const
   // TODO: deal with macro_2_0
   str += "macro_rules!";
 
-  str += rule_name;
+  str += rule_name.as_string ();
 
   str += "\n Macro rules: ";
   if (rules.empty ())
@@ -1559,7 +1559,7 @@ std::string
 FieldAccessExpr::as_string () const
 {
   // TODO: rewrite dump to better reflect non-literal exprs
-  return receiver->as_string () + "." + field;
+  return receiver->as_string () + "." + field.as_string ();
 }
 
 std::string
@@ -2179,7 +2179,7 @@ LifetimeParam::as_string () const
 std::string
 MacroMatchFragment::as_string () const
 {
-  return "$" + ident + ": " + frag_spec.as_string ();
+  return "$" + ident.as_string () + ": " + frag_spec.as_string ();
 }
 
 std::string
@@ -2256,7 +2256,7 @@ TypeParam::as_string () const
   else
     str += outer_attr.as_string ();
 
-  str += "\n Identifier: " + type_representation;
+  str += "\n Identifier: " + type_representation.as_string ();
 
   str += "\n Type param bounds: ";
   if (!has_type_param_bounds ())
@@ -2565,7 +2565,7 @@ std::string
 StructExprFieldIdentifierValue::as_string () const
 {
   // TODO: rewrite to work with non-linearisable exprs
-  return field_name + " : " + StructExprFieldWithVal::as_string ();
+  return field_name.as_string () + " : " + StructExprFieldWithVal::as_string ();
 }
 
 std::string
@@ -2604,7 +2604,7 @@ std::string
 EnumItem::as_string () const
 {
   std::string str = VisItem::as_string ();
-  str += variant_name;
+  str += variant_name.as_string ();
 
   return str;
 }
@@ -2691,7 +2691,7 @@ StructField::as_string () const
   if (has_visibility ())
     str += "\n" + visibility.as_string ();
 
-  str += " " + field_name + " : " + field_type->as_string ();
+  str += " " + field_name.as_string () + " : " + field_type->as_string ();
 
   return str;
 }
@@ -2713,7 +2713,7 @@ ExternalTypeItem::as_string () const
 {
   auto str = append_attributes (outer_attrs, OUTER);
 
-  str += "type " + item_name + ";";
+  str += "type " + item_name.as_string () + ";";
 
   return str;
 }
@@ -2733,7 +2733,7 @@ ExternalStaticItem::as_string () const
     str += "mut ";
 
   // add name
-  str += item_name;
+  str += item_name.as_string ();
 
   // add type on new line
   str += "\n Type: " + item_type->as_string ();
@@ -2753,7 +2753,7 @@ ExternalFunctionItem::as_string () const
   str += "fn ";
 
   // add name
-  str += item_name;
+  str += item_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -2850,7 +2850,8 @@ TraitItemFunc::as_string () const
 std::string
 TraitFunctionDecl::as_string () const
 {
-  std::string str = qualifiers.as_string () + "fn " + function_name;
+  std::string str
+    = qualifiers.as_string () + "fn " + function_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -2920,7 +2921,8 @@ TraitItemMethod::as_string () const
 std::string
 TraitMethodDecl::as_string () const
 {
-  std::string str = qualifiers.as_string () + "fn " + function_name;
+  std::string str
+    = qualifiers.as_string () + "fn " + function_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -2979,7 +2981,7 @@ TraitItemConst::as_string () const
   // TODO: rewrite to work with non-linearisable exprs
   std::string str = append_attributes (outer_attrs, OUTER);
 
-  str += "\nconst " + name + " : " + type->as_string ();
+  str += "\nconst " + name.as_string () + " : " + type->as_string ();
 
   if (has_expression ())
     str += " = " + expr->as_string ();
@@ -2992,7 +2994,7 @@ TraitItemType::as_string () const
 {
   std::string str = append_attributes (outer_attrs, OUTER);
 
-  str += "\ntype " + name;
+  str += "\ntype " + name.as_string ();
 
   str += "\n Type param bounds: ";
   if (!has_type_param_bounds ())
@@ -3167,7 +3169,7 @@ MaybeNamedParam::as_string () const
     case UNNAMED:
       break;
     case IDENTIFIER:
-      str = name + " : ";
+      str = name.as_string () + " : ";
       break;
     case WILDCARD:
       str = "_ : ";
@@ -3216,7 +3218,7 @@ MetaItemSeq::as_string () const
 std::string
 MetaListPaths::as_string () const
 {
-  std::string str = ident + "(";
+  std::string str = ident.as_string () + "(";
 
   auto i = paths.begin ();
   auto e = paths.end ();
@@ -3234,7 +3236,7 @@ MetaListPaths::as_string () const
 std::string
 MetaListNameValueStr::as_string () const
 {
-  std::string str = ident + "(";
+  std::string str = ident.as_string () + "(";
 
   auto i = strs.begin ();
   auto e = strs.end ();
@@ -3313,7 +3315,7 @@ Module::process_file_path ()
   // file that contains the 'mod <file>;' directive
   std::string including_fpath (outer_filename);
 
-  std::string expected_file_path = module_name + ".rs";
+  std::string expected_file_path = module_name.as_string () + ".rs";
   std::string expected_dir_path = "mod.rs";
 
   auto dir_slash_pos = including_fpath.rfind (file_separator);
@@ -3366,8 +3368,8 @@ Module::process_file_path ()
   bool file_mod_found = file_exists (file_mod_path);
 
   // Then, search for <directory>/<module_name>/mod.rs
-  std::string dir_mod_path
-    = current_directory_name + module_name + file_separator + expected_dir_path;
+  std::string dir_mod_path = current_directory_name + module_name.as_string ()
+			     + file_separator + expected_dir_path;
   bool dir_mod_found = file_exists (dir_mod_path);
 
   bool multiple_candidates_found = file_mod_found && dir_mod_found;
@@ -3376,12 +3378,13 @@ Module::process_file_path ()
   if (multiple_candidates_found)
     rust_error_at (locus,
 		   "two candidates found for module %s: %s.rs and %s%smod.rs",
-		   module_name.c_str (), module_name.c_str (),
-		   module_name.c_str (), file_separator);
+		   module_name.as_string ().c_str (),
+		   module_name.as_string ().c_str (),
+		   module_name.as_string ().c_str (), file_separator);
 
   if (no_candidates_found)
     rust_error_at (locus, "no candidate found for module %s",
-		   module_name.c_str ());
+		   module_name.as_string ().c_str ());
 
   if (no_candidates_found || multiple_candidates_found)
     return;
@@ -3878,7 +3881,7 @@ MetaItemLitExpr::check_cfg_predicate (const Session &) const
 bool
 MetaListNameValueStr::check_cfg_predicate (const Session &session) const
 {
-  if (ident == "all")
+  if (ident.as_string () == "all")
     {
       for (const auto &str : strs)
 	{
@@ -3887,7 +3890,7 @@ MetaListNameValueStr::check_cfg_predicate (const Session &session) const
 	}
       return true;
     }
-  else if (ident == "any")
+  else if (ident.as_string () == "any")
     {
       for (const auto &str : strs)
 	{
@@ -3896,7 +3899,7 @@ MetaListNameValueStr::check_cfg_predicate (const Session &session) const
 	}
       return false;
     }
-  else if (ident == "not")
+  else if (ident.as_string () == "not")
     {
       if (strs.size () != 1)
 	{
@@ -3918,7 +3921,7 @@ MetaListNameValueStr::check_cfg_predicate (const Session &session) const
 		     "cfg predicate could not be checked for "
 		     "MetaListNameValueStr with ident of "
 		     "'%s' - ident must be 'all' or 'any'",
-		     ident.c_str ());
+		     ident.as_string ().c_str ());
       return false;
     }
 }
@@ -3926,7 +3929,7 @@ MetaListNameValueStr::check_cfg_predicate (const Session &session) const
 bool
 MetaListPaths::check_cfg_predicate (const Session &session) const
 {
-  if (ident == "all")
+  if (ident.as_string () == "all")
     {
       for (const auto &path : paths)
 	{
@@ -3935,7 +3938,7 @@ MetaListPaths::check_cfg_predicate (const Session &session) const
 	}
       return true;
     }
-  else if (ident == "any")
+  else if (ident.as_string () == "any")
     {
       for (const auto &path : paths)
 	{
@@ -3944,7 +3947,7 @@ MetaListPaths::check_cfg_predicate (const Session &session) const
 	}
       return false;
     }
-  else if (ident == "not")
+  else if (ident.as_string () == "not")
     {
       if (paths.size () != 1)
 	{
@@ -3966,7 +3969,7 @@ MetaListPaths::check_cfg_predicate (const Session &session) const
 		     "cfg predicate could not be checked for "
 		     "MetaListNameValueStr with ident of "
 		     "'%s' - ident must be 'all' or 'any'",
-		     ident.c_str ());
+		     ident.as_string ().c_str ());
       return false;
     }
 }
@@ -4029,7 +4032,7 @@ MetaItemSeq::check_cfg_predicate (const Session &session) const
 bool
 MetaWord::check_cfg_predicate (const Session &session) const
 {
-  return session.options.target_data.has_key (ident);
+  return session.options.target_data.has_key (ident.as_string ());
 }
 
 bool
@@ -4048,10 +4051,13 @@ MetaNameValueStr::check_cfg_predicate (const Session &session) const
   // DEBUG
   rust_debug (
     "checked key-value pair for cfg: '%s', '%s' - is%s in target data",
-    ident.c_str (), str.c_str (),
-    session.options.target_data.has_key_value_pair (ident, str) ? "" : " not");
+    ident.as_string ().c_str (), str.c_str (),
+    session.options.target_data.has_key_value_pair (ident.as_string (), str)
+      ? ""
+      : " not");
 
-  return session.options.target_data.has_key_value_pair (ident, str);
+  return session.options.target_data.has_key_value_pair (ident.as_string (),
+							 str);
 }
 
 bool
@@ -4080,7 +4086,7 @@ MetaNameValueStr::to_attribute () const
   // FIXME: What location do we put here? Is the literal above supposed to have
   // an empty location as well?
   // Should MetaNameValueStr keep a location?
-  return Attribute (SimplePath::from_str (ident, ident_locus),
+  return Attribute (SimplePath::from_str (ident.as_string (), ident_locus),
 		    std::unique_ptr<AttrInputLiteral> (
 		      new AttrInputLiteral (std::move (lit_expr))));
 }
@@ -4107,7 +4113,8 @@ MetaItemSeq::to_attribute () const
 Attribute
 MetaWord::to_attribute () const
 {
-  return Attribute (SimplePath::from_str (ident, ident_locus), nullptr);
+  return Attribute (SimplePath::from_str (ident.as_string (), ident_locus),
+		    nullptr);
 }
 
 Attribute
@@ -4125,7 +4132,7 @@ MetaListPaths::to_attribute () const
 
   std::unique_ptr<AttrInputMetaItemContainer> new_seq_container (
     new AttrInputMetaItemContainer (std::move (new_seq)));
-  return Attribute (SimplePath::from_str (ident, ident_locus),
+  return Attribute (SimplePath::from_str (ident.as_string (), ident_locus),
 		    std::move (new_seq_container));
 }
 
@@ -4140,7 +4147,7 @@ MetaListNameValueStr::to_attribute () const
 
   std::unique_ptr<AttrInputMetaItemContainer> new_seq_container (
     new AttrInputMetaItemContainer (std::move (new_seq)));
-  return Attribute (SimplePath::from_str (ident, ident_locus),
+  return Attribute (SimplePath::from_str (ident.as_string (), ident_locus),
 		    std::move (new_seq_container));
 }
 
@@ -4986,4 +4993,11 @@ MetaWord::accept_vis (ASTVisitor &vis)
 }
 
 } // namespace AST
+
+std::ostream &
+operator<< (std::ostream &os, Identifier const &i)
+{
+  return os << i.as_string ();
+}
+
 } // namespace Rust
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 893b4bb17b9..a4caee7237d 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -28,11 +28,30 @@
 
 namespace Rust {
 // TODO: remove typedefs and make actual types for these
-typedef std::string Identifier;
 typedef int TupleIndex;
 struct Session;
 struct MacroExpander;
 
+class Identifier
+{
+public:
+  Identifier (std::string ident = "")
+    : ident (ident), node_id (Analysis::Mappings::get ()->get_next_node_id ())
+  {}
+
+  NodeId get_node_id () const { return node_id; }
+  const std::string &as_string () const { return ident; }
+
+  bool empty () const { return ident.empty (); }
+
+private:
+  std::string ident;
+  NodeId node_id;
+};
+
+std::ostream &
+operator<< (std::ostream &os, Identifier const &i);
+
 namespace AST {
 // foward decl: ast visitor
 class ASTVisitor;
@@ -60,11 +79,11 @@ class Node : public Visitable
 public:
   /**
    * Get the kind of Node this is. This is used to differentiate various AST
-   * elements with very little overhead when extracting the derived type through
-   * static casting is not necessary.
+   * elements with very little overhead when extracting the derived type
+   * through static casting is not necessary.
    */
-  // FIXME: Mark this as `= 0` in the future to make sure every node implements
-  // it
+  // FIXME: Mark this as `= 0` in the future to make sure every node
+  // implements it
   virtual Kind get_ast_kind () const { return Kind::UNKNOWN; }
 };
 
@@ -93,8 +112,8 @@ public:
 
   virtual std::string as_string () const = 0;
 
-  /* Converts token tree to a flat token stream. Tokens must be pointer to avoid
-   * mutual dependency with Token. */
+  /* Converts token tree to a flat token stream. Tokens must be pointer to
+   * avoid mutual dependency with Token. */
   virtual std::vector<std::unique_ptr<Token>> to_token_stream () const = 0;
 
 protected:
@@ -151,9 +170,9 @@ class Token : public TokenTree, public MacroMatch
 
   const_TokenPtr tok_ref;
 
-  /* new idea: wrapper around const_TokenPtr used for heterogeneuous storage in
-   * token trees. rather than convert back and forth when parsing macros, just
-   * wrap it. */
+  /* new idea: wrapper around const_TokenPtr used for heterogeneuous storage
+   * in token trees. rather than convert back and forth when parsing macros,
+   * just wrap it. */
 
 public:
   // Unique pointer custom clone function
@@ -250,15 +269,15 @@ protected:
   // No virtual for now as not polymorphic but can be in future
   /*virtual*/ Token *clone_token_impl () const { return new Token (*this); }
 
-  /* Use covariance to implement clone function as returning this object rather
-   * than base */
+  /* Use covariance to implement clone function as returning this object
+   * rather than base */
   Token *clone_token_tree_impl () const final override
   {
     return clone_token_impl ();
   }
 
-  /* Use covariance to implement clone function as returning this object rather
-   * than base */
+  /* Use covariance to implement clone function as returning this object
+   * rather than base */
   Token *clone_macro_match_impl () const final override
   {
     return clone_token_impl ();
@@ -282,8 +301,8 @@ public:
   };
 
 private:
-  /* TODO: maybe make subclasses of each type of literal with their typed values
-   * (or generics) */
+  /* TODO: maybe make subclasses of each type of literal with their typed
+   * values (or generics) */
   std::string value_as_string;
   LitType type;
   PrimitiveCoreType type_hint;
@@ -310,8 +329,8 @@ public:
   bool is_error () const { return type == ERROR; }
 };
 
-/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to
- * be defined */
+/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr
+ * to be defined */
 class AttrInputLiteral;
 
 /* TODO: move applicable stuff into here or just don't include it because
@@ -571,8 +590,8 @@ public:
   // Call to parse attribute body to meta item syntax.
   void parse_attr_to_meta_item ();
 
-  /* Determines whether cfg predicate is true and item with attribute should not
-   * be stripped. Attribute body must already be parsed to meta item. */
+  /* Determines whether cfg predicate is true and item with attribute should
+   * not be stripped. Attribute body must already be parsed to meta item. */
   bool check_cfg_predicate (const Session &session) const;
 
   // Returns whether body has been parsed to meta item form or not.
@@ -583,7 +602,8 @@ public:
   std::vector<Attribute> separate_cfg_attrs () const;
 
 protected:
-  // not virtual as currently no subclasses of Attribute, but could be in future
+  // not virtual as currently no subclasses of Attribute, but could be in
+  // future
   /*virtual*/ Attribute *clone_attribute_impl () const
   {
     return new Attribute (*this);
@@ -849,8 +869,8 @@ public:
   DelimType get_delim_type () const { return delim_type; }
 };
 
-/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr to
- * be defined */
+/* Forward decl - definition moved to rust-expr.h as it requires LiteralExpr
+ * to be defined */
 class AttrInputLiteral;
 
 // abstract base meta item class
@@ -879,8 +899,9 @@ class MetaListPaths;
 // Forward decl - defined in rust-macro.h
 class MetaListNameValueStr;
 
-/* Base statement abstract class. Note that most "statements" are not allowed in
- * top-level module scope - only a subclass of statements called "items" are. */
+/* Base statement abstract class. Note that most "statements" are not allowed
+ * in top-level module scope - only a subclass of statements called "items"
+ * are. */
 class Stmt : public Node
 {
 public:
@@ -1022,9 +1043,9 @@ protected:
   // pure virtual clone implementation
   virtual ExprWithoutBlock *clone_expr_without_block_impl () const = 0;
 
-  /* Save having to specify two clone methods in derived classes by making expr
-   * clone return exprwithoutblock clone. Hopefully won't affect performance too
-   * much. */
+  /* Save having to specify two clone methods in derived classes by making
+   * expr clone return exprwithoutblock clone. Hopefully won't affect
+   * performance too much. */
   ExprWithoutBlock *clone_expr_impl () const final override
   {
     return clone_expr_without_block_impl ();
@@ -1042,7 +1063,8 @@ public:
 
 /* HACK: IdentifierExpr, delete when figure out identifier vs expr problem in
  * Pratt parser */
-/* Alternatively, identifiers could just be represented as single-segment paths
+/* Alternatively, identifiers could just be represented as single-segment
+ * paths
  */
 class IdentifierExpr : public ExprWithoutBlock
 {
@@ -1057,7 +1079,7 @@ public:
       locus (locus)
   {}
 
-  std::string as_string () const override { return ident; }
+  std::string as_string () const override { return ident.as_string (); }
 
   Location get_locus () const override final { return locus; }
 
@@ -1181,9 +1203,9 @@ protected:
   // Clone function implementation as pure virtual method
   virtual TypeNoBounds *clone_type_no_bounds_impl () const = 0;
 
-  /* Save having to specify two clone methods in derived classes by making type
-   * clone return typenobounds clone. Hopefully won't affect performance too
-   * much. */
+  /* Save having to specify two clone methods in derived classes by making
+   * type clone return typenobounds clone. Hopefully won't affect performance
+   * too much. */
   TypeNoBounds *clone_type_impl () const final override
   {
     return clone_type_no_bounds_impl ();
@@ -1192,8 +1214,8 @@ protected:
   TypeNoBounds () : Type () {}
 };
 
-/* Abstract base class representing a type param bound - Lifetime and TraitBound
- * extends it */
+/* Abstract base class representing a type param bound - Lifetime and
+ * TraitBound extends it */
 class TypeParamBound : public Visitable
 {
 public:
@@ -1271,16 +1293,16 @@ public:
   std::string get_lifetime_name () const { return lifetime_name; }
 
 protected:
-  /* Use covariance to implement clone function as returning this object rather
-   * than base */
+  /* Use covariance to implement clone function as returning this object
+   * rather than base */
   Lifetime *clone_type_param_bound_impl () const override
   {
     return new Lifetime (node_id, lifetime_type, lifetime_name, locus);
   }
 };
 
-/* Base generic parameter in AST. Abstract - can be represented by a Lifetime or
- * Type param */
+/* Base generic parameter in AST. Abstract - can be represented by a Lifetime
+ * or Type param */
 class GenericParam : public Visitable
 {
 public:
@@ -1363,8 +1385,8 @@ public:
   Kind get_kind () const override final { return Kind::Lifetime; }
 
 protected:
-  /* Use covariance to implement clone function as returning this object rather
-   * than base */
+  /* Use covariance to implement clone function as returning this object
+   * rather than base */
   LifetimeParam *clone_generic_param_impl () const override
   {
     return new LifetimeParam (*this);
@@ -1957,4 +1979,15 @@ class PathExpr : public ExprWithoutBlock
 } // namespace AST
 } // namespace Rust
 
+namespace std {
+template <> struct less<Rust::Identifier>
+{
+  bool operator() (const Rust::Identifier &lhs,
+		   const Rust::Identifier &rhs) const
+  {
+    return lhs.as_string () < rhs.as_string ();
+  }
+};
+} // namespace std
+
 #endif
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 8ea2c8c5a8b..9a1da7afb8b 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -1667,7 +1667,7 @@ public:
       locus (locus)
   {}
 
-  std::string as_string () const override { return field_name; }
+  std::string as_string () const override { return field_name.as_string (); }
 
   Location get_locus () const override final { return locus; }
 
@@ -1741,7 +1741,7 @@ public:
 
   void accept_vis (ASTVisitor &vis) override;
 
-  std::string get_field_name () const { return field_name; }
+  std::string get_field_name () const { return field_name.as_string (); }
 
   Location get_locus () const override final { return locus; }
 
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 4563f61b394..5b3529bf4e9 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -752,7 +752,7 @@ public:
   // Creates an error state method.
   static Method create_error ()
   {
-    return Method ("", FunctionQualifiers (Location (), NONE, true),
+    return Method ({""}, FunctionQualifiers (Location (), NONE, true),
 		   std::vector<std::unique_ptr<GenericParam>> (),
 		   SelfParam::create_error (), std::vector<FunctionParam> (),
 		   nullptr, WhereClause::create_empty (), nullptr,
@@ -1136,7 +1136,7 @@ public:
   Location get_locus () const override final { return locus; }
 
   // Invalid if name is empty, so base stripping on that.
-  void mark_for_strip () override { module_name = ""; }
+  void mark_for_strip () override { module_name = {""}; }
   bool is_marked_for_strip () const override { return module_name.empty (); }
 
 protected:
@@ -1865,7 +1865,7 @@ public:
   Location get_locus () const override final { return locus; }
 
   // Invalid if name is empty, so base stripping on that.
-  void mark_for_strip () override { struct_name = ""; }
+  void mark_for_strip () override { struct_name = {""}; }
   bool is_marked_for_strip () const override { return struct_name.empty (); }
 
   Identifier get_struct_name () const { return struct_name; }
@@ -2240,7 +2240,7 @@ public:
   Identifier get_identifier () const { return variant_name; }
 
   // Based on idea that name is never empty.
-  void mark_for_strip () override { variant_name = ""; }
+  void mark_for_strip () override { variant_name = {""}; }
   bool is_marked_for_strip () const override { return variant_name.empty (); }
 
 protected:
@@ -2461,7 +2461,7 @@ public:
   Identifier get_identifier () const { return enum_name; }
 
   // Invalid if name is empty, so base stripping on that.
-  void mark_for_strip () override { enum_name = ""; }
+  void mark_for_strip () override { enum_name = {""}; }
   bool is_marked_for_strip () const override { return enum_name.empty (); }
 
   // TODO: this mutable getter seems really dodgy. Think up better way.
@@ -2561,7 +2561,7 @@ public:
   void accept_vis (ASTVisitor &vis) override;
 
   // Invalid if name is empty, so base stripping on that.
-  void mark_for_strip () override { union_name = ""; }
+  void mark_for_strip () override { union_name = {""}; }
   bool is_marked_for_strip () const override { return union_name.empty (); }
 
   // TODO: this mutable getter seems really dodgy. Think up better way.
@@ -2907,7 +2907,7 @@ public:
   std::string as_string () const;
 
   // Invalid if function name is empty, so base stripping on that.
-  void mark_for_strip () { function_name = ""; }
+  void mark_for_strip () { function_name = {""}; }
   bool is_marked_for_strip () const { return function_name.empty (); }
 
   // TODO: this mutable getter seems really dodgy. Think up better way.
@@ -3120,7 +3120,7 @@ public:
   std::string as_string () const;
 
   // Invalid if method name is empty, so base stripping on that.
-  void mark_for_strip () { function_name = ""; }
+  void mark_for_strip () { function_name = {""}; }
   bool is_marked_for_strip () const { return function_name.empty (); }
 
   // TODO: this mutable getter seems really dodgy. Think up better way.
@@ -3399,7 +3399,7 @@ public:
   void accept_vis (ASTVisitor &vis) override;
 
   // Invalid if name is empty, so base stripping on that.
-  void mark_for_strip () override { name = ""; }
+  void mark_for_strip () override { name = {""}; }
   bool is_marked_for_strip () const override { return name.empty (); }
 
   // TODO: this mutable getter seems really dodgy. Think up better way.
@@ -3534,7 +3534,7 @@ public:
   void accept_vis (ASTVisitor &vis) override;
 
   // Invalid if trait name is empty, so base stripping on that.
-  void mark_for_strip () override { name = ""; }
+  void mark_for_strip () override { name = {""}; }
   bool is_marked_for_strip () const override { return name.empty (); }
 
   // TODO: think of better way to do this
@@ -4346,7 +4346,7 @@ public:
   void accept_vis (ASTVisitor &vis) override;
 
   // Based on idea that nane should never be empty.
-  void mark_for_strip () override { item_name = ""; };
+  void mark_for_strip () override { item_name = {""}; };
   bool is_marked_for_strip () const override { return item_name.empty (); };
 
   // TODO: this mutable getter seems really dodgy. Think up better way.
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index 77c9b8479bf..877df2a4e00 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -537,7 +537,7 @@ public:
   void accept_vis (ASTVisitor &vis) override;
 
   // Invalid if rule name is empty, so base stripping on that.
-  void mark_for_strip () override { rule_name = ""; }
+  void mark_for_strip () override { rule_name = {""}; }
   bool is_marked_for_strip () const override { return rule_name.empty (); }
 
   // TODO: this mutable getter seems really dodgy. Think up better way.
@@ -921,7 +921,7 @@ public:
     : ident (std::move (ident)), ident_locus (ident_locus)
   {}
 
-  std::string as_string () const override { return ident; }
+  std::string as_string () const override { return ident.as_string (); }
 
   void accept_vis (ASTVisitor &vis) override;
 
@@ -960,7 +960,7 @@ public:
 
   std::string as_string () const override
   {
-    return ident + " = \"" + str + "\"";
+    return ident.as_string () + " = \"" + str + "\"";
   }
 
   void accept_vis (ASTVisitor &vis) override;
diff --git a/gcc/rust/ast/rust-path.cc b/gcc/rust/ast/rust-path.cc
index 9a3489b15f7..ee6a6fb482e 100644
--- a/gcc/rust/ast/rust-path.cc
+++ b/gcc/rust/ast/rust-path.cc
@@ -96,7 +96,7 @@ GenericArg::disambiguate_to_type () const
   rust_assert (get_kind () == Kind::Either);
 
   auto segment = std::unique_ptr<TypePathSegment> (
-    new TypePathSegment (path, false, locus));
+    new TypePathSegment (path.as_string (), false, locus));
   auto segments = std::vector<std::unique_ptr<TypePathSegment>> ();
   segments.emplace_back (std::move (segment));
 
@@ -108,14 +108,14 @@ std::string
 GenericArgsBinding::as_string () const
 {
   // TODO: rewrite to work with non-literalisable types
-  return identifier + " = " + type->as_string ();
+  return identifier.as_string () + " = " + type->as_string ();
 }
 
 std::string
 ConstGenericParam::as_string () const
 {
   std::string str ("ConstGenericParam: ");
-  str += "const " + name + ": " + type->as_string ();
+  str += "const " + name.as_string () + ": " + type->as_string ();
 
   if (has_default_value ())
     str += " = " + get_default_value ().as_string ();
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index 8e4eb197360..cad9d5d2c38 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -77,7 +77,7 @@ public:
   // Creates an error state generic args binding.
   static GenericArgsBinding create_error ()
   {
-    return GenericArgsBinding ("", nullptr);
+    return GenericArgsBinding ({""}, nullptr);
   }
 
   // Pointer type for type in constructor to enable polymorphism
@@ -159,19 +159,20 @@ public:
 
   static GenericArg create_error ()
   {
-    return GenericArg (nullptr, nullptr, "", Kind::Error, Location ());
+    return GenericArg (nullptr, nullptr, {""}, Kind::Error, Location ());
   }
 
   static GenericArg create_const (std::unique_ptr<Expr> expression)
   {
     auto locus = expression->get_locus ();
-    return GenericArg (std::move (expression), nullptr, "", Kind::Const, locus);
+    return GenericArg (std::move (expression), nullptr, {""}, Kind::Const,
+		       locus);
   }
 
   static GenericArg create_type (std::unique_ptr<Type> type)
   {
     auto locus = type->get_locus ();
-    return GenericArg (nullptr, std::move (type), "", Kind::Type, locus);
+    return GenericArg (nullptr, std::move (type), {""}, Kind::Type, locus);
   }
 
   static GenericArg create_ambiguous (Identifier path, Location locus)
@@ -245,7 +246,7 @@ public:
   {
     rust_assert (kind == Kind::Either);
 
-    return path;
+    return path.as_string ();
   }
 
   std::string as_string () const
@@ -255,7 +256,7 @@ public:
       case Kind::Error:
 	gcc_unreachable ();
       case Kind::Either:
-	return "Ambiguous: " + path;
+	return "Ambiguous: " + path.as_string ();
       case Kind::Const:
 	return "Const: { " + expression->as_string () + " }";
       case Kind::Type:
diff --git a/gcc/rust/ast/rust-pattern.cc b/gcc/rust/ast/rust-pattern.cc
index 14179ca1027..e4712c34e08 100644
--- a/gcc/rust/ast/rust-pattern.cc
+++ b/gcc/rust/ast/rust-pattern.cc
@@ -48,7 +48,7 @@ IdentifierPattern::as_string () const
   if (is_mut)
     str += "mut ";
 
-  str += variable_ident;
+  str += variable_ident.as_string ();
 
   if (has_pattern_to_bind ())
     str += " @ " + to_bind->as_string ();
@@ -126,7 +126,7 @@ StructPatternFieldIdentPat::as_string () const
 
   str += "\n";
 
-  str += ident + " : " + ident_pattern->as_string ();
+  str += ident.as_string () + " : " + ident_pattern->as_string ();
 
   return str;
 }
@@ -144,7 +144,7 @@ StructPatternFieldIdent::as_string () const
   if (has_mut)
     str += "mut ";
 
-  str += ident;
+  str += ident.as_string ();
 
   return str;
 }
diff --git a/gcc/rust/ast/rust-type.h b/gcc/rust/ast/rust-type.h
index 7fa1bc61e9b..7b679d5cc15 100644
--- a/gcc/rust/ast/rust-type.h
+++ b/gcc/rust/ast/rust-type.h
@@ -813,7 +813,7 @@ public:
   // Creates an error state param.
   static MaybeNamedParam create_error ()
   {
-    return MaybeNamedParam ("", UNNAMED, nullptr, {}, Location ());
+    return MaybeNamedParam ({""}, UNNAMED, nullptr, {}, Location ());
   }
 
   Location get_locus () const { return locus; }
diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc
index 4a95530f148..836ac82b6fc 100644
--- a/gcc/rust/backend/rust-compile-base.cc
+++ b/gcc/rust/backend/rust-compile-base.cc
@@ -197,13 +197,13 @@ HIRCompileBase::handle_deprecated_attribute_on_fndecl (
 	  if (!converted_item)
 	    continue;
 	  auto key_value = converted_item->get_name_value_pair ();
-	  if (key_value.first.compare ("since") == 0)
+	  if (key_value.first.as_string ().compare ("since") == 0)
 	    {
 	      // valid, but this is handled by Cargo and some third-party audit
 	      // tools
 	      continue;
 	    }
-	  else if (key_value.first.compare ("note") == 0)
+	  else if (key_value.first.as_string ().compare ("note") == 0)
 	    {
 	      const auto &msg_str = key_value.second;
 	      if (value)
@@ -213,7 +213,7 @@ HIRCompileBase::handle_deprecated_attribute_on_fndecl (
 	  else
 	    {
 	      rust_error_at (attr.get_locus (), "unknown meta item %qs",
-			     key_value.first.c_str ());
+			     key_value.first.as_string ().c_str ());
 	    }
 	}
     }
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 9daad0ad7f3..5f724f5f0c2 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -561,8 +561,8 @@ CompileExpr::visit (HIR::FieldAccessExpr &expr)
       rust_assert (adt->number_of_variants () == 1);
 
       TyTy::VariantDef *variant = adt->get_variants ().at (0);
-      bool ok
-	= variant->lookup_field (expr.get_field_name (), nullptr, &field_index);
+      bool ok = variant->lookup_field (expr.get_field_name ().as_string (),
+				       nullptr, &field_index);
       rust_assert (ok);
     }
   else if (receiver->get_kind () == TyTy::TypeKind::REF)
@@ -576,8 +576,8 @@ CompileExpr::visit (HIR::FieldAccessExpr &expr)
       rust_assert (adt->number_of_variants () == 1);
 
       TyTy::VariantDef *variant = adt->get_variants ().at (0);
-      bool ok
-	= variant->lookup_field (expr.get_field_name (), nullptr, &field_index);
+      bool ok = variant->lookup_field (expr.get_field_name ().as_string (),
+				       nullptr, &field_index);
       rust_assert (ok);
 
       tree indirect = indirect_expression (receiver_ref, expr.get_locus ());
diff --git a/gcc/rust/backend/rust-compile-extern.h b/gcc/rust/backend/rust-compile-extern.h
index 30360df9ea0..1f18d1a23ca 100644
--- a/gcc/rust/backend/rust-compile-extern.h
+++ b/gcc/rust/backend/rust-compile-extern.h
@@ -60,7 +60,7 @@ public:
 					      &resolved_type);
     rust_assert (ok);
 
-    std::string name = item.get_item_name ();
+    std::string name = item.get_item_name ().as_string ();
     // FIXME this is assuming C ABI
     std::string asm_name = name;
 
@@ -130,8 +130,8 @@ public:
       }
 
     tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);
-    std::string ir_symbol_name = function.get_item_name ();
-    std::string asm_name = function.get_item_name ();
+    std::string ir_symbol_name = function.get_item_name ().as_string ();
+    std::string asm_name = function.get_item_name ().as_string ();
     if (fntype->get_abi () == ABI::RUST)
       {
 	// then we need to get the canonical path of it and mangle it
diff --git a/gcc/rust/backend/rust-compile-fnparam.cc b/gcc/rust/backend/rust-compile-fnparam.cc
index 9f08ea1369f..9a9d5b3790f 100644
--- a/gcc/rust/backend/rust-compile-fnparam.cc
+++ b/gcc/rust/backend/rust-compile-fnparam.cc
@@ -54,10 +54,8 @@ CompileFnParam::visit (HIR::IdentifierPattern &pattern)
   if (!pattern.is_mut ())
     decl_type = ctx->get_backend ()->immutable_type (decl_type);
 
-  compiled_param
-    = ctx->get_backend ()->parameter_variable (fndecl,
-					       pattern.get_identifier (),
-					       decl_type, locus);
+  compiled_param = ctx->get_backend ()->parameter_variable (
+    fndecl, pattern.get_identifier ().as_string (), decl_type, locus);
 }
 
 void
diff --git a/gcc/rust/backend/rust-compile-implitem.cc b/gcc/rust/backend/rust-compile-implitem.cc
index 445a1531861..190812dfdec 100644
--- a/gcc/rust/backend/rust-compile-implitem.cc
+++ b/gcc/rust/backend/rust-compile-implitem.cc
@@ -86,8 +86,8 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
   auto vis = HIR::Visibility (HIR::Visibility::VisType::PUBLIC);
   HIR::TraitFunctionDecl &function = func.get_decl ();
   tree fndecl
-    = compile_function (function.get_function_name (), function.get_self (),
-			function.get_function_params (),
+    = compile_function (function.get_function_name ().as_string (),
+			function.get_self (), function.get_function_params (),
 			function.get_qualifiers (), vis,
 			func.get_outer_attrs (), func.get_locus (),
 			func.get_block_expr ().get (), canonical_path, fntype);
diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc
index b83ef56788b..f3102b0df67 100644
--- a/gcc/rust/backend/rust-compile-item.cc
+++ b/gcc/rust/backend/rust-compile-item.cc
@@ -178,7 +178,7 @@ CompileItem::visit (HIR::Function &function)
     ctx->push_const_context ();
 
   tree fndecl
-    = compile_function (function.get_function_name (),
+    = compile_function (function.get_function_name ().as_string (),
 			function.get_self_param (),
 			function.get_function_params (),
 			function.get_qualifiers (), function.get_visibility (),
diff --git a/gcc/rust/backend/rust-compile-pattern.cc b/gcc/rust/backend/rust-compile-pattern.cc
index 742dfa0c632..6d7678d03a7 100644
--- a/gcc/rust/backend/rust-compile-pattern.cc
+++ b/gcc/rust/backend/rust-compile-pattern.cc
@@ -299,8 +299,8 @@ CompilePatternBindings::visit (HIR::StructPattern &pattern)
 	      = static_cast<HIR::StructPatternFieldIdent &> (*field.get ());
 
 	    size_t offs = 0;
-	    ok
-	      = variant->lookup_field (ident.get_identifier (), nullptr, &offs);
+	    ok = variant->lookup_field (ident.get_identifier ().as_string (),
+					nullptr, &offs);
 	    rust_assert (ok);
 
 	    tree binding = error_mark_node;
diff --git a/gcc/rust/backend/rust-compile-struct-field-expr.cc b/gcc/rust/backend/rust-compile-struct-field-expr.cc
index f2f243bd9fd..ca14bff63d1 100644
--- a/gcc/rust/backend/rust-compile-struct-field-expr.cc
+++ b/gcc/rust/backend/rust-compile-struct-field-expr.cc
@@ -69,7 +69,7 @@ CompileStructExprField::visit (HIR::StructExprFieldIdentifier &field)
   Analysis::NodeMapping mappings_copy1 = field.get_mappings ();
   Analysis::NodeMapping mappings_copy2 = field.get_mappings ();
 
-  HIR::PathIdentSegment ident_seg (field.get_field_name ());
+  HIR::PathIdentSegment ident_seg (field.get_field_name ().as_string ());
   HIR::PathExprSegment seg (mappings_copy1, ident_seg, field.get_locus (),
 			    HIR::GenericArgs::create_empty ());
   HIR::PathInExpression expr (mappings_copy2, {seg}, field.get_locus (), false,
diff --git a/gcc/rust/backend/rust-compile-var-decl.h b/gcc/rust/backend/rust-compile-var-decl.h
index 9a3fcb594cd..0378ef519a3 100644
--- a/gcc/rust/backend/rust-compile-var-decl.h
+++ b/gcc/rust/backend/rust-compile-var-decl.h
@@ -42,10 +42,9 @@ public:
     if (!pattern.is_mut ())
       translated_type = ctx->get_backend ()->immutable_type (translated_type);
 
-    Bvariable *var
-      = ctx->get_backend ()->local_variable (fndecl, pattern.get_identifier (),
-					     translated_type, NULL /*decl_var*/,
-					     pattern.get_locus ());
+    Bvariable *var = ctx->get_backend ()->local_variable (
+      fndecl, pattern.get_identifier ().as_string (), translated_type,
+      NULL /*decl_var*/, pattern.get_locus ());
 
     HirId stmt_id = pattern.get_pattern_mappings ().get_hirid ();
     ctx->insert_var_decl (stmt_id, var);
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index a5d6abb1f82..b7d0741a23c 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -316,7 +316,8 @@ HIRCompileBase::compute_address_for_trait_item (
 
       HIR::Function *fn = static_cast<HIR::Function *> (impl_item.get ());
       bool found_associated_item
-	= fn->get_function_name ().compare (ref->get_identifier ()) == 0;
+	= fn->get_function_name ().as_string ().compare (ref->get_identifier ())
+	  == 0;
       if (found_associated_item)
 	associated_function = fn;
     }
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index 8725e780dc9..c52c0b862c0 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -152,7 +152,7 @@ check_extern_call (HIR::ExternalItem *maybe_fn, HIR::ExternBlock *parent_block,
 
   // Some intrinsics are safe to call
   if (parent_block->get_abi () == Rust::ABI::INTRINSIC
-      && is_safe_intrinsic (maybe_fn->get_item_name ()))
+      && is_safe_intrinsic (maybe_fn->get_item_name ().as_string ()))
     return;
 
   rust_error_at (locus,
diff --git a/gcc/rust/checks/lints/rust-lint-marklive.cc b/gcc/rust/checks/lints/rust-lint-marklive.cc
index 553842a7224..a92395fb513 100644
--- a/gcc/rust/checks/lints/rust-lint-marklive.cc
+++ b/gcc/rust/checks/lints/rust-lint-marklive.cc
@@ -51,7 +51,7 @@ public:
   // TODO not only fn main can be a entry point.
   void visit (HIR::Function &function) override
   {
-    if (function.get_function_name () == "main")
+    if (function.get_function_name ().as_string () == "main")
       {
 	entryPoints.push_back (function.get_mappings ().get_hirid ());
       }
@@ -224,7 +224,8 @@ MarkLive::visit (HIR::FieldAccessExpr &expr)
   // get the field index
   size_t index;
   TyTy::StructFieldType *field;
-  bool ok = variant->lookup_field (expr.get_field_name (), &field, &index);
+  bool ok = variant->lookup_field (expr.get_field_name ().as_string (), &field,
+				   &index);
   rust_assert (ok);
   if (index >= variant->num_fields ())
     {
diff --git a/gcc/rust/checks/lints/rust-lint-scan-deadcode.h b/gcc/rust/checks/lints/rust-lint-scan-deadcode.h
index 499ed71facc..f84d3569048 100644
--- a/gcc/rust/checks/lints/rust-lint-scan-deadcode.h
+++ b/gcc/rust/checks/lints/rust-lint-scan-deadcode.h
@@ -61,16 +61,17 @@ public:
 	      = mappings->lookup_associated_impl (hirId);
 	    if (!implBlock->has_trait_ref ())
 	      {
-		rust_warning_at (function.get_locus (), 0,
-				 "associated function is never used: %<%s%>",
-				 function.get_function_name ().c_str ());
+		rust_warning_at (
+		  function.get_locus (), 0,
+		  "associated function is never used: %<%s%>",
+		  function.get_function_name ().as_string ().c_str ());
 	      }
 	  }
 	else
 	  {
-	    rust_warning_at (function.get_locus (), 0,
-			     "function is never used: %<%s%>",
-			     function.get_function_name ().c_str ());
+	    rust_warning_at (
+	      function.get_locus (), 0, "function is never used: %<%s%>",
+	      function.get_function_name ().as_string ().c_str ());
 	  }
       }
   }
@@ -80,11 +81,12 @@ public:
     HirId hirId = stct.get_mappings ().get_hirid ();
     if (should_warn (hirId) && !stct.get_visibility ().is_public ())
       {
-	bool name_starts_underscore = stct.get_identifier ().at (0) == '_';
+	bool name_starts_underscore
+	  = stct.get_identifier ().as_string ().at (0) == '_';
 	if (!name_starts_underscore)
 	  rust_warning_at (stct.get_locus (), 0,
 			   "struct is never constructed: %<%s%>",
-			   stct.get_identifier ().c_str ());
+			   stct.get_identifier ().as_string ().c_str ());
       }
     else
       {
@@ -97,7 +99,7 @@ public:
 	      {
 		rust_warning_at (field.get_locus (), 0,
 				 "field is never read: %<%s%>",
-				 field.get_field_name ().c_str ());
+				 field.get_field_name ().as_string ().c_str ());
 	      }
 	  }
       }
@@ -111,7 +113,7 @@ public:
       {
 	rust_warning_at (stct.get_locus (), 0,
 			 "struct is never constructed: %<%s%>",
-			 stct.get_identifier ().c_str ());
+			 stct.get_identifier ().as_string ().c_str ());
       }
   }
 
diff --git a/gcc/rust/expand/rust-derive-clone.cc b/gcc/rust/expand/rust-derive-clone.cc
index 2ffcafc957b..34886b25146 100644
--- a/gcc/rust/expand/rust-derive-clone.cc
+++ b/gcc/rust/expand/rust-derive-clone.cc
@@ -50,7 +50,7 @@ DeriveClone::clone_fn (std::unique_ptr<Expr> &&clone_expr)
   auto big_self_type = builder.single_type_path ("Self");
 
   return std::unique_ptr<TraitImplItem> (
-    new Method ("clone", builder.fn_qualifiers (), /* generics */ {},
+    new Method ({"clone"}, builder.fn_qualifiers (), /* generics */ {},
 		SelfParam (Lifetime::error (), /* is_mut */ false, loc),
 		/* function params */ {}, std::move (big_self_type),
 		WhereClause::create_empty (), std::move (block),
@@ -111,11 +111,11 @@ DeriveClone::visit_tuple (TupleStruct &item)
       clone_call (builder.ref (builder.tuple_idx ("self", idx))));
 
   auto path = std::unique_ptr<Expr> (new PathInExpression (
-    builder.path_in_expression ({item.get_identifier ()})));
+    builder.path_in_expression ({item.get_identifier ().as_string ()})));
   auto constructor = builder.call (std::move (path), std::move (cloned_fields));
 
-  expanded
-    = clone_impl (clone_fn (std::move (constructor)), item.get_identifier ());
+  expanded = clone_impl (clone_fn (std::move (constructor)),
+			 item.get_identifier ().as_string ());
 }
 
 void
@@ -123,16 +123,17 @@ DeriveClone::visit_struct (StructStruct &item)
 {
   if (item.is_unit_struct ())
     {
-      auto unit_ctor = builder.struct_expr_struct (item.get_struct_name ());
+      auto unit_ctor
+	= builder.struct_expr_struct (item.get_struct_name ().as_string ());
       expanded = clone_impl (clone_fn (std::move (unit_ctor)),
-			     item.get_struct_name ());
+			     item.get_struct_name ().as_string ());
       return;
     }
 
   auto cloned_fields = std::vector<std::unique_ptr<StructExprField>> ();
   for (auto &field : item.get_fields ())
     {
-      auto name = field.get_field_name ();
+      auto name = field.get_field_name ().as_string ();
       auto expr = clone_call (
 	builder.ref (builder.field_access (builder.identifier ("self"), name)));
 
@@ -140,9 +141,10 @@ DeriveClone::visit_struct (StructStruct &item)
 	builder.struct_expr_field (std::move (name), std::move (expr)));
     }
 
-  auto ctor
-    = builder.struct_expr (item.get_struct_name (), std::move (cloned_fields));
-  expanded = clone_impl (clone_fn (std::move (ctor)), item.get_struct_name ());
+  auto ctor = builder.struct_expr (item.get_struct_name ().as_string (),
+				   std::move (cloned_fields));
+  expanded = clone_impl (clone_fn (std::move (ctor)),
+			 item.get_struct_name ().as_string ());
 }
 
 void
@@ -177,7 +179,8 @@ DeriveClone::visit_union (Union &item)
 
   auto block = builder.block (std::move (stmts), std::move (tail_expr));
 
-  expanded = clone_impl (clone_fn (std::move (block)), item.get_identifier ());
+  expanded = clone_impl (clone_fn (std::move (block)),
+			 item.get_identifier ().as_string ());
 }
 
 } // namespace AST
diff --git a/gcc/rust/expand/rust-derive-copy.cc b/gcc/rust/expand/rust-derive-copy.cc
index bc5db626fba..51a6599ac27 100644
--- a/gcc/rust/expand/rust-derive-copy.cc
+++ b/gcc/rust/expand/rust-derive-copy.cc
@@ -54,25 +54,25 @@ DeriveCopy::copy_impl (std::string name)
 void
 DeriveCopy::visit_struct (StructStruct &item)
 {
-  expanded = copy_impl (item.get_struct_name ());
+  expanded = copy_impl (item.get_struct_name ().as_string ());
 }
 
 void
 DeriveCopy::visit_tuple (TupleStruct &item)
 {
-  expanded = copy_impl (item.get_struct_name ());
+  expanded = copy_impl (item.get_struct_name ().as_string ());
 }
 
 void
 DeriveCopy::visit_enum (Enum &item)
 {
-  expanded = copy_impl (item.get_identifier ());
+  expanded = copy_impl (item.get_identifier ().as_string ());
 }
 
 void
 DeriveCopy::visit_union (Union &item)
 {
-  expanded = copy_impl (item.get_identifier ());
+  expanded = copy_impl (item.get_identifier ().as_string ());
 }
 
 } // namespace AST
diff --git a/gcc/rust/expand/rust-macro-expand.cc b/gcc/rust/expand/rust-macro-expand.cc
index 0d8b930cb58..0ed349abb03 100644
--- a/gcc/rust/expand/rust-macro-expand.cc
+++ b/gcc/rust/expand/rust-macro-expand.cc
@@ -503,10 +503,12 @@ MacroExpander::match_matcher (Parser<MacroInvocLexer> &parser,
 	    size_t offs_end = source.get_offs ();
 	    if (in_repetition)
 	      sub_stack.append_fragment (
-		MatchedFragment (fragment->get_ident (), offs_begin, offs_end));
+		MatchedFragment (fragment->get_ident ().as_string (),
+				 offs_begin, offs_end));
 	    else
 	      sub_stack.insert_metavar (
-		MatchedFragment (fragment->get_ident (), offs_begin, offs_end));
+		MatchedFragment (fragment->get_ident ().as_string (),
+				 offs_begin, offs_end));
 	  }
 	  break;
 
@@ -617,8 +619,8 @@ MacroExpander::match_n_matches (Parser<MacroInvocLexer> &parser,
 		// creating a metavariable, but a repetition of one, which is
 		// really different.
 		sub_stack.append_fragment (
-		  MatchedFragment (fragment->get_ident (), offs_begin,
-				   offs_end));
+		  MatchedFragment (fragment->get_ident ().as_string (),
+				   offs_begin, offs_end));
 	      }
 	      break;
 
@@ -703,10 +705,10 @@ MacroExpander::match_repetition_skipped_metavars (
   AST::MacroMatchFragment &fragment)
 {
   auto &stack_map = sub_stack.peek ();
-  auto it = stack_map.find (fragment.get_ident ());
+  auto it = stack_map.find (fragment.get_ident ().as_string ());
 
   if (it == stack_map.end ())
-    sub_stack.insert_matches (fragment.get_ident (),
+    sub_stack.insert_matches (fragment.get_ident ().as_string (),
 			      MatchedFragmentContainer::zero ());
 }
 
diff --git a/gcc/rust/hir/rust-ast-lower-base.cc b/gcc/rust/hir/rust-ast-lower-base.cc
index d1bc05bbf0f..82d1d2cb001 100644
--- a/gcc/rust/hir/rust-ast-lower-base.cc
+++ b/gcc/rust/hir/rust-ast-lower-base.cc
@@ -675,12 +675,14 @@ struct_field_name_exists (std::vector<HIR::StructField> &fields,
 {
   for (auto &field : fields)
     {
-      if (field.get_field_name ().compare (new_field.get_field_name ()) == 0)
+      if (field.get_field_name ().as_string ().compare (
+	    new_field.get_field_name ().as_string ())
+	  == 0)
 	{
 	  RichLocation r (new_field.get_locus ());
 	  r.add_range (field.get_locus ());
 	  rust_error_at (r, "duplicate field name %qs",
-			 field.get_field_name ().c_str ());
+			 field.get_field_name ().as_string ().c_str ());
 	  return true;
 	}
     }
diff --git a/gcc/rust/hir/rust-ast-lower-expr.cc b/gcc/rust/hir/rust-ast-lower-expr.cc
index 578fc462712..ad907a82359 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.cc
+++ b/gcc/rust/hir/rust-ast-lower-expr.cc
@@ -235,7 +235,7 @@ ASTLoweringExpr::visit (AST::IdentifierExpr &expr)
 				  UNKNOWN_LOCAL_DEFID);
   Analysis::NodeMapping mapping2 (mapping1);
 
-  HIR::PathIdentSegment ident_seg (expr.get_ident ());
+  HIR::PathIdentSegment ident_seg (expr.get_ident ().as_string ());
   HIR::PathExprSegment seg (mapping1, ident_seg, expr.get_locus (),
 			    HIR::GenericArgs::create_empty ());
   translated = new HIR::PathInExpression (mapping2, {seg}, expr.get_locus (),
diff --git a/gcc/rust/hir/rust-ast-lower-type.cc b/gcc/rust/hir/rust-ast-lower-type.cc
index 71ab1e7eb44..e35e4f4d31f 100644
--- a/gcc/rust/hir/rust-ast-lower-type.cc
+++ b/gcc/rust/hir/rust-ast-lower-type.cc
@@ -461,7 +461,7 @@ ASTLowerGenericParam::visit (AST::ConstGenericParam &param)
     default_expr = ASTLoweringExpr::translate (
       param.get_default_value ().get_expression ().get ());
 
-  translated = new HIR::ConstGenericParam (param.get_name (),
+  translated = new HIR::ConstGenericParam (param.get_name ().as_string (),
 					   std::unique_ptr<Type> (type),
 					   std::unique_ptr<Expr> (default_expr),
 					   mapping, param.get_locus ());
diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc
index b46b5dd3d9a..a103385d6a7 100644
--- a/gcc/rust/hir/rust-hir-dump.cc
+++ b/gcc/rust/hir/rust-hir-dump.cc
@@ -420,7 +420,7 @@ Dump::visit (Function &func)
   // function name
   stream << indentation << "func_name: ";
   auto func_name = func.get_function_name ();
-  stream << func_name;
+  stream << func_name.as_string ();
   stream << ",\n";
 
   // return type
@@ -549,7 +549,7 @@ void
 Dump::visit (IdentifierPattern &ident)
 {
   auto ident_name = ident.get_identifier ();
-  stream << ident_name;
+  stream << ident_name.as_string ();
 }
 void
 Dump::visit (WildcardPattern &)
diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h
index ba9d0aae0df..64f94fc081b 100644
--- a/gcc/rust/hir/tree/rust-hir-expr.h
+++ b/gcc/rust/hir/tree/rust-hir-expr.h
@@ -1460,7 +1460,7 @@ public:
       field_name (std::move (field_identifier))
   {}
 
-  std::string as_string () const override { return field_name; }
+  std::string as_string () const override { return field_name.as_string (); }
 
   void accept_vis (HIRFullVisitor &vis) override;
   void accept_vis (HIRExpressionVisitor &vis) override;
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index adb5ef6cedd..695f3254335 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -1230,7 +1230,7 @@ public:
 
   std::string get_impl_item_name () const override final
   {
-    return get_function_name ();
+    return get_function_name ().as_string ();
   }
 
 protected:
@@ -1354,7 +1354,7 @@ public:
 
   std::string get_impl_item_name () const override final
   {
-    return get_new_type_name ();
+    return get_new_type_name ().as_string ();
   }
 
 protected:
@@ -2117,7 +2117,10 @@ public:
 
   // Returns whether constant item is an "unnamed" (wildcard underscore used
   // as identifier) constant.
-  bool is_unnamed () const { return identifier == std::string ("_"); }
+  bool is_unnamed () const
+  {
+    return identifier.as_string () == std::string ("_");
+  }
 
   Location get_locus () const override final { return locus; }
 
@@ -2130,7 +2133,7 @@ public:
 
   Expr *get_expr () { return const_expr.get (); }
 
-  std::string get_identifier () const { return identifier; }
+  Identifier get_identifier () const { return identifier; }
 
   Analysis::NodeMapping get_impl_mappings () const override
   {
@@ -2146,7 +2149,7 @@ public:
 
   std::string get_impl_item_name () const override final
   {
-    return get_identifier ();
+    return get_identifier ().as_string ();
   }
 
 protected:
@@ -2401,7 +2404,7 @@ public:
 
   const std::string trait_identifier () const override final
   {
-    return decl.get_function_name ();
+    return decl.get_function_name ().as_string ();
   }
 
   TraitItemKind get_item_kind () const override final
@@ -2490,7 +2493,10 @@ public:
     return expr;
   }
 
-  const std::string trait_identifier () const override final { return name; }
+  const std::string trait_identifier () const override final
+  {
+    return name.as_string ();
+  }
 
   TraitItemKind get_item_kind () const override final
   {
@@ -2579,7 +2585,10 @@ public:
     return type_param_bounds;
   }
 
-  const std::string trait_identifier () const override final { return name; }
+  const std::string trait_identifier () const override final
+  {
+    return name.as_string ();
+  }
 
   TraitItemKind get_item_kind () const override final
   {
@@ -2999,7 +3008,7 @@ private:
   Analysis::NodeMapping mappings;
 
 public:
-  bool has_name () const { return name != "_"; }
+  bool has_name () const { return name.as_string () != "_"; }
 
   NamedFunctionParam (Analysis::NodeMapping mappings, Identifier name,
 		      std::unique_ptr<Type> param_type)
diff --git a/gcc/rust/hir/tree/rust-hir-path.h b/gcc/rust/hir/tree/rust-hir-path.h
index b615fbfbb33..b005e71ec42 100644
--- a/gcc/rust/hir/tree/rust-hir-path.h
+++ b/gcc/rust/hir/tree/rust-hir-path.h
@@ -71,7 +71,7 @@ public:
   // Creates an error state generic args binding.
   static GenericArgsBinding create_error ()
   {
-    return GenericArgsBinding ("", nullptr);
+    return GenericArgsBinding ({""}, nullptr);
   }
 
   // Pointer type for type in constructor to enable polymorphism
diff --git a/gcc/rust/hir/tree/rust-hir-type.h b/gcc/rust/hir/tree/rust-hir-type.h
index de1aa8ba5da..9435e4a2db1 100644
--- a/gcc/rust/hir/tree/rust-hir-type.h
+++ b/gcc/rust/hir/tree/rust-hir-type.h
@@ -730,7 +730,7 @@ public:
   // Creates an error state param.
   static MaybeNamedParam create_error ()
   {
-    return MaybeNamedParam ("", UNNAMED, nullptr, Location ());
+    return MaybeNamedParam ({""}, UNNAMED, nullptr, Location ());
   }
 
   Location get_locus () const { return locus; }
diff --git a/gcc/rust/hir/tree/rust-hir.cc b/gcc/rust/hir/tree/rust-hir.cc
index ac047067f82..de1c82593f5 100644
--- a/gcc/rust/hir/tree/rust-hir.cc
+++ b/gcc/rust/hir/tree/rust-hir.cc
@@ -168,7 +168,7 @@ std::string
 Module::as_string () const
 {
   // get module string for "[vis] mod [name]"
-  std::string str = VisItem::as_string () + "mod " + module_name;
+  std::string str = VisItem::as_string () + "mod " + module_name.as_string ();
 
   // inner attributes
   str += "\n inner attributes: ";
@@ -223,7 +223,7 @@ StaticItem::as_string () const
       str += " mut";
     }
 
-  str += name;
+  str += name.as_string ();
 
   // DEBUG: null pointer check
   if (type == nullptr)
@@ -266,7 +266,7 @@ TupleStruct::as_string () const
 {
   std::string str = VisItem::as_string ();
 
-  str += "struct " + struct_name;
+  str += "struct " + struct_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -323,7 +323,7 @@ ConstantItem::as_string () const
 {
   std::string str = VisItem::as_string ();
 
-  str += "const " + identifier;
+  str += "const " + identifier.as_string ();
 
   // DEBUG: null pointer check
   if (type == nullptr)
@@ -425,7 +425,7 @@ StructStruct::as_string () const
 {
   std::string str = VisItem::as_string ();
 
-  str += "struct " + struct_name;
+  str += "struct " + struct_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -581,7 +581,7 @@ UseTreeRebind::as_string () const
       // nothing to add, just path
       break;
     case IDENTIFIER:
-      path_str += " as " + identifier;
+      path_str += " as " + identifier.as_string ();
       break;
     case WILDCARD:
       path_str += " as _";
@@ -598,7 +598,7 @@ std::string
 Enum::as_string () const
 {
   std::string str = VisItem::as_string ();
-  str += enum_name;
+  str += enum_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -669,7 +669,7 @@ Trait::as_string () const
       str += "unsafe ";
     }
 
-  str += "trait " + name;
+  str += "trait " + name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -756,7 +756,7 @@ Union::as_string () const
 {
   std::string str = VisItem::as_string ();
 
-  str += "union " + union_name;
+  str += "union " + union_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -834,7 +834,7 @@ Function::as_string () const
       str += "void ";
     }
 
-  str += function_name;
+  str += function_name.as_string ();
 
   if (has_generics ())
     {
@@ -985,7 +985,7 @@ TypeAlias::as_string () const
 {
   std::string str = VisItem::as_string ();
 
-  str += " " + new_type_name;
+  str += " " + new_type_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -1458,7 +1458,7 @@ DereferenceExpr::as_string () const
 std::string
 FieldAccessExpr::as_string () const
 {
-  return receiver->as_string () + "." + field;
+  return receiver->as_string () + "." + field.as_string ();
 }
 
 std::string
@@ -2118,7 +2118,7 @@ TypeParam::as_string () const
       str += outer_attr.as_string ();
     }
 
-  str += "\n Identifier: " + type_representation;
+  str += "\n Identifier: " + type_representation.as_string ();
 
   str += "\n Type param bounds: ";
   if (!has_type_param_bounds ())
@@ -2284,7 +2284,7 @@ GenericArgs::as_string () const
 std::string
 GenericArgsBinding::as_string () const
 {
-  return identifier + " = " + type->as_string ();
+  return identifier.as_string () + " = " + type->as_string ();
 }
 
 std::string
@@ -2457,7 +2457,7 @@ StructPatternFieldIdent::as_string () const
       str += "mut ";
     }
 
-  str += ident;
+  str += ident.as_string ();
 
   return str;
 }
@@ -2481,7 +2481,7 @@ StructPatternFieldIdentPat::as_string () const
 
   str += "\n";
 
-  str += ident + " : " + ident_pattern->as_string ();
+  str += ident.as_string () + " : " + ident_pattern->as_string ();
 
   return str;
 }
@@ -2562,7 +2562,7 @@ IdentifierPattern::as_string () const
       str += "mut ";
     }
 
-  str += variable_ident;
+  str += variable_ident.as_string ();
 
   if (has_pattern_to_bind ())
     {
@@ -2991,7 +2991,7 @@ StructExprFieldWithVal::as_string () const
 std::string
 StructExprFieldIdentifierValue::as_string () const
 {
-  return field_name + " : " + StructExprFieldWithVal::as_string ();
+  return field_name.as_string () + " : " + StructExprFieldWithVal::as_string ();
 }
 
 std::string
@@ -3035,7 +3035,7 @@ std::string
 EnumItem::as_string () const
 {
   std::string str = Item::as_string ();
-  str += variant_name;
+  str += variant_name.as_string ();
   str += " ";
   switch (get_enum_item_kind ())
     {
@@ -3165,7 +3165,7 @@ StructField::as_string () const
       str += "\n" + visibility.as_string ();
     }
 
-  str += " " + field_name + " : " + field_type->as_string ();
+  str += " " + field_name.as_string () + " : " + field_type->as_string ();
 
   return str;
 }
@@ -3219,7 +3219,7 @@ ExternalStaticItem::as_string () const
     }
 
   // add name
-  str += get_item_name ();
+  str += get_item_name ().as_string ();
 
   // add type on new line
   str += "\n Type: " + item_type->as_string ();
@@ -3235,7 +3235,7 @@ ExternalFunctionItem::as_string () const
   str += "fn ";
 
   // add name
-  str += get_item_name ();
+  str += get_item_name ().as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -3299,7 +3299,7 @@ ExternalFunctionItem::as_string () const
 std::string
 NamedFunctionParam::as_string () const
 {
-  std::string str = name;
+  std::string str = name.as_string ();
 
   str += "\n Type: " + param_type->as_string ();
 
@@ -3357,7 +3357,8 @@ TraitItemFunc::as_string () const
 std::string
 TraitFunctionDecl::as_string () const
 {
-  std::string str = qualifiers.as_string () + "fn " + function_name;
+  std::string str
+    = qualifiers.as_string () + "fn " + function_name.as_string ();
 
   // generic params
   str += "\n Generic params: ";
@@ -3441,7 +3442,7 @@ TraitItemConst::as_string () const
 	}
     }
 
-  str += "\nconst " + name + " : " + type->as_string ();
+  str += "\nconst " + name.as_string () + " : " + type->as_string ();
 
   if (has_expression ())
     {
@@ -3469,7 +3470,7 @@ TraitItemType::as_string () const
 	}
     }
 
-  str += "\ntype " + name;
+  str += "\ntype " + name.as_string ();
 
   str += "\n Type param bounds: ";
   if (!has_type_param_bounds ())
@@ -3655,7 +3656,7 @@ MaybeNamedParam::as_string () const
     case UNNAMED:
       break;
     case IDENTIFIER:
-      str = name + " : ";
+      str = name.as_string () + " : ";
       break;
     case WILDCARD:
       str = "_ : ";
diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h
index 0258f5f24fb..b3d3f7d476a 100644
--- a/gcc/rust/hir/tree/rust-hir.h
+++ b/gcc/rust/hir/tree/rust-hir.h
@@ -27,7 +27,6 @@
 #include "rust-diagnostics.h"
 
 namespace Rust {
-typedef std::string Identifier;
 typedef int TupleIndex;
 
 namespace HIR {
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index bc87ed72345..6bce55c43a9 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -2160,10 +2160,10 @@ Parser<ManagedTokenSource>::parse_macro_match_fragment ()
   Location fragment_locus = lexer.peek_token ()->get_locus ();
   skip_token (DOLLAR_SIGN);
 
-  Identifier ident = "";
+  Identifier ident{""};
   auto identifier = lexer.peek_token ();
   if (identifier->get_id () == UNDERSCORE)
-    ident = "_";
+    ident = {"_"};
   else
     ident = identifier->get_str ();
 
@@ -2411,7 +2411,7 @@ Parser<ManagedTokenSource>::parse_module (AST::Visibility vis,
     {
       return nullptr;
     }
-  Identifier name = module_name->get_str ();
+  Identifier name{module_name->get_str ()};
 
   const_TokenPtr t = lexer.peek_token ();
 
@@ -2431,7 +2431,7 @@ Parser<ManagedTokenSource>::parse_module (AST::Visibility vis,
 	// parse inner attributes
 	AST::AttrVec inner_attrs = parse_inner_attributes ();
 
-	std::string default_path = name;
+	std::string default_path = name.as_string ();
 
 	if (inline_module_stack.empty ())
 	  {
@@ -2445,7 +2445,7 @@ Parser<ManagedTokenSource>::parse_module (AST::Visibility vis,
 
 	    std::string subdir;
 	    if (get_file_subdir (filename, subdir))
-	      default_path = subdir + file_separator + name;
+	      default_path = subdir + file_separator + name.as_string ();
 	  }
 
 	std::string module_path_name
@@ -2825,7 +2825,7 @@ Parser<ManagedTokenSource>::parse_use_tree ()
 
 		return std::unique_ptr<AST::UseTreeRebind> (
 		  new AST::UseTreeRebind (AST::UseTreeRebind::WILDCARD,
-					  std::move (path), locus, "_"));
+					  std::move (path), locus, {"_"}));
 	      default:
 		add_error (Error (
 		  t->get_locus (),
@@ -9666,7 +9666,7 @@ Parser<ManagedTokenSource>::parse_maybe_named_param (AST::AttrVec outer_attrs)
   else if (current->get_id () == UNDERSCORE && next->get_id () == COLON)
     {
       // wildcard param
-      name = "_";
+      name = {"_"};
       kind = AST::MaybeNamedParam::WILDCARD;
       lexer.skip_token (1);
     }
diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h
index a5860956509..126fc299f17 100644
--- a/gcc/rust/resolve/rust-ast-resolve-implitem.h
+++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h
@@ -51,8 +51,8 @@ public:
 
   void visit (AST::TypeAlias &type) override
   {
-    auto decl
-      = CanonicalPath::new_seg (type.get_node_id (), type.get_new_type_name ());
+    auto decl = CanonicalPath::new_seg (type.get_node_id (),
+					type.get_new_type_name ().as_string ());
     auto path = prefix.append (decl);
 
     resolver->get_type_scope ().insert (
@@ -82,8 +82,9 @@ public:
 
   void visit (AST::Function &function) override
   {
-    auto decl = CanonicalPath::new_seg (function.get_node_id (),
-					function.get_function_name ());
+    auto decl
+      = CanonicalPath::new_seg (function.get_node_id (),
+				function.get_function_name ().as_string ());
     auto path = prefix.append (decl);
 
     resolver->get_name_scope ().insert (
@@ -99,7 +100,7 @@ public:
   void visit (AST::Method &method) override
   {
     auto decl = CanonicalPath::new_seg (method.get_node_id (),
-					method.get_method_name ());
+					method.get_method_name ().as_string ());
     auto path = prefix.append (decl);
 
     resolver->get_name_scope ().insert (
@@ -138,7 +139,7 @@ public:
   {
     auto decl = CanonicalPath::new_seg (
       function.get_node_id (),
-      function.get_trait_function_decl ().get_identifier ());
+      function.get_trait_function_decl ().get_identifier ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
@@ -157,7 +158,8 @@ public:
   void visit (AST::TraitItemMethod &method) override
   {
     auto decl = CanonicalPath::new_seg (
-      method.get_node_id (), method.get_trait_method_decl ().get_identifier ());
+      method.get_node_id (),
+      method.get_trait_method_decl ().get_identifier ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
@@ -175,8 +177,9 @@ public:
 
   void visit (AST::TraitItemConst &constant) override
   {
-    auto decl = CanonicalPath::new_seg (constant.get_node_id (),
-					constant.get_identifier ());
+    auto decl
+      = CanonicalPath::new_seg (constant.get_node_id (),
+				constant.get_identifier ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
@@ -194,8 +197,8 @@ public:
 
   void visit (AST::TraitItemType &type) override
   {
-    auto decl
-      = CanonicalPath::new_seg (type.get_node_id (), type.get_identifier ());
+    auto decl = CanonicalPath::new_seg (type.get_node_id (),
+					type.get_identifier ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
@@ -233,8 +236,9 @@ public:
 
   void visit (AST::ExternalFunctionItem &function) override
   {
-    auto decl = CanonicalPath::new_seg (function.get_node_id (),
-					function.get_identifier ());
+    auto decl
+      = CanonicalPath::new_seg (function.get_node_id (),
+				function.get_identifier ().as_string ());
     auto path = prefix.append (decl);
 
     resolver->get_name_scope ().insert (
@@ -252,8 +256,8 @@ public:
 
   void visit (AST::ExternalStaticItem &item) override
   {
-    auto decl
-      = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+    auto decl = CanonicalPath::new_seg (item.get_node_id (),
+					item.get_identifier ().as_string ());
     auto path = prefix.append (decl);
 
     resolver->get_name_scope ().insert (
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc
index 8d29e9bcd25..8f73cf8d11d 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-item.cc
@@ -46,8 +46,8 @@ ResolveTraitItems::go (AST::TraitItem *item, const CanonicalPath &prefix,
 void
 ResolveTraitItems::visit (AST::TraitItemType &type)
 {
-  auto decl
-    = CanonicalPath::new_seg (type.get_node_id (), type.get_identifier ());
+  auto decl = CanonicalPath::new_seg (type.get_node_id (),
+				      type.get_identifier ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
   mappings->insert_canonical_path (type.get_node_id (), cpath);
@@ -60,7 +60,8 @@ void
 ResolveTraitItems::visit (AST::TraitItemFunc &func)
 {
   auto decl = CanonicalPath::new_seg (
-    func.get_node_id (), func.get_trait_function_decl ().get_identifier ());
+    func.get_node_id (),
+    func.get_trait_function_decl ().get_identifier ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
   mappings->insert_canonical_path (func.get_node_id (), cpath);
@@ -108,9 +109,9 @@ ResolveTraitItems::visit (AST::TraitItemFunc &func)
 void
 ResolveTraitItems::visit (AST::TraitItemMethod &func)
 {
-  auto decl
-    = CanonicalPath::new_seg (func.get_node_id (),
-			      func.get_trait_method_decl ().get_identifier ());
+  auto decl = CanonicalPath::new_seg (
+    func.get_node_id (),
+    func.get_trait_method_decl ().get_identifier ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
   mappings->insert_canonical_path (func.get_node_id (), cpath);
@@ -133,7 +134,7 @@ ResolveTraitItems::visit (AST::TraitItemMethod &func)
 
   // self turns into (self: Self) as a function param
   AST::SelfParam &self_param = function.get_self_param ();
-  AST::IdentifierPattern self_pattern (self_param.get_node_id (), "self",
+  AST::IdentifierPattern self_pattern (self_param.get_node_id (), {"self"},
 				       self_param.get_locus (),
 				       self_param.get_has_ref (),
 				       self_param.get_is_mut (),
@@ -186,7 +187,7 @@ void
 ResolveTraitItems::visit (AST::TraitItemConst &constant)
 {
   auto decl = CanonicalPath::new_seg (constant.get_node_id (),
-				      constant.get_identifier ());
+				      constant.get_identifier ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
   mappings->insert_canonical_path (constant.get_node_id (), cpath);
@@ -214,7 +215,8 @@ void
 ResolveItem::visit (AST::TypeAlias &alias)
 {
   auto talias
-    = CanonicalPath::new_seg (alias.get_node_id (), alias.get_new_type_name ());
+    = CanonicalPath::new_seg (alias.get_node_id (),
+			      alias.get_new_type_name ().as_string ());
   auto path = prefix.append (talias);
   auto cpath = canonical_prefix.append (talias);
   mappings->insert_canonical_path (alias.get_node_id (), cpath);
@@ -237,7 +239,8 @@ ResolveItem::visit (AST::TypeAlias &alias)
 void
 ResolveItem::visit (AST::Module &module)
 {
-  auto mod = CanonicalPath::new_seg (module.get_node_id (), module.get_name ());
+  auto mod = CanonicalPath::new_seg (module.get_node_id (),
+				     module.get_name ().as_string ());
   auto path = prefix.append (mod);
   auto cpath = canonical_prefix.append (mod);
   mappings->insert_canonical_path (module.get_node_id (), cpath);
@@ -271,8 +274,9 @@ ResolveItem::visit (AST::Module &module)
 void
 ResolveItem::visit (AST::TupleStruct &struct_decl)
 {
-  auto decl = CanonicalPath::new_seg (struct_decl.get_node_id (),
-				      struct_decl.get_identifier ());
+  auto decl
+    = CanonicalPath::new_seg (struct_decl.get_node_id (),
+			      struct_decl.get_identifier ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
   mappings->insert_canonical_path (struct_decl.get_node_id (), cpath);
@@ -306,7 +310,7 @@ void
 ResolveItem::visit (AST::Enum &enum_decl)
 {
   auto decl = CanonicalPath::new_seg (enum_decl.get_node_id (),
-				      enum_decl.get_identifier ());
+				      enum_decl.get_identifier ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
   mappings->insert_canonical_path (enum_decl.get_node_id (), cpath);
@@ -337,8 +341,8 @@ ResolveItem::visit (AST::EnumItem &item)
   // Since at this point we cannot have visibilities on enum items anymore, we
   // can skip handling them
 
-  auto decl
-    = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+  auto decl = CanonicalPath::new_seg (item.get_node_id (),
+				      item.get_identifier ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
   mappings->insert_canonical_path (item.get_node_id (), cpath);
@@ -347,8 +351,8 @@ ResolveItem::visit (AST::EnumItem &item)
 void
 ResolveItem::visit (AST::EnumItemTuple &item)
 {
-  auto decl
-    = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+  auto decl = CanonicalPath::new_seg (item.get_node_id (),
+				      item.get_identifier ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
   mappings->insert_canonical_path (item.get_node_id (), cpath);
@@ -365,8 +369,8 @@ ResolveItem::visit (AST::EnumItemTuple &item)
 void
 ResolveItem::visit (AST::EnumItemStruct &item)
 {
-  auto decl
-    = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+  auto decl = CanonicalPath::new_seg (item.get_node_id (),
+				      item.get_identifier ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
   mappings->insert_canonical_path (item.get_node_id (), cpath);
@@ -383,8 +387,8 @@ ResolveItem::visit (AST::EnumItemStruct &item)
 void
 ResolveItem::visit (AST::EnumItemDiscriminant &item)
 {
-  auto decl
-    = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+  auto decl = CanonicalPath::new_seg (item.get_node_id (),
+				      item.get_identifier ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
 
@@ -394,8 +398,9 @@ ResolveItem::visit (AST::EnumItemDiscriminant &item)
 void
 ResolveItem::visit (AST::StructStruct &struct_decl)
 {
-  auto decl = CanonicalPath::new_seg (struct_decl.get_node_id (),
-				      struct_decl.get_identifier ());
+  auto decl
+    = CanonicalPath::new_seg (struct_decl.get_node_id (),
+			      struct_decl.get_identifier ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
   mappings->insert_canonical_path (struct_decl.get_node_id (), cpath);
@@ -428,8 +433,9 @@ ResolveItem::visit (AST::StructStruct &struct_decl)
 void
 ResolveItem::visit (AST::Union &union_decl)
 {
-  auto decl = CanonicalPath::new_seg (union_decl.get_node_id (),
-				      union_decl.get_identifier ());
+  auto decl
+    = CanonicalPath::new_seg (union_decl.get_node_id (),
+			      union_decl.get_identifier ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
   mappings->insert_canonical_path (union_decl.get_node_id (), cpath);
@@ -460,8 +466,8 @@ ResolveItem::visit (AST::Union &union_decl)
 void
 ResolveItem::visit (AST::StaticItem &var)
 {
-  auto decl
-    = CanonicalPath::new_seg (var.get_node_id (), var.get_identifier ());
+  auto decl = CanonicalPath::new_seg (var.get_node_id (),
+				      var.get_identifier ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
   mappings->insert_canonical_path (var.get_node_id (), cpath);
@@ -488,8 +494,9 @@ ResolveItem::visit (AST::ConstantItem &constant)
 void
 ResolveItem::visit (AST::Function &function)
 {
-  auto decl = CanonicalPath::new_seg (function.get_node_id (),
-				      function.get_function_name ());
+  auto decl
+    = CanonicalPath::new_seg (function.get_node_id (),
+			      function.get_function_name ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
 
@@ -611,8 +618,8 @@ ResolveItem::visit (AST::InherentImpl &impl_block)
 void
 ResolveItem::visit (AST::Method &method)
 {
-  auto decl
-    = CanonicalPath::new_seg (method.get_node_id (), method.get_method_name ());
+  auto decl = CanonicalPath::new_seg (method.get_node_id (),
+				      method.get_method_name ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
   mappings->insert_canonical_path (method.get_node_id (), cpath);
@@ -641,7 +648,7 @@ ResolveItem::visit (AST::Method &method)
 
   // self turns into (self: Self) as a function param
   AST::SelfParam &self_param = method.get_self_param ();
-  AST::IdentifierPattern self_pattern (self_param.get_node_id (), "self",
+  AST::IdentifierPattern self_pattern (self_param.get_node_id (), {"self"},
 				       self_param.get_locus (),
 				       self_param.get_has_ref (),
 				       self_param.get_is_mut (),
@@ -818,7 +825,7 @@ ResolveItem::visit (AST::Trait &trait)
 
   // we need to inject an implicit self TypeParam here
   AST::TypeParam *implicit_self
-    = new AST::TypeParam ("Self", trait.get_locus ());
+    = new AST::TypeParam ({"Self"}, trait.get_locus ());
   trait.insert_implict_self (
     std::unique_ptr<AST::GenericParam> (implicit_self));
   CanonicalPath Self = CanonicalPath::get_big_self (trait.get_node_id ());
@@ -946,7 +953,7 @@ flatten_rebind (const AST::UseTreeRebind &rebind,
 
       // Add the identifier as a new path
       rebind_path.get_segments ().back ()
-	= AST::SimplePathSegment (new_seg, Location ());
+	= AST::SimplePathSegment (new_seg.as_string (), Location ());
 
       paths.emplace_back (rebind_path);
     }
@@ -1095,7 +1102,7 @@ ResolveExternItem::visit (AST::ExternalFunctionItem &function)
 {
   NodeId scope_node_id = function.get_node_id ();
   auto decl = CanonicalPath::new_seg (function.get_node_id (),
-				      function.get_identifier ());
+				      function.get_identifier ().as_string ());
   auto path = prefix.append (decl);
   auto cpath = canonical_prefix.append (decl);
 
@@ -1208,7 +1215,7 @@ rust_flatten_rebind (void)
   auto frob = Rust::AST::SimplePath::from_str ("frobulator", Location ());
 
   auto rebind = Rust::AST::UseTreeRebind (Rust::AST::UseTreeRebind::IDENTIFIER,
-					  frob, Location (), "saindoux");
+					  frob, Location (), {"saindoux"});
 
   auto paths = std::vector<Rust::AST::SimplePath> ();
   Rust::Resolver::flatten_rebind (rebind, paths);
@@ -1228,8 +1235,9 @@ rust_flatten_rebind_nested (void)
 
   auto foo_bar_baz = Rust::AST::SimplePath ({foo, bar, baz});
 
-  auto rebind = Rust::AST::UseTreeRebind (Rust::AST::UseTreeRebind::IDENTIFIER,
-					  foo_bar_baz, Location (), "saindoux");
+  auto rebind
+    = Rust::AST::UseTreeRebind (Rust::AST::UseTreeRebind::IDENTIFIER,
+				foo_bar_baz, Location (), {"saindoux"});
 
   auto paths = std::vector<Rust::AST::SimplePath> ();
   Rust::Resolver::flatten_rebind (rebind, paths);
diff --git a/gcc/rust/resolve/rust-ast-resolve-pattern.cc b/gcc/rust/resolve/rust-ast-resolve-pattern.cc
index 0346ed87533..00d6cc71a77 100644
--- a/gcc/rust/resolve/rust-ast-resolve-pattern.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-pattern.cc
@@ -44,7 +44,7 @@ PatternDeclaration::go (AST::Pattern *pattern, Rib::ItemType type,
 
       rust_error_at (info.get_locus (), ErrorCode ("E0408"),
 		     "variable '%s' is not bound in all patterns",
-		     ident.c_str ());
+		     ident.as_string ().c_str ());
     }
 
   for (auto &map_entry : resolver.inconsistent_bindings)
@@ -55,7 +55,7 @@ PatternDeclaration::go (AST::Pattern *pattern, Rib::ItemType type,
       rust_error_at (
 	info.get_locus (), ErrorCode ("E0409"),
 	"variable '%s' is bound inconsistently across pattern alternatives",
-	ident.c_str ());
+	ident.as_string ().c_str ());
     }
 }
 
@@ -244,7 +244,7 @@ PatternDeclaration::visit (AST::AltPattern &pattern)
   auto idents = bindings_with_ctx.back ().idents;
   bindings_with_ctx.pop_back ();
   for (auto &ident : idents)
-    bindings_with_ctx.back ().idents.insert (ident);
+    bindings_with_ctx.back ().idents.insert (ident.as_string ());
 
   // ...we repopulate the binding_info_map correctly (the initial bindings
   // stored in the tmp_binding_map + all the bindings from all the alts)
@@ -281,14 +281,14 @@ PatternDeclaration::add_new_binding (Identifier ident, NodeId node_id,
 	  rust_error_at (info.get_locus (), ErrorCode ("E0415"),
 			 "identifier '%s' is bound more than once in the "
 			 "same parameter list",
-			 ident.c_str ());
+			 ident.as_string ().c_str ());
 	}
       else
 	{
 	  rust_error_at (
 	    info.get_locus (), ErrorCode ("E0416"),
 	    "identifier '%s' is bound more than once in the same pattern",
-	    ident.c_str ());
+	    ident.as_string ().c_str ());
 	}
 
       return;
@@ -297,9 +297,9 @@ PatternDeclaration::add_new_binding (Identifier ident, NodeId node_id,
   if (!identifier_or_bound)
     {
       bindings_with_ctx.back ().idents.insert (ident);
-      resolver->get_name_scope ().insert (CanonicalPath::new_seg (node_id,
-								  ident),
-					  node_id, info.get_locus (), type);
+      resolver->get_name_scope ().insert (
+	CanonicalPath::new_seg (node_id, ident.as_string ()), node_id,
+	info.get_locus (), type);
     }
 
   binding_info_map.insert ({ident, info});
diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h
index 99680684a59..5c33712e102 100644
--- a/gcc/rust/resolve/rust-ast-resolve-stmt.h
+++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h
@@ -84,8 +84,9 @@ public:
 
   void visit (AST::TupleStruct &struct_decl) override
   {
-    auto decl = CanonicalPath::new_seg (struct_decl.get_node_id (),
-					struct_decl.get_identifier ());
+    auto decl
+      = CanonicalPath::new_seg (struct_decl.get_node_id (),
+				struct_decl.get_identifier ().as_string ());
     auto path = decl; // this ensures we have the correct relative resolution
     auto cpath = canonical_prefix.append (decl);
     mappings->insert_canonical_path (struct_decl.get_node_id (), cpath);
@@ -116,8 +117,9 @@ public:
 
   void visit (AST::Enum &enum_decl) override
   {
-    auto decl = CanonicalPath::new_seg (enum_decl.get_node_id (),
-					enum_decl.get_identifier ());
+    auto decl
+      = CanonicalPath::new_seg (enum_decl.get_node_id (),
+				enum_decl.get_identifier ().as_string ());
     auto path = decl; // this ensures we have the correct relative resolution
     auto cpath = canonical_prefix.append (decl);
     mappings->insert_canonical_path (enum_decl.get_node_id (), cpath);
@@ -149,7 +151,8 @@ public:
   void visit (AST::EnumItem &item) override
   {
     auto decl = enum_prefix.append (
-      CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ()));
+      CanonicalPath::new_seg (item.get_node_id (),
+			      item.get_identifier ().as_string ()));
     auto path = decl; // this ensures we have the correct relative resolution
     auto cpath = canonical_prefix.append (decl);
     mappings->insert_canonical_path (item.get_node_id (), cpath);
@@ -168,7 +171,8 @@ public:
   void visit (AST::EnumItemTuple &item) override
   {
     auto decl = enum_prefix.append (
-      CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ()));
+      CanonicalPath::new_seg (item.get_node_id (),
+			      item.get_identifier ().as_string ()));
     auto path = decl; // this ensures we have the correct relative resolution
     auto cpath = canonical_prefix.append (decl);
     mappings->insert_canonical_path (item.get_node_id (), cpath);
@@ -193,7 +197,8 @@ public:
   void visit (AST::EnumItemStruct &item) override
   {
     auto decl = enum_prefix.append (
-      CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ()));
+      CanonicalPath::new_seg (item.get_node_id (),
+			      item.get_identifier ().as_string ()));
     auto path = decl; // this ensures we have the correct relative resolution
     auto cpath = canonical_prefix.append (decl);
     mappings->insert_canonical_path (item.get_node_id (), cpath);
@@ -218,7 +223,8 @@ public:
   void visit (AST::EnumItemDiscriminant &item) override
   {
     auto decl = enum_prefix.append (
-      CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ()));
+      CanonicalPath::new_seg (item.get_node_id (),
+			      item.get_identifier ().as_string ()));
     auto path = decl; // this ensures we have the correct relative resolution
     auto cpath = canonical_prefix.append (decl);
     mappings->insert_canonical_path (item.get_node_id (), cpath);
@@ -236,8 +242,9 @@ public:
 
   void visit (AST::StructStruct &struct_decl) override
   {
-    auto decl = CanonicalPath::new_seg (struct_decl.get_node_id (),
-					struct_decl.get_identifier ());
+    auto decl
+      = CanonicalPath::new_seg (struct_decl.get_node_id (),
+				struct_decl.get_identifier ().as_string ());
     auto path = decl; // this ensures we have the correct relative resolution
     auto cpath = canonical_prefix.append (decl);
     mappings->insert_canonical_path (struct_decl.get_node_id (), cpath);
@@ -273,8 +280,9 @@ public:
 
   void visit (AST::Union &union_decl) override
   {
-    auto decl = CanonicalPath::new_seg (union_decl.get_node_id (),
-					union_decl.get_identifier ());
+    auto decl
+      = CanonicalPath::new_seg (union_decl.get_node_id (),
+				union_decl.get_identifier ().as_string ());
     auto path = decl; // this ensures we have the correct relative resolution
     auto cpath = canonical_prefix.append (decl);
     mappings->insert_canonical_path (union_decl.get_node_id (), cpath);
@@ -308,8 +316,9 @@ public:
 
   void visit (AST::Function &function) override
   {
-    auto decl = CanonicalPath::new_seg (function.get_node_id (),
-					function.get_function_name ());
+    auto decl
+      = CanonicalPath::new_seg (function.get_node_id (),
+				function.get_function_name ().as_string ());
     auto path = decl; // this ensures we have the correct relative resolution
     auto cpath = canonical_prefix.append (decl);
     mappings->insert_canonical_path (function.get_node_id (), cpath);
diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
index 1ab9af8e40a..bd918dffcb0 100644
--- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h
+++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
@@ -47,8 +47,8 @@ public:
 
   void visit (AST::Module &module) override
   {
-    auto mod
-      = CanonicalPath::new_seg (module.get_node_id (), module.get_name ());
+    auto mod = CanonicalPath::new_seg (module.get_node_id (),
+				       module.get_name ().as_string ());
     auto path = prefix.append (mod);
     auto cpath = canonical_prefix.append (mod);
 
@@ -76,8 +76,9 @@ public:
 
   void visit (AST::TypeAlias &alias) override
   {
-    auto talias = CanonicalPath::new_seg (alias.get_node_id (),
-					  alias.get_new_type_name ());
+    auto talias
+      = CanonicalPath::new_seg (alias.get_node_id (),
+				alias.get_new_type_name ().as_string ());
     auto path = prefix.append (talias);
     auto cpath = canonical_prefix.append (talias);
 
@@ -97,8 +98,9 @@ public:
 
   void visit (AST::TupleStruct &struct_decl) override
   {
-    auto decl = CanonicalPath::new_seg (struct_decl.get_node_id (),
-					struct_decl.get_identifier ());
+    auto decl
+      = CanonicalPath::new_seg (struct_decl.get_node_id (),
+				struct_decl.get_identifier ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
@@ -118,8 +120,9 @@ public:
 
   void visit (AST::Enum &enum_decl) override
   {
-    auto decl = CanonicalPath::new_seg (enum_decl.get_node_id (),
-					enum_decl.get_identifier ());
+    auto decl
+      = CanonicalPath::new_seg (enum_decl.get_node_id (),
+				enum_decl.get_identifier ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
@@ -145,8 +148,8 @@ public:
 
   void visit (AST::EnumItem &item) override
   {
-    auto decl
-      = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+    auto decl = CanonicalPath::new_seg (item.get_node_id (),
+					item.get_identifier ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
@@ -167,8 +170,8 @@ public:
 
   void visit (AST::EnumItemTuple &item) override
   {
-    auto decl
-      = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+    auto decl = CanonicalPath::new_seg (item.get_node_id (),
+					item.get_identifier ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
@@ -189,8 +192,8 @@ public:
 
   void visit (AST::EnumItemStruct &item) override
   {
-    auto decl
-      = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+    auto decl = CanonicalPath::new_seg (item.get_node_id (),
+					item.get_identifier ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
@@ -211,8 +214,8 @@ public:
 
   void visit (AST::EnumItemDiscriminant &item) override
   {
-    auto decl
-      = CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ());
+    auto decl = CanonicalPath::new_seg (item.get_node_id (),
+					item.get_identifier ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
@@ -233,8 +236,9 @@ public:
 
   void visit (AST::StructStruct &struct_decl) override
   {
-    auto decl = CanonicalPath::new_seg (struct_decl.get_node_id (),
-					struct_decl.get_identifier ());
+    auto decl
+      = CanonicalPath::new_seg (struct_decl.get_node_id (),
+				struct_decl.get_identifier ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
@@ -254,8 +258,9 @@ public:
 
   void visit (AST::Union &union_decl) override
   {
-    auto decl = CanonicalPath::new_seg (union_decl.get_node_id (),
-					union_decl.get_identifier ());
+    auto decl
+      = CanonicalPath::new_seg (union_decl.get_node_id (),
+				union_decl.get_identifier ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
@@ -275,8 +280,8 @@ public:
 
   void visit (AST::StaticItem &var) override
   {
-    auto decl
-      = CanonicalPath::new_seg (var.get_node_id (), var.get_identifier ());
+    auto decl = CanonicalPath::new_seg (var.get_node_id (),
+					var.get_identifier ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
@@ -316,8 +321,9 @@ public:
 
   void visit (AST::Function &function) override
   {
-    auto decl = CanonicalPath::new_seg (function.get_node_id (),
-					function.get_function_name ());
+    auto decl
+      = CanonicalPath::new_seg (function.get_node_id (),
+				function.get_function_name ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
@@ -380,8 +386,8 @@ public:
 
   void visit (AST::Trait &trait) override
   {
-    auto decl
-      = CanonicalPath::new_seg (trait.get_node_id (), trait.get_identifier ());
+    auto decl = CanonicalPath::new_seg (trait.get_node_id (),
+					trait.get_identifier ().as_string ());
     auto path = prefix.append (decl);
     auto cpath = canonical_prefix.append (decl);
 
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h
index fd8307b8cd6..ac2fd17c355 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -173,8 +173,9 @@ public:
 	  }
       }
 
-    auto seg = CanonicalPath::new_seg (param.get_node_id (),
-				       param.get_type_representation ());
+    auto seg
+      = CanonicalPath::new_seg (param.get_node_id (),
+				param.get_type_representation ().as_string ());
     resolver->get_type_scope ().insert (
       seg, param.get_node_id (), param.get_locus (), false, Rib::ItemType::Type,
       [&] (const CanonicalPath &, NodeId, Location locus) -> void {
diff --git a/gcc/rust/resolve/rust-early-name-resolver.cc b/gcc/rust/resolve/rust-early-name-resolver.cc
index caa6e12c446..47d4e1b7bd1 100644
--- a/gcc/rust/resolve/rust-early-name-resolver.cc
+++ b/gcc/rust/resolve/rust-early-name-resolver.cc
@@ -901,7 +901,7 @@ void
 EarlyNameResolver::visit (AST::MacroRulesDefinition &rules_def)
 {
   auto path = CanonicalPath::new_seg (rules_def.get_node_id (),
-				      rules_def.get_rule_name ());
+				      rules_def.get_rule_name ().as_string ());
   resolver.get_macro_scope ().insert (path, rules_def.get_node_id (),
 				      rules_def.get_locus ());
 
@@ -979,7 +979,7 @@ EarlyNameResolver::visit (AST::MacroInvocation &invoc)
   if (is_builtin)
     {
       auto builtin_kind
-	= builtin_macro_from_string (rules_def->get_rule_name ());
+	= builtin_macro_from_string (rules_def->get_rule_name ().as_string ());
       invoc.map_to_builtin (builtin_kind);
     }
 
diff --git a/gcc/rust/typecheck/rust-autoderef.cc b/gcc/rust/typecheck/rust-autoderef.cc
index c70420a7c30..7c8c55d7db9 100644
--- a/gcc/rust/typecheck/rust-autoderef.cc
+++ b/gcc/rust/typecheck/rust-autoderef.cc
@@ -208,7 +208,9 @@ resolve_operator_overload_fn (
       HIR::Function *fn = impl_item.second;
 
       if (parent->has_trait_ref ()
-	  && fn->get_function_name ().compare (associated_item_name) == 0)
+	  && fn->get_function_name ().as_string ().compare (
+	       associated_item_name)
+	       == 0)
 	{
 	  TraitReference *trait_reference
 	    = TraitResolver::Lookup (*parent->get_trait_ref ().get ());
diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.cc b/gcc/rust/typecheck/rust-hir-dot-operator.cc
index af4b87ef2cc..1c8ee000a10 100644
--- a/gcc/rust/typecheck/rust-hir-dot-operator.cc
+++ b/gcc/rust/typecheck/rust-hir-dot-operator.cc
@@ -137,8 +137,9 @@ MethodResolver::select (TyTy::BaseType &receiver)
       if (!func->is_method ())
 	return true;
 
-      bool name_matches
-	= func->get_function_name ().compare (segment_name.as_string ()) == 0;
+      bool name_matches = func->get_function_name ().as_string ().compare (
+			    segment_name.as_string ())
+			  == 0;
       if (!name_matches)
 	return true;
 
@@ -199,103 +200,104 @@ MethodResolver::select (TyTy::BaseType &receiver)
   };
 
   std::vector<trait_item_candidate> trait_fns;
-  mappings->iterate_impl_blocks ([&] (HirId id,
-				      HIR::ImplBlock *impl) mutable -> bool {
-    bool is_trait_impl = impl->has_trait_ref ();
-    if (!is_trait_impl)
-      return true;
-
-    // look for impl implementation else lookup the associated trait item
-    for (auto &impl_item : impl->get_impl_items ())
-      {
-	bool is_fn = impl_item->get_impl_item_type ()
-		     == HIR::ImplItem::ImplItemType::FUNCTION;
-	if (!is_fn)
-	  continue;
-
-	HIR::Function *func = static_cast<HIR::Function *> (impl_item.get ());
-	if (!func->is_method ())
-	  continue;
-
-	bool name_matches
-	  = func->get_function_name ().compare (segment_name.as_string ()) == 0;
-	if (!name_matches)
-	  continue;
-
-	TyTy::BaseType *ty = nullptr;
-	if (!query_type (func->get_mappings ().get_hirid (), &ty))
-	  continue;
-	if (ty->get_kind () == TyTy::TypeKind::ERROR)
-	  continue;
-
-	rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF);
-	TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty);
-	const TyTy::BaseType *impl_self
-	  = TypeCheckItem::ResolveImplBlockSelf (*impl);
-
-	// see:
-	// https://gcc-rust.zulipchat.com/#narrow/stream/266897-general/topic/Method.20Resolution/near/338646280
-	// https://github.com/rust-lang/rust/blob/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/compiler/rustc_typeck/src/check/method/probe.rs#L650-L660
-	bool impl_self_is_ptr
-	  = impl_self->get_kind () == TyTy::TypeKind::POINTER;
-	bool impl_self_is_ref = impl_self->get_kind () == TyTy::TypeKind::REF;
-	if (receiver_is_raw_ptr && impl_self_is_ptr)
-	  {
-	    const TyTy::PointerType &sptr
-	      = *static_cast<const TyTy::PointerType *> (impl_self);
-	    const TyTy::PointerType &ptr
-	      = *static_cast<const TyTy::PointerType *> (raw);
-
-	    // we could do this via lang-item assemblies if we refactor this
-	    bool mut_match = sptr.mutability () == ptr.mutability ();
-	    if (!mut_match)
-	      continue;
-	  }
-	else if (receiver_is_ref && impl_self_is_ref)
-	  {
-	    const TyTy::ReferenceType &sptr
-	      = *static_cast<const TyTy::ReferenceType *> (impl_self);
-	    const TyTy::ReferenceType &ptr
-	      = *static_cast<const TyTy::ReferenceType *> (raw);
-
-	    // we could do this via lang-item assemblies if we refactor this
-	    bool mut_match = sptr.mutability () == ptr.mutability ();
-	    if (!mut_match)
-	      continue;
-	  }
-
-	inherent_impl_fns.push_back ({func, impl, fnty});
+  mappings->iterate_impl_blocks (
+    [&] (HirId id, HIR::ImplBlock *impl) mutable -> bool {
+      bool is_trait_impl = impl->has_trait_ref ();
+      if (!is_trait_impl)
 	return true;
-      }
 
-    TraitReference *trait_ref
-      = TraitResolver::Resolve (*impl->get_trait_ref ().get ());
-    rust_assert (!trait_ref->is_error ());
+      // look for impl implementation else lookup the associated trait item
+      for (auto &impl_item : impl->get_impl_items ())
+	{
+	  bool is_fn = impl_item->get_impl_item_type ()
+		       == HIR::ImplItem::ImplItemType::FUNCTION;
+	  if (!is_fn)
+	    continue;
+
+	  HIR::Function *func = static_cast<HIR::Function *> (impl_item.get ());
+	  if (!func->is_method ())
+	    continue;
+
+	  bool name_matches = func->get_function_name ().as_string ().compare (
+				segment_name.as_string ())
+			      == 0;
+	  if (!name_matches)
+	    continue;
+
+	  TyTy::BaseType *ty = nullptr;
+	  if (!query_type (func->get_mappings ().get_hirid (), &ty))
+	    continue;
+	  if (ty->get_kind () == TyTy::TypeKind::ERROR)
+	    continue;
+
+	  rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF);
+	  TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty);
+	  const TyTy::BaseType *impl_self
+	    = TypeCheckItem::ResolveImplBlockSelf (*impl);
+
+	  // see:
+	  // https://gcc-rust.zulipchat.com/#narrow/stream/266897-general/topic/Method.20Resolution/near/338646280
+	  // https://github.com/rust-lang/rust/blob/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/compiler/rustc_typeck/src/check/method/probe.rs#L650-L660
+	  bool impl_self_is_ptr
+	    = impl_self->get_kind () == TyTy::TypeKind::POINTER;
+	  bool impl_self_is_ref = impl_self->get_kind () == TyTy::TypeKind::REF;
+	  if (receiver_is_raw_ptr && impl_self_is_ptr)
+	    {
+	      const TyTy::PointerType &sptr
+		= *static_cast<const TyTy::PointerType *> (impl_self);
+	      const TyTy::PointerType &ptr
+		= *static_cast<const TyTy::PointerType *> (raw);
+
+	      // we could do this via lang-item assemblies if we refactor this
+	      bool mut_match = sptr.mutability () == ptr.mutability ();
+	      if (!mut_match)
+		continue;
+	    }
+	  else if (receiver_is_ref && impl_self_is_ref)
+	    {
+	      const TyTy::ReferenceType &sptr
+		= *static_cast<const TyTy::ReferenceType *> (impl_self);
+	      const TyTy::ReferenceType &ptr
+		= *static_cast<const TyTy::ReferenceType *> (raw);
+
+	      // we could do this via lang-item assemblies if we refactor this
+	      bool mut_match = sptr.mutability () == ptr.mutability ();
+	      if (!mut_match)
+		continue;
+	    }
 
-    auto item_ref
-      = trait_ref->lookup_trait_item (segment_name.as_string (),
-				      TraitItemReference::TraitItemType::FN);
-    if (item_ref->is_error ())
-      return true;
+	  inherent_impl_fns.push_back ({func, impl, fnty});
+	  return true;
+	}
 
-    const HIR::Trait *trait = trait_ref->get_hir_trait_ref ();
-    HIR::TraitItem *item = item_ref->get_hir_trait_item ();
-    if (item->get_item_kind () != HIR::TraitItem::TraitItemKind::FUNC)
-      return true;
+      TraitReference *trait_ref
+	= TraitResolver::Resolve (*impl->get_trait_ref ().get ());
+      rust_assert (!trait_ref->is_error ());
 
-    HIR::TraitItemFunc *func = static_cast<HIR::TraitItemFunc *> (item);
-    if (!func->get_decl ().is_method ())
-      return true;
+      auto item_ref
+	= trait_ref->lookup_trait_item (segment_name.as_string (),
+					TraitItemReference::TraitItemType::FN);
+      if (item_ref->is_error ())
+	return true;
 
-    TyTy::BaseType *ty = item_ref->get_tyty ();
-    rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF);
-    TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty);
+      const HIR::Trait *trait = trait_ref->get_hir_trait_ref ();
+      HIR::TraitItem *item = item_ref->get_hir_trait_item ();
+      if (item->get_item_kind () != HIR::TraitItem::TraitItemKind::FUNC)
+	return true;
 
-    trait_item_candidate candidate{func, trait, fnty, trait_ref, item_ref};
-    trait_fns.push_back (candidate);
+      HIR::TraitItemFunc *func = static_cast<HIR::TraitItemFunc *> (item);
+      if (!func->get_decl ().is_method ())
+	return true;
 
-    return true;
-  });
+      TyTy::BaseType *ty = item_ref->get_tyty ();
+      rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF);
+      TyTy::FnType *fnty = static_cast<TyTy::FnType *> (ty);
+
+      trait_item_candidate candidate{func, trait, fnty, trait_ref, item_ref};
+      trait_fns.push_back (candidate);
+
+      return true;
+    });
 
   // lookup specified bounds for an associated item
   struct precdicate_candidate
diff --git a/gcc/rust/typecheck/rust-hir-path-probe.cc b/gcc/rust/typecheck/rust-hir-path-probe.cc
index 83012ed5ef5..faa4fdad692 100644
--- a/gcc/rust/typecheck/rust-hir-path-probe.cc
+++ b/gcc/rust/typecheck/rust-hir-path-probe.cc
@@ -207,7 +207,7 @@ void
 PathProbeType::visit (HIR::TypeAlias &alias)
 {
   Identifier name = alias.get_new_type_name ();
-  if (search.as_string ().compare (name) == 0)
+  if (search.as_string ().compare (name.as_string ()) == 0)
     {
       HirId tyid = alias.get_mappings ().get_hirid ();
       TyTy::BaseType *ty = nullptr;
@@ -227,7 +227,7 @@ void
 PathProbeType::visit (HIR::ConstantItem &constant)
 {
   Identifier name = constant.get_identifier ();
-  if (search.as_string ().compare (name) == 0)
+  if (search.as_string ().compare (name.as_string ()) == 0)
     {
       HirId tyid = constant.get_mappings ().get_hirid ();
       TyTy::BaseType *ty = nullptr;
@@ -247,7 +247,7 @@ void
 PathProbeType::visit (HIR::Function &function)
 {
   Identifier name = function.get_function_name ();
-  if (search.as_string ().compare (name) == 0)
+  if (search.as_string ().compare (name.as_string ()) == 0)
     {
       HirId tyid = function.get_mappings ().get_hirid ();
       TyTy::BaseType *ty = nullptr;
diff --git a/gcc/rust/typecheck/rust-hir-trait-reference.cc b/gcc/rust/typecheck/rust-hir-trait-reference.cc
index 6afb6f4df6d..a24b99f0e49 100644
--- a/gcc/rust/typecheck/rust-hir-trait-reference.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-reference.cc
@@ -158,7 +158,7 @@ std::string
 TraitReference::get_name () const
 {
   rust_assert (!is_error ());
-  return hir_trait_ref->get_name ();
+  return hir_trait_ref->get_name ().as_string ();
 }
 
 std::string
diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
index 099c6729483..a8a026a7f9a 100644
--- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc
+++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc
@@ -40,7 +40,7 @@ ResolveTraitItemToRef::visit (HIR::TraitItemType &type)
   // create trait-item-ref
   Location locus = type.get_locus ();
   bool is_optional = false;
-  std::string identifier = type.get_name ();
+  std::string identifier = type.get_name ().as_string ();
 
   resolved = TraitItemReference (identifier, is_optional,
 				 TraitItemReference::TraitItemType::TYPE, &type,
@@ -53,7 +53,7 @@ ResolveTraitItemToRef::visit (HIR::TraitItemConst &cst)
   // create trait-item-ref
   Location locus = cst.get_locus ();
   bool is_optional = cst.has_expr ();
-  std::string identifier = cst.get_name ();
+  std::string identifier = cst.get_name ().as_string ();
 
   resolved = TraitItemReference (identifier, is_optional,
 				 TraitItemReference::TraitItemType::CONST, &cst,
@@ -66,7 +66,7 @@ ResolveTraitItemToRef::visit (HIR::TraitItemFunc &fn)
   // create trait-item-ref
   Location locus = fn.get_locus ();
   bool is_optional = fn.has_block_defined ();
-  std::string identifier = fn.get_decl ().get_function_name ();
+  std::string identifier = fn.get_decl ().get_function_name ().as_string ();
 
   resolved = TraitItemReference (identifier, is_optional,
 				 TraitItemReference::TraitItemType::FN, &fn,
@@ -185,7 +185,8 @@ TraitResolver::resolve_trait (HIR::Trait *trait_reference)
 	    substitutions.push_back (
 	      TyTy::SubstitutionParamMapping (typaram, param_type));
 
-	    if (typaram.get_type_representation ().compare ("Self") == 0)
+	    if (typaram.get_type_representation ().as_string ().compare ("Self")
+		== 0)
 	      {
 		rust_assert (param_type->get_kind () == TyTy::TypeKind::PARAM);
 		TyTy::ParamType *p
@@ -317,7 +318,7 @@ void
 TraitItemReference::resolve_item (HIR::TraitItemType &type)
 {
   TyTy::BaseType *ty
-    = new TyTy::PlaceholderType (type.get_name (),
+    = new TyTy::PlaceholderType (type.get_name ().as_string (),
 				 type.get_mappings ().get_hirid ());
   context->insert_type (type.get_mappings (), ty);
 }
@@ -414,8 +415,9 @@ AssociatedImplTrait::setup_raw_associated_types ()
       HIR::TypeAlias &type = *static_cast<HIR::TypeAlias *> (impl_item.get ());
 
       TraitItemReference *resolved_trait_item = nullptr;
-      bool ok = trait->lookup_trait_item (type.get_new_type_name (),
-					  &resolved_trait_item);
+      bool ok
+	= trait->lookup_trait_item (type.get_new_type_name ().as_string (),
+				    &resolved_trait_item);
       if (!ok)
 	continue;
       if (resolved_trait_item->get_trait_item_type ()
@@ -611,8 +613,9 @@ AssociatedImplTrait::setup_associated_types (
       HIR::TypeAlias &type = *static_cast<HIR::TypeAlias *> (impl_item.get ());
 
       TraitItemReference *resolved_trait_item = nullptr;
-      bool ok = trait->lookup_trait_item (type.get_new_type_name (),
-					  &resolved_trait_item);
+      bool ok
+	= trait->lookup_trait_item (type.get_new_type_name ().as_string (),
+				    &resolved_trait_item);
       if (!ok)
 	continue;
       if (resolved_trait_item->get_trait_item_type ()
diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
index bb02181c655..9fcb442e0de 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
@@ -83,7 +83,8 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item)
   RustIdent ident{*canonical_path, item.get_locus ()};
   variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
 				  item.get_mappings ().get_defid (),
-				  item.get_identifier (), ident, discim_expr);
+				  item.get_identifier ().as_string (), ident,
+				  discim_expr);
 }
 
 void
@@ -113,7 +114,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item)
   RustIdent ident{*canonical_path, item.get_locus ()};
   variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
 				  item.get_mappings ().get_defid (),
-				  item.get_identifier (), ident,
+				  item.get_identifier ().as_string (), ident,
 				  item.get_discriminant_expression ().get ());
 }
 
@@ -162,7 +163,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item)
   RustIdent ident{*canonical_path, item.get_locus ()};
   variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
 				  item.get_mappings ().get_defid (),
-				  item.get_identifier (), ident,
+				  item.get_identifier ().as_string (), ident,
 				  TyTy::VariantDef::VariantType::TUPLE,
 				  discim_expr, fields);
 }
@@ -180,8 +181,8 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item)
 	= TypeCheckType::Resolve (field.get_field_type ().get ());
       TyTy::StructFieldType *ty_field
 	= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
-				     field.get_field_name (), field_type,
-				     field.get_locus ());
+				     field.get_field_name ().as_string (),
+				     field_type, field.get_locus ());
       fields.push_back (ty_field);
       context->insert_type (field.get_mappings (), ty_field->get_field_type ());
     }
@@ -210,7 +211,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item)
   RustIdent ident{*canonical_path, item.get_locus ()};
   variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
 				  item.get_mappings ().get_defid (),
-				  item.get_identifier (), ident,
+				  item.get_identifier ().as_string (), ident,
 				  TyTy::VariantDef::VariantType::STRUCT,
 				  discrim_expr, fields);
 }
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 8affe983ba8..c0bfa1c8352 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1008,11 +1008,12 @@ TypeCheckExpr::visit (HIR::FieldAccessExpr &expr)
   TyTy::VariantDef *vaiant = adt->get_variants ().at (0);
 
   TyTy::StructFieldType *lookup = nullptr;
-  bool found = vaiant->lookup_field (expr.get_field_name (), &lookup, nullptr);
+  bool found = vaiant->lookup_field (expr.get_field_name ().as_string (),
+				     &lookup, nullptr);
   if (!found)
     {
       rust_error_at (expr.get_locus (), "unknown field [%s] for type [%s]",
-		     expr.get_field_name ().c_str (),
+		     expr.get_field_name ().as_string ().c_str (),
 		     adt->as_string ().c_str ());
       return;
     }
@@ -1681,7 +1682,9 @@ TypeCheckExpr::resolve_operator_overload (
       HIR::Function *fn = impl_item.second;
 
       if (parent->has_trait_ref ()
-	  && fn->get_function_name ().compare (associated_item_name) == 0)
+	  && fn->get_function_name ().as_string ().compare (
+	       associated_item_name)
+	       == 0)
 	{
 	  TraitReference *trait_reference
 	    = TraitResolver::Lookup (*parent->get_trait_ref ().get ());
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
index 130f4a51cbd..c9f3bc1edb2 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
@@ -142,13 +142,13 @@ TypeCheckTopLevelExternItem::visit (HIR::ExternalFunctionItem &function)
 
   RustIdent ident{
     CanonicalPath::new_seg (function.get_mappings ().get_nodeid (),
-			    function.get_item_name ()),
+			    function.get_item_name ().as_string ()),
     function.get_locus ()};
 
   auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (),
 				  function.get_mappings ().get_defid (),
-				  function.get_item_name (), ident, flags,
-				  parent.get_abi (), std::move (params),
+				  function.get_item_name ().as_string (), ident,
+				  flags, parent.get_abi (), std::move (params),
 				  ret_type, std::move (substitutions));
 
   context->insert_type (function.get_mappings (), fnType);
@@ -225,11 +225,9 @@ TypeCheckImplItem::visit (HIR::Function &function)
       // compilation to know parameter names. The types are ignored but we
       // reuse the HIR identifier pattern which requires it
       HIR::SelfParam &self_param = function.get_self_param ();
-      HIR::IdentifierPattern *self_pattern
-	= new HIR::IdentifierPattern (mapping, "self", self_param.get_locus (),
-				      self_param.is_ref (),
-				      self_param.get_mut (),
-				      std::unique_ptr<HIR::Pattern> (nullptr));
+      HIR::IdentifierPattern *self_pattern = new HIR::IdentifierPattern (
+	mapping, {"self"}, self_param.get_locus (), self_param.is_ref (),
+	self_param.get_mut (), std::unique_ptr<HIR::Pattern> (nullptr));
 
       // might have a specified type
       TyTy::BaseType *self_type = nullptr;
@@ -289,14 +287,15 @@ TypeCheckImplItem::visit (HIR::Function &function)
   rust_assert (ok);
 
   RustIdent ident{*canonical_path, function.get_locus ()};
-  auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (),
-				  function.get_mappings ().get_defid (),
-				  function.get_function_name (), ident,
-				  function.is_method ()
-				    ? TyTy::FnType::FNTYPE_IS_METHOD_FLAG
-				    : TyTy::FnType::FNTYPE_DEFAULT_FLAGS,
-				  ABI::RUST, std::move (params), ret_type,
-				  std::move (substitutions));
+  auto fnType
+    = new TyTy::FnType (function.get_mappings ().get_hirid (),
+			function.get_mappings ().get_defid (),
+			function.get_function_name ().as_string (), ident,
+			function.is_method ()
+			  ? TyTy::FnType::FNTYPE_IS_METHOD_FLAG
+			  : TyTy::FnType::FNTYPE_DEFAULT_FLAGS,
+			ABI::RUST, std::move (params), ret_type,
+			std::move (substitutions));
 
   context->insert_type (function.get_mappings (), fnType);
   result = fnType;
@@ -385,7 +384,7 @@ TypeCheckImplItemWithTrait::visit (HIR::ConstantItem &constant)
   const auto tref = trait_reference.get ();
   const TraitItemReference *raw_trait_item = nullptr;
   bool found
-    = tref->lookup_trait_item_by_type (constant.get_identifier (),
+    = tref->lookup_trait_item_by_type (constant.get_identifier ().as_string (),
 				       TraitItemReference::TraitItemType::CONST,
 				       &raw_trait_item);
 
@@ -395,7 +394,7 @@ TypeCheckImplItemWithTrait::visit (HIR::ConstantItem &constant)
       RichLocation r (constant.get_locus ());
       r.add_range (trait_reference.get_locus ());
       rust_error_at (r, "constant %<%s%> is not a member of trait %<%s%>",
-		     constant.get_identifier ().c_str (),
+		     constant.get_identifier ().as_string ().c_str (),
 		     trait_reference.get_name ().c_str ());
       return;
     }
@@ -420,7 +419,7 @@ TypeCheckImplItemWithTrait::visit (HIR::ConstantItem &constant)
 
       rust_error_at (
 	r, "constant %<%s%> has an incompatible type for trait %<%s%>",
-	constant.get_identifier ().c_str (),
+	constant.get_identifier ().as_string ().c_str (),
 	trait_reference.get_name ().c_str ());
     }
 }
@@ -436,7 +435,7 @@ TypeCheckImplItemWithTrait::visit (HIR::TypeAlias &type)
   const auto tref = trait_reference.get ();
   const TraitItemReference *raw_trait_item = nullptr;
   bool found
-    = tref->lookup_trait_item_by_type (type.get_new_type_name (),
+    = tref->lookup_trait_item_by_type (type.get_new_type_name ().as_string (),
 				       TraitItemReference::TraitItemType::TYPE,
 				       &raw_trait_item);
 
@@ -446,7 +445,7 @@ TypeCheckImplItemWithTrait::visit (HIR::TypeAlias &type)
       RichLocation r (type.get_locus ());
       r.add_range (trait_reference.get_locus ());
       rust_error_at (r, "type alias %<%s%> is not a member of trait %<%s%>",
-		     type.get_new_type_name ().c_str (),
+		     type.get_new_type_name ().as_string ().c_str (),
 		     trait_reference.get_name ().c_str ());
       return;
     }
@@ -471,7 +470,7 @@ TypeCheckImplItemWithTrait::visit (HIR::TypeAlias &type)
 
       rust_error_at (
 	r, "type alias %<%s%> has an incompatible type for trait %<%s%>",
-	type.get_new_type_name ().c_str (),
+	type.get_new_type_name ().as_string ().c_str (),
 	trait_reference.get_name ().c_str ());
     }
 
@@ -496,10 +495,9 @@ TypeCheckImplItemWithTrait::visit (HIR::Function &function)
   // map the impl item to the associated trait item
   const auto tref = trait_reference.get ();
   const TraitItemReference *raw_trait_item = nullptr;
-  bool found
-    = tref->lookup_trait_item_by_type (function.get_function_name (),
-				       TraitItemReference::TraitItemType::FN,
-				       &raw_trait_item);
+  bool found = tref->lookup_trait_item_by_type (
+    function.get_function_name ().as_string (),
+    TraitItemReference::TraitItemType::FN, &raw_trait_item);
 
   // unknown trait item
   if (!found || raw_trait_item->is_error ())
@@ -507,7 +505,7 @@ TypeCheckImplItemWithTrait::visit (HIR::Function &function)
       RichLocation r (function.get_locus ());
       r.add_range (trait_reference.get_locus ());
       rust_error_at (r, "method %<%s%> is not a member of trait %<%s%>",
-		     function.get_function_name ().c_str (),
+		     function.get_function_name ().as_string ().c_str (),
 		     trait_reference.get_name ().c_str ());
       return;
     }
@@ -532,7 +530,7 @@ TypeCheckImplItemWithTrait::visit (HIR::Function &function)
 
       rust_error_at (r,
 		     "method %<%s%> has an incompatible type for trait %<%s%>",
-		     function.get_function_name ().c_str (),
+		     function.get_function_name ().as_string ().c_str (),
 		     trait_reference.get_name ().c_str ());
     }
 }
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index a34ae0766d6..ca411d0ce82 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -180,10 +180,12 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
 
   // its a single variant ADT
   std::vector<TyTy::VariantDef *> variants;
-  variants.push_back (new TyTy::VariantDef (
-    struct_decl.get_mappings ().get_hirid (),
-    struct_decl.get_mappings ().get_defid (), struct_decl.get_identifier (),
-    ident, TyTy::VariantDef::VariantType::TUPLE, nullptr, std::move (fields)));
+  variants.push_back (
+    new TyTy::VariantDef (struct_decl.get_mappings ().get_hirid (),
+			  struct_decl.get_mappings ().get_defid (),
+			  struct_decl.get_identifier ().as_string (), ident,
+			  TyTy::VariantDef::VariantType::TUPLE, nullptr,
+			  std::move (fields)));
 
   // Process #[repr(X)] attribute, if any
   const AST::AttrVec &attrs = struct_decl.get_outer_attrs ();
@@ -193,7 +195,7 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl)
   TyTy::BaseType *type
     = new TyTy::ADTType (struct_decl.get_mappings ().get_hirid (),
 			 mappings->get_next_hir_id (),
-			 struct_decl.get_identifier (), ident,
+			 struct_decl.get_identifier ().as_string (), ident,
 			 TyTy::ADTType::ADTKind::TUPLE_STRUCT,
 			 std::move (variants), std::move (substitutions), repr);
 
@@ -220,8 +222,8 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
 	= TypeCheckType::Resolve (field.get_field_type ().get ());
       TyTy::StructFieldType *ty_field
 	= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
-				     field.get_field_name (), field_type,
-				     field.get_locus ());
+				     field.get_field_name ().as_string (),
+				     field_type, field.get_locus ());
       fields.push_back (ty_field);
       context->insert_type (field.get_mappings (), ty_field->get_field_type ());
     }
@@ -235,10 +237,12 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
 
   // its a single variant ADT
   std::vector<TyTy::VariantDef *> variants;
-  variants.push_back (new TyTy::VariantDef (
-    struct_decl.get_mappings ().get_hirid (),
-    struct_decl.get_mappings ().get_defid (), struct_decl.get_identifier (),
-    ident, TyTy::VariantDef::VariantType::STRUCT, nullptr, std::move (fields)));
+  variants.push_back (
+    new TyTy::VariantDef (struct_decl.get_mappings ().get_hirid (),
+			  struct_decl.get_mappings ().get_defid (),
+			  struct_decl.get_identifier ().as_string (), ident,
+			  TyTy::VariantDef::VariantType::STRUCT, nullptr,
+			  std::move (fields)));
 
   // Process #[repr(X)] attribute, if any
   const AST::AttrVec &attrs = struct_decl.get_outer_attrs ();
@@ -248,7 +252,7 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
   TyTy::BaseType *type
     = new TyTy::ADTType (struct_decl.get_mappings ().get_hirid (),
 			 mappings->get_next_hir_id (),
-			 struct_decl.get_identifier (), ident,
+			 struct_decl.get_identifier ().as_string (), ident,
 			 TyTy::ADTType::ADTKind::STRUCT_STRUCT,
 			 std::move (variants), std::move (substitutions), repr);
 
@@ -286,7 +290,7 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
   TyTy::BaseType *type
     = new TyTy::ADTType (enum_decl.get_mappings ().get_hirid (),
 			 mappings->get_next_hir_id (),
-			 enum_decl.get_identifier (), ident,
+			 enum_decl.get_identifier ().as_string (), ident,
 			 TyTy::ADTType::ADTKind::ENUM, std::move (variants),
 			 std::move (substitutions));
 
@@ -313,8 +317,8 @@ TypeCheckItem::visit (HIR::Union &union_decl)
 	= TypeCheckType::Resolve (variant.get_field_type ().get ());
       TyTy::StructFieldType *ty_variant
 	= new TyTy::StructFieldType (variant.get_mappings ().get_hirid (),
-				     variant.get_field_name (), variant_type,
-				     variant.get_locus ());
+				     variant.get_field_name ().as_string (),
+				     variant_type, variant.get_locus ());
       fields.push_back (ty_variant);
       context->insert_type (variant.get_mappings (),
 			    ty_variant->get_field_type ());
@@ -330,15 +334,17 @@ TypeCheckItem::visit (HIR::Union &union_decl)
 
   // there is only a single variant
   std::vector<TyTy::VariantDef *> variants;
-  variants.push_back (new TyTy::VariantDef (
-    union_decl.get_mappings ().get_hirid (),
-    union_decl.get_mappings ().get_defid (), union_decl.get_identifier (),
-    ident, TyTy::VariantDef::VariantType::STRUCT, nullptr, std::move (fields)));
+  variants.push_back (
+    new TyTy::VariantDef (union_decl.get_mappings ().get_hirid (),
+			  union_decl.get_mappings ().get_defid (),
+			  union_decl.get_identifier ().as_string (), ident,
+			  TyTy::VariantDef::VariantType::STRUCT, nullptr,
+			  std::move (fields)));
 
   TyTy::BaseType *type
     = new TyTy::ADTType (union_decl.get_mappings ().get_hirid (),
 			 mappings->get_next_hir_id (),
-			 union_decl.get_identifier (), ident,
+			 union_decl.get_identifier ().as_string (), ident,
 			 TyTy::ADTType::ADTKind::UNION, std::move (variants),
 			 std::move (substitutions));
 
@@ -473,9 +479,9 @@ TypeCheckItem::visit (HIR::Function &function)
   RustIdent ident{*canonical_path, function.get_locus ()};
   auto fnType = new TyTy::FnType (function.get_mappings ().get_hirid (),
 				  function.get_mappings ().get_defid (),
-				  function.get_function_name (), ident,
-				  TyTy::FnType::FNTYPE_DEFAULT_FLAGS, ABI::RUST,
-				  std::move (params), ret_type,
+				  function.get_function_name ().as_string (),
+				  ident, TyTy::FnType::FNTYPE_DEFAULT_FLAGS,
+				  ABI::RUST, std::move (params), ret_type,
 				  std::move (substitutions));
 
   context->insert_type (function.get_mappings (), fnType);
diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
index 474e6c80f8b..7854780cc94 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
@@ -201,16 +201,16 @@ TypeCheckPattern::visit (HIR::StructPattern &pattern)
 	      = static_cast<HIR::StructPatternFieldIdentPat &> (*field.get ());
 
 	    TyTy::StructFieldType *field = nullptr;
-	    if (!variant->lookup_field (ident.get_identifier (), &field,
-					nullptr))
+	    if (!variant->lookup_field (ident.get_identifier ().as_string (),
+					&field, nullptr))
 	      {
 		rust_error_at (ident.get_locus (), ErrorCode ("E0026"),
 			       "variant %s does not have a field named %s",
 			       variant->get_identifier ().c_str (),
-			       ident.get_identifier ().c_str ());
+			       ident.get_identifier ().as_string ().c_str ());
 		break;
 	      }
-	    named_fields.push_back (ident.get_identifier ());
+	    named_fields.push_back (ident.get_identifier ().as_string ());
 
 	    TyTy::BaseType *fty = field->get_field_type ();
 	    TypeCheckPattern::Resolve (ident.get_pattern ().get (), fty);
@@ -222,16 +222,16 @@ TypeCheckPattern::visit (HIR::StructPattern &pattern)
 	      = static_cast<HIR::StructPatternFieldIdent &> (*field.get ());
 
 	    TyTy::StructFieldType *field = nullptr;
-	    if (!variant->lookup_field (ident.get_identifier (), &field,
-					nullptr))
+	    if (!variant->lookup_field (ident.get_identifier ().as_string (),
+					&field, nullptr))
 	      {
 		rust_error_at (ident.get_locus (), ErrorCode ("E0026"),
 			       "variant %s does not have a field named %s",
 			       variant->get_identifier ().c_str (),
-			       ident.get_identifier ().c_str ());
+			       ident.get_identifier ().as_string ().c_str ());
 		break;
 	      }
-	    named_fields.push_back (ident.get_identifier ());
+	    named_fields.push_back (ident.get_identifier ().as_string ());
 
 	    // setup the type on this pattern
 	    TyTy::BaseType *fty = field->get_field_type ();
diff --git a/gcc/rust/typecheck/rust-hir-type-check-struct.cc b/gcc/rust/typecheck/rust-hir-type-check-struct.cc
index ca043348431..780f3bc50f7 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-struct.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-struct.cc
@@ -241,7 +241,7 @@ TypeCheckStructExpr::resolve (HIR::StructExprStructFields &struct_expr)
 void
 TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifierValue &field)
 {
-  auto it = fields_assigned.find (field.field_name);
+  auto it = fields_assigned.find (field.field_name.as_string ());
   if (it != fields_assigned.end ())
     {
       rust_fatal_error (field.get_locus (), "used more than once");
@@ -250,7 +250,8 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifierValue &field)
 
   size_t field_index;
   TyTy::StructFieldType *field_type;
-  bool ok = variant->lookup_field (field.field_name, &field_type, &field_index);
+  bool ok = variant->lookup_field (field.field_name.as_string (), &field_type,
+				   &field_index);
   if (!ok)
     {
       rust_error_at (field.get_locus (), "unknown field");
@@ -269,7 +270,7 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifierValue &field)
 		     field.get_locus ());
   if (resolved_field_value_expr != nullptr)
     {
-      fields_assigned.insert (field.field_name);
+      fields_assigned.insert (field.field_name.as_string ());
       adtFieldIndexToField[field_index] = &field;
     }
 }
@@ -314,7 +315,7 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIndexValue &field)
 void
 TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifier &field)
 {
-  auto it = fields_assigned.find (field.get_field_name ());
+  auto it = fields_assigned.find (field.get_field_name ().as_string ());
   if (it != fields_assigned.end ())
     {
       rust_fatal_error (field.get_locus (), "used more than once");
@@ -323,8 +324,8 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifier &field)
 
   size_t field_index;
   TyTy::StructFieldType *field_type;
-  bool ok = variant->lookup_field (field.get_field_name (), &field_type,
-				   &field_index);
+  bool ok = variant->lookup_field (field.get_field_name ().as_string (),
+				   &field_type, &field_index);
   if (!ok)
     {
       rust_error_at (field.get_locus (), "unknown field");
@@ -336,7 +337,7 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifier &field)
   Analysis::NodeMapping mappings_copy1 = field.get_mappings ();
   Analysis::NodeMapping mappings_copy2 = field.get_mappings ();
 
-  HIR::PathIdentSegment ident_seg (field.get_field_name ());
+  HIR::PathIdentSegment ident_seg (field.get_field_name ().as_string ());
   HIR::PathExprSegment seg (mappings_copy1, ident_seg, field.get_locus (),
 			    HIR::GenericArgs::create_empty ());
   HIR::PathInExpression expr (mappings_copy2, {seg}, field.get_locus (), false,
@@ -354,7 +355,7 @@ TypeCheckStructExpr::visit (HIR::StructExprFieldIdentifier &field)
   if (resolved_field_value_expr != nullptr)
 
     {
-      fields_assigned.insert (field.get_field_name ());
+      fields_assigned.insert (field.get_field_name ().as_string ());
       adtFieldIndexToField[field_index] = &field;
     }
 }
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc
index 0675c491a93..d309101d107 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-type.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc
@@ -709,7 +709,7 @@ TypeResolveGenericParam::visit (HIR::TypeParam &param)
       // bounds otherwise it will be a trait cycle
       HirId implicit_id = mappings->get_next_hir_id ();
       TyTy::ParamType *p
-	= new TyTy::ParamType (param.get_type_representation (),
+	= new TyTy::ParamType (param.get_type_representation ().as_string (),
 			       param.get_locus (), implicit_id, param,
 			       {} /*empty specified bounds*/);
       context->insert_implicit_type (implicit_id, p);
@@ -750,10 +750,10 @@ TypeResolveGenericParam::visit (HIR::TypeParam &param)
 	}
     }
 
-  resolved
-    = new TyTy::ParamType (param.get_type_representation (), param.get_locus (),
-			   param.get_mappings ().get_hirid (), param,
-			   specified_bounds);
+  resolved = new TyTy::ParamType (param.get_type_representation ().as_string (),
+				  param.get_locus (),
+				  param.get_mappings ().get_hirid (), param,
+				  specified_bounds);
 }
 
 void
diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc
index e483af31d1a..edcbc086b23 100644
--- a/gcc/rust/typecheck/rust-hir-type-check.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check.cc
@@ -213,12 +213,10 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
       // for compilation to know parameter names. The types are ignored
       // but we reuse the HIR identifier pattern which requires it
       HIR::SelfParam &self_param = function.get_self ();
-      HIR::IdentifierPattern *self_pattern
-	= new HIR::IdentifierPattern (mapping, "self", self_param.get_locus (),
-				      self_param.is_ref (),
-				      self_param.is_mut () ? Mutability::Mut
-							   : Mutability::Imm,
-				      std::unique_ptr<HIR::Pattern> (nullptr));
+      HIR::IdentifierPattern *self_pattern = new HIR::IdentifierPattern (
+	mapping, {"self"}, self_param.get_locus (), self_param.is_ref (),
+	self_param.is_mut () ? Mutability::Mut : Mutability::Imm,
+	std::unique_ptr<HIR::Pattern> (nullptr));
       // might have a specified type
       TyTy::BaseType *self_type = nullptr;
       if (self_param.has_type ())
@@ -280,7 +278,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const
   auto resolved
     = new TyTy::FnType (fn.get_mappings ().get_hirid (),
 			fn.get_mappings ().get_defid (),
-			function.get_function_name (), ident,
+			function.get_function_name ().as_string (), ident,
 			function.is_method ()
 			  ? TyTy::FnType::FNTYPE_IS_METHOD_FLAG
 			  : TyTy::FnType::FNTYPE_DEFAULT_FLAGS,
diff --git a/gcc/rust/typecheck/rust-tyty-subst.cc b/gcc/rust/typecheck/rust-tyty-subst.cc
index 9c304d92933..252b292f60e 100644
--- a/gcc/rust/typecheck/rust-tyty-subst.cc
+++ b/gcc/rust/typecheck/rust-tyty-subst.cc
@@ -586,17 +586,18 @@ SubstitutionRef::get_mappings_from_generic_args (HIR::GenericArgs &args)
 		}
 
 	      // resolve to relevant binding
-	      auto binding_item
-		= lookup_associated_type (binding.get_identifier ());
+	      auto binding_item = lookup_associated_type (
+		binding.get_identifier ().as_string ());
 	      if (binding_item.is_error ())
 		{
-		  rust_error_at (binding.get_locus (),
-				 "unknown associated type binding: %s",
-				 binding.get_identifier ().c_str ());
+		  rust_error_at (
+		    binding.get_locus (), "unknown associated type binding: %s",
+		    binding.get_identifier ().as_string ().c_str ());
 		  return SubstitutionArgumentMappings::error ();
 		}
 
-	      binding_arguments[binding.get_identifier ()] = resolved;
+	      binding_arguments[binding.get_identifier ().as_string ()]
+		= resolved;
 	    }
 	}
       else
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 4c7cb869861..27817acf0c3 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -185,7 +185,7 @@ check_doc_attribute (const AST::Attribute &attribute)
 		      ->get_name_value_pair ();
 
 		// FIXME: Check for other stuff than #[doc(alias = ...)]
-		if (name_value.first == "alias")
+		if (name_value.first.as_string () == "alias")
 		  check_doc_alias (name_value.second, attribute.get_locus ());
 	      }
 	  }
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 2f6d02d4187..fd78e564aec 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -876,17 +876,18 @@ Mappings::insert_macro_def (AST::MacroRulesDefinition *macro)
 		   });
   if (should_be_builtin)
     {
-      auto builtin = MacroBuiltin::builtins.lookup (macro->get_rule_name ());
+      auto builtin
+	= MacroBuiltin::builtins.lookup (macro->get_rule_name ().as_string ());
       if (!MacroBuiltin::builtins.is_iter_ok (builtin))
 	{
 	  rust_error_at (macro->get_locus (),
 			 "cannot find a built-in macro with name %qs",
-			 macro->get_rule_name ().c_str ());
+			 macro->get_rule_name ().as_string ().c_str ());
 	  return;
 	}
 
-      auto transcriber
-	= MacroBuiltin::builtin_transcribers.find (macro->get_rule_name ());
+      auto transcriber = MacroBuiltin::builtin_transcribers.find (
+	macro->get_rule_name ().as_string ());
       macro->set_builtin_transcriber (transcriber->second);
     }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-16 17:55 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 17:55 [gcc r14-7701] gccrs: ast: Change Identifier definition Arthur Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).