aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast
AgeCommit message (Collapse)AuthorFilesLines
2025-04-28gccrs: Visit visibility in UseDeclarationPierre-Emmanuel Patry1-0/+1
Default visitor should visit all it's children. gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit visibility. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-28gccrs: Some assorted tweaks and bug fixesOwen Avery1-1/+1
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit the loop labels of WhileLetLoopExpr instances before visiting their scrutinee expressions. * resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Pass the glob import's path directly to NameResolutionContext::resolve_path. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Remove unnecessary call to Identifier::as_string. (flatten_glob): Improve handling of cases where a glob use tree has no path. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-28gccrs: Use specialized param visit function for paramsPierre-Emmanuel Patry2-2/+12
This commit introduce a new public function to visit function parameters in the default visitor. It allows visitors derived from DefaultVisitor to override only a small part of the default visitor. gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit_function_params): Add specialized function to visit function parameters. (DefaultASTVisitor::visit): Remove parameter visit and call specialized function instead. * ast/rust-ast-visitor.h: Add function prototye. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove function. (Late::visit_function_params): Override specialized visit function. * resolve/rust-late-name-resolver-2.0.h: Add overriden function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-28gccrs: Add hash function for IdentifiersPierre-Emmanuel Patry1-0/+13
gcc/rust/ChangeLog: * ast/rust-ast.h: Add hash function. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-28gccrs: Add equality operator for identifiersPierre-Emmanuel Patry1-0/+5
gcc/rust/ChangeLog: * ast/rust-ast.h: Add equality operator. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-28gccrs: Remove error state for GenericArgPierre-Emmanuel Patry4-25/+11
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-28gccrs: Fix ICE with empty generic argumentsPhilip Herron1-1/+2
We have an assertion when accessing generic args if there are any which is really useful so this adds the missing guards for the case where they are specified but empty. Fixes Rust-GCC#3649 gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): add guard * expand/rust-expand-visitor.cc (ExpandVisitor::visit): add guard gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 is missing error for this * rust/compile/issue-3649.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-28gccrs: Add LlvmInlineAsm node dumpPierre-Emmanuel Patry1-1/+38
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Dump llvm inline asm tokens. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-28gccrs: Parse and lower llvm asm nodePierre-Emmanuel Patry3-15/+62
Add a new HIR LlvmInlineAsm HIR node as well as some structures to represent it's options and operands. Lower AST::LlvmInlineAsm node to it and then create a tree from that node. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove unreachable code. * ast/rust-expr.h (struct LlvmOperand): Add LlvmOperand struct to represent input and outputs. (class LlvmInlineAsm): Add input, output and clobber operands. (struct TupleTemplateStr): Add locus getter. * backend/rust-compile-block.h: Add visit for LlvmInlineAsm. * backend/rust-compile-expr.cc (CompileExpr::visit): Add llvm inline asm stmt compilation. * backend/rust-compile-expr.h: Add function prototype. * backend/rust-compile-asm.h (class CompileLlvmAsm): Add llvm asm hir not to gimple. * backend/rust-compile-asm.cc (CompileLlvmAsm::CompileLlvmAsm): Add constructor. (CompileLlvmAsm::construct_operands): Add function to construct operand tree. (CompileLlvmAsm::construct_clobbers): Add function to construct clobber tree. (CompileLlvmAsm::tree_codegen_asm): Generate the whole tree for a given llvm inline assembly node. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Add visit function. * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Add function prototype. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Add visit function. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Add visit function prototype. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Add visit function. * checks/errors/rust-const-checker.h: Add visit function prototype. * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit): Add visit function. * checks/errors/rust-hir-pattern-analysis.h: Add visit function prototype. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Add visit function. * checks/errors/rust-unsafe-checker.h: Add function prototype. * expand/rust-macro-builtins-asm.cc (parse_llvm_templates): Parse templates. (parse_llvm_arguments): Add function to parse non template tokens. (parse_llvm_operands): Add function to parse operands, either input or output. (parse_llvm_outputs): Add function to parse and collect llvm asm outputs. (parse_llvm_inputs): Likewise with inputs. (parse_llvm_clobbers): Add function to parse llvm asm clobbers. (parse_llvm_options): Add function to parse llvm asm options. (parse_llvm_asm): Add function to parse llvm asm. * expand/rust-macro-builtins-asm.h (class LlvmAsmContext): Add context for llvm asm parser. (parse_llvm_outputs): Add function prototype. (parse_llvm_inputs): Likewise. (parse_llvm_clobbers): Likewise. (parse_llvm_options): Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Lower AST llvm asm node to HIR. * hir/rust-ast-lower-expr.h: Add function prototype. * hir/rust-hir-dump.cc (Dump::visit): Add visit function. * hir/rust-hir-dump.h: Add function prototype. * hir/tree/rust-hir-expr-abstract.h: Add HIR llvm asm node kind. * hir/tree/rust-hir-expr.h (struct LlvmOperand): Add LlvmOperand type to represent input and outputs. (class LlvmInlineAsm): Add LlvmInlineAsm hir node. * hir/tree/rust-hir-full-decls.h (class LlvmInlineAsm): Add LlvmInlineAsm hir node forward declaration. * hir/tree/rust-hir-visitor.h: Add visit functions for LlvmInlineAsm hir node. * hir/tree/rust-hir.cc (LlvmInlineAsm::accept_vis): Add hir node visitor related functions. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Type check input and output operands. * typecheck/rust-hir-type-check-expr.h: Add function prototype. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit input and output operand expressions. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Resolve input and output expressions. * resolve/rust-ast-resolve-expr.h: Add function prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-28gccrs: Add llvmInlineAsm nodePierre-Emmanuel Patry7-1/+71
InlineAsm node does not support memory clobbers. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Make visitor unreachable. * ast/rust-ast-collector.h: Add visit for LlvmInlineAsmNode. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Add visit function for the default ast visitor. * ast/rust-ast-visitor.h: Add function prototype. * ast/rust-ast.cc (LlvmInlineAsm::accept_vis): Add accept_vis to LlvmInlineAsm node. * ast/rust-ast.h: Add LlvmInlineAsm node kind. * ast/rust-expr.h (class LlvmInlineAsm): Add LlvmInlineAsm node. * expand/rust-derive.h: Add visit function for LlvmInlineAsm node. * expand/rust-macro-builtins-asm.cc (MacroBuiltin::llvm_asm_handler): Add handler for llvm inline assembly nodes. (parse_llvm_asm): Add function to parse llvm assembly nodes. * expand/rust-macro-builtins-asm.h (parse_llvm_asm): Add function prototypes. * expand/rust-macro-builtins.cc (inline_llvm_asm_maker): Add macro transcriber. * expand/rust-macro-builtins.h: Add transcriber function prototype. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add visit function for LlvmInlineAsm node. * hir/rust-ast-lower-base.h: Add visit function prototype. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add visit function for LlvmInlineAsm node. * resolve/rust-ast-resolve-base.h: Add visit function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-14gccrs: ast: Add get_locus() to DelimTokenTreeArthur Cohen1-0/+1
gcc/rust/ChangeLog: * ast/rust-ast.h (DelimTokenTree::get_locus): New function.
2025-04-14gccrs: ast: Support outer attributes for AST::RangeExprArthur Cohen1-6/+6
gcc/rust/ChangeLog: * ast/rust-expr.h (class RangeExpr): Add empty outer attributes and allow getting them and setting them.
2025-04-08gccrs: fix ICE segfault with empty feature gateMatty Kuhn1-0/+3
This patch fixes an issue where an empty feature gate would segfault, instead of reporting a syntax error to the user. gcc/rust/ChangeLog: * ast/rust-ast.h: (AST::Attribute): add empty_input function * checks/errors/rust-feature-gate.cc: (FeatureGate::visit): check for empty feature gate gcc/testsuite/ChangeLog: * rust/compile/feature.rs: add an invalid empty feature to produce an error Signed-off-by: Matty Kuhn <matty.kuhn.1@gmail.com>
2025-04-08gccrs: Rename label getter to uncheckedPierre-Emmanuel Patry4-5/+8
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Update label getter call. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast.cc (BreakExpr::as_string): Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise. * ast/rust-expr.h: Add optional getter and rename label getter to get_label_unchecked. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-08gccrs: Rename label getter in ContinueExprPierre-Emmanuel Patry4-5/+8
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Call unchecked getter. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast.cc (ContinueExpr::as_string): Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise. * ast/rust-expr.h: Add new getter for the optional and rename getter to get_label_unchecked. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-08gccrs: Migrate error state to optionalsPierre-Emmanuel Patry8-45/+32
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: Update ast visitor with proper check for looplabelPierre-Emmanuel Patry1-1/+2
The visitor was visiting loop label even when they did not exist. gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Add check for loop label before visiting it. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-08gccrs: Remove unused error constructor and getterPierre-Emmanuel Patry1-5/+0
These constructor for eroneous state are not in use anymore since we replaced this error state with an optional in the parent nodes. gcc/rust/ChangeLog: * ast/rust-expr.h: Remove error getter and constructor. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-08gccrs: Make loop label truly optionalPierre-Emmanuel Patry3-24/+27
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-04-08gccrs: Visit loop label before predicate expressionPierre-Emmanuel Patry1-1/+1
If the label is referenced within the while predicate expression it has to be resolved before the latter. gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Change default visit order. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove test from exclusion list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-08gccrs: Add check for labelPierre-Emmanuel Patry1-1/+2
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit loop label only if it exists. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove passing test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-08gccrs: nr2.0: Remove duplicate self visitOwen Avery1-2/+0
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Remove explicit visitation of a function's self parameter, as if it exists it'll be visited as one of the function parameters. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entry. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-08gccrs: hir: Add default qualifier to function, lower it properlyArthur Cohen2-5/+7
gcc/rust/ChangeLog: * ast/rust-ast.cc (Function::Function): Rename is_default -> has_default. (Function::operator=): Likewise. * ast/rust-item.h (class Function): Add `is_default` method. * hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): Lower default qualifier. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise. * hir/tree/rust-hir-item.cc (Function::Function): Add `is_default` member. (Function::operator=): Likewise. * hir/tree/rust-hir-item.h (enum class Defaultness): New enum. (class Function): Use it. gcc/testsuite/ChangeLog: * rust/compile/min_specialization1.rs: New test.
2025-03-31gccrs: dump: Handle let-else properlyArthur Cohen1-0/+8
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Add handling for diverging else expression.
2025-03-31gccrs: ast: Add optional diverging else to AST::LetStmtArthur Cohen2-2/+30
gcc/rust/ChangeLog: * ast/rust-stmt.h (class LetStmt): Add optional expression for diverging else. * ast/rust-ast-builder.cc (Builder::let): Use new API.
2025-03-24gccrs: nr2.0: Adjust visitors for struct expressionsOwen Avery1-0/+2
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Make sure to always visit the struct name. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Avoid visiting the struct name twice. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: Reduce usage of rust-session-manager.hOwen Avery1-1/+0
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-24gccrs: ast: Add base for desugaring try expressionsArthur Cohen2-0/+246
gcc/rust/ChangeLog: * Make-lang.in: Compile it. * ast/rust-desugar-question-mark.cc: New file. * ast/rust-desugar-question-mark.h: New file. gcc/testsuite/ChangeLog: * rust/compile/try-expr1.rs: New test.
2025-03-24gccrs: ast: builder: Add new builder methodsArthur Cohen2-7/+56
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::statementify): New. (Builder::function): Add generic params optional argument. (Builder::path_in_expression): Add opening_scope_resolution optional argument. (Builder::block): Add function for creating empty blocks. (Builder::generic_type_param): New. * ast/rust-ast-builder.h (ptrify): New.
2025-03-24gccrs: Remove some member functions from SingleASTNodeOwen Avery1-17/+0
gcc/rust/ChangeLog: * ast/rust-ast.h (SingleASTNode::take_trait_item): Remove. (SingleASTNode::take_impl_item): Remove. (SingleASTNode::take_trait_impl_item): Remove. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Replace calls to aforementioned functions with calls to SingleASTNode::take_assoc_item. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: Remove PathInExpression::get_pattern_node_idOwen Avery1-2/+0
gcc/rust/ChangeLog: * ast/rust-path.h (PathInExpression::get_pattern_node_id): Remove. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: ast-builder: Add new methods for creating operator expressionsArthur Cohen2-0/+66
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::literal_bool): New method. (Builder::comparison_expr): Likewise. (Builder::boolean_operation): Likewise. * ast/rust-ast-builder.h: Declare them.
2025-03-24gccrs: ast-builder: Improve function generation.Arthur Cohen2-17/+17
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::block): Change return type. (Builder::loop): Use new APIs. * ast/rust-ast-builder.h: Change return type of block functions.
2025-03-24gccrs: ast: Add DesugarForLoop classArthur Cohen2-0/+312
gcc/rust/ChangeLog: * ast/rust-desugar-for-loops.cc: New file. * ast/rust-desugar-for-loops.h: New file. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Make lowering of for-loops an unreachable. * Make-lang.in: Compile it. gcc/testsuite/ChangeLog: * rust/compile/for-loop1.rs: New test. * rust/compile/for-loop2.rs: New test. * rust/execute/torture/for-loop1.rs: New test. * rust/execute/torture/for-loop2.rs: New test. * rust/compile/nr2/exclude: Exclude for-loop1.rs
2025-03-24gccrs: ast: builder: Fix arguments of Builder::letArthur Cohen2-5/+5
gcc/rust/ChangeLog: * ast/rust-ast-builder.h: Mark all arguments as &&. * ast/rust-ast-builder.cc (Builder::let): Likewise.
2025-03-24gccrs: ast-builder: Add methods for QualifiedPathInExpressionsArthur Cohen2-8/+40
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::qualified_path_in_expression): New. (Builder::function): Change the return type. * ast/rust-ast-builder.h: Declare qualified_path_in_expression functions. * expand/rust-derive-debug.cc (DeriveDebug::stub_debug_fn): Adapt to new APIs.
2025-03-24gccrs: ast: builder: Add Return expression builderArthur Cohen2-0/+11
gcc/rust/ChangeLog: * ast/rust-ast-builder.h: Declare it. * ast/rust-ast-builder.cc (Builder::return_expr): Define it.
2025-03-24gccrs: ast-builder: Add new methods for functions, traits and tuples.Arthur Cohen2-2/+96
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc: New methods. * ast/rust-ast-builder.h: Declare them.
2025-03-24gccrs: ast-builder: Add new functions to create type paths.Arthur Cohen2-1/+24
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::type_path): New functions. * ast/rust-ast-builder.h: Declare them.
2025-03-24gccrs: ast: Add new Expr::KindsArthur Cohen2-0/+41
Collapses all of the OperatorExprs into Expr instead of first having to check for OperatorExpr and then check for each OperatorExpr::Kind. gcc/rust/ChangeLog: * ast/rust-ast.h: Add new Expr::Kinds. * ast/rust-expr.h: Implement missing get_expr_kind(), Add get_function_expr_ptr()
2025-03-24gccrs: ast: Add Path::is_lang_item()Arthur Cohen1-0/+2
gcc/rust/ChangeLog: * ast/rust-path.h: New function.
2025-03-24gccrs: ast: More visitors to allow lang item paths in expressionsArthur Cohen2-4/+20
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Adapt visitor to lang item PathInExpressions. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * hir/rust-ast-lower.cc (ASTLoweringExprWithBlock::visit): Likewise. (ASTLowerPathInExpression::visit): Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise.
2025-03-24gccrs: lang-items: Collect enum variants as lang itemsArthur Cohen2-0/+10
gcc/rust/ChangeLog: * ast/rust-collect-lang-items.h: Declare visitor. * ast/rust-collect-lang-items.cc (CollectLangItems::visit): New.
2025-03-24gccrs: ast-builder: Add extra parameter for TypeParam builderArthur Cohen2-2/+8
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::new_type_param): Add optional extra trait bounds. * ast/rust-ast-builder.h: Likewise.
2025-03-21gccrs: ast-builder: Add new methods for building structsArthur Cohen2-2/+15
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc: Add new methods for constructing struct exprs. * ast/rust-ast-builder.h: Mention how to build tuple expressions.
2025-03-21gccrs: ast-builder: Add new methods around type paths.Arthur Cohen2-3/+67
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc: New functions. * ast/rust-ast-builder.h: Declare them.
2025-03-21gccrs: builder: Allow generating struct statementsArthur Cohen2-0/+46
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::struct_struct): New function. * ast/rust-ast-builder.h (vec): New function.
2025-03-21gccrs: ast-collector: Fix tuple struct pattern collectionArthur Cohen1-4/+1
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Visit tuple pattern items as separated by commas.
2025-03-21gccrs: ast-collector: Adapt to lang item type path segmentsArthur Cohen1-8/+15
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Fix collector to better handle lang item type path segments.
2025-03-21gccrs: lang-items: Collect struct lang items.Arthur Cohen2-0/+10
gcc/rust/ChangeLog: * ast/rust-collect-lang-items.cc (CollectLangItems::visit): New. * ast/rust-collect-lang-items.h: New.