aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/expand
AgeCommit message (Collapse)AuthorFilesLines
11 daysast: collector: visit InlineAsm node during ast dump0xn4utilus2-24/+13
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Implement for InlineAsm. * ast/rust-ast-full-decls.h (enum class): Move InlineAsmOption enum inside InlineAsm. * ast/rust-expr.h (enum class): Likewise. (class InlineAsm): Likewise. * expand/rust-macro-builtins-asm.cc (check_and_set): Likewise. (parse_options): Likewise. * expand/rust-macro-builtins-asm.h (check_and_set): Likewise. * hir/tree/rust-hir-expr.cc (InlineAsm::InlineAsm): Likewise. * hir/tree/rust-hir-expr.h: Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
2025-05-02derive(PartialEq): Allow deriving enum structsArthur Cohen1-14/+52
gcc/rust/ChangeLog: * expand/rust-derive-partial-eq.cc (DerivePartialEq::match_enum_tuple): Remove debug call. (DerivePartialEq::match_enum_struct): Add proper implementation. (DerivePartialEq::visit_enum): Call it. gcc/testsuite/ChangeLog: * rust/execute/torture/derive-partialeq2.rs: New test.
2025-04-28Completely duplicate path nodePierre-Emmanuel Patry1-1/+7
Both nodes had the same id, this led to a resolution conflict. gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::clone_enum_struct): Clone path to avoid using the same nodeid. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove now passing test from exclusion list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-18gccrs: 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-17Parse and lower llvm asm nodePierre-Emmanuel Patry2-2/+235
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-17Add llvmInlineAsm nodePierre-Emmanuel Patry5-1/+43
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-17Emit error with old asm syntax in new asm blocksPierre-Emmanuel Patry1-0/+8
gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (parse_asm_arg): Emit error message. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-14attributes: Handle external tool annotations like rustfmt::Arthur Cohen1-1/+0
gcc/rust/ChangeLog: * util/rust-attribute-values.h: Add RUSTFMT value. * util/rust-attributes.cc: Define the attribute. * util/rust-attributes.h (enum CompilerPass): Add EXTERNAL variant. * expand/rust-macro-builtins.cc: Fix formatting.
2025-04-14Add `#[track_caller]` as known attributebeamandala1-0/+1
gcc/rust/ChangeLog: * expand/rust-macro-builtins.cc (MacroBuiltin::builtin_transcribers): Add entry for track_caller. * util/rust-attribute-values.h: add `TRACK_CALLER` attribute. * util/rust-attributes.cc: add `track_caller` attribute definition. gcc/testsuite/ChangeLog: * rust/compile/track_caller.rs: New test. Signed-off-by: Bhavesh Mandalapu <mandalapubhavesh@gmail.com>
2025-04-14format_args: Allow extraneous commas, improve safetyArthur Cohen1-0/+7
gcc/rust/ChangeLog: * expand/rust-macro-builtins-format-args.cc (format_args_parse_arguments): Improve safety, allow extra commas after end of argument list. gcc/testsuite/ChangeLog: * rust/compile/format_args_extra_comma.rs: New test.
2025-04-14expansion: Desugar doc comments into attributes before expansionArthur Cohen3-1/+132
gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (MacroExpander::expand_decl_macro): Call into TokenTreeDesugar. * expand/rust-token-tree-desugar.cc: New file. * expand/rust-token-tree-desugar.h: New file. * Make-lang.in: Compile them. gcc/testsuite/ChangeLog: * rust/compile/macros/mbe/macro-issue3709-1.rs: New test. * rust/compile/macros/mbe/macro-issue3709-2.rs: New test.
2025-04-14expansion: Only add fragments if the matcher succeededArthur Cohen1-7/+8
gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (MacroExpander::match_n_matches): Do not insert fragments and substack fragments if the matcher failed. gcc/testsuite/ChangeLog: * rust/compile/macros/mbe/macro-issue3708.rs: New test.
2025-04-07Migrate error state to optionalsPierre-Emmanuel Patry1-1/+1
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-07Make loop label truly optionalPierre-Emmanuel Patry4-8/+4
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-28Add ending newline to rust-macro-builtins-log-debug.ccOwen Avery1-1/+1
gcc/rust/ChangeLog: * expand/rust-macro-builtins-log-debug.cc: Add newline to end of file. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-19Prevent multiple resolution insertionOwen Avery2-20/+36
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::clone_impl): Avoid using the same node id multiple times. (DeriveClone::clone_enum_identifier): Likewise. (DeriveClone::clone_enum_tuple): Likewise. * expand/rust-derive-copy.cc (DeriveCopy::copy_impl): Likewise. * resolve/rust-ast-resolve-item.cc (flatten_list): Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Prevent reinsertion of resolutions. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_fn_trait_call): Likewise. * resolve/rust-name-resolver.cc (Resolver::insert_resolved_name): Catch multiple resolution insertions. (Resolver::insert_resolved_type): Likewise. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-06expansion: Correctly expand $crate metavarArthur Cohen4-14/+75
gcc/rust/ChangeLog: * expand/rust-macro-expand.cc: Use new SubstituteCtx API. * expand/rust-macro-expand.h: Likewise. * expand/rust-macro-substitute-ctx.cc: Implement proper expansion of $crate. * expand/rust-macro-substitute-ctx.h: Adapt APIs to take macro definition when substituting. * util/rust-hir-map.cc (Mappings::insert_macro_def): Store crate information when inserting macro definition in mappings. (Mappings::lookup_macro_def_crate): New. * util/rust-hir-map.h: Adapt mappings to store crate in which macros were defined. gcc/testsuite/ChangeLog: * rust/execute/crate-metavar1.rs: New test. * rust/compile/crate-metavar1.rs: New test.
2025-03-05Reduce usage of rust-session-manager.hOwen Avery4-2/+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-02-25expansion: Expand generic args in generic type path segmentsArthur Cohen1-1/+3
gcc/rust/ChangeLog: * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Correctly visit the generic args of a generic type path segment. gcc/testsuite/ChangeLog: * rust/compile/issue-2015.rs: New test.
2025-02-24derive(Hash): Add implementation.Arthur Cohen3-9/+367
gcc/rust/ChangeLog: * Make-lang.in: Compile it. * expand/rust-derive.cc (DeriveVisitor::derive): Call it. * expand/rust-derive-hash.cc: New file. * expand/rust-derive-hash.h: New file. gcc/testsuite/ChangeLog: * rust/compile/derive-hash1.rs: New test. * rust/compile/nr2/exclude: Add testcase to exclusion list.
2025-02-24derive(Debug): Use builder's ptrify function insteadArthur Cohen1-8/+0
gcc/rust/ChangeLog: * expand/rust-derive-debug.cc (ptrify): Remove function.
2025-02-24Remove some member functions from SingleASTNodeOwen Avery1-3/+4
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-02-23Fix expansion of macros inside modulesOwen Avery2-0/+7
gcc/rust/ChangeLog: * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Override DefaultASTVisitor in order to expand a module's items, rather than directly visit them. * expand/rust-expand-visitor.h (ExpandVisitor::visit): Add override. gcc/testsuite/ChangeLog: * rust/compile/macros/mbe/macro-expand-module.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-02-20derive(Eq): Create copies of Eq typepath to avoid NodeId confusionArthur Cohen1-1/+5
gcc/rust/ChangeLog: * expand/rust-derive-eq.cc: Copy `Eq` typepath.
2025-02-20derive(Eq): Also derive StructuralEqArthur Cohen3-37/+43
gcc/rust/ChangeLog: * expand/rust-derive-eq.cc: Adapt functions to return two generated impls. * expand/rust-derive-eq.h: Likewise. * expand/rust-derive.cc (DeriveVisitor::derive): Likewise.
2025-02-20derive(PartialEq): Also derive StructuralPartialEqArthur Cohen3-23/+32
gcc/rust/ChangeLog: * expand/rust-derive-partial-eq.cc: Adapt signatures to generate two impls. * expand/rust-derive-partial-eq.h: Likewise. * expand/rust-derive.cc (DeriveVisitor::derive): Adapt to multiple item generation. gcc/testsuite/ChangeLog: * rust/compile/derive-eq-invalid.rs: Declare StructuralPartialEq. * rust/compile/derive-partialeq1.rs: Likewise. * rust/execute/torture/derive-partialeq1.rs: Likewise.
2025-02-20expand: Allow built-in derives to generate multiple itemsArthur Cohen3-15/+22
gcc/rust/ChangeLog: * expand/rust-derive.cc (DeriveVisitor::derive): Return a vector of items. * expand/rust-derive.h: Change return type. * expand/rust-expand-visitor.cc: Insert all generated items into the AST.
2025-02-20derive(PartialEq): Add partial implementationArthur Cohen3-0/+391
We are still missing some deriving for enums, as part of our codegen and nameres for rebinding struct field patterns is missing. gcc/rust/ChangeLog: * expand/rust-derive-partial-eq.cc: New file. * expand/rust-derive-partial-eq.h: New file. * expand/rust-derive.cc (DeriveVisitor::derive): Call them. * Make-lang.in: Compile them. gcc/testsuite/ChangeLog: * rust/compile/derive-eq-invalid.rs: Mark PartialEq def as a lang item. * rust/compile/derive-partialeq1.rs: New test. * rust/execute/torture/derive-partialeq1.rs: New test. * rust/compile/nr2/exclude: Exclude all of them.
2025-02-20derive(Clone): chore: CleanupArthur Cohen2-25/+17
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc: Cleanup implementation, avoid repetitions. * expand/rust-derive-clone.h: Likewise.
2025-02-20derive(Eq): Add implementation.Arthur Cohen3-0/+291
gcc/rust/ChangeLog: * expand/rust-derive.cc (DeriveVisitor::derive): Call into DeriveEq. * expand/rust-derive-eq.cc: New file. * expand/rust-derive-eq.h: New file. * Make-lang.in: Compile them. gcc/testsuite/ChangeLog: * rust/compile/derive-eq-invalid.rs: New test.
2025-02-04inline-asm: Fix some warningsArthur Cohen2-7/+21
gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (strip_double_quotes): Special case empty strings ("\"\""). (parse_reg_operand): Remove use of the `struct` keyword. (parse_reg_operand_in): Likewise. (parse_reg_operand_out): Likewise. * expand/rust-macro-builtins.cc: Add llvm_asm! built-in macro as an alias to asm!.
2025-02-04derive(Default): Add implementationArthur Cohen3-0/+233
gcc/rust/ChangeLog: * expand/rust-derive.cc (DeriveVisitor::derive): Call DeriveDefault. * expand/rust-derive-default.cc: New file. * expand/rust-derive-default.h: New file. * Make-lang.in: Compile them. gcc/testsuite/ChangeLog: * rust/compile/derive-default1.rs: New test. * rust/execute/torture/derive-default1.rs: New test. * rust/compile/nr2/exclude: Exclude them.
2025-02-04ast-builder: Add methods for QualifiedPathInExpressionsArthur Cohen1-2/+2
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-02-02derive(Debug): Add stub implementation.Arthur Cohen3-0/+191
gcc/rust/ChangeLog: * expand/rust-derive-debug.cc: New file. * expand/rust-derive-debug.h: New file. * Make-lang.in: Compile them. * expand/rust-derive.cc (DeriveVisitor::derive): Call into DeriveDebug. gcc/testsuite/ChangeLog: * rust/compile/derive-debug1.rs: New test. * rust/compile/nr2/exclude: Exclude it.
2025-02-02derive(Clone, Copy): Cleanup using new method from DeriveVisitorArthur Cohen2-163/+11
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc: Cleanup using DeriveVisitor::setup_impl_generics. * expand/rust-derive-copy.cc: Likewise.
2025-02-02derive-visitor: Add method for setting up derived impl genericsArthur Cohen2-0/+97
gcc/rust/ChangeLog: * expand/rust-derive.cc (DeriveVisitor::setup_impl_generics): New method. * expand/rust-derive.h: Declare it, define DeriveVisitor::ImplGenerics struct.
2025-01-31Add option_env! supportLiam Naddell3-1/+83
gcc/rust/ChangeLog: * expand/rust-macro-builtins-utility.cc: Add macro expansion for option_env with eager expansion * expand/rust-macro-builtins.cc: Add option_env to builtin list * expand/rust-macro-builtins.h: Add option_env handler to header file * resolve/rust-late-name-resolver-2.0.cc: Prevent NR2.0 from recursing into lang-item segments gcc/testsuite/ChangeLog: * rust/compile/macros/builtin/option_env1.rs: Add success case for option_env * rust/compile/macros/builtin/option_env2.rs: Add failure case for option_env * rust/execute/torture/builtin_macro_option_env.rs: Add execution case for option_env
2025-01-28ast: More visitors to allow lang item paths in expressionsArthur Cohen2-6/+11
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-01-21derive(Copy): Improve bounds when deriving CopyArthur Cohen1-2/+7
gcc/rust/ChangeLog: * expand/rust-derive-copy.cc: Always add an extra Copy bound on generic Copy impls.
2025-01-21derive(Clone): Use lang item bounds on AssertParamIsCopyArthur Cohen1-6/+5
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::visit_union): Use lang items for Copy and Sized bounds. gcc/testsuite/ChangeLog: * rust/compile/derive_macro6.rs: Add lang item attribute to Copy trait.
2025-01-21derive(Clone): Add Clone bound on generated impl blocksArthur Cohen1-6/+11
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc: Add extra bound when deriving generic Clone
2025-01-20derive(Clone): Implement derive clone for enum struct variantsArthur Cohen1-7/+78
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::clone_enum_struct): New function for deriving enum struct variants. (DeriveClone::visit_enum): Call into the new function. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: * rust/compile/derive_clone_enum1.rs: New test. * rust/compile/derive_clone_enum2.rs: New test. * rust/compile/derive_clone_enum3.rs: New test. * rust/execute/torture/derive_clone_enum1.rs: New test.
2025-01-20derive(Clone): Implement clone for enum tuple variantsArthur Cohen2-4/+66
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::variant_match_path): New function. (DeriveClone::clone_enum_identifier): Rename. (DeriveClone::clone_enum_tuple): New function. (DeriveClone::visit_enum): Visit tuple variants properly. * expand/rust-derive-clone.h: Declare new functions.
2025-01-20derive(Clone): Add deriving of simple enum variantsArthur Cohen2-2/+53
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc: Clone enum identifier variants properly * expand/rust-derive-clone.h: Declare new functions used.
2025-01-20derive(Clone): Add note about Clone::clone()Arthur Cohen1-4/+10
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::clone_call): Mention using `clone_fn` lang item in the future.
2025-01-20derive(Clone): Use lang item for PhantomData in CloneArthur Cohen1-1/+1
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::visit_union): Create a lang item path instead of a regular path.
2025-01-20derive(Copy): Use copy lang item when deriving Copy.Arthur Cohen1-6/+2
gcc/rust/ChangeLog: * expand/rust-derive-copy.cc: Use lang item path.
2025-01-20derive(Clone): Manually generate AssertParamIsCopy struct for unionsArthur Cohen1-4/+34
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::visit_union): Manually generate the struct used for asserting a union implements Copy.
2025-01-16ast: Refactor how lang item paths are handled.Arthur Cohen2-3/+3
Lang item typepaths were not handled properly, and required a complete overhaul. All old classes that concerned lang item paths are now modified to use a simpler version of `AST::LangItemPath`, which has been removed. TypePath segments can now be lang items, as this is requied for having generic lang item paths such as PhantomData<T>. gcc/rust/ChangeLog: * ast/rust-path.h: Rework how lang item paths are represented. * ast/rust-path.cc: Likewise. * ast/rust-item.h: Likewise. * ast/rust-ast.cc: Likewise. * ast/rust-ast-collector.cc: Adapt to new lang item path system. * ast/rust-ast-collector.h: Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.h: Likewise. * expand/rust-derive-copy.cc: Likewise. * expand/rust-derive.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h: Likewise. * hir/rust-ast-lower-type.cc (ASTLowerTypePath::translate): Likewise. (ASTLowerTypePath::visit): Likewise. * hir/rust-ast-lower-type.h: Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h: Likewise. * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise. * resolve/rust-ast-resolve-type.h: Likewise. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise. * resolve/rust-late-name-resolver-2.0.h: Likewise. * hir/tree/rust-hir-path.cc (TypePathSegment::TypePathSegment): Likewise. (TypePathSegmentGeneric::TypePathSegmentGeneric): Likewise. * hir/tree/rust-hir-path.h: Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. * ast/rust-ast-builder.cc: Likewise. * ast/rust-ast-builder.h: Likewise.
2025-01-06ast: Add new Kind enums for more precise downcastingArthur Cohen2-3/+3
This commit adds things like Item::Kind, Expr::Kind, etc, and implements the associated `get_*_kind` functions. It also removes the more generic AST::Kind enum we were using, which was incomplete and painful to use. gcc/rust/ChangeLog: * ast/rust-ast.h: Add new Kind enums, remove Node class. * ast/rust-builtin-ast-nodes.h: Use new Kind enums. * ast/rust-expr.h (class LoopLabel): Likewise. * ast/rust-item.h: Likewise. * ast/rust-macro.h: Likewise. * ast/rust-path.h: Likewise. * expand/rust-macro-builtins-helpers.cc: Likewise. * expand/rust-macro-builtins-utility.cc (MacroBuiltin::concat_handler): Likewise. (MacroBuiltin::stringify_handler): Likewise. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise. * resolve/rust-early-name-resolver.cc: Likewise. * hir/rust-ast-lower.cc (ASTLoweringBlock::visit): Likewise.