diff options
Diffstat (limited to 'gcc/rust/hir/rust-ast-lower-item.cc')
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-item.cc | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-item.cc b/gcc/rust/hir/rust-ast-lower-item.cc index 171737a..f4396b5 100644 --- a/gcc/rust/hir/rust-ast-lower-item.cc +++ b/gcc/rust/hir/rust-ast-lower-item.cc @@ -451,13 +451,16 @@ ASTLoweringItem::visit (AST::Function &function) mappings.insert_location (function_body->get_mappings ().get_hirid (), function.get_locus ()); + Defaultness defaultness + = function.is_default () ? Defaultness::Default : Defaultness::Final; + auto fn = new HIR::Function (mapping, std::move (function_name), std::move (qualifiers), std::move (generic_params), std::move (function_params), std::move (return_type), std::move (where_clause), std::move (function_body), std::move (vis), function.get_outer_attrs (), - HIR::SelfParam::error (), locus); + tl::nullopt, defaultness, locus); // add the mappings for the function params at the end for (auto ¶m : fn->get_function_params ()) @@ -572,6 +575,12 @@ ASTLoweringItem::visit (AST::Trait &trait) generic_params = lower_generic_params (trait.get_generic_params ()); } + // TODO: separate "Self" from normal generic parameters + // in HIR as well as in AST? + HIR::GenericParam *self_param + = ASTLowerGenericParam::translate (trait.get_implicit_self ()); + generic_params.emplace (generic_params.begin (), self_param); + std::vector<std::unique_ptr<HIR::TypeParamBound>> type_param_bounds; if (trait.has_type_param_bounds ()) { @@ -600,17 +609,18 @@ ASTLoweringItem::visit (AST::Trait &trait) mappings.get_next_hir_id (crate_num), mappings.get_next_localdef_id (crate_num)); - auto trait_unsafety = Unsafety::Normal; - if (trait.is_unsafe ()) - { - trait_unsafety = Unsafety::Unsafe; - } + auto trait_unsafety + = trait.is_unsafe () ? Unsafety::Unsafe : Unsafety::Normal; HIR::Trait *hir_trait = new HIR::Trait (mapping, trait.get_identifier (), trait_unsafety, std::move (generic_params), std::move (type_param_bounds), where_clause, std::move (trait_items), vis, trait.get_outer_attrs (), trait.get_locus ()); + + if (trait.is_auto ()) + mappings.insert_auto_trait (hir_trait); + translated = hir_trait; for (auto trait_item_id : trait_item_ids) |