aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/expand
AgeCommit message (Collapse)AuthorFilesLines
7 daysgccrs: attributes: 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.
7 daysgccrs: Add `#[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>
7 daysgccrs: format_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.
7 daysgccrs: expansion: 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.
7 daysgccrs: expansion: 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.
14 daysgccrs: Migrate 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>
14 daysgccrs: Make 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-31gccrs: Add 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-24gccrs: Prevent 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-24gccrs: expansion: 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-24gccrs: Reduce 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-03-24gccrs: expansion: 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-03-24gccrs: derive(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-03-24gccrs: derive(Debug): Use builder's ptrify function insteadArthur Cohen1-8/+0
gcc/rust/ChangeLog: * expand/rust-derive-debug.cc (ptrify): Remove function.
2025-03-24gccrs: Remove 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-03-24gccrs: Fix 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-03-24gccrs: derive(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-03-24gccrs: derive(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-03-24gccrs: derive(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-03-24gccrs: expand: 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-03-24gccrs: derive(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-03-24gccrs: derive(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-03-24gccrs: derive(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-03-24gccrs: inline-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-03-24gccrs: derive(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-03-24gccrs: ast-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-03-24gccrs: derive(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-03-24gccrs: derive(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-03-24gccrs: derive-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-03-24gccrs: Add 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-03-24gccrs: ast: 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-03-24gccrs: derive(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-03-24gccrs: derive(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-03-24gccrs: derive(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-03-21gccrs: derive(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-03-21gccrs: derive(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-03-21gccrs: derive(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-03-21gccrs: derive(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-03-21gccrs: derive(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-03-21gccrs: derive(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-03-21gccrs: derive(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-03-21gccrs: ast: 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-03-21gccrs: ast: 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.
2025-03-21gccrs: Remove Rust::make_uniqueOwen Avery3-6/+5
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-21gccrs: derive(Copy): Use new LangItemPathArthur Cohen1-2/+4
gcc/rust/ChangeLog: * expand/rust-derive-copy.cc: Use new LangItemPath for derive(Copy).
2025-03-19gccrs: Fix compiler error on ast wrong implicit construct push_backbadumbatish1-1/+2
gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (parse_reg_operand_in): Fix compiler error on ast wrong implicit construct push_back
2025-03-19gccrs: Provide input operand for gccrsbadumbatish1-4/+5
gcc/rust/ChangeLog: * backend/rust-compile-asm.cc (CompileAsm::asm_construct_inputs): Provide input operand for gccrs * expand/rust-macro-builtins-asm.cc (parse_reg_operand_in): Move expr to In (expand_inline_asm_strings): Add comments to debug strings gcc/testsuite/ChangeLog: * rust/compile/inline_asm_parse_operand.rs: Remove inout, functionality not supported. Remove redundant {} * rust/execute/torture/inline_asm_mov_x_5_ARM.rs: Add operand in * rust/execute/torture/inline_asm_mov_x_5_x86_64.rs: Likewise
2025-03-19gccrs: Rework InlineAsmOperandOwen Avery1-1/+2
Not thrilled with some of this boilerplate, but it does seem like an improvement. gcc/rust/ChangeLog: * ast/rust-expr.h (InlineAsmOperand): Replace multiple mutually-exclusive tl::optional fields with a std::unique_ptr and modify nested classes to allow this. Also, make getters return references where possible. * expand/rust-macro-builtins-asm.cc (parse_reg_operand_out): Pass location when constructing InlineAsmOperand. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-19rust: Add support for Clone and Copy derive on generic typesPhilip Herron4-16/+168
When we generate derivations for Copy and Clone we need to make sure the associated impl block sets up the generic parameters and arguments correctly. This patch introduces the framework to copy chunks of the AST because we need to make sure these new AST nodes have their own associated id, calling clone on the nodes will just confuse name-resolution and subsequent mappings. Fixes #3139 gcc/rust/ChangeLog: * Make-lang.in: new objects * ast/rust-ast-builder.cc (Builder::generic_type_path_segment): new helper (Builder::single_generic_type_path): likewise (Builder::new_type): likewise (Builder::new_lifetime_param): likewise (Builder::new_type_param): likewise (Builder::new_lifetime): likewise (Builder::new_generic_args): likewise * ast/rust-ast-builder.h: new helper decls * ast/rust-ast.h: new const getters * ast/rust-path.h: likewise * ast/rust-type.h: likewise * expand/rust-derive-clone.cc (DeriveClone::clone_impl): take the types generics (DeriveClone::visit_tuple): likewise (DeriveClone::visit_struct): likewise (DeriveClone::visit_union): likewise * expand/rust-derive-clone.h: update header * expand/rust-derive-copy.cc (DeriveCopy::copy_impl): similarly take type generics (DeriveCopy::visit_struct): likewise (DeriveCopy::visit_tuple): likewise (DeriveCopy::visit_enum): likewise (DeriveCopy::visit_union): likewise * expand/rust-derive-copy.h: likewse * ast/rust-ast-builder-type.cc: New file. * ast/rust-ast-builder-type.h: New file. gcc/testsuite/ChangeLog: * rust/compile/issue-3139-1.rs: New test. * rust/compile/issue-3139-2.rs: New test. * rust/compile/issue-3139-3.rs: New test. * rust/compile/nr2/exclude: these all break nr2
2025-03-19gccrs: Rehaul, Apply code review from Arthurbadumbatish2-45/+26
gcc/rust/ChangeLog: * backend/rust-compile-asm.cc (CompileAsm::visit): Change API, public/private, comments, formatting from code review (CompileAsm::asm_build_expr): Likewise. (CompileAsm::tree_codegen_asm): Likewise. * backend/rust-compile-asm.h (class CompileAsm): Likewise. * backend/rust-compile-expr.cc (CompileExpr::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * expand/rust-macro-builtins-asm.cc (strip_double_quotes): Likewise. (parse_options): Likewise. (parse_asm_arg): Likewise. (expand_inline_asm_strings): Likewise. (parse_asm): Likewise. * expand/rust-macro-builtins-asm.h (strip_double_quotes): Likewise. (expand_inline_asm_strings): Likewise. (expand_inline_asm_string): Likewise. * hir/tree/rust-hir-expr.h: Likewise. gcc/testsuite/ChangeLog: * rust/compile/inline_asm_typecheck.rs: Change comments