aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/parse
AgeCommit message (Collapse)AuthorFilesLines
2025-12-03gccrs: Remove non leaf errorsPierre-Emmanuel Patry1-35/+9
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_function): Return a nullptr on error instead of a valid function. (Parser::parse_let_stmt): Remove non leaf error. (Parser::parse_if_expr): Likewise. (Parser::parse_loop_expr): Likewise. (Parser::parse_expr): Return error on null denotation error. gcc/testsuite/ChangeLog: * rust/compile/braced_macro_arm.rs: Remove parent errors. * rust/compile/issue-407-2.rs: Likewise. * rust/compile/issue-407.rs: Likewise. * rust/compile/issue-4162.rs: Likewise. * rust/compile/issue-867.rs: Likewise. * rust/compile/raw_ref_op_invalid.rs: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-12-03gccrs: Remove non-leaf error message in delimited ttPierre-Emmanuel Patry1-15/+7
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_delim_token_tree): Remove error message. (Parser::parse_token_tree): Split error message. gcc/testsuite/ChangeLog: * rust/compile/macros/mbe/macro-issue3608.rs: Remove error. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-12-03gccrs: Remove non-leaf item in crate parsing failure errorPierre-Emmanuel Patry1-4/+0
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_items): Remove item parsing error. gcc/testsuite/ChangeLog: * rust/compile/braced_macro_arm.rs: Remove superfluous error message matching. * rust/compile/decl_macro6.rs: Likewise. * rust/compile/decl_macro7.rs: Likewise. * rust/compile/extern_type_item_missing_semi.rs: Likewise. * rust/compile/issue-2187.rs: Likewise. * rust/compile/issue-407-2.rs: Likewise. * rust/compile/issue-407.rs: Likewise. * rust/compile/issue-4162.rs: Likewise. * rust/compile/issue-867.rs: Likewise. * rust/compile/macros/mbe/macro-issue1053-2.rs: Likewise. * rust/compile/macros/mbe/macro-issue1395-2.rs: Likewise. * rust/compile/macros/mbe/macro-issue3608.rs: Likewise. * rust/compile/macros/mbe/macro27.rs: Likewise. * rust/compile/macros/mbe/macro28.rs: Likewise. * rust/compile/macros/mbe/macro29.rs: Likewise. * rust/compile/macros/mbe/macro30.rs: Likewise. * rust/compile/macros/mbe/macro31.rs: Likewise. * rust/compile/macros/mbe/macro33.rs: Likewise. * rust/compile/macros/mbe/macro35.rs: Likewise. * rust/compile/macros/mbe/macro37.rs: Likewise. * rust/compile/macros/mbe/macro38.rs: Likewise. * rust/compile/macros/mbe/macro39.rs: Likewise. * rust/compile/macros/mbe/macro48.rs: Likewise. * rust/compile/parse_invalid_specialization.rs: Likewise. * rust/compile/parse_simple_path_fail_1.rs: Likewise. * rust/compile/parse_simple_path_fail_2.rs: Likewise. * rust/compile/raw-string-loc.rs: Likewise. * rust/compile/raw-byte-string-loc.rs: Likewise. * rust/compile/self_const_ptr.rs: Likewise. * rust/compile/self_mut_ptr.rs: Likewise. * rust/compile/static_var1.rs: Likewise. * rust/compile/self_ptr.rs: Likewise. * rust/compile/torture/identifier-missing-impl-1.rs: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-11-25gccrs: stop an infinite loop at END_OF_FILELúcio Boari Fleury1-1/+2
gcc/rust/ChangeLog: * parse/rust-parse-impl.h: Add early exit condition to parsing loop. Signed-off-by: Lúcio Boari Fleury <lucboari@gmail.com>
2025-11-25gccrs: Add support for initial generic associated typesPhilip Herron1-2/+10
This patch is the initial part in supporting generic associated types. In rust we have trait item types that get implemented for example: trait Foo<T> { type Bar } impl<T> Foo for T { type Bar = T } The trait position uses a Ty::Placeholder which is just a thing that gets set for lazy evaluation to the impl type alias which is actually a Ty::Projection see: 0798add3d3c1bf4b20ecc1b4fa1047ba4ba19759 For more info the projection type needs to hold onto generics in order to properly support generic types this GAT's support extends this all the way to the placeholder which still needs to be done. Fixes Rust-GCC#4276 gcc/rust/ChangeLog: * ast/rust-ast.cc (TraitItemType::as_string): add generic params * ast/rust-ast.h: remove old comment * ast/rust-item.h: add generic params to associated type * ast/rust-type.h: remove old comment * hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit): hir lowering for gat's * hir/tree/rust-hir-item.cc (TraitItemType::TraitItemType): gat's on TraitItemType (TraitItemType::operator=): preserve generic params * hir/tree/rust-hir-item.h: likewise * hir/tree/rust-hir.cc (TraitItemType::as_string): likewise * parse/rust-parse-impl.h (Parser::parse_trait_type): hit the < and parse params * typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItemWithTrait::visit): typecheck * typecheck/rust-tyty.cc (BaseType::has_substitutions_defined): dont destructure gcc/testsuite/ChangeLog: * rust/compile/gat1.rs: New test. * rust/execute/torture/gat1.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-11-17gccrs: fix ICE on missing pattern in while loopLucas Ly Ba1-1/+8
Adds a proper check for missing patterns in while expressions. Fixes Rust-GCC#4162 gcc/rust/ChangeLog: * parse/rust-parse-impl.h(Parser<ManagedTokenSource>::parse_while_let_loop_expr): Add check for missing pattern. gcc/testsuite/ChangeLog: * rust/compile/issue-4162.rs: New test. Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
2025-11-17gccrs: Fix ICE with non-trailing const defaultsvishruth-thimmaiah1-3/+31
When a const generic with a default value is not trailing, emit an error. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_generic_params): Emit an error when const generics with a default value is not trailing. gcc/testsuite/ChangeLog: * rust/compile/const_generics_17.rs: New test. * rust/compile/generics14.rs: New test. Signed-off-by: vishruth-thimmaiah <vishruththimmaiah@gmail.com>
2025-11-17gccrs: Add minus sign compilation for LiteralPatternYap Zhi Heng1-1/+1
GIMPLE output for literalpattern_neg.rs test case: ... x = -55; RUSTTMP.2 = x; if (RUSTTMP.2 == 55) goto <D.113>; else goto <D.114>; <D.113>: { RUSTTMP.1 = 1; goto <D.107>; } <D.114>: if (RUSTTMP.2 == -55) goto <D.115>; else goto <D.116>; <D.115>: { RUSTTMP.1 = 0; goto <D.107>; } <D.116>: if (1 != 0) goto <D.117>; else goto <D.118>; <D.117>: { RUSTTMP.1 = 1; goto <D.107>; } ... gcc/rust/ChangeLog: * parse/rust-parse-impl.h (parse_literal_or_range_pattern): Parse minus sign properly for LiteralPattern. * ast/rust-pattern.h (LiteralPattern): Add has_minus boolean for LiteralPattern. * hir/tree/rust-hir-pattern.h (LiteralPattern): Ditto. * ast/rust-pattern.cc (LiteralPattern::as_string): Update to include minus sign if present. * hir/tree/rust-hir.cc (LiteralPattern::as_string): Ditto. * hir/rust-ast-lower-pattern.cc (visit(LiteralPattern)): Pass has_minus boolean from AST to HIR. * backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit(LiteralPattern)): Compile litexpr as negative if minus sign is present. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-10-30gccrs: Add HIR lowering support for rest pattern in struct patterns' ASTYap Zhi Heng1-3/+3
gcc/rust/ChangeLog: * ast/rust-pattern.h (StructPatternElements): Rename has_struct_pattern_etc to has_rest_pattern, and has_etc to has_rest to signify presense of rest patterns more clearly. * ast/rust-pattern.cc (StructPatternElements::as_string): Rename variables accordingly. * ast/rust-ast-collector.cc: Rename variables accordingly. * expand/rust-cfg-strip.cc: Rename variables accordingly. * parse/rust-parse-impl.h: Rename variable accordingly. * hir/tree/rust-hir-pattern.h (StructPatternElements): Add a boolean to track presense of rest pattern. * hir/rust-ast-lower-pattern.cc (visit(StructPattern)): Add support for lowering rest pattern to HIR. * typecheck/rust-hir-type-check-pattern.cc (visit(StructPattern)): Remove size check when rest pattern is present. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-10-30gccrs: Protect from errors in alternate pattern parsingOwen Avery1-2/+8
Fixes https://github.com/Rust-GCC/gccrs/issues/4155. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_pattern): Ignore inner patterns which fail to parse. gcc/testsuite/ChangeLog: * rust/compile/issue-4155.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-10-30gccrs: Remove AST::TraitItemConstOwen Avery2-6/+5
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove overload for TraitItemConst. * ast/rust-ast-collector.h (TokenCollector::visit): Likewise. * ast/rust-ast-pointer-visitor.cc (PointerVisitor::visit): Likewise. * ast/rust-ast-pointer-visitor.h (PointerVisitor::visit): Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.h (ASTVisitor::visit): Likewise. (DefaultASTVisitor::visit): Likewise. * expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise. * expand/rust-cfg-strip.h (CfgStrip::visit): Likewise. * expand/rust-derive.h (DeriveVisitor::visit): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h (ExpandVisitor::visit): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h (ASTLoweringBase::visit): Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. * util/rust-attributes.h (AttributeChecker::visit): Likewise. * ast/rust-ast.cc (ConstantItem::as_string): Handle missing expression. (TraitItemConst::as_string): Remove function definition. (TraitItemConst::accept_vis): Remove function definition. * ast/rust-item.h (ConstantItem::mark_for_strip): Adjust comment. (ConstantItem::has_expr): Make const. (class TraitItemConst): Remove definition. * ast/rust-ast-full-decls.h (class TraitItemConst): Remove declaration. * hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit): Handle ConstantItem instead of TraitItemConst. * hir/rust-ast-lower-implitem.h (ASTLowerTraitItem::visit): Likewise. * parse/rust-parse-impl.h (Parser::parse_trait_const): Return pointer to ConstantItem instead of TraitItemConst. * parse/rust-parse.h (Parser::parse_trait_const): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-10-30gccrs: Remove Parser::parse_tuple_index_expr_floatOwen Avery1-35/+0
Unlike in C, floating point literals can't start with a '.', and therefore could never be split into a '.' followed by an integer. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::left_denotation): Remove usage of parse_tuple_index_expr_float. (Parser::parse_closure_expr_pratt): Remove function. gcc/testsuite/ChangeLog: * rust/compile/parse_float_dot.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-10-30gccrs: Refactor AST Patterns that hold multiple pattern itemsYap Zhi Heng1-18/+18
Patterns include TuplePattern, TupleStructPattern & SlicePattern. Besides making their pattern items container class inherit from a common `PatternItems` base class just like in HIR for better standardization, mentions of `Range` are also changed to `HasRest` or `NoRest`. gcc/rust/ChangeLog: * ast/rust-pattern.h: - Add a new base abstract class `PatternItems` which are used by pattern items class class derivatives for `TuplePattern`, `TupleStructPattern` & `SlicePattern`. - Standardized the derived class names to have `HasRest` or `NoRest` as suffixes. - Values for the common `ItemType` enum is updated to `HAS_REST` or `NO_REST`. * ast/rust-pattern.cc: Renamed the classes accordingly. * ast/rust-ast-collector.cc: Renamed the classes accordingly. * ast/rust-ast-collector.h: Renamed the classes accordingly. * ast/rust-ast-full-decls.h: Renamed the classes accordingly. * ast/rust-ast-visitor.cc: Renamed the classes accordingly. * ast/rust-ast-visitor.h: Renamed the classes accordingly. * ast/rust-desugar-for-loops.cc: Renamed the classes accordingly. * ast/rust-desugar-question-mark.cc: Renamed the classes accordingly. * expand/rust-cfg-strip.cc: Renamed the classes accordingly. * expand/rust-cfg-strip.h: Renamed the classes accordingly. * expand/rust-derive-clone.cc: Renamed the classes accordingly. * expand/rust-derive-cmp-common.cc: Renamed the classes accordingly. * expand/rust-derive-hash.cc: Renamed the classes accordingly. * expand/rust-derive-ord.cc: Renamed the classes accordingly. * expand/rust-derive-partial-eq.cc: Renamed the classes accordingly. * expand/rust-derive.h: Renamed the classes accordingly. * expand/rust-expand-visitor.cc: Renamed the classes accordingly. * expand/rust-expand-visitor.h: Renamed the classes accordingly. * hir/rust-ast-lower-base.cc: Renamed the classes accordingly. * hir/rust-ast-lower-base.h: Renamed the classes accordingly. * hir/rust-ast-lower-pattern.cc: Renamed the classes accordingly. * hir/tree/rust-hir-pattern.h: Renamed the classes accordingly. * parse/rust-parse-impl.h: Renamed the classes accordingly. * resolve/rust-ast-resolve-base.cc: Renamed the classes accordingly. * resolve/rust-ast-resolve-base.h: Renamed the classes accordingly. * resolve/rust-ast-resolve-pattern.cc: Renamed the classes accordingly. * util/rust-attributes.cc: Renamed the classes accordingly. * util/rust-attributes.h: Renamed the classes accordingly. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-10-30gccrs: Remove Parser::parse_path_in_expression_prattOwen Avery2-137/+14
This improves our handling of PathInExpression and fixes https://github.com/Rust-GCC/gccrs/issues/4056. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_expr): Avoid skipping or splitting tokens. (Parser::null_denotation): Assume initial token was not skipped and adjust function signature to match. Use parse_path_in_expression instead of parse_path_in_expression_pratt and handle SCOPE_RESOLUTION. (Parser::parse_path_in_expression_pratt): Remove function. * parse/rust-parse.h (null_denotation): Remove initial token parameter. (parse_path_in_expression_pratt): Remove function. gcc/testsuite/ChangeLog: * rust/compile/global-path-array.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-10-30gccrs: Expect identifier subpatterns to be non-altOwen Avery1-2/+3
Fixes https://github.com/Rust-GCC/gccrs/issues/4071. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_identifier_pattern): Use parse_pattern_no_alt to parse identifier pattern subpatterns. (Parser::parse_ident_leading_pattern): Likewise. gcc/testsuite/ChangeLog: * rust/compile/parse_closure_bind.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-10-30gccrs: Fix Self macro invocation parsing failurePierre-Emmanuel Patry1-3/+8
No check was performed and the value was assumed non null. Path conversion returned an empty path for "Self" due to a hack in generics Self injection that prevented any "Self!" macro from beeing recognized correctly. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_stmt_or_expr): Add null check on parse_macro_invocation_partial call. * ast/rust-path.cc (Path::convert_to_simple_path): Do not exclude capitalized "Self". gcc/testsuite/ChangeLog: * rust/compile/issue-3974.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-10-30gccrs: Detect failure to match an ident metavariableOwen Avery1-0/+1
Fixes https://github.com/Rust-GCC/gccrs/issues/4054 gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_identifier_or_keyword_token): Record error on failure. gcc/testsuite/ChangeLog: * rust/compile/macros/mbe/macro-issue4054.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-10-30gccrs: Handle attributes in expression macrosOwen Avery1-1/+5
gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (transcribe_expression): Parse any outer attributes before parsing an expression. * parse/rust-parse.h (Parser::parse_outer_attributes): Make public. gcc/testsuite/ChangeLog: * rust/compile/attr-macro.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-10-30gccrs: Improve vector usages and avoid copies.Pierre-Emmanuel Patry1-7/+6
Several place built an object before copying it in a vector. This commit favorise in place construction and use readily available vector size to reserve memory beforehand. gcc/rust/ChangeLog: * ast/rust-expr.h (struct TupleClobber): Add constructor. * backend/rust-compile-context.h (struct fncontext): Likewise. * typecheck/rust-hir-dot-operator.h: Likewise. * typecheck/rust-tyty-variance-analysis-private.h (struct Constraint): Likewise. * typecheck/rust-unify.h: Likewise. * ast/rust-ast-builder.cc (Builder::new_lifetime_param): Add memory reservation and construct in place. (Builder::new_generic_args): Likewise. * ast/rust-ast-collector.cc (TokenCollector::newline): Likewise. (TokenCollector::indentation): Likewise. (TokenCollector::comment): Likewise. * ast/rust-desugar-apit.cc: Likewise. * ast/rust-path.cc (Path::convert_to_simple_path): Likewise. (TypePath::as_simple_path): Likewise. * ast/rust-path.h: Likewise. * backend/rust-compile-type.cc (TyTyResolveCompile::visit): Likewise. (TyTyResolveCompile::create_dyn_obj_record): Likewise. * checks/errors/rust-hir-pattern-analysis.cc (Matrix::specialize): Likewise. (WitnessMatrix::apply_constructor): Likewise. (check_match_usefulness): Likewise. * expand/rust-derive-clone.cc (DeriveClone::clone_fn): Likewise. * expand/rust-macro-builtins-asm.cc (parse_clobber_abi): Likewise. * expand/rust-macro-expand.cc (MacroExpander::parse_proc_macro_output): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_generic_args): Likewise. (ASTLoweringBase::lower_extern_block): Likewise. * hir/rust-ast-lower-enumitem.h: Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-extern.h: Likewise. * hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): Likewise. (ASTLowerTraitItem::visit): Likewise. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Likewise. * hir/rust-ast-lower.cc (ASTLowering::go): Likewise. (ASTLoweringBlock::visit): Likewise. (ASTLoweringIfLetBlock::desugar_iflet): Likewise. (ASTLoweringExprWithBlock::visit): Likewise. (ASTLowerPathInExpression::visit): Likewise. (ASTLowerQualPathInExpression::visit): Likewise. * hir/tree/rust-hir.cc (PathPattern::convert_to_simple_path): Likewise. (TypePath::as_simple_path): Likewise. * metadata/rust-export-metadata.cc (ExportContext::emit_function): Likewise. * parse/rust-parse-impl.h (Parser::parse_decl_macro_def): Likewise. (Parser::parse_lifetime_params): Likewise. * resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise. (ResolveItem::visit): Likewise. (flatten_list): Likewise. * resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit): Likewise. * typecheck/rust-autoderef.cc (AutoderefCycle::try_autoderefed): Likewise. * typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsized): Likewise. * typecheck/rust-hir-dot-operator.cc: Likewise. * typecheck/rust-hir-path-probe.cc: Likewise. * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_fn_trait_call): Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): Likewise. (TypeCheckImplItem::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::resolve): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): Likewise. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. * typecheck/rust-typecheck-context.cc (TypeCheckContext::push_return_type): Likewise. (TypeCheckContext::insert_associated_impl_mapping): Likewise. * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Likewise. (TypeBoundsProbe::add_trait_bound): Likewise. (TypeBoundPredicate::operator=): Likewise. (TypeBoundPredicateItem::get_tyty_for_receiver): Likewise. (TypeBoundPredicate::get_associated_type_items): Likewise. * typecheck/rust-tyty-call.cc (TypeCheckMethodCallExpr::go): Likewise. * typecheck/rust-tyty-subst.cc (SubstitutionRef::clone_substs): Likewise. (SubstitutionRef::infer_substitions): Likewise. (SubstitutionRef::are_mappings_bound): Likewise. * typecheck/rust-tyty-variance-analysis.cc (GenericTyPerCrateCtx::query_generic_variance): Likewise. (GenericTyVisitorCtx::add_constraint): Likewise. * typecheck/rust-tyty.cc (FnPtr::clone): Likewise. (DynamicObjectType::get_object_items): Likewise. * typecheck/rust-unify.cc (UnifyRules::Resolve): Likewise. (UnifyRules::go): Likewise. (UnifyRules::expect_tuple): Likewise. * util/rust-canonical-path.h: Likewise. * util/rust-token-converter.cc (convert): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-10-30gccrs: Fix friendly class to friendly struct qualificationPierre-Emmanuel Patry1-1/+1
gcc/rust/ChangeLog: * parse/rust-parse.h: Change class to struct for friend qualification. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Make AttributeParser rely more on ParserOwen Avery1-0/+4
gcc/rust/ChangeLog: * ast/rust-ast.cc (AttributeParser::parse_meta_item_inner): Handle removal of AttributeParser-specific functions. (AttributeParser::parse_path_meta_item): Likewise. (AttributeParser::parse_meta_item_seq): Likewise. (AttributeParser::parse_meta_item_lit): Likewise. (AttributeParser::parse_literal): Remove function. (AttributeParser::parse_simple_path): Likewise. (AttributeParser::parse_simple_path_segment): Likewise. (AttributeParser::peek_token): Likewise. (AttributeParser::skip_token): Likewise. * ast/rust-macro.h (AttributeParser::parse_simple_path): Likewise. (AttributeParser::parse_simple_path_segment): Likewise. (AttributeParser::parse_literal): Likewise. (AttributeParser::peek_token): Likewise. (AttributeParser::skip_token): Likewise. * parse/rust-parse.h (Parser): Make AttributeParser a friend class. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: Avoid including rust-parse-impl.h in rust-parse.hOwen Avery5-7/+92
This should reduce incremental compile times when modifying rust-parse-impl.h and not rust-parse.h. gcc/rust/ChangeLog: * Make-lang.in (GRS_OBJS): Add entries. * parse/rust-parse-impl.h: Adjust header comment. (Parser::parse_lifetime_params_objs): Fix bug and add comment. (Parser::unexpected_token): Likewise. * parse/rust-parse.h: Remove inclusion of "rust-parse-impl.h". * parse/rust-parse-impl-lexer.cc: New file. * parse/rust-parse-impl-macro.cc: New file. * parse/rust-parse-impl-proc-macro.cc: New file. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: Add rest pattern support for AST::SlicePatternYap Zhi Heng1-11/+61
The main change can be found in ast/rust-pattern.h, which introduces 2 item types for AST::SlicePattern - one without rest pattern (SlicePatternItemsNoRest) & the other with it (SlicePatternItemsHasRest). This led to a number of cascading changes as seen in the changelog. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc: Add support for the 2 new classes. * ast/rust-ast-collector.h: Header file update for above. * ast/rust-ast-full-decls.h: Add forward decls for the 2 new classes. * ast/rust-ast-visitor.cc: Add visit support for the 2 new classes. * ast/rust-ast-visitor.h: Header file update for above. * ast/rust-pattern.cc: Implementation of certain methods for the 2 new classes. * ast/rust-pattern.h: Define the 2 new classes. Update SlicePattern to be able to hold 2 kinds of items - SlicePatternItemsNoRest or SlicePatternItemsRest. * expand/rust-cfg-strip.cc: Add support for the 2 new classes. * expand/rust-cfg-strip.h: Header file update for above. * expand/rust-derive.h: Add visits for the 2 new classes. * hir/rust-ast-lower-base.cc: Add visits for the 2 new classes. * hir/rust-ast-lower-base.h: Header file update for above. * hir/rust-ast-lower-pattern.cc: Update lowering of SlicePattern to support SlicePatternItemsNoRest. * parse/rust-parse-impl.h (parse_slice_pattern()): Add support for parsing DOT_DOT into respective SlicePatternItems. * resolve/rust-ast-resolve-base.cc: Add visits for the 2 new classes. * resolve/rust-ast-resolve-base.h: Header file update for above. * resolve/rust-ast-resolve-pattern.cc: Update SlicePattern resolution to support new classes. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05gccrs: ast: Use AnonConst for array type sizesArthur Cohen2-3/+38
gcc/rust/ChangeLog: * ast/rust-expr.h: Add handling for deferred consts. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast.cc (AnonConst::as_string): Likewise. (ArrayType::as_string): Likewise. * ast/rust-type.h (class ArrayType): Use AnonConst for sizes. * parse/rust-parse-impl.h (Parser::parse_anon_const): New function. (Parser::parse_slice_or_array_type): Call it. * parse/rust-parse.h: Declare it.
2025-08-05gccrs: Improve parsing of simple pathsOwen Avery2-67/+73
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_simple_path): Be more careful about skipping SCOPE_RESOLUTION tokens. (Parser::parse_simple_path_segment): Allow parsing from a starting offset. (Parser::parse_use_tree): Handle a non-skipped SCOPE_RESOLUTION token. * parse/rust-parse.h (Parser::parse_simple_path_segment): Add parameter for parsing from a starting offset. gcc/testsuite/ChangeLog: * rust/compile/parse_simple_path_fail_1.rs: New test. * rust/compile/parse_simple_path_fail_2.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: Parse try expressionsOwen Avery2-0/+34
This doesn't do anything beyond creating TryExpr and parsing them, so try expressions shouldn't be able to make it past AST lowering yet. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Add visitor for TryExpr. * ast/rust-ast-collector.h (TokenCollector::visit): Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.h (ASTVisitor::visit): Likewise. (DefaultASTVisitor::visit): Likewise. * expand/rust-derive.h (DeriveVisitor::visit): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h (ASTLoweringBase::visit): Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h (ResolverBase::visit): Likewise. * ast/rust-ast-full-decls.h (class TryExpr): New forward class declaration. * ast/rust-ast.cc (TryExpr::as_string): New function. (TryExpr::accept_vis): Likewise. * ast/rust-expr.h (class TryExpr): New class. * parse/rust-parse.h (Parser::parse_try_expr): New function. * parse/rust-parse-impl.h (Parser::parse_try_expr): Likewise. (Parser::null_denotation_not_path): Use parse_try_expr to parse try expressions. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: Change enum to enum classPierre-Emmanuel Patry2-3/+5
gcc/rust/ChangeLog: * parse/rust-parse-impl.h: Add enum prefix. * parse/rust-parse.h (enum ParseSelfError): Change from enum... (enum class): To enum class. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: parser: fix ICE std::out_of_range with path attrs to nonexisting pathVishruth-Thimmaiah1-4/+11
Stops an ICE from occuring when path attribute is empty Fixes Rust-GCC#3607. gcc/rust/ChangeLog: * parse/rust-parse.cc (Rust::extract_module_path): Handle empty or whitespace-only path attributes. gcc/testsuite/ChangeLog: * rust/compile/torture/extern_mod2.rs: New test to ensure an error is emitted for empty path attributes. Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
2025-08-05gccrs: parser: Add base for parsing const blocksArthur Cohen2-0/+32
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_const_block_expr): New function. * parse/rust-parse.h: Declare it.
2025-08-05gccrs: Remove rvalue reference bindingOwen Avery1-7/+4
This should be unnecessary, since even C++11 has implicit move. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_expr_stmt): Avoid reference binding and remove std::move in return statements. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: Reindent using last clang-format configurationMarc Poulhiès4-125/+209
It changes declaration and switch case indentation to follow GNU coding style. gcc/rust/ChangeLog: * ast/rust-ast-builder-type.cc (ASTTypeBuilder::visit): Reindent. * ast/rust-ast-builder.cc (Builder::new_generic_args): Likewise. * ast/rust-ast-collector.cc (TokenCollector::visit): Likewise. * ast/rust-ast-dump.h (debug): Likewise. * ast/rust-ast-formatting.h (indent_spaces): Likewise. (get_string_in_delims): Likewise. (get_mode_dump_desc): Likewise. (append_attributes): Likewise. (unquote_string): Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast.cc (Attribute::get_traits_to_derive): Likewise. (UseTreeGlob::as_string): Likewise. (UseTreeList::as_string): Likewise. (AttributeParser::parse_path_meta_item): Likewise. (FormatArgs::set_outer_attrs): Likewise. * ast/rust-ast.h (operator<<): Likewise. * ast/rust-cond-compilation.h: Likewise. * ast/rust-desugar-apit.cc: Likewise. * ast/rust-fmt.h (collect_pieces): Likewise. (clone_pieces): Likewise. * ast/rust-pattern.h (tokenid_to_rangekind): Likewise. * backend/rust-compile-context.cc (Context::type_hasher): Likewise. * backend/rust-compile-expr.cc (CompileExpr::visit): Likewise. * backend/rust-compile-intrinsic.cc (get_identifier): Likewise. (offset_handler): Likewise. (sizeof_handler): Likewise. (transmute_handler): Likewise. (rotate_handler): Likewise. (wrapping_op_handler_inner): Likewise. (op_with_overflow_inner): Likewise. (uninit_handler): Likewise. (move_val_init_handler): Likewise. (assume_handler): Likewise. (discriminant_value_handler): Likewise. (variant_count_handler): Likewise. (prefetch_data_handler): Likewise. (atomic_store_handler_inner): Likewise. (atomic_load_handler_inner): Likewise. (unchecked_op_inner): Likewise. (copy_handler_inner): Likewise. (expect_handler_inner): Likewise. (try_handler_inner): Likewise. * backend/rust-compile-pattern.cc (compile_range_pattern_bound): Likewise. (CompilePatternCheckExpr::visit): Likewise. (CompilePatternBindings::visit): Likewise. (CompilePatternLet::visit): Likewise. * backend/rust-compile-var-decl.h: Likewise. * backend/rust-constexpr.cc (verify_constant): Likewise. (find_array_ctor_elt): Likewise. (array_index_cmp): Likewise. (potential_constant_expression_1): Likewise. (unshare_constructor): Likewise. (maybe_save_constexpr_fundef): Likewise. (returns): Likewise. (breaks): Likewise. (continues): Likewise. (switches): Likewise. (constant_value_1): Likewise. (decl_constant_value): Likewise. (non_const_var_error): Likewise. (eval_constant_expression): Likewise. (constexpr_fn_retval): Likewise. (eval_store_expression): Likewise. (eval_call_expression): Likewise. (eval_binary_expression): Likewise. (get_function_named_in_call): Likewise. (eval_statement_list): Likewise. (extract_string_elt): Likewise. (eval_conditional_expression): Likewise. (eval_bit_field_ref): Likewise. (eval_loop_expr): Likewise. (eval_switch_expr): Likewise. (eval_unary_expression): Likewise. (get_or_insert_ctor_field): Likewise. (eval_and_check_array_index): Likewise. * backend/rust-constexpr.h (maybe_save_constexpr_fundef): Likewise. * backend/rust-mangle-v0.cc (v0_path): Likewise. (v0_complex_type_prefix): Likewise. * backend/rust-mangle.h (legacy_mangle_item): Likewise. (v0_mangle_item): Likewise. * backend/rust-tree.cc (convert_to_void): Likewise. (find_parameter_packs_r): Likewise. (rs_tree_equal): Likewise. (publicly_uniquely_derived_p): Likewise. (instantiation_dependent_expression_p): Likewise. (type_has_nontrivial_copy_init): Likewise. (is_normal_capture_proxy): Likewise. (is_bitfield_expr_with_lowered_type): Likewise. (undeduced_auto_decl): Likewise. (require_deduced_type): Likewise. (gt_pch_nx): Likewise. (lvalue_kind): Likewise. * backend/rust-tree.h (LANG_DECL_MIN_CHECK): Likewise. (LANG_DECL_FN_CHECK): Likewise. (LANG_DECL_NS_CHECK): Likewise. (LANG_DECL_PARM_CHECK): Likewise. (LANG_DECL_DECOMP_CHECK): Likewise. (resort_type_member_vec): Likewise. (convert_to_void): Likewise. (mark_discarded_use): Likewise. (mark_exp_read): Likewise. (mark_use): Likewise. (mark_rvalue_use): Likewise. (mark_lvalue_use): Likewise. (mark_lvalue_use_nonread): Likewise. (convert_from_reference): Likewise. (maybe_warn_nodiscard): Likewise. (expr_loc_or_loc): Likewise. (expr_loc_or_input_loc): Likewise. (get_fndecl_from_callee): Likewise. (pointer_offset_expression): Likewise. (is_empty_class): Likewise. (is_really_empty_class): Likewise. (rs_type_quals): Likewise. (init_modules): Likewise. (lookup_add): Likewise. (ovl_make): Likewise. (struct c_fileinfo): Likewise. (get_fileinfo): Likewise. (cxx_make_type): Likewise. (build_cplus_array_type): Likewise. (comptypes): Likewise. (rs_build_qualified_type_real): Likewise. (vector_targets_convertible_p): Likewise. (get_class_binding_direct): Likewise. (lang_check_failed): Likewise. (check_for_uninitialized_const_var): Likewise. (cp_fold_maybe_rvalue): Likewise. (fold_offsetof): Likewise. (fold_non_dependent_expr): Likewise. (in_immediate_context): Likewise. (cxx_mark_addressable): Likewise. (decl_constant_value): Likewise. (is_class_type): Likewise. (fold_builtin_is_pointer_inverconvertible_with_class): Likewise. (c_common_type_for_mode): Likewise. (next_common_initial_seqence): Likewise. (fold_builtin_is_corresponding_member): Likewise. (maybe_constant_value): Likewise. (rs_walk_subtrees): Likewise. (make_tree_vector): Likewise. (release_tree_vector): Likewise. (location_of): Likewise. (maybe_constant_init): Likewise. (explain_invalid_constexpr_fn): Likewise. (literal_type_p): Likewise. (maybe_constexpr_fn): Likewise. (fold_non_dependent_init): Likewise. * checks/errors/borrowck/polonius/rust-polonius.h (polonius_run): Likewise. (FFIVector__new): Likewise. (FFIVector__new_vec_pair): Likewise. (FFIVector__new_vec_triple): Likewise. (FFIVector__push): Likewise. (FFIVector__push_vec_triple): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-pattern.cc (PatternBindingBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-dump.cc (Dump::visit): Likewise. * checks/errors/borrowck/rust-bir-fact-collector.h (points): Likewise. * checks/errors/borrowck/rust-bir-place.h: Likewise. * checks/errors/borrowck/rust-bir-visitor.h: Likewise. * checks/errors/privacy/rust-privacy-check.cc (saw_errors): Likewise. * checks/errors/privacy/rust-privacy-ctx.h (rust_privacy_ctx_test): Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_for_privacy_violation): Likewise. (PrivacyReporter::check_base_type_privacy): Likewise. (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit): Likewise. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::resolve_visibility): Likewise. * checks/errors/rust-hir-pattern-analysis.cc (Constructor::is_covered_by): Likewise. (PlaceInfo::specialize): Likewise. (WitnessPat::to_string): Likewise. (WitnessMatrix::apply_constructor): Likewise. (lower_pattern): Likewise. (lower_tuple_pattern): Likewise. (lower_struct_pattern): Likewise. * checks/errors/rust-hir-pattern-analysis.h (check_match_usefulness): Likewise. * expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_generic_args): Likewise. * expand/rust-derive-eq.cc (DeriveEq::visit_enum): Likewise. * expand/rust-derive.cc: Likewise. * expand/rust-expand-format-args.cc (expand_format_args): Likewise. * expand/rust-expand-visitor.h (is_derive): Likewise. (is_builtin): Likewise. * expand/rust-macro-builtins-asm.cc (expand_inline_asm_strings): Likewise. * expand/rust-macro-builtins-asm.h (parse_asm): Likewise. (check_identifier): Likewise. (check_and_set): Likewise. (parse_label): Likewise. (parse_llvm_outputs): Likewise. (parse_llvm_inputs): Likewise. (parse_llvm_clobbers): Likewise. (parse_llvm_options): Likewise. * expand/rust-macro-builtins-helpers.h (make_macro_path_str): Likewise. (make_token): Likewise. (make_string): Likewise. (macro_end_token): Likewise. (parse_single_string_literal): Likewise. (source_relative_path): Likewise. (load_file_bytes): Likewise. * expand/rust-macro-expand.cc (MacroExpander::match_fragment): Likewise. (MacroExpander::match_matcher): Likewise. (MacroExpander::match_n_matches): Likewise. * expand/rust-macro-substitute-ctx.cc (SubstituteCtx::substitute_token): Likewise. * expand/rust-proc-macro.h (load_macros): Likewise. (generate_proc_macro_decls_symbol): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_generic_args): Likewise. (ASTLoweringBase::lower_range_pattern_bound): Likewise. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Likewise. * hir/rust-ast-lower.h (struct_field_name_exists): Likewise. (translate_visibility): Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/rust-hir-dump.h (debug): Likewise. * hir/tree/rust-hir.cc (UseTreeGlob::as_string): Likewise. (UseTreeList::as_string): Likewise. * lex/rust-lex.cc (Lexer::parse_escape): Likewise. (Lexer::parse_utf8_escape): Likewise. * lex/rust-lex.h (rust_input_source_test): Likewise. * lex/rust-token.cc (RS_TOKEN_KEYWORD_2015): Likewise. * lex/rust-token.h (get_token_description): Likewise. (token_id_to_str): Likewise. (token_id_is_keyword): Likewise. (token_id_keyword_string): Likewise. (get_type_hint_string): Likewise. (nfc_normalize_token_string): Likewise. * metadata/rust-export-metadata.cc (PublicInterface::write_to_path): Likewise. * metadata/rust-import-archive.cc: Likewise. * metadata/rust-imports.h (add_search_path): Likewise. * parse/rust-cfg-parser.h (parse_cfg_option): Likewise. (rust_cfg_parser_test): Likewise. * parse/rust-parse-impl.h (Parser::skip_generics_right_angle): Likewise. (Parser::parse_attr_input): Likewise. (Parser::parse_macro_match): Likewise. (Parser::parse_visibility): Likewise. (Parser::parse_module): Likewise. (Parser::parse_use_tree): Likewise. (Parser::parse_generic_param): Likewise. (Parser::parse_struct): Likewise. (Parser::parse_enum_item): Likewise. (Parser::parse_inherent_impl_item): Likewise. (Parser::parse_external_item): Likewise. (Parser::parse_generic_arg): Likewise. (Parser::parse_type_path_segment): Likewise. (Parser::parse_expr_stmt): Likewise. (Parser::parse_if_expr): Likewise. (Parser::parse_if_let_expr): Likewise. (Parser::parse_type): Likewise. (Parser::parse_for_prefixed_type): Likewise. (Parser::parse_slice_or_array_type): Likewise. (Parser::parse_type_no_bounds): Likewise. (Parser::parse_range_pattern_bound): Likewise. (Parser::parse_pattern_no_alt): Likewise. (Parser::parse_grouped_or_tuple_pattern): Likewise. (Parser::parse_ident_leading_pattern): Likewise. (Parser::parse_tuple_struct_items): Likewise. (Parser::parse_stmt_or_expr): Likewise. (Parser::parse_struct_expr_field): Likewise. (Parser::null_denotation): Likewise. (Parser::left_denotation): Likewise. (Parser::parse_closure_expr_pratt): Likewise. * parse/rust-parse.cc (peculiar_fragment_match_compatible): Likewise. (is_match_compatible): Likewise. * parse/rust-parse.h (extract_module_path): Likewise. (is_match_compatible): Likewise. * resolve/rust-ast-resolve-expr.cc (translate_operand): Likewise. * resolve/rust-ast-resolve-item.cc (flatten_glob): Likewise. (flatten_rebind): Likewise. (flatten_list): Likewise. (flatten): Likewise. * resolve/rust-ast-resolve-item.h (rust_simple_path_resolve_test): Likewise. * resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit): Likewise. (resolve_range_pattern_bound): Likewise. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. (ResolveTypeToCanonicalPath::visit): Likewise. * resolve/rust-ast-resolve.cc (saw_errors): Likewise. * resolve/rust-early-name-resolver-2.0.cc (Early::finalize_rebind_import): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (flatten_glob): Likewise. * rust-backend.h (init): Likewise. (debug): Likewise. (get_identifier_node): Likewise. (wchar_type): Likewise. (get_pointer_size): Likewise. (raw_str_type): Likewise. (integer_type): Likewise. (float_type): Likewise. (pointer_type): Likewise. (reference_type): Likewise. (immutable_type): Likewise. (function_type): Likewise. (function_type_variadic): Likewise. (function_ptr_type): Likewise. (struct_type): Likewise. (union_type): Likewise. (array_type): Likewise. (named_type): Likewise. (type_field_offset): Likewise. (var_expression): Likewise. (float_constant_expression): Likewise. (string_constant_expression): Likewise. (char_constant_expression): Likewise. (wchar_constant_expression): Likewise. (boolean_constant_expression): Likewise. (convert_expression): Likewise. (struct_field_expression): Likewise. (compound_expression): Likewise. (conditional_expression): Likewise. (negation_expression): Likewise. (arithmetic_or_logical_expression): Likewise. (arithmetic_or_logical_expression_checked): Likewise. (comparison_expression): Likewise. (lazy_boolean_expression): Likewise. (constructor_expression): Likewise. (array_constructor_expression): Likewise. (array_initializer): Likewise. (array_index_expression): Likewise. (call_expression): Likewise. (init_statement): Likewise. (assignment_statement): Likewise. (return_statement): Likewise. (if_statement): Likewise. (loop_expression): Likewise. (exit_expression): Likewise. (statement_list): Likewise. (exception_handler_statement): Likewise. (block): Likewise. (block_add_statements): Likewise. (global_variable): Likewise. (global_variable_set_init): Likewise. (local_variable): Likewise. (parameter_variable): Likewise. (static_chain_variable): Likewise. (temporary_variable): Likewise. (label): Likewise. (function): Likewise. (function_defer_statement): Likewise. (function_set_parameters): Likewise. (write_global_definitions): Likewise. (fill_in_fields): Likewise. * rust-diagnostics.cc (expand_format): Likewise. (expand_message): Likewise. (va_constructor): Likewise. * rust-diagnostics.h (RUST_ATTRIBUTE_GCC_DIAG): Likewise. (rust_open_quote): Likewise. (rust_close_quote): Likewise. (rust_debug_loc): Likewise. * rust-gcc.cc (non_zero_size_type): Likewise. * rust-object-export.h (rust_field_alignment): Likewise. (rust_read_export_data): Likewise. (rust_write_export_data): Likewise. * rust-session-manager.cc (saw_errors): Likewise. (rust_get_linemap): Likewise. (validate_crate_name): Likewise. (Session::load_extern_crate): Likewise. * rust-session-manager.h (rust_crate_name_validation_test): Likewise. * rust-system.h (rust_preserve_from_gc): Likewise. (rust_localize_identifier): Likewise. * rust-target.h (rust_add_target_info): Likewise. * typecheck/rust-autoderef.cc: * typecheck/rust-casts.cc (TypeCastRules::cast_rules): Likewise. * typecheck/rust-coercion.cc (TypeCoercionRules::do_coercion): Likewise. (TypeCoercionRules::coerce_unsafe_ptr): Likewise. (TypeCoercionRules::coerce_borrowed_pointer): Likewise. * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): Likewise. (TraitItemReference::is_object_safe): Likewise. * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. (typecheck_inline_asm_operand): Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): Likewise. (TypeCheckImplItemWithTrait::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::apply_trait_bounds): Likewise. (ResolveWhereClauseItem::visit): Likewise. * typecheck/rust-hir-type-check.cc (saw_errors): Likewise. (TraitItemReference::get_type_from_fn): Likewise. * typecheck/rust-type-util.h (query_type): Likewise. (types_compatable): Likewise. (unify_site): Likewise. (unify_site_and): Likewise. (coercion_site): Likewise. (try_coercion): Likewise. (cast_site): Likewise. * typecheck/rust-tyty-bounds.cc: * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Likewise. * typecheck/rust-tyty-cmp.h: * typecheck/rust-tyty-variance-analysis.h (query_field_regions): Likewise. * typecheck/rust-tyty.cc (BaseType::is_unit): Likewise. (BaseType::has_substitutions_defined): Likewise. (BaseType::needs_generic_substitutions): Likewise. (BaseType::get_subst_argument_mappings): Likewise. (InferType::default_type): Likewise. (InferType::apply_primitive_type_hint): Likewise. * typecheck/rust-tyty.h (is_primitive_type_kind): Likewise. * typecheck/rust-unify.cc (UnifyRules::expect_inference_variable): Likewise. (UnifyRules::expect_adt): Likewise. (UnifyRules::expect_str): Likewise. (UnifyRules::expect_reference): Likewise. (UnifyRules::expect_pointer): Likewise. (UnifyRules::expect_param): Likewise. (UnifyRules::expect_array): Likewise. (UnifyRules::expect_slice): Likewise. (UnifyRules::expect_fndef): Likewise. (UnifyRules::expect_fnptr): Likewise. (UnifyRules::expect_tuple): Likewise. (UnifyRules::expect_bool): Likewise. (UnifyRules::expect_char): Likewise. (UnifyRules::expect_int): Likewise. (UnifyRules::expect_uint): Likewise. (UnifyRules::expect_float): Likewise. (UnifyRules::expect_isize): Likewise. (UnifyRules::expect_usize): Likewise. (UnifyRules::expect_never): Likewise. (UnifyRules::expect_placeholder): Likewise. (UnifyRules::expect_projection): Likewise. (UnifyRules::expect_dyn): Likewise. (UnifyRules::expect_closure): Likewise. (UnifyRules::expect_opaque): Likewise. * util/rust-abi.h (get_abi_from_string): Likewise. (get_string_from_abi): Likewise. * util/rust-attributes.cc (check_doc_attribute): Likewise. * util/rust-base62.h (base62_integer): Likewise. * util/rust-dir-owner.h (get_file_subdir): Likewise. * util/rust-edition.h (get_rust_edition): Likewise. * util/rust-punycode.h (encode_punycode): Likewise. (rust_punycode_encode_test): Likewise. * util/rust-token-converter.cc (convert): Likewise. (from_tokenstream): Likewise. * util/rust-token-converter.h (convert): Likewise. (convert_literal): Likewise. * util/rust-unicode.h (is_alphabetic): Likewise. (is_ascii_only): Likewise. (is_numeric): Likewise. (is_nfc_qc_no): Likewise. (is_nfc_qc_maybe): Likewise. (nfc_quick_check): Likewise. (rust_nfc_qc_test): Likewise. (rust_utf8_normalize_test): Likewise. (rust_utf8_property_test): Likewise. * util/rust-unwrap-segment.h (unwrap_segment_node_id): Likewise. libgrust/ChangeLog: * libproc_macro_internal/ffistring.h (FFIString__new): Likewise. (FFIString__drop): Likewise. * libproc_macro_internal/ident.h (Ident__new): Likewise. (Ident__new_raw): Likewise. (Ident__drop): Likewise. (Ident__clone): Likewise. * libproc_macro_internal/literal.h (Literal__from_string): Likewise. * libproc_macro_internal/proc_macro.h (bridge_is_available): Likewise. * libproc_macro_internal/tokenstream.h (TokenStream__new): Likewise. (TokenStream__with_capacity): Likewise. (TokenSream__push): Likewise. (TokenStream__from_string): Likewise. (TokenStream__clone): Likewise. (TokenStream__drop): Likewise.
2025-08-05gccrs: Fix Attr metavariable bindingOwen Avery1-1/+4
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_attr_input): Handle more delimeter tokens and the END_OF_FILE token. (Parser::skip_after_end_attribute): Handle the END_OF_FILE token. gcc/testsuite/ChangeLog: * rust/compile/macros/mbe/meta-param.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: desugar APIT impl traitsPhilip Herron1-11/+2
Argument position impl traits are simply syntatic sugar for generics. This adds a new desugar pass to do this. So for example: fn foo(a: impl Value, b: impl Value) -> i32 Is desugared into: fn foo<T: Value, U: Value> (a: T, b: U) -> i32 So it just works like any normal generic function. There are more complex cases such as: fn foo(_value: impl Bar<Baz = impl Foo>) -> i32 Which has a generic argument binding which needs to be turned into a where constraint: fn foo<T, U>(_value: T) -> i32 where T: Bar<Baz = U>, U: Foo, Fixes Rust-GCC#2015 Fixes Rust-GCC#1487 Fixes Rust-GCC#3454 Fixes Rust-GCC#1482 gcc/rust/ChangeLog: * Make-lang.in: new desugar file * ast/rust-ast.cc (ImplTraitTypeOneBound::as_string): its a unique_ptr now (FormatArgs::set_outer_attrs): reformat * ast/rust-path.h: remove has_generic_args assertion (can be empty because of desugar) * ast/rust-type.h (class ImplTraitTypeOneBound): add copy ctor and use unique_ptr * hir/rust-ast-lower-type.cc (ASTLoweringType::visit): update to use unique_ptr * parse/rust-parse-impl.h (Parser::parse_type): reuse the existing unique_ptr instead (Parser::parse_type_no_bounds): likewise (Parser::parse_pattern): likewise * resolve/rust-ast-resolve-type.cc (ResolveType::visit): its a unique_ptr now * rust-session-manager.cc (Session::compile_crate): call desugar * ast/rust-desugar-apit.cc: New file. * ast/rust-desugar-apit.h: New file. gcc/testsuite/ChangeLog: * rust/compile/issue-2015.rs: fully supported now * rust/compile/nr2/exclude: nr2 cant handle some of these * rust/compile/issue-1487.rs: New test. * rust/compile/issue-3454.rs: New test. * rust/execute/torture/impl_desugar-2.rs: New test. * rust/execute/torture/impl_desugar.rs: New test. * rust/execute/torture/impl_trait1.rs: New test. * rust/execute/torture/impl_trait2.rs: New test. * rust/execute/torture/impl_trait3.rs: New test. * rust/execute/torture/impl_trait4.rs: New test. * rust/execute/torture/issue-1482.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-28gccrs: Remove error state for GenericArgPierre-Emmanuel Patry2-17/+21
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove error kind and change function call. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Change call name. * ast/rust-path.cc (ConstGenericParam::as_string): Likewise. * ast/rust-path.h: Remove error kind. * hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): Change call name. * parse/rust-parse-impl.h (Parser::parse_generic_param): Use optional on parsing failure. (Parser::parse_generic_arg): Likewise. (Parser::parse_path_generic_args): Likewise. * parse/rust-parse.h: Likewise. * resolve/rust-ast-resolve-type.h: Change call name. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-08gccrs: Change optional to expected for parse_loop_labelPierre-Emmanuel Patry2-7/+19
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_loop_label): Change function return type to expected. (Parser::parse_labelled_loop_expr): Adapt call location to new return type. * parse/rust-parse.h (enum class): Update function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-08gccrs: Migrate error state to optionalsPierre-Emmanuel Patry2-55/+75
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::self_ref_param): Remove error state and use optional. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check label before visiting. * ast/rust-ast.cc (ContinueExpr::as_string): Retrieve label value. (Lifetime::as_string): Retrieve lifetime value. (ReferenceType::as_string): Likewise. (SelfParam::as_string): Likewise. * ast/rust-ast.h: Remove lifetime and LifetimeParam error state. * ast/rust-desugar-for-loops.cc (DesugarForLoops::DesugarCtx::make_break_arm): Use optional instead of error state. * ast/rust-expr.h (class ContinueExpr): Make label optional. * ast/rust-item.h (class SelfParam): Make lifetime optional. * ast/rust-type.h (class ReferenceType): Likewise. * backend/rust-compile-base.cc: Use optional for self param instead of error state. * backend/rust-compile-base.h: Update function prototype. * expand/rust-derive-clone.cc (DeriveClone::clone_fn): Use optional. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): Lower lifetime only if it exists. * hir/rust-ast-lower-block.h: Lower loop label only if it exists. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): Remove references to error state. (ASTLowerTraitItem::visit): Lower self param only if it exists. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Use nullopt for default value instead of SelfParam error state. * hir/rust-ast-lower.cc (ASTLoweringExprWithBlock::visit): Lower label only if it exists. * hir/rust-hir-dump.cc (Dump::do_traitfunctiondecl): Print self only if it exists. (Dump::visit): Liewise. * hir/tree/rust-hir-bound.h: Remove error state. * hir/tree/rust-hir-expr.cc (ContinueExpr::ContinueExpr): Use optional in constructor for loop label. (BreakExpr::BreakExpr): Likewise. * hir/tree/rust-hir-expr.h (class ContinueExpr): Remove error state implementation. (class BreakExpr): Likewise. * hir/tree/rust-hir-generic-param.h: Likewise. * hir/tree/rust-hir-item.cc (SelfParam::SelfParam): Make lifetime optional. (Function::Function): Make self param optional. * hir/tree/rust-hir-item.h (class Function): Likewise. * hir/tree/rust-hir-type.cc (ReferenceType::ReferenceType): Make lifetime optional. * hir/tree/rust-hir-type.h (class ReferenceType): Likewise. * hir/tree/rust-hir.cc (ContinueExpr::as_string): Use new getter. (BreakExpr::as_string): Likewise. (Lifetime::as_string): Likewise. (ReferenceType::as_string): Likewise. (TraitFunctionDecl::as_string): Likewise. (SelfParam::as_string): Remove error state checking. * parse/rust-parse-impl.h (Parser::parse_generic_param): Adapt to optional. (Parser::parse_lifetime_params): Likewise. (Parser::parse_lifetime_params_objs): Likewise. (Parser::parse_lifetime_param): Likewise. (Parser::parse_lifetime_where_clause_item): Likewise. (Parser::parse_type_param_bound): Likewise. (Parser::parse_lifetime_bounds): Likewise. (Parser::parse_path_generic_args): Likewise. (Parser::parse_self_param): Likewise. (Parser::parse_break_expr): Likewise. (Parser::parse_continue_expr): Likewise. (Parser::parse_reference_type_inner): Likewise. * parse/rust-parse.h (class ParseLifetimeParamError): Add new class for lifetime param parsing errors. (class ParseLifetimeError): Add new class for lifetime parsing errors. (enum ParseSelfError): Add new class for self param parsing errors. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): Use unchecked getter in checked context. And make anonymous region. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-08gccrs: Make loop label truly optionalPierre-Emmanuel Patry2-46/+46
A loop label error state was in use to represent missing loop label but this may be easily forgotten and the optional nature of the label was misrepresented. gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::block): Call with a nullopt instead of an error loop label. (WhileLetLoopExpr::as_string): Use getter function and adapt to newtype. * ast/rust-ast.cc (WhileLoopExpr::as_string): Likewise. (LoopExpr::as_string): Likewise. (BreakExpr::as_string): Likewise. (ForLoopExpr::as_string): Likewise. * ast/rust-expr.h (class BlockExpr): Make loop label optional. (class BreakExpr): Likewise. * expand/rust-derive-clone.cc (DeriveClone::clone_fn): Use nullopt. * expand/rust-derive-debug.cc (DeriveDebug::stub_debug_fn): Likewise. * expand/rust-derive-default.cc (DeriveDefault::default_fn): Likewise. * expand/rust-derive-eq.cc: Likewise. * parse/rust-parse-impl.h (Parser::parse_block_expr): Use optional for arguments. (Parser::parse_loop_expr): Likewise. (Parser::parse_while_loop_expr): Likewise. (Parser::parse_while_let_loop_expr): Likewise. (Parser::parse_for_loop_expr): Likewise. (Parser::parse_labelled_loop_expr): Likewise. (Parser::parse_loop_label): Return an optional. * parse/rust-parse.h: Update function prototype and use nullopt for default values. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-31gccrs: parser: Parse let-else statementsArthur Cohen1-1/+5
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_let_stmt): Add new parsing in case of `else` token.
2025-03-24gccrs: Reduce usage of rust-session-manager.hOwen Avery1-3/+2
gcc/rust/ChangeLog: * util/rust-edition.cc: New file. * util/rust-edition.h: New file. * Make-lang.in: Add rust-edition.o to the object list. * ast/rust-pattern.cc: Remove inclusion of rust-session-manager.h. * expand/rust-macro-expand.cc: Likewise. * expand/rust-macro-builtins-helpers.h: Likewise. * expand/rust-macro-builtins-include.cc: Include rust-session-manager.h. * expand/rust-macro-builtins-utility.cc: Likewise. * lex/rust-lex.cc: Include rust-edition.h instead of rust-session-manager.h. (Lexer::classify_keyword): Use get_rust_edition instead of Session and CompileOptions. * parse/rust-parse-impl.h: Include rust-edition.h instead of rust-session-manager.h. (Parser::parse_async_item): Use get_rust_edition instead of Session and CompileOptions. * checks/errors/rust-feature.h: Include rust-edition.h instead of rust-session-manager.h. (class Feature): Use Rust::Edition instead of Rust::CompileOptions::Edition. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-21gccrs: Remove dead code related to external functionsOwen Avery2-104/+0
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove visitor for NamedFunctionParam. * ast/rust-ast-collector.h (TokenCollector::visit): Likewise. * ast/rust-ast-full-decls.h (class NamedFunctionParam): Remove forward declaration. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Remove visitor for NamedFunctionParam. * ast/rust-ast-visitor.h (DefaultASTVisitor::visit): Likewise. * ast/rust-ast.cc (NamedFunctionParam::as_string): Remove. * ast/rust-item.h (class NamedFunctionParam): Remove. (class ExternalFunctionItem): Remove. * parse/rust-parse-impl.h (Parser::parse_named_function_param): Remove. (Parser::parse_named_function_params): Remove. * parse/rust-parse.h (Parser::parse_named_function_param): Remove. (Parser::parse_named_function_params): Remove. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-21gccrs: Remove Rust::make_uniqueOwen Avery1-12/+11
Since our bootstrap requirement has been bumped to C++14, we don't need a custom implementation of std::make_unique anymore. gcc/rust/ChangeLog: * ast/rust-ast-builder-type.cc: Remove inclusion of rust-make-unique.h. * ast/rust-ast-builder.cc: Likewise. (Builder::array): Use std::make_unique instead of Rust::make_unique. * ast/rust-ast.cc (Attribute::get_traits_to_derive): Likewise. * ast/rust-macro.h: Remove inclusion of rust-make-unique.h. (MacroRulesDefinition::mbe): Use std::make_unique instead of Rust::make_unique. (MacroRulesDefinition::decl_macro): Likewise. * ast/rust-path.h (PathInExpression::PathInExpression): Likewise. (QualifiedPathInExpression::QualifiedPathInExpression): Likewise. * backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): Likewise. * expand/rust-derive-copy.cc (DeriveCopy::copy_impl): Likewise. * expand/rust-expand-format-args.cc (expand_format_args): Likewise. * expand/rust-macro-builtins-asm.cc: Remove inclusion of rust-make-unique.h. (parse_asm): Use std::make_unique instead of Rust::make_unique. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * hir/tree/rust-hir-expr.cc (StructExprStructFields::StructExprStructFields): Likewise. (StructExprStructFields::operator=): Likewise. * hir/tree/rust-hir.cc (TypePath::to_trait_bound): Likewise. * lex/rust-token.h: Remove inclusion of rust-make-unique.h. (Token::Token): Use std::make_unique instead of Rust::make_unique. * metadata/rust-import-archive.cc: Remove inclusion of rust-make-unique.h. (Import::find_archive_export_data): Use std::make_unique instead of Rust::make_unique. * metadata/rust-imports.cc: Remove inclusion of rust-make-unique.h. (Import::find_export_data): Use std::make_unique instead of Rust::make_unique. (Import::find_object_export_data): Likewise. * parse/rust-parse-impl.h: Remove inclusion of rust-make-unique.h. (Parser::parse_function_param): Use std::make_unique instead of Rust::make_unique. (Parser::parse_self_param): Likewise. (Parser::parse_array_expr): Likewise. * typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit): Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): Likewise. (TypeCheckImplItem::visit): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeResolveGenericParam::visit): Likewise. * typecheck/rust-hir-type-check.cc: Remove inclusion of rust-make-unique.h. (TraitItemReference::get_type_from_fn): Use std::make_unique instead of Rust::make_unique. * typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): Likewise. * util/rust-make-unique.h: Removed. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-17gccrs: Add RAW_STRING_LITERALansh1-0/+17
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Handle case for RAW_STRING_LITERAL. * ast/rust-ast.cc (AttributeParser::parse_meta_item_inner): Likewise. (AttributeParser::parse_literal): Likewise. * ast/rust-ast.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_literal): Likewise. * lex/rust-lex.cc (Lexer::parse_raw_string): Likewise. * lex/rust-token.cc (Token::as_string): Likewise. * lex/rust-token.h (enum PrimitiveCoreType): Likewise. * parse/rust-parse-impl.h (Parser::parse_attr_input): Likewise. (Parser::parse_literal_expr): Likewise. (Parser::parse_pattern_no_alt): Likewise. Signed-off-by: ansh <anshmalik2002@gmail.com>
2025-03-17gccrs: Add exclusive_range_pattern feature gatePierre-Emmanuel Patry1-2/+2
This syntax is experimental and shall be explicitely enabled in the crate attributes as it cannot be used in stable rust. gcc/rust/ChangeLog: * checks/errors/rust-feature-gate.cc (FeatureGate::visit): Gate the excluded pattern. * checks/errors/rust-feature-gate.h: Update the function prototype and delete two empty implementations in order to use default visitor behavior. * checks/errors/rust-feature.cc (Feature::create): Add the new exclusive range pattern feature gate. * checks/errors/rust-feature.h: Add new feature enum variant for exclusive range patterns. * parse/rust-parse-impl.h (Parser::parse_pattern_no_alt): Forward the token location to the AST. (Parser::parse_ident_leading_pattern): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17gccrs: Parse exclusive range patternPierre-Emmanuel Patry1-14/+19
Exclusive range pattern were not handled by the parser as this an experimental feature. gcc/rust/ChangeLog: * ast/rust-pattern.cc (tokenid_to_rangekind): Add a new function to get a range kind from the current token type. (RangePattern::as_string): Change the string representation for range pattern in order to handle excluded ranges. * ast/rust-pattern.h (enum class): Add new enum class to differentiate range kinds. (tokenid_to_rangekind): New prototype for a function that converts a token id to it's corresponding range kind. (class RangePattern): Change the class to accept a range kind instead of an ellipsis boolean. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Abort when an excluded pattern has been found as we do not handle their lowering yet. * parse/rust-parse-impl.h (Parser::parse_literal_or_range_pattern): Parse excluded range patterns. (Parser::parse_pattern_no_alt): Likewise. (Parser::parse_ident_leading_pattern): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17gccrs: Parse raw ref operatorPierre-Emmanuel Patry1-7/+39
The raw ref operator is an unstable feature required to obtain a pointer to unaligned adresses (mainly unaligned struct fields) without UB. gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::ref): Adapt constructor to the new API. * ast/rust-ast-collector.cc (TokenCollector::visit): Emit a raw weak keyword when required. * ast/rust-ast.cc (BorrowExpr::as_string): Change as_string representation to handle raw ref operator. * ast/rust-expr.h (class BorrowExpr): Add raw discriminant. * expand/rust-macro-builtins-include.cc: Adapt constructor to the new API. * parse/rust-parse-impl.h: Handle the raw weak keyword. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17gccrs: Add outer attributes to struct expr fieldsPierre-Emmanuel Patry1-0/+5
Struct fields can have outer attributes on their field for various purpose, this behavior should be reflected upon struct expr fields. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Output field attributes. * ast/rust-expr.h (class StructExprField): Add outer attributes member. * parse/rust-parse-impl.h (Parser::parse_struct_expr_field): Parse outer attributes and store them in the appropriate AST node. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17gccrs: Allow multiple outer attributes on generic paramsPierre-Emmanuel Patry1-7/+7
Previously generic params only allowed one outer attribute in front of them. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Visit outer attributes. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Change outer attribute visit, we need to visit all of them. * ast/rust-ast.cc (LifetimeParam::as_string): Change as_string implementation to allow multiple outer attributes. (TypeParam::as_string): Likewise. * ast/rust-ast.h (class LifetimeParam): Allow multiple outer attributes. * ast/rust-item.h (class TypeParam): Likewise. * ast/rust-path.h: Likewise. * parse/rust-parse-impl.h (Parser::parse_generic_param): Change call to outer attribute parsing to collect several attributes. (Parser::parse_lifetime_param): Likewise. (Parser::parse_type_param): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17gccrs: Fix generic parameter parsingPierre-Emmanuel Patry1-1/+1
Generic parameter parsing failed when an outer attribute was used on it. gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_generic_param): Change token reference to be the last token after all outer attributes have been parsed. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17gccrs: Parse box expressionsPierre-Emmanuel Patry2-0/+26
Add support for old box expression syntax. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Add visit member function for BoxExpr nodes. * ast/rust-ast-collector.h: Add visit function prototype. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Add visit member function to default ast visitor. * ast/rust-ast-visitor.h: Add visit function's prototype. * ast/rust-ast.cc (BoxExpr::as_string): Add as_string function implementation for BoxExpr. (BoxExpr::accept_vis): Add accept_vis implementation to BoxExpr. * ast/rust-expr.h (class BoxExpr): Add BoxExpr class to represent boxed expressions. * expand/rust-derive.h: Add BoxExpr visit function prototype. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add BoxExpr visitor implementation. * hir/rust-ast-lower-base.h: Add visit function's prototype. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Add BoxExpr visitor implementation. * hir/rust-ast-lower-expr.h: Add visit function's prototype. * parse/rust-parse-impl.h (Parser::parse_box_expr): Add parse_box_expr function's implementation. * parse/rust-parse.h: Add parse_box_expr function's prototype. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add resolver visit implementation. * resolve/rust-ast-resolve-base.h: Add resolver's visit function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17gccrs: mingw: Fix build with patch from Liu HaoArthur Cohen1-1/+1
This commit adds Liu Hao's patch from https://github.com/lhmouse/MINGW-packages/blob/5859d27b2b6101204a08ad9702cb2937f8797be9/mingw-w64-gcc/0100-rust-fix.patch gcc/rust/ChangeLog: * checks/errors/borrowck/rust-borrow-checker.cc (mkdir_wrapped): Remove. (BorrowChecker::go): Use `mkdir` instead. * expand/rust-proc-macro.cc (register_callback): Use Windows APIs to open dynamic proc macro library. (load_macros_array): Likewise. * parse/rust-parse.cc (defined): Replace separators in paths using std::replace.