aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
AgeCommit message (Collapse)AuthorFilesLines
2024-02-22Daily bump.GCC Administrator1-0/+47
2024-02-21Update copyright years.Sahil Yeole74-75/+75
Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com>
2024-02-21gccrs: Add variadic check on function params0xn4utilus1-4/+8
gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add variadic check on all parameters. gcc/testsuite/ChangeLog: * rust/compile/issue-2850.rs: New test. Signed-off-by: 0xn4utilus <gyanendrabanjare8@gmail.com>
2024-02-21gccrs: Fix lookup of TuplePattern sub-pattern typesOwen Avery1-6/+6
gcc/rust/ChangeLog: * backend/rust-compile-pattern.cc (CompilePatternLet::visit): Lookup type of sub-pattern, not tuple pattern itself. gcc/testsuite/ChangeLog: * rust/compile/issue-2847-b.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-02-21gccrs: add powi intrinsicsMarc Poulhiès2-3/+29
gcc/rust/ChangeLog: * backend/rust-builtins.cc (BuiltinsContext::register_rust_mappings): Add powi and reformat. * backend/rust-builtins.h: Add missing copyright header. gcc/testsuite/ChangeLog: * rust/compile/torture/intrinsics-math.rs: Adjust pow test, add test for powi. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2024-02-21gccrs: expand: Fix formatting for "macro not found" errorArthur Cohen1-3/+3
gcc/rust/ChangeLog: * expand/rust-macro-expand.h (struct MacroExpander): Nitpick: fix formatting of emitted error.
2024-02-21gccrs: Fix rebinding importsOwen Avery2-93/+109
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-item.cc (flatten_glob): Use Import class. (flatten_rebind): Likewise. (flatten_list): Likewise. (flatten): Likewise. (flatten_use_dec_to_paths): Likewise. (flatten_use_dec_to_imports): Likewise. (ResolveItem::visit): Likewise. (Import::add_prefix): New. (rust_flatten_nested_glob): Adjust test. (rust_flatten_glob): Likewise. (rust_flatten_rebind_none): Likewise. (rust_flatten_rebind): Likewise. (rust_flatten_rebind_nested): Likewise. (rust_flatten_list): Likewise. * resolve/rust-ast-resolve-item.h (class Import): New. gcc/testsuite/ChangeLog: * rust/compile/use_2.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-02-21gccrs: Fix typo in RegionConstraints instanceArthur Cohen1-1/+1
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-implitem.h: Fix typo in field (region_costraints -> region_constraints).
2024-02-08Daily bump.GCC Administrator1-0/+315
2024-02-07gccrs: Fix macro parsing for trait items.Kushal Pal1-18/+19
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_trait_item): Handle macros in trait items similar to how its handled for trait implementation items. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-02-07gccrs: Remove obsolete classes and functions.Kushal Pal30-1302/+0
Trait functions now use AST::Function class, so classes AST::TraitItemFunc, AST::TraitItemMethod, AST::TraitFunctionDecl, AST::TraitMethodDecl and their related functions can be removed. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove obsolete classes and functions. * ast/rust-ast-collector.h: Likewise. * ast/rust-ast-full-decls.h (class TraitFunctionDecl): Likewise. (class TraitItemFunc): Likewise. (class TraitMethodDecl): Likewise. (class TraitItemMethod): Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.h: Likewise. * ast/rust-ast.cc (TraitItemFunc::TraitItemFunc): Likewise. (TraitItemFunc::operator=): Likewise. (TraitItemFunc::as_string): Likewise. (TraitFunctionDecl::as_string): Likewise. (TraitItemMethod::TraitItemMethod): Likewise. (TraitItemMethod::operator=): Likewise. (TraitItemMethod::as_string): Likewise. (TraitMethodDecl::as_string): Likewise. (TraitItemFunc::accept_vis): Likewise. (TraitItemMethod::accept_vis): Likewise. * ast/rust-item.h (class TraitFunctionDecl): Likewise. (class TraitItemFunc): Likewise. (class TraitMethodDecl): Likewise. (class TraitItemMethod): Likewise. * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Likewise. * checks/errors/rust-ast-validation.h: Likewise. * checks/errors/rust-feature-gate.h: Likewise. * expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_trait_function_decl): Likewise. (CfgStrip::maybe_strip_trait_method_decl): Likewise. (CfgStrip::visit): Likewise. * expand/rust-cfg-strip.h: Likewise. * expand/rust-derive.h: Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::expand_trait_function_decl): Likewise. (ExpandVisitor::expand_trait_method_decl): Likewise. (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h: Likewise. * hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit): Likewise. * hir/rust-ast-lower-implitem.h: Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h: Likewise. * resolve/rust-ast-resolve-implitem.h (visit): Likewise. * resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise. * resolve/rust-ast-resolve-item.h: Likewise. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise. * resolve/rust-default-resolver.h: Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Likewise. * resolve/rust-toplevel-name-resolver-2.0.h: Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. * util/rust-attributes.h: Likewise. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-02-07gccrs: Parse trait functions as `AST::Function`.Kushal Pal1-125/+2
To use AST::Function for trait functions, we can parse trait functions using available parse_function(). gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_trait_item): Use parse_function() to parse trait functions. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-02-07gccrs: Add missing visitors for AST::Function.Kushal Pal5-0/+196
To use AST::Function instead of AST::TraitItemFunc and AST::TraitItemMethod, we need to provide similar visitors during lowering and resolving phase. gcc/rust/ChangeLog: * hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit): Provide visitor for AST::Function. * hir/rust-ast-lower-implitem.h: Likewise. * resolve/rust-ast-resolve-implitem.h: Likewise. * resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise. * resolve/rust-ast-resolve-item.h: Likewise. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-02-07gccrs: Add checks for Trait functionsKushal Pal1-7/+11
Since we want to use AST::Function class for trait functions as well, we need to check against specific conditions in ASTValidation phase. gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add checks for Trait functions. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-02-07gccrs: Use AssociatedItem in place of TraitItemKushal Pal5-16/+17
gcc/rust/ChangeLog: * ast/rust-ast.h: Replace TraitItem with AssociatedItem. * ast/rust-item.h (class Trait): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * parse/rust-parse-impl.h (Parser::parse_trait): Likewise. * parse/rust-parse.h: Likewise. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-02-07gccrs: fix bug in pattern check for tuplesPhilip Herron1-2/+4
We can point to generic parent types which means we need to do the shallow resolve thing that rustc does. We have destructure which is similar to get what the parameter type points to. Fixes #2775 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): use destructure gcc/testsuite/ChangeLog: * rust/compile/issue-2775.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-02-07gccrs: Move the Implementation of implitem lowering into its own file.Nobel Singh3-396/+439
This patch moves the implementation of the implitem lowering from rust-ast-lower-implitem.h into the rust-ast-lower-implitem.cc file. gcc/rust/ChangeLog: * Make-lang.in: Add rust-ast-lower-implitem.cc to list of objects. * hir/rust-ast-lower-implitem.h (RUST_AST_LOWER_IMPLITEM_H): Remove implementation. * hir/rust-ast-lower-implitem.cc: Copy implementation from header. Signed-off-by: Nobel Singh <Nobel2073@gmail.com>
2024-02-07gccrs: refactor inference variable computation into a seperate methodPhilip Herron3-33/+44
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check.cc (TypeResolution::Resolve): refactor * typecheck/rust-hir-type-check.h: new prototype * typecheck/rust-typecheck-context.cc (TypeCheckContext::compute_inference_variables): x
2024-02-07gccrs: remove similar hack in type paths as we had in path expressionsPhilip Herron1-16/+0
This keeps the resolution code in line with paths. Addresses #2723 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-type.cc: remove hack
2024-02-07gccrs: remove old generics hack to reuse generic symbols from previous segPhilip Herron1-19/+2
This patch introduces one regression because generics are getting better understood over time. The code here used to apply generics with the same symbol from previous segments which was a bit of a hack with out limited inference variable support. The regression looks like it will be related to another issue which needs to default integer inference variables much more aggresivly to default integer. Fixes #2723 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): remove hack gcc/testsuite/ChangeLog: * rust/compile/issue-1773.rs: Moved to... * rust/compile/issue-1773.rs.bak: ...here. * rust/compile/issue-2723-1.rs: New test. * rust/compile/issue-2723-2.rs: New test.
2024-02-07gccrs: Fix ICE accessing empty vector without checkPhilip Herron1-1/+2
Fixes #2747 gcc/rust/ChangeLog: * typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args): fix gcc/testsuite/ChangeLog: * rust/compile/issue-2747.rs: New test.
2024-02-07gccrs: Set the default ABI to C for extern blocks and extern functionsNobel Singh1-2/+2
Previously, the default ABI was set to Rust, which is not correct for extern blocks and extern functions. This patch changes the default ABI to C for these cases. gcc/rust/ChangeLog: * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_qualifiers): Change default ABI to C for extern functions (ASTLoweringBase::lower_extern_block): Likewise Signed-off-by: Nobel Singh <nobel2073@gmail.com>
2024-02-07gccrs: TyTy: Store reference to type before any substitutionsJakub Dupak2-2/+11
gcc/rust/ChangeLog: * typecheck/rust-tyty.cc (BaseType::BaseType): Store orig ref. (BaseType::get_orig_ref): Add getter. * typecheck/rust-tyty.h: Store orig ref. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-02-07gccrs: TyTy: Store region constraintsJakub Dupak12-53/+151
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): Add region constraints. (TypeCheckImplItem::visit): Add region constraints. * typecheck/rust-hir-type-check-implitem.h: Add region constraints. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::ResolveImplBlockSelf): Add region constraints. (TypeCheckItem::visit): Add region constraints. (TypeCheckItem::resolve_impl_item): Add region constraints. (TypeCheckItem::resolve_impl_block_substitutions): Add region constraints. * typecheck/rust-hir-type-check-item.h: Add region constraints. * typecheck/rust-hir-type-check-type.cc (ResolveWhereClauseItem::Resolve): Add region constraints. (ResolveWhereClauseItem::visit): Add region constraints. * typecheck/rust-hir-type-check-type.h (class ResolveWhereClauseItem): Add region constraints. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Add region constraints. * typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::TypeBoundPredicate): Add region constraints. * typecheck/rust-tyty-subst.cc (SubstitutionRef::get_region_constraints): Add region constraints. * typecheck/rust-tyty-subst.h (class BaseType): Add region constraints. (struct RegionConstraints): Add region constraints. * typecheck/rust-tyty.cc (BaseType::monomorphized_clone): Add region constraints. (ADTType::clone): Add region constraints. (FnType::clone): Add region constraints. (ProjectionType::clone): Add region constraints. * typecheck/rust-tyty.h: Add region constraints. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-02-07gccrs: Typecheck: add regions (lifetimes) to TyTyJakub Dupak18-177/+585
gcc/rust/ChangeLog: * typecheck/rust-hir-trait-resolve.cc: add regions * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): add regions, resolve generic lifetimes * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): add regions * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): add regions, resolve lifetimes (TypeCheckImplItem::visit): add regions, resove lifetimes * typecheck/rust-hir-type-check-implitem.h: add default value for result * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): add regions, resove lifetimes (TypeCheckItem::resolve_impl_block_substitutions): add regions, resove lifetimes * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): add regions, resove lifetimes (TypeCheckExpr::resolve_root_path): add regions, resove lifetimes (TypeCheckExpr::resolve_segments): add regions, resove lifetimes * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): add regions, resove lifetimes (TypeCheckType::resolve_root_path): add regions, resove lifetimes (ResolveWhereClauseItem::Resolve): add regions, resove lifetimes (ResolveWhereClauseItem::visit): add regions, resove lifetimes * typecheck/rust-hir-type-check.cc (TypeCheckContext::LifetimeResolver::resolve): add regions, resolve lifetimes (TraitItemReference::get_type_from_fn): add regions, resove lifetimes * typecheck/rust-hir-type-check.h: add regions, resove lifetimes * typecheck/rust-substitution-mapper.cc (SubstMapper::SubstMapper): add regions, resove lifetimes (SubstMapper::Resolve): add regions, resove lifetimes (SubstMapper::InferSubst): add regions, resove lifetimes (SubstMapper::visit): add regions, resove lifetimes * typecheck/rust-substitution-mapper.h: add regions, resove lifetimes * typecheck/rust-typecheck-context.cc (TypeCheckContext::TypeCheckContext): lifetime resolution (TypeCheckContext::regions_from_generic_args): lifetime resolution helper * typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::TypeBoundPredicate): add regions, resove lifetimes (TypeBoundPredicate::operator=): add regions, resove lifetimes (TypeBoundPredicate::apply_generic_arguments): add regions, resove lifetimes (TypeBoundPredicateItem::get_tyty_for_receiver): add regions, resove lifetimes * typecheck/rust-tyty-subst.cc (SubstitutionArgumentMappings::get_regions): add regions, resove lifetimes (SubstitutionArgumentMappings::get_mut_regions): getter (SubstitutionArgumentMappings::error): split error and empty (SubstitutionArgumentMappings::empty): split error and empty (SubstitutionArgumentMappings::find_symbol): helper (SubstitutionRef::get_num_lifetime_params): getter (SubstitutionRef::get_num_type_params): getter (SubstitutionRef::needs_substitution): extend to regions (SubstitutionRef::get_mappings_from_generic_args): helper (SubstitutionRef::infer_substitions): add regions * typecheck/rust-tyty-subst.h (class RegionParamList): region param handler * typecheck/rust-tyty.cc (BaseType::monomorphized_clone): add regions, resove lifetimes (InferType::default_type): add regions, resove lifetimes (FnType::clone): add regions, resove lifetimes (ReferenceType::ReferenceType): add regions (ReferenceType::get_region): getter (ReferenceType::clone): add regions * typecheck/rust-tyty.h: add regions, resove Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-02-07gccrs: HIR: Add mising getterJakub Dupak1-0/+5
gcc/rust/ChangeLog: * hir/tree/rust-hir-item.h: Add missing getter Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-02-07gccrs: TyTy: Region (lifetime) representationJakub Dupak1-0/+110
gcc/rust/ChangeLog: * typecheck/rust-tyty-region.h: New file. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-02-07gccrs: Typecheck: lifetime interning and resolution toolJakub Dupak2-1/+279
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check.h (class Lifetime): add interned lifetime class * typecheck/rust-typecheck-context.cc (TypeCheckContext::TypeCheckContext): add resolution tool (TypeCheckContext::intern_lifetime): add method to intern lifetime from tyctx (TypeCheckContext::lookup_lifetime): add method to lookup lifetime from tyctx (TypeCheckContext::intern_and_insert_lifetime): add a helper method Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-02-07gccrs: Implement quick-check for UnicodeRaiki Tamura7-82/+280
gcc/rust/ChangeLog: * rust-lang.cc (run_rust_tests): Add test. * rust-system.h: Add <algorithm>. * util/make-rust-unicode.py: Output NFC_Quick_Check table. * util/rust-codepoint.h (struct Codepoint): Add is_supplementary method. * util/rust-unicode-data.h: Generated. * util/rust-unicode.cc (binary_search_sorted_array): Removed. (lookup_cc): Remove namespace. (is_alphabetic): Use std::binary_search (nfc_quick_check): New function. (nfc_normalize): Use nfc_quick_check. (is_nfc_qc_maybe): New function. (is_nfc_qc_no): New function. (rust_nfc_qc_test): New test. * util/rust-unicode.h (is_nfc_qc_no): New function. (is_nfc_qc_maybe): New function. (enum class): New enum class. (nfc_quick_check): New function. (rust_nfc_qc_test): New test. Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
2024-02-07gccrs: Parse normal functions with `self` parameter correctlyKushal Pal1-2/+2
Fixes #2812 gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_function): Skip token if its a COMMA. gcc/testsuite/ChangeLog: * rust/compile/issue-2812.rs: New test. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-01-31Daily bump.GCC Administrator1-0/+839
2024-01-30gccrs: Remove TraitImplItemOwen Avery8-42/+26
gcc/rust/ChangeLog: * ast/rust-ast-full-decls.h (class TraitImplItem): Remove forward declaration. (class AssociatedItem): Add forward declaration. * ast/rust-ast.h (class TraitImplItem): Remove. (class TraitItem): Inherit from AssociatedItem. (SingleASTNode::take_trait_impl_item): Return std::unique_ptr<AssociatedItem> instead of std::unique_ptr<TraitImplItem>. * ast/rust-item.h (class Function): Inherit from AssociatedItem instead of TraitImplItem. (class TypeAlias): Likewise. (class ConstantItem): Likewise. (class TraitImpl): Store items as AssociatedItem. * expand/rust-derive-clone.cc (DeriveClone::clone_fn): Return std::unique_ptr<AssociatedItem>. (DeriveClone::clone_impl): Take std::unique_ptr<AssociatedItem>. * expand/rust-derive-clone.h (DeriveClone::clone_fn): Return std::unique_ptr<AssociatedItem>. (DeriveClone::clone_impl): Take std::unique_ptr<AssociatedItem>. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Handle changes to SingleASTNode::take_trait_impl_item. * parse/rust-parse-impl.h (Parser::parse_impl): Parse TraitImpl as containing AssociatedItem. (Parser::parse_trait_impl_item): Return std::unique_ptr<AssociatedItem>. (Parser::parse_trait_impl_function_or_method): Likewise. * parse/rust-parse.h (Parser::parse_trait_impl_item): Return std::unique_ptr<AssociatedItem>. (Parser::parse_trait_impl_function_or_method): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-30gccrs: Add improved error when no fields in initializerRobert Goss3-3/+72
If a struct type with a variant that has fields is initialized with some fields the expression HIR StructExprStructFields is checked that all the fields are assigned. However, if no fields are initialized the HIR StructExprStruct is generated. This doesn't check if the struct is a unit during typechekc and only fails at the compile stage with a ICE. Add a check at the typecheck stage that makes sure the struct does not have a variant with fields and give an error message based on the rustc one. We have also updated the message given in the case where one field was present to list the missing fields and match more closely the new message. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit) Add additional check * typecheck/rust-hir-type-check-struct-field.h: A helper method to make error added * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve) Update message gcc/testsuite/ChangeLog: * rust/compile/missing_constructor_fields.rs: Added case with no initializers Signed-off-by: Robert Goss <goss.robert@gmail.com>
2024-01-30gccrs: AST: Fix for lifetime loweringJakub Dupak1-4/+17
gcc/rust/ChangeLog: * hir/rust-ast-lower-type.cc (ASTLoweringTypeBounds::visit): fix for lifetimes (ASTLowerWhereClauseItem::visit): fix for lifetimes Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30gccrs: AST: Fix for lifetime parsingJakub Dupak2-16/+27
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_where_clause): fix parsing (Parser::parse_where_clause_item): fix parsing (Parser::parse_type_bound_where_clause_item): fix parsing (Parser::parse_trait_bound): fix parsing * parse/rust-parse.h: fix parsing Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30gccrs: Added newline to get more readable lexdumpKushal Pal1-1/+1
Fixes #2783 gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::dump_and_skip): Changed " " to '\n' Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-01-30gccrs: Unify storage of associated items in SingleASTNodeOwen Avery5-87/+42
gcc/rust/ChangeLog: * ast/rust-ast-fragment.cc (Fragment::assert_single_fragment): Update. * ast/rust-ast.h (class TraitImplItem): Move definition before that of TraitItem. (class TraitItem): Inherit from TraitImplItem instead of AssociatedItem. (class SingleASTNode): Unify handling of associated items. (SingleASTNode::take_assoc_item): Move from... (SingleASTNode::take_impl_item): ...here, but leave stub calling take_assoc_item behind. (SingleASTNode::take_trait_item): Cast associated item to TraitItem. (SingleASTNode::take_trait_impl_item): Cast associated item to TraitImplItem. * ast/rust-ast.cc (SingleASTNode::SingleASTNode): Unify handling of associated items. (SingleASTNode::operator=): Likewise. (SingleASTNode::accept_vis): Likewise. (SingleASTNode::is_error): Likewise. (SingleASTNode::as_string): Likewise. * ast/rust-item.h (class Function): Remove direct inheritence from AssociatedItem. (class ConstantItem): Likewise. * ast/rust-macro.h (class MacroInvocation): Remove direct inheritence from AssociatedItem and TraitImplItem.
2024-01-30gccrs: Add improved error when a field is redefined in a struct constructorRobert Goss2-32/+64
Fixes #2381 If a struct type is initialized with one of it's fields repeated it will currently issue an error at the use site. However we would like to give the rust error code and (like rustc) show both the specifications for the field to help the user diagnose the issue. We move the check after the index for the field has been established so we can look up if the field has already been defined and get it's location. We update the visit method to return if it has handled an error otherwise we then output a second fatal error as not all the field in the specification have been processed. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-struct-field.h: Allow visit to return a bool * typecheck/rust-hir-type-check-struct.cc: Improve check of repeat fields gcc/testsuite/ChangeLog: * rust/compile/repeated_constructor_fields.rs: Added case with constructor field repeated Signed-off-by: Robert Goss <goss.robert@gmail.com>
2024-01-30gccrs: Handle `async` keyword for regular implementationsKushal Pal1-0/+1
Fixes #2788 gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_inherent_impl_item): Added switch-case for ASYNC token. gcc/testsuite/ChangeLog: * rust/compile/issue-2788.rs: New test. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-01-30gccrs: Fix inconsistent formattingKushal Pal1-1/+1
gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Enclose const in single quotes. gcc/testsuite/ChangeLog: * rust/compile/const_trait_fn.rs: Enclose const in single quotes. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-01-30gccrs: Handle `async` functions in traitsKushal Pal2-3/+11
Fixes #2785 gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Added check for `async` functions inside trait. * parse/rust-parse-impl.h (Parser::parse_trait_item): Added switch-case for ASYNC token. gcc/testsuite/ChangeLog: * rust/compile/issue-2785.rs: New test. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-01-30gccrs: Handle newlines during string parsing while lexingNirmal Patel1-11/+29
If newline strings are encountered while lexing, the lexer now handles newline characters by incrementing current line number. This provides correct line number when displaying errors. If the lexer encounters end of file before string end, then it will use the start of the string as the location to an report error. gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::parse_byte_string): Handle newline while parsing byte strings (Lexer::parse_string): Handle newline while parsing strings Signed-off-by: Nirmal Patel <nirmal@nirmal.dev>
2024-01-30gccrs: TyTy: Refactor FnType deprecated APIJakub Dupak6-12/+9
gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Use new API. * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Use new API. * typecheck/rust-tyty-cmp.h: Remove old API. * typecheck/rust-tyty.cc (FnPtr::is_equal): Use new API. * typecheck/rust-tyty.h: Remove old API. * typecheck/rust-unify.cc (UnifyRules::expect_fnptr): Use new API. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30gccrs: ast: Lower 'for' lifetimesJakub Dupak1-0/+7
gcc/rust/ChangeLog: * hir/rust-ast-lower-type.cc (ASTLoweringType::visit): For lifetimes. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30gccrs: ast: Infer static lifetime for const and static itemsJakub Dupak6-19/+46
(probably incomplete propagation) gcc/rust/ChangeLog: * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_lifetime): Propagate static requirement. * hir/rust-ast-lower-base.h: Propagate static requirement. * hir/rust-ast-lower-implitem.h: Propagate static requirement. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Propagate static requirement. * hir/rust-ast-lower-type.cc (ASTLoweringType::translate): Propagate static requirement. (ASTLoweringType::visit): Propagate static requirement. * hir/rust-ast-lower-type.h: Propagate static requirement. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30gccrs: ast: Full lifetime elision handlingJakub Dupak2-13/+14
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_generic_param): Lifetime elision control. (Parser::parse_lifetime_where_clause_item): Lifetime elision control. (Parser::parse_type_param_bound): Lifetime elision control. (Parser::parse_lifetime_bounds): Lifetime elision control. (Parser::parse_lifetime): Lifetime elision control. (Parser::parse_path_generic_args): Lifetime elision control. (Parser::parse_self_param): Lifetime elision control. (Parser::parse_break_expr): Lifetime elision control. (Parser::parse_continue_expr): Lifetime elision control. (Parser::parse_reference_type_inner): Lifetime elision control. * parse/rust-parse.h: Lifetime elision control. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30gccrs: ast: Unify explicitly and implicitly elided lifettimesJakub Dupak3-7/+7
gcc/rust/ChangeLog: * ast/rust-ast.h: Elided lifetime static constructor * ast/rust-type.h: Default lifetime to elided. * parse/rust-parse-impl.h (Parser::parse_lifetime_param): Use elided lifetime. (Parser::parse_lifetime): Use elided lifetime/ (Parser::lifetime_from_token): Use elided lifetime. (Parser::parse_self_param): Use elided lifetime. (Parser::parse_reference_type_inner): Use elided lifetime. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30gccrs: ast: Fix lifetime type parsingJakub Dupak1-2/+2
There was a mismatch whether lifetime 'static is parsed as "static" or "'static". gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::lifetime_from_token): Fix matched pattern. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-30gccrs: Generate error for `async` trait fucntionsKushal Pal1-0/+5
Fixes #2767 gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Added check for `async` function inside trait. gcc/testsuite/ChangeLog: * rust/compile/issue-2767.rs: New test. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
2024-01-30gccrs: Handle `async` qualifier inside traitKushal Pal1-0/+2
Fixes #2778 gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_trait_impl_item): Handled `async` items Signed-off-by: Kushal Pal <kushalpal109@gmail.com>