]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
4 months agoc++: pack indexing and if consteval
Jason Merrill [Sat, 22 Mar 2025 14:52:14 +0000 (10:52 -0400)] 
c++: pack indexing and if consteval

The pack index is manifestly constant-evaluated, and the call to
maybe_constant_value needs to reflect that or we wrongly complain about
non-constant index if the evaluation uses if consteval.

gcc/cp/ChangeLog:

* semantics.cc (finish_type_pack_element): Pass mce_true to
maybe_constant_value.

gcc/testsuite/ChangeLog:

* g++.dg/cpp26/pack-indexing16.C: New test.

4 months agocobol: Move includes before system.h
Iain Sandoe [Sat, 15 Mar 2025 22:37:58 +0000 (22:37 +0000)] 
cobol: Move includes before system.h

This just moves an include ahead of cobol-system.h which
in turn includes system.h.

gcc/cobol/ChangeLog:

* cdf-copy.cc: Move host include before system.h

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
4 months agolibgomp/plugin/plugin-nvptx.c: Fix device used for stream creation
Tobias Burnus [Mon, 24 Mar 2025 15:08:20 +0000 (16:08 +0100)] 
libgomp/plugin/plugin-nvptx.c: Fix device used for stream creation

libgomp/ChangeLog:

* plugin/plugin-nvptx.c (GOMP_OFFLOAD_interop): Set context for
stream creation to use the specified device.

4 months agoRemove buffer overflow in cobol driver
Andreas Schwab [Mon, 24 Mar 2025 10:39:29 +0000 (11:39 +0100)] 
Remove buffer overflow in cobol driver

PR cobol/119390
* gcobolspec.cc (lang_specific_driver): Use pointer instead of
copying into fixed array.

4 months agotestsuite: d: Break up Wbuiltin_declaration_mismatch2.d into smaller tests
Iain Buclaw [Mon, 24 Mar 2025 13:07:49 +0000 (14:07 +0100)] 
testsuite: d: Break up Wbuiltin_declaration_mismatch2.d into smaller tests

gcc/testsuite/ChangeLog:

* gdc.dg/Wbuiltin_declaration_mismatch2.d: Split test into ...
* gdc.dg/Wbuiltin_declaration_mismatch3.d: New test.
* gdc.dg/Wbuiltin_declaration_mismatch4.d: New test.
* gdc.dg/Wbuiltin_declaration_mismatch5.d: New test.
* gdc.dg/Wbuiltin_declaration_mismatch6.d: New test.

4 months agogccrs: support generic super traits recursively
Philip Herron [Sat, 22 Mar 2025 17:40:48 +0000 (17:40 +0000)] 
gccrs: support generic super traits recursively

In order to handle generic super traits on any trait bound we need to ensure
we track the TypeBoundPredicate as part of the TraitReference instead of just
the raw TraitReferences because these will have any applied generics enplace.

Then for any TypeBoundPredicate it takes a copy of the super traits because
this is the usage of a TraitBound and we can apply generics which then need
to be recursively applied up the chain of super predicates.

The main tweak is around TypeBoundPredicate::lookup_associated_item because
we need to associate the predicate with the item we are looking up so the caller
can respect the generics correctly as well.

Fixes Rust-GCC#3502

gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc: update call
* typecheck/rust-hir-trait-reference.cc (TraitReference::lookup_trait_item): track predicate
(TraitReference::is_equal): likewise
(TraitReference::is_object_safe): likewise
(TraitReference::satisfies_bound): likewise
* typecheck/rust-hir-trait-reference.h: likewise
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): likewise
* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::TypeBoundPredicate): track super traits
(TypeBoundPredicate::operator=): likewise
(TypeBoundPredicate::apply_generic_arguments): ensure we apply to super predicates
(TypeBoundPredicateItem::operator=): take copy of parent predicate
(TypeBoundPredicateItem::error): pass error instead of nullptr
(TypeBoundPredicateItem::is_error): update to no longer check for nullptr
(TypeBoundPredicateItem::get_parent): updated
(TypeBoundPredicateItem::get_tyty_for_receiver): likewise
(TypeBoundPredicate::get_associated_type_items): likewise
* typecheck/rust-tyty-bounds.h (class TypeBoundPredicateItem): move
* typecheck/rust-tyty-subst.cc: flag to handle placeholder Self on traits
* typecheck/rust-tyty-subst.h (class TypeBoundPredicateItem): likewise
* typecheck/rust-tyty.h (class TypeBoundPredicateItem): refactored

gcc/testsuite/ChangeLog:

* rust/execute/torture/issue-3502.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: nr2.0: Fix StructExprFieldIdentifier handling
Owen Avery [Mon, 3 Mar 2025 01:03:12 +0000 (20:03 -0500)] 
gccrs: nr2.0: Fix StructExprFieldIdentifier handling

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Add visitor for StructExprFieldIdentifier.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: nr2.0: Adjust indentifier expression handling
Owen Avery [Wed, 19 Mar 2025 00:28:25 +0000 (20:28 -0400)] 
gccrs: nr2.0: Adjust indentifier expression handling

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Make sure to return early after a resolution
error, improve the resolution error message, fix a typo, handle
ambiguous resolutions, and remove an old comment.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Modify multiple definition error
Owen Avery [Sun, 23 Feb 2025 21:45:41 +0000 (16:45 -0500)] 
gccrs: Modify multiple definition error

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-expr.cc
(ResolveExpr::visit): Modify error message.
* resolve/rust-ast-resolve-implitem.h
(ResolveToplevelImplItem::visit): Likewise.
(ResolveTopLevelTraitItems::visit): Likewise.
(ResolveToplevelExternItem::visit): Likewise.
* resolve/rust-ast-resolve-stmt.cc
(ResolveStmt::visit): Likewise.
* resolve/rust-ast-resolve-stmt.h
(ResolveStmt::visit): Likewise.
* resolve/rust-ast-resolve-toplevel.h
(ResolveTopLevel::visit): Likewise.
* resolve/rust-ast-resolve-type.h
(ResolveGenericParams::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.
* rust/compile/redef_error2.rs: Modify expected error.
* rust/compile/redef_error5.rs: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: nr2.0: Adjust visitors for struct expressions
Owen Avery [Sun, 9 Feb 2025 08:28:43 +0000 (03:28 -0500)] 
gccrs: nr2.0: Adjust visitors for struct expressions

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>
4 months agogccrs: Prevent multiple resolution insertion
Owen Avery [Wed, 26 Feb 2025 14:56:42 +0000 (09:56 -0500)] 
gccrs: Prevent multiple resolution insertion

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>
4 months agogccrs: nr2.0: Fix test self-path2.rs
Owen Avery [Sun, 9 Feb 2025 20:16:59 +0000 (15:16 -0500)] 
gccrs: nr2.0: Fix test self-path2.rs

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-path.cc
(ResolvePath::resolve_path): Adjust the error message for a lower
self segment in the middle of a path.
* resolve/rust-ast-resolve-type.cc
(ResolveRelativeTypePath::go): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove self-path2.rs
* rust/compile/self-path2.rs: Adjust expected errors.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: emit an error for type or const parameters on foreign items
Ryutaro Okada [Fri, 14 Mar 2025 12:25:03 +0000 (21:25 +0900)] 
gccrs: emit an error for type or const parameters on foreign items

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit):
emit an error for type or const parameters on foreign items

gcc/testsuite/ChangeLog:

* rust/compile/extern_generics.rs: New test.

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
4 months agogccrs: Fix modules with same name as builtins causing ICE (#3315)
Liam Naddell [Tue, 11 Feb 2025 21:42:41 +0000 (16:42 -0500)] 
gccrs: Fix modules with same name as builtins causing ICE (#3315)

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h (ForeverStack): Add a dedicated prelude node for
the Language prelude
* resolve/rust-forever-stack.hxx (ForeverStack): Add support code for the
prelude node
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Move
language prelude builtins to the prelude context
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::scoped): Add code for handling
the prelude corner case
* resolve/rust-rib.h (Rib::Kind): Add a special Prelude rib type

gcc/testsuite/ChangeLog:

* rust/compile/issue-3315-1.rs: Add test for module with same name
as builtin
* rust/compile/issue-3315-2.rs: Test with utilization of i32
type
* rust/compile/nr2/exclude: issue-3315-2.rs Does not work with
NR2.0

Signed-off-by: Liam Naddell <liamnprg@gmail.com>
4 months agogccrs: nr2.0: Check compile/torture/*.rs tests
Owen Avery [Sun, 2 Mar 2025 23:54:37 +0000 (18:54 -0500)] 
gccrs: nr2.0: Check compile/torture/*.rs tests

gcc/testsuite/ChangeLog:

* rust/compile/nr2/compile.exp: Adjust to cover tests in the
torture subdirectory.
* rust/compile/nr2/exclude: Add entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Remove mangling tests from exclusion list
Pierre-Emmanuel Patry [Tue, 11 Mar 2025 13:35:04 +0000 (14:35 +0100)] 
gccrs: Remove mangling tests from exclusion list

Those tests are now passing.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove two mangling tests from exclusion
file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Fix canonical path parent resolution
Pierre-Emmanuel Patry [Tue, 11 Mar 2025 13:33:05 +0000 (14:33 +0100)] 
gccrs: Fix canonical path parent resolution

The algorithm was comparing using the wrong id, this lead to some
mangling errors as an erroneous parent was selected.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Fix the id comparison.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Insert crate name in canonical path
Pierre-Emmanuel Patry [Mon, 10 Mar 2025 15:05:18 +0000 (16:05 +0100)] 
gccrs: Insert crate name in canonical path

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Insert a new segment with the crate's
name as canonical's path prefix.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add a function to get the crate number from node id
Pierre-Emmanuel Patry [Mon, 10 Mar 2025 14:13:27 +0000 (15:13 +0100)] 
gccrs: Add a function to get the crate number from node id

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::lookup_crate_num): Add function to
retrieve crate number from it's node id.
(Mappings::node_is_crate): change function with call to
lookup_crate_num to avoid looping through all crates.
(Mappings::insert_ast_crate): Populate node id to crate number map.
* util/rust-hir-map.h: Change function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Remove finalize import visitor
Pierre-Emmanuel Patry [Thu, 13 Mar 2025 14:18:58 +0000 (15:18 +0100)] 
gccrs: Remove finalize import visitor

This visitor is not used anymore.

gcc/rust/ChangeLog:

* resolve/rust-finalize-imports-2.0.cc (FinalizeImports::FinalizeImports):
Remove constructor.
(FinalizeImports::go): Remove function.
(FinalizeImports::visit): Likewise.
* resolve/rust-finalize-imports-2.0.h (class FinalizeImports): Remove
FinalizeImports class.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Remove tests from exclusion list
Pierre-Emmanuel Patry [Thu, 13 Mar 2025 13:51:53 +0000 (14:51 +0100)] 
gccrs: Remove tests from exclusion list

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove issue-1786 and issue-3033 from
exclusion list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Move import mapping resolution to in tree visit
Pierre-Emmanuel Patry [Thu, 13 Mar 2025 12:41:38 +0000 (13:41 +0100)] 
gccrs: Move import mapping resolution to in tree visit

Import mapping was relying on resolve_path which in turn relies on
the cursor function. This means the mapping resolver should be called
from the correct scope instead of being called from the crate scope.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::Early): Move the
top level visitor from the function scope to attributes.
(Early::go): Remove top level visitor creation and adapt calling code.
Remove call to mapping resolution and import finalization.
(Early::finalize_simple_import): Move the finalization from it's
visitor.
(Early::finalize_glob_import): Likewise.
(Early::finalize_rebind_import): Likewise.
(Early::visit): Add mapping resolution and finalization in
UseDeclaration visitor function.
* resolve/rust-finalize-imports-2.0.cc (finalize_simple_import): Move
function.
(finalize_glob_import): Likewise.
(finalize_rebind_import): Likewise.
(FinalizeImports::visit): Remove call to finalizers.
* resolve/rust-early-name-resolver-2.0.h (class Early): Add top level
attribute.
* resolve/rust-finalize-imports-2.0.h: Add function prototypes.
* resolve/rust-toplevel-name-resolver-2.0.h: Change getter return type
to reference.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: check for recursion trait cycle with bounds checks
Philip Herron [Wed, 12 Mar 2025 17:03:25 +0000 (17:03 +0000)] 
gccrs: check for recursion trait cycle with bounds checks

We need to be careful when doing bounds check as to not create a recusive
trait resolution. This patch checks for that case and fixes a bad type
is equal check on ADT Types which was caught with a regression here.

Fixes Rust-GCC#3126

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::ResolveHirItem): new helper
* typecheck/rust-hir-trait-resolve.h: add helper prototype
* typecheck/rust-type-util.cc (query_type): add debug
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): check for recursion
* typecheck/rust-tyty.cc (VariantDef::is_equal): fix is equal check

gcc/testsuite/ChangeLog:

* rust/execute/torture/issue-3126.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: track DefId on ADT Types this could be useful information
Philip Herron [Tue, 18 Feb 2025 17:45:58 +0000 (17:45 +0000)] 
gccrs: track DefId on ADT Types this could be useful information

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): track DefId of origin
* typecheck/rust-tyty.cc (BaseType::monomorphized_clone): likewise
(ADTType::ADTType): likewise
(ADTType::get_id): likewise
(ADTType::clone): likewise
* typecheck/rust-tyty.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: remove visitor which is not needed here
Philip Herron [Tue, 18 Feb 2025 17:44:05 +0000 (17:44 +0000)] 
gccrs: remove visitor which is not needed here

Just a small refactor to remove a visitor which is not needed.

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (ResolvePathRef::Compile): remove visitor
(ResolvePathRef::ResolvePathRef): likewise
(ResolvePathRef::visit): likewise
* backend/rust-compile-resolve-path.h (class ResolvePathRef): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Fix some small issues
Owen Avery [Tue, 11 Mar 2025 16:03:34 +0000 (12:03 -0400)] 
gccrs: Fix some small issues

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc
(assume_handler): Fix copy/paste error.
* typecheck/rust-hir-type-check-pattern.cc
(TypeCheckPattern::visit): Fix spelling mistake.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Add a test for enum variant name resolution
Pierre-Emmanuel Patry [Wed, 5 Mar 2025 10:56:49 +0000 (11:56 +0100)] 
gccrs: Add a test for enum variant name resolution

Highlight the fact that a value inside an enum definition refers to
a struct outside of the enum and not to the enum variant's name
directly.

gcc/testsuite/ChangeLog:

* rust/compile/enum_variant_name.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Remove nr2 exhaustiveness test from exclusion list
Pierre-Emmanuel Patry [Tue, 4 Mar 2025 17:12:14 +0000 (18:12 +0100)] 
gccrs: Remove nr2 exhaustiveness test from exclusion list

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add enum variant string information to definition
Pierre-Emmanuel Patry [Tue, 4 Mar 2025 15:59:11 +0000 (16:59 +0100)] 
gccrs: Add enum variant string information to definition

New enum variant status now appears in the string representation of
the resolver's definition.

gcc/rust/ChangeLog:

* resolve/rust-rib.cc (Rib::Definition::to_string): Add enum variant
status.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Keep definition provenance to skip enum variants
Pierre-Emmanuel Patry [Tue, 4 Mar 2025 15:41:48 +0000 (16:41 +0100)] 
gccrs: Keep definition provenance to skip enum variants

Enum variants shouldn't be accessed directly even from within an enum.
This commit keeps the provenance for enum variants definition so we
can skip them when resolving a value within an enum definition.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: Add new function to insert enum
variants and add argument to resolver's get function to explicitely
skip enum variants.
* resolve/rust-forever-stack.hxx: Update function
definitions.
* resolve/rust-name-resolution-context.cc (NameResolutionContext::insert_variant):
Add function to insert enum variants.
* resolve/rust-name-resolution-context.h: Add function's prototype.
* resolve/rust-rib.cc (Rib::Definition::Definition): Add new boolean to
hint at enum variant provenance.
(Rib::Definition::is_variant): New getter for variant status.
(Rib::Definition::Shadowable): Update constructor to opt out of enum
variants.
(Rib::Definition::Globbed): Likewise.
(Rib::Definition::NonShadowable): Change constructor to forward enum
variant provenance status.
* resolve/rust-rib.h: Update function prototypes.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::insert_enum_variant_or_error_out):
Add function to insert enum variants in the name resolver.
(TopLevel::visit): Update several enum variant's visitor function
with the new enum variant name resolving code.
* resolve/rust-toplevel-name-resolver-2.0.h: Update function
prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add rib kind debug representation
Pierre-Emmanuel Patry [Thu, 27 Feb 2025 11:28:32 +0000 (12:28 +0100)] 
gccrs: Add rib kind debug representation

Rib kind had no string representation, and thus were not used in the
debug string representation.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Output rib kind.
* resolve/rust-rib.h: Add function to get string representation from
a rib kind.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: nr2.0: Set the node id of the root node
Owen Avery [Tue, 18 Feb 2025 08:56:33 +0000 (03:56 -0500)] 
gccrs: nr2.0: Set the node id of the root node

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h
(ForeverStack::ForeverStack): Set the node id of the root node
to that of the current crate.
* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Use the node id of the root
node during resolution of crate segments.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: expansion: Correctly expand $crate metavar
Arthur Cohen [Mon, 24 Feb 2025 12:09:17 +0000 (13:09 +0100)] 
gccrs: expansion: Correctly expand $crate metavar

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.

4 months agogccrs: nr2.0: Make sure PathInExpression is default resolved
Owen Avery [Tue, 18 Feb 2025 08:06:09 +0000 (03:06 -0500)] 
gccrs: nr2.0: Make sure PathInExpression is default resolved

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Call DefaultResolver::visit earlier, in order to
ensure it is called even if Late::visit returns early.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Reduce usage of rust-session-manager.h
Owen Avery [Sat, 1 Mar 2025 23:05:07 +0000 (18:05 -0500)] 
gccrs: Reduce usage of rust-session-manager.h

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>
4 months agogccrs: session-manager: Call into DesugarQuestionMark
Arthur Cohen [Thu, 23 Jan 2025 11:46:09 +0000 (11:46 +0000)] 
gccrs: session-manager: Call into DesugarQuestionMark

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Call DesugarQuestionMark::go().

4 months agogccrs: lower: Error out when lowering ErrorPropagationExpr
Arthur Cohen [Thu, 23 Jan 2025 11:44:33 +0000 (11:44 +0000)] 
gccrs: lower: Error out when lowering ErrorPropagationExpr

Adapt functions for lowering nodes that should never reach the lowering phase to cause an
unreachable, and mark them as final so as it not possible to override them in other visitors.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-base.cc: Adapt functions for ErrorPropagationExpr and MacroInvocation.
* hir/rust-ast-lower-base.h: Mark them as final.
* hir/rust-ast-lower-expr.cc: Remove previous definition for those overrides.
* hir/rust-ast-lower-expr.h: Likewise.

4 months agogccrs: ast: Add base for desugaring try expressions
Arthur Cohen [Wed, 22 Jan 2025 17:20:37 +0000 (17:20 +0000)] 
gccrs: ast: Add base for desugaring try expressions

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.

4 months agogccrs: Adjust unknown macro error message
Owen Avery [Tue, 25 Feb 2025 15:16:18 +0000 (10:16 -0500)] 
gccrs: Adjust unknown macro error message

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc
(Early::visit): Adjust error produced when macro resolution
fails.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/macro43.rs: Adjust expected errors.
* rust/compile/macros/mbe/macro44.rs: Likewise.
* rust/compile/nested_macro_use2.rs: Likewise.
* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: nr2.0: Handle lang item type path segments
Owen Avery [Sun, 9 Feb 2025 08:02:58 +0000 (03:02 -0500)] 
gccrs: nr2.0: Handle lang item type path segments

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Stop when hitting a lang
item segment.
(ForeverStack::resolve_segments): Resolve lang item segments.
(ForeverStacl::resolve_path): Handle single segment lang item
paths and add comment.
* util/rust-unwrap-segment.cc
(unwrap_segment_get_lang_item): Add.
* util/rust-unwrap-segment.h
(unwrap_segment_get_lang_item): Add.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: expansion: Expand generic args in generic type path segments
Arthur Cohen [Mon, 24 Feb 2025 11:18:54 +0000 (12:18 +0100)] 
gccrs: expansion: Expand generic args in generic type path segments

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.

4 months agogccrs: name-resolution: early: Remove overzealous overrides
Arthur Cohen [Mon, 24 Feb 2025 11:18:39 +0000 (12:18 +0100)] 
gccrs: name-resolution: early: Remove overzealous overrides

Some empty overrides were incorrectly being set-up instead of using the correct behavior
from DefaultASTVisitor.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver.cc: Remove definitions.
* resolve/rust-early-name-resolver.h: Remove declarations.

4 months agogccrs: lower: Always crash when lowering macro invocations
Arthur Cohen [Mon, 24 Feb 2025 11:16:11 +0000 (12:16 +0100)] 
gccrs: lower: Always crash when lowering macro invocations

gcc/rust/ChangeLog:

* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add base implementation
for visitor.

4 months agogccrs: nr2.0: Implement macro_use for modules
Owen Avery [Wed, 19 Feb 2025 02:20:45 +0000 (21:20 -0500)] 
gccrs: nr2.0: Implement macro_use for modules

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc:
Include rust-attribute-values.h.
(Early::visit): If a module has a macro_use attribute, avoid
pushing a new textual macro scope.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Adjust type path resolution error message
Owen Avery [Mon, 10 Feb 2025 02:42:21 +0000 (21:42 -0500)] 
gccrs: Adjust type path resolution error message

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc
(ResolveRelativeTypePath::go): Adjust error message to match
the 2.0 name resolver.

gcc/testsuite/ChangeLog:

* rust/compile/additional-trait-bounds2.rs: Adjust expected
errors.
* rust/compile/const_generics_4.rs: Likewise.
* rust/compile/const_generics_7.rs: Likewise.
* rust/compile/generic-default1.rs: Likewise.
* rust/compile/generics5.rs: Likewise.
* rust/compile/generics9.rs: Likewise.
* rust/compile/issue-2423.rs: Likewise.
* rust/compile/method2.rs: Likewise.
* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: hir-dump: Fix more segfaults in the HIR dump
Arthur Cohen [Fri, 20 Dec 2024 18:00:48 +0000 (18:00 +0000)] 
gccrs: hir-dump: Fix more segfaults in the HIR dump

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc: Check unique_ptr members are present before
visiting them.
* hir/tree/rust-hir-path.h: Add `has_{type, trait}` methods to
QualifiedPathInType.

4 months agogccrs: derive(Hash): Add implementation.
Arthur Cohen [Thu, 20 Feb 2025 17:01:28 +0000 (17:01 +0000)] 
gccrs: derive(Hash): Add implementation.

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.

4 months agogccrs: derive(Debug): Use builder's ptrify function instead
Arthur Cohen [Fri, 21 Feb 2025 14:54:09 +0000 (14:54 +0000)] 
gccrs: derive(Debug): Use builder's ptrify function instead

gcc/rust/ChangeLog:

* expand/rust-derive-debug.cc (ptrify): Remove function.

4 months agogccrs: ast: builder: Add new builder methods
Arthur Cohen [Fri, 21 Feb 2025 14:52:17 +0000 (14:52 +0000)] 
gccrs: ast: builder: Add new builder methods

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.

4 months agogccrs: Remove some member functions from SingleASTNode
Owen Avery [Sat, 22 Feb 2025 03:51:32 +0000 (22:51 -0500)] 
gccrs: Remove some member functions from SingleASTNode

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>
4 months agogccrs: Fix expansion of macros inside modules
Owen Avery [Sat, 22 Feb 2025 00:07:59 +0000 (19:07 -0500)] 
gccrs: Fix expansion of macros inside modules

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>
4 months agogccrs: Remove PathInExpression::get_pattern_node_id
Owen Avery [Sat, 22 Feb 2025 03:50:51 +0000 (22:50 -0500)] 
gccrs: Remove PathInExpression::get_pattern_node_id

gcc/rust/ChangeLog:

* ast/rust-path.h
(PathInExpression::get_pattern_node_id): Remove.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: derive(Eq): Create copies of Eq typepath to avoid NodeId confusion
Arthur Cohen [Thu, 20 Feb 2025 09:11:21 +0000 (09:11 +0000)] 
gccrs: derive(Eq): Create copies of Eq typepath to avoid NodeId confusion

gcc/rust/ChangeLog:

* expand/rust-derive-eq.cc: Copy `Eq` typepath.

4 months agogccrs: derive(Eq): Also derive StructuralEq
Arthur Cohen [Tue, 4 Feb 2025 15:12:25 +0000 (16:12 +0100)] 
gccrs: derive(Eq): Also derive StructuralEq

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.

4 months agogccrs: derive(PartialEq): Also derive StructuralPartialEq
Arthur Cohen [Tue, 4 Feb 2025 15:06:33 +0000 (16:06 +0100)] 
gccrs: derive(PartialEq): Also derive StructuralPartialEq

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.

4 months agogccrs: expand: Allow built-in derives to generate multiple items
Arthur Cohen [Tue, 4 Feb 2025 08:58:14 +0000 (09:58 +0100)] 
gccrs: expand: Allow built-in derives to generate multiple items

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.

4 months agogccrs: derive(PartialEq): Add partial implementation
Arthur Cohen [Thu, 30 Jan 2025 13:41:11 +0000 (14:41 +0100)] 
gccrs: derive(PartialEq): Add partial implementation

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.

4 months agogccrs: derive(Clone): chore: Cleanup
Arthur Cohen [Fri, 31 Jan 2025 17:58:24 +0000 (17:58 +0000)] 
gccrs: derive(Clone): chore: Cleanup

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc: Cleanup implementation, avoid repetitions.
* expand/rust-derive-clone.h: Likewise.

4 months agogccrs: ast-builder: Add new methods for creating operator expressions
Arthur Cohen [Fri, 31 Jan 2025 13:24:02 +0000 (13:24 +0000)] 
gccrs: ast-builder: Add new methods for creating operator expressions

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.

4 months agogccrs: ast-builder: Improve function generation.
Arthur Cohen [Thu, 30 Jan 2025 13:56:37 +0000 (14:56 +0100)] 
gccrs: ast-builder: Improve function generation.

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.

4 months agogccrs: derive(Eq): Add implementation.
Arthur Cohen [Thu, 30 Jan 2025 13:04:17 +0000 (14:04 +0100)] 
gccrs: derive(Eq): Add implementation.

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.

4 months agogccrs: nr2.0: Run DefaultResolver::visit on PathInExpression
Owen Avery [Tue, 4 Feb 2025 10:53:10 +0000 (05:53 -0500)] 
gccrs: nr2.0: Run DefaultResolver::visit on PathInExpression

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): When visiting a PathInExpression instance, call
into DefaultResolver::visit, ensuring generic arguments are
visited.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: nr2.0: Fix issue with external crates
Owen Avery [Tue, 18 Feb 2025 07:03:56 +0000 (02:03 -0500)] 
gccrs: nr2.0: Fix issue with external crates

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): When visiting an external crate declaration,
handle failed crate name lookups. This can happen when
Session::load_extern_crate fails to load a crate during the
CfgStrip phase.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Add comments to resolve_segments
Owen Avery [Mon, 17 Feb 2025 23:33:08 +0000 (18:33 -0500)] 
gccrs: Add comments to resolve_segments

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx
(ForeverStack::resolve_segments): Add comments explaining
the behaviour of a while loop.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Add type check on if-expr
Benjamin Thos [Mon, 16 Dec 2024 13:11:38 +0000 (14:11 +0100)] 
gccrs: Add type check on if-expr

Check if an if-expr returns void type or a coercible type like an early return.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Add check on if-expr.

gcc/testsuite/ChangeLog:

* rust/compile/implicit_returns_err3.rs: Change test to be valid.
* rust/compile/torture/if.rs: Likewise.
* rust/compile/if-without-else.rs: New test.

Signed-off-by: Benjamin Thos <benjamin.thos@epita.fr>
4 months agogccrs: nr2.0: Resolve paths which start with Self
Owen Avery [Tue, 4 Feb 2025 10:02:38 +0000 (05:02 -0500)] 
gccrs: nr2.0: Resolve paths which start with Self

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Be more careful about
applying ForeverStack::find_closest_module.
(ForeverStack::resolve_segments): Allow traversal into parent
nodes when not in a module node or root node, which
ForeverStack::find_starting_point previously made moot through
use of ForeverStack::find_closest_module. Also, when a child
node lookup fails when resolving in the type namespace, attempt
a rib lookup as a fallback.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Avoid throwing a resolution error for type paths
when the typechecker may be able to finish the resolution. Also,
throw an error when a resolution is ambiguous.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: initial setup for new OpaqueType to represent Impl types
Philip Herron [Sun, 16 Feb 2025 01:42:05 +0000 (01:42 +0000)] 
gccrs: initial setup for new OpaqueType to represent Impl types

This completes the initial setup and boilerplate for the new type in the
typesystem. This is not functional yet but its a big patch already.

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): new tyty::OpaqueType
* backend/rust-compile-type.h: likewise
* checks/errors/borrowck/rust-bir-fact-collector.h: likewise
* checks/errors/borrowck/rust-bir-place.h: likewise
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy):
likewise
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
* typecheck/rust-hir-type-check-type.h: likewise
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): likewise
* typecheck/rust-substitution-mapper.h: likewise
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_sized_builtin): likewise
* typecheck/rust-tyty-call.h: likewise
* typecheck/rust-tyty-cmp.h (class OpaqueCmp): likewise
* typecheck/rust-tyty-variance-analysis-private.h: likewise
* typecheck/rust-tyty-visitor.h: likewise
* typecheck/rust-tyty.cc (TypeKindFormat::to_string): likewise
(BaseType::is_unit): likewise
(BaseType::destructure): likewise
(BaseType::has_substitutions_defined): likewise
(BaseType::needs_generic_substitutions): likewise
(OpaqueType::OpaqueType): likewise
(OpaqueType::can_resolve): likewise
(OpaqueType::accept_vis): likewise
(OpaqueType::as_string): likewise
(OpaqueType::get_name): likewise
(OpaqueType::can_eq): likewise
(OpaqueType::clone): likewise
(OpaqueType::resolve): likewise
(OpaqueType::is_equal): likewise
(OpaqueType::handle_substitions): likewise
* typecheck/rust-tyty.h (enum TypeKind): likewise
(class OpaqueType): likewise
* typecheck/rust-unify.cc (UnifyRules::go): likewise
(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_placeholder): likewise
(UnifyRules::expect_projection): likewise
(UnifyRules::expect_dyn): likewise
(UnifyRules::expect_opaque): likewise
* typecheck/rust-unify.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Add name resolution and HIR lowering for ImplTraitType's
Philip Herron [Sat, 15 Feb 2025 21:22:16 +0000 (21:22 +0000)] 
gccrs: Add name resolution and HIR lowering for ImplTraitType's

Our AST has ImplTraitType for multiple bounds and a singular
ImplTraitTypeOneBound, this patch desugars these into a simple
HIR::ImplTraitType. It also does the name resolution for this.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-struct.h: remove HIR::ImplTraitTypeOneBound
* checks/errors/borrowck/rust-function-collector.h: likewise
* checks/errors/rust-const-checker.cc (ConstChecker::visit): likewise
* checks/errors/rust-const-checker.h: likewise
* checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit): likewise
* checks/errors/rust-hir-pattern-analysis.h: likewise
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): likewise
* checks/errors/rust-unsafe-checker.h: likewise
* hir/rust-ast-lower-type.cc (ASTLoweringType::translate): likewise
(ASTLoweringType::visit): likewise
* hir/rust-ast-lower-type.h: cleanup
* hir/rust-hir-dump.cc (Dump::visit): remove ImplTraitTypeOneBound
* hir/rust-hir-dump.h: likewise
* hir/tree/rust-hir-full-decls.h (class ImplTraitTypeOneBound): likewise
* hir/tree/rust-hir-type.h (class ImplTraitTypeOneBound): likewise
* hir/tree/rust-hir-visitor.h: likewise
* hir/tree/rust-hir.cc (ImplTraitTypeOneBound::as_string):  likewise
(ImplTraitTypeOneBound::accept_vis):  likewise
* resolve/rust-ast-resolve-type.cc (ResolveType::go): likewise
(ResolveType::visit): likewise
* resolve/rust-ast-resolve-type.h: add name resolution
* typecheck/rust-hir-type-check-type.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: improve error diagnostic for bad type-resolution in CallExpr
Philip Herron [Fri, 14 Feb 2025 17:32:20 +0000 (17:32 +0000)] 
gccrs: improve error diagnostic for bad type-resolution in CallExpr

We have the type information for the resolved call lets tell the user about
it in the diagnostic and apply the correct error code.

Fixes Rust-GCC#2035

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): improve error diag

gcc/testsuite/ChangeLog:

* rust/compile/generics4.rs: cleanup
* rust/compile/generics6.rs: likewise
* rust/compile/type-bindings1.rs: likewise
* rust/compile/unconstrained_type_param.rs: likewise
* rust/compile/issue-2035.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: self paths are patterns but we dont have mappings for it
Philip Herron [Thu, 13 Feb 2025 17:45:09 +0000 (17:45 +0000)] 
gccrs: self paths are patterns but we dont have mappings for it

With simple patterns we dont introduce any more inference varaibles as
they are already declared in a specific way. This would only lead to
more unconstrained inference varaibles than is required.

Fixes Rust-GCC#3022

gcc/rust/ChangeLog:

* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): add location mappings
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): check for self

gcc/testsuite/ChangeLog:

* rust/compile/issue-3022.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: fix name resolution for generics where type param is declared later
Philip Herron [Thu, 13 Feb 2025 17:01:31 +0000 (17:01 +0000)] 
gccrs: fix name resolution for generics where type param is declared later

Rust allows you to use generics within type bounds when they are declared
later on. This changes the name resolution to walk the genric params
in two passes to ensure the type parameters are setup before drilling down
into the type parameters

This issue has exposed another type checking issue which needs fixed in
a subseqent patch.

Addresses Rust-GCC#3022

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): use new api
(ResolveItem::visit): likewise
(ResolveExternItem::visit): likewise
* resolve/rust-ast-resolve-stmt.h: likewise
* resolve/rust-ast-resolve-type.h (class ResolveGenericParam): remove
(class ResolveGenericParams): added new api

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: fix unconstrained generics check to handle recursive generics
Philip Herron [Thu, 13 Feb 2025 14:09:17 +0000 (14:09 +0000)] 
gccrs: fix unconstrained generics check to handle recursive generics

Generics can be constrained within other generic types so this check needs
to be recursive.

Fixes Rust-GCC#3031

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc (walk_types_to_constrain): recursive walker
* typecheck/rust-tyty.cc (BaseType::get_subst_argument_mappings): new helper
* typecheck/rust-tyty.h: prototype

gcc/testsuite/ChangeLog:

* rust/compile/issue-3031.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: add diagnostic for E0229 no associated type arguments allowed here
Philip Herron [Wed, 12 Feb 2025 17:10:31 +0000 (17:10 +0000)] 
gccrs: add diagnostic for E0229 no associated type arguments allowed here

It seems bounds in qualified paths are not allowed to specify associated
type bindings because its going to be associated with the impl block
anyway.

Fixes Rust-GCC#2369

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.h: add flag
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
* typecheck/rust-tyty-bounds.cc: new diagnostic

gcc/testsuite/ChangeLog:

* rust/compile/issue-2369.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: remove name resolution inserts from type-path
Philip Herron [Wed, 12 Feb 2025 16:44:55 +0000 (16:44 +0000)] 
gccrs: remove name resolution inserts from type-path

We resolve path segments and inserted their resolution into the name
resolution space which was an old hack to use this as information in
code-gen/check-passes in order to help things move forward but this is
not nessecary

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): remove name resolution info
(TypeCheckType::resolve_root_path): likewise
* typecheck/rust-hir-type-check-type.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: enum type layout needs to respect the enum repr type
Philip Herron [Tue, 11 Feb 2025 17:51:22 +0000 (17:51 +0000)] 
gccrs: enum type layout needs to respect the enum repr type

Addresses Rust-GCC#3352

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::get_implicit_enumeral_node_type):
use repr
(TyTyResolveCompile::visit): update prototype
* backend/rust-compile-type.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: add variant_count intrinsic
Philip Herron [Tue, 11 Feb 2025 17:42:24 +0000 (17:42 +0000)] 
gccrs: add variant_count intrinsic

Addresses Rust-GCC#3348

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (variant_count_handler): new intrinsic

gcc/testsuite/ChangeLog:

* rust/execute/torture/enum_intrinsics2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: add discriminant value intrinsic
Philip Herron [Mon, 10 Feb 2025 16:28:30 +0000 (16:28 +0000)] 
gccrs: add discriminant value intrinsic

This is pretty nasty piece of rust in my opinion the return type of this
intrinsic results into a lang item associated type:

  <T as DiscriminantKind>::Discriminant

This is a special case which needs to support mapping onto the repr type
of the associated ADT that is passed in, but defaults to iszie otherwise.

This patch assumes we only come accross this case in a HIR::CALL_EXPR, so
and makes assumutions that its always of this function signiture. I will
do some checking in libcore to verify that assumption. More work is needed
to parse the repr type on enums but the code is there to support this when
its in to change the types etc.

Addresses Rust-GCC#3348

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (discriminant_value_handler): new handler
* typecheck/rust-hir-trait-resolve.cc (TraitItemReference::resolve_item): track the defid
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): default isize
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): special case CallExpr
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): parse repr options enum
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): remove bad diagnostic
* typecheck/rust-tyty.cc (PlaceholderType::PlaceholderType): track defid
(PlaceholderType::clone): likewise
(PlaceholderType::get_def_id): likeiwse
* typecheck/rust-tyty.h: placeholder track defid
* util/rust-lang-item.cc: add new lang items
* util/rust-lang-item.h: likewise

gcc/testsuite/ChangeLog:

* rust/execute/torture/enum_intrinsics1.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Get rid of duplicate interface gccrs#3396
GS-GOAT [Sat, 8 Feb 2025 06:33:18 +0000 (12:03 +0530)] 
gccrs: Get rid of duplicate interface gccrs#3396

gcc/rust/ChangeLog:

* typecheck/rust-autoderef.cc
(insert_implicit_type): Update single-parameter call to
pass explicit HirId.
* typecheck/rust-hir-type-check-expr.cc: Same.
* typecheck/rust-hir-type-check-pattern.cc: Same.
* typecheck/rust-hir-type-check.h: Removed call
to the duplicate interface.
* typecheck/rust-typecheck-context.cc
(TypeCheckContext::insert_implicit_type): Removed the
interface with no HirId field.

Signed-off-by: Guransh Singh <guransh766@gmail.com>
4 months agogccrs: remove bad type checking diagnostic
Philip Herron [Tue, 4 Feb 2025 17:15:15 +0000 (17:15 +0000)] 
gccrs: remove bad type checking diagnostic

This was a bad diagnostic added when I was working on slices and iterators
also the name of the function is also bad. This is all about setting up
associated types based on the current context of the bounds assocated with
the associated trait bounds on this function.

The tell tale is that this didnt have an associated rust error code so
this is most definetly not the correct error diagnostic.

Fixes Rust-GCC#3403

gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc (SubstitutionRef::monomorphize): remove diagnostic

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3403.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: session manager: Call into DesugarForLoops
Arthur Cohen [Wed, 22 Jan 2025 14:14:45 +0000 (14:14 +0000)] 
gccrs: session manager: Call into DesugarForLoops

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Call the visitor.

4 months agogccrs: ast: Add DesugarForLoop class
Arthur Cohen [Sun, 22 Dec 2024 15:59:27 +0000 (15:59 +0000)] 
gccrs: ast: Add DesugarForLoop class

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

4 months agogccrs: ast: builder: Fix arguments of Builder::let
Arthur Cohen [Wed, 22 Jan 2025 14:07:05 +0000 (14:07 +0000)] 
gccrs: ast: builder: Fix arguments of Builder::let

gcc/rust/ChangeLog:

* ast/rust-ast-builder.h: Mark all arguments as &&.
* ast/rust-ast-builder.cc (Builder::let): Likewise.

4 months agogccrs: nr2.0: Resolve instances of TypePath more accurately
Owen Avery [Thu, 23 Jan 2025 01:12:46 +0000 (20:12 -0500)] 
gccrs: nr2.0: Resolve instances of TypePath more accurately

gcc/rust/ChangeLog:

* util/rust-unwrap-segment.cc: New file.
* util/rust-unwrap-segment.h: New file.
* Make-lang.in: Add rust-unwrap-segment.o to the object list.
* resolve/rust-forever-stack.hxx: Include rust-unwrap-segment.h.
(ForeverStack::find_starting_point): Use unwrap_type_segment.
(ForeverStack::resolve_segments): Likewise.
(ForeverStack::resolve_path): Likewise.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Resolve type paths using
NameResolutionContext::resolve_path.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::resolve_path): Use
unwrap_segment_node_id.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: inline-asm: Fix some warnings
Arthur Cohen [Wed, 29 Jan 2025 14:41:19 +0000 (14:41 +0000)] 
gccrs: inline-asm: Fix some warnings

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!.

4 months agogccrs: Add warning about default visitor usage
Pierre-Emmanuel Patry [Tue, 4 Feb 2025 12:53:30 +0000 (13:53 +0100)] 
gccrs: Add warning about default visitor usage

We already lost some time on this unusual pattern, a comment will
hopefully prevent this from happening again.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add
warning about current code.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add test case to show issue is fixed
Philip Herron [Mon, 3 Feb 2025 20:43:57 +0000 (20:43 +0000)] 
gccrs: Add test case to show issue is fixed

This was fixed as part of: "gccrs: Fix compilation of trait-items which map to impl items"

Fixes Rust-GCC#3402

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3402-1.rs: New test.
* rust/compile/issue-3402-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: derive(Default): Add implementation
Arthur Cohen [Thu, 30 Jan 2025 12:10:51 +0000 (13:10 +0100)] 
gccrs: derive(Default): Add implementation

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.

4 months agogccrs: ast-builder: Add methods for QualifiedPathInExpressions
Arthur Cohen [Thu, 30 Jan 2025 12:07:48 +0000 (13:07 +0100)] 
gccrs: ast-builder: Add methods for QualifiedPathInExpressions

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.

4 months agogccrs: Fix compilation of trait-items which map to impl items
Philip Herron [Mon, 3 Feb 2025 16:19:30 +0000 (16:19 +0000)] 
gccrs: Fix compilation of trait-items which map to impl items

When we have paths such as Try::from_error the Try references the Trait
and then from_error references the from_error trait item. So this resolves
directly to a trait implementation which has the type:

  fn <Self> (v: placeholder) -> Self

Remember that a path such as: Try::from_error gets handled by doing a
clever substitution: <T? as Try>::from_error

The main piece here is that we resolve this function type and for
monomoprhization we know this is a trait call but we know that all trait's
have an implicit Self type param which in this case is Result<i32, i32>
so when it comes to knowing which impl block this is we got rid of the old
bad insert/lookup receiver hack and use the specified type to know which
impl block we are talking about to generate the function.

The hard part here is inside rust-compil-item.cc, where we have the
'concete' type which is the trait item fntype of:

  fn <Result<i32, i32>> (v : i32) -> Result<i32,i32>

This does not really match the signiture of the impl item for Result
which is:

  fn <T, E> (v: i32) -> Result<T, E>

So what we need to do is actually infer this by inputing inference
variables on the impl fntype then unify'ing the trait object to this to
compute the types of this to monomorphize this.

Fixes Rust-GCC#3381

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): remove receiver interface
* backend/rust-compile-item.cc (CompileItem::visit): monomorphize trait to impl item
* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): use trait item Self
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): remove receiver interface
(TypeCheckExpr::resolve_fn_trait_call): likewise
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): likewise
(TypeCheckExpr::resolve_segments): likewise
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
* typecheck/rust-hir-type-check.h: likewise
* typecheck/rust-typecheck-context.cc (TypeCheckContext::insert_receiver): remove
(TypeCheckContext::lookup_receiver): remove

gcc/testsuite/ChangeLog:

* rust/execute/torture/issue-3381.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Fix bad generic substitution error on fn/adt types
Philip Herron [Mon, 3 Feb 2025 15:25:50 +0000 (15:25 +0000)] 
gccrs: Fix bad generic substitution error on fn/adt types

When passing generics around we try to adjust them because there are cases
where the names are adjusted from other generics this can fail for traits
because of the implicit Self and we just need to continue on without
adjustment.

Fxies Rust-GCC#3382

gcc/rust/ChangeLog:

* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit):
continue on for trait item mode.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this.
* rust/compile/issue-3382.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Fix crash in privay reporter for placeholder types
Philip Herron [Mon, 3 Feb 2025 15:14:48 +0000 (15:14 +0000)] 
gccrs: Fix crash in privay reporter for placeholder types

This guards against a crash but i think this should actually be treated
as if its a generic type like below. But for now this addresses a crash which can occur.

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy):
Add guard for placeholder

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: coercion sites allow for type inference as well.
Philip Herron [Mon, 3 Feb 2025 15:45:12 +0000 (15:45 +0000)] 
gccrs: coercion sites allow for type inference as well.

Addresses Rust-GCC#3382 and Rust-GCC#3381

gcc/rust/ChangeLog:

* typecheck/rust-type-util.cc (coercion_site): allow inference vars

gcc/testsuite/ChangeLog:

* rust/compile/reference1.rs: fix error message

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Fix ICE during path probe
Philip Herron [Mon, 3 Feb 2025 15:15:40 +0000 (15:15 +0000)] 
gccrs: Fix ICE during path probe

It is valid for the query to fail here so its valid to not assert here.

gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc (PathProbeType::visit): remove assertion

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Fix ICE when fn_once and fn_once_output lang item is not defined
Philip Herron [Mon, 3 Feb 2025 15:14:01 +0000 (15:14 +0000)] 
gccrs: Fix ICE when fn_once and fn_once_output lang item is not defined

We needed to check for the optional has a value here or not it leads to an
ICE.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): add checks for lang items

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Fix bug in type resolution of paths
Owen Avery [Sat, 4 Jan 2025 19:59:54 +0000 (14:59 -0500)] 
gccrs: Fix bug in type resolution of paths

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc
(Early::resolve_glob_import): Use
NameResolutionContext::resolve_path instead of
ForeverStack::resolve_path.
(Early::visit): Likewise.
(Early::visit_attributes): Likewise.
* resolve/rust-early-name-resolver-2.0.h
(Early::resolve_path_in_all_ns): Likewise.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Likewise, insert segment resolutions not
handled by NameResolutionContext::resolve_path, and avoid throwing
an error when path resolution could be finished by the typechecker.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::resolve_path): Add.
* typecheck/rust-hir-type-check-path.cc
(TypeCheckExpr::resolve_root_path): Use segment node ids instead
of the path node id to look up segment resolutions when using
the 2.0 resolver, as is done with the 1.0 resolver.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::resolve_root_path): Likewise.
* resolve/rust-forever-stack.h
(ForeverStack::resolve_path): Add callback parameter for
inserting segment resolutions.
(ForeverStack::find_starting_point): Likewise.
(ForeverStack::resolve_segments): Likewise.
* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Likewise.
(ForeverStack::resolve_segments): Likewise.
(ForeverStack::resolve_path): Likewise and avoid resolving
inside TraitOrImpl ribs.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: nr2.0: Remove accidental copies of resolver
Owen Avery [Mon, 21 Oct 2024 22:02:48 +0000 (18:02 -0400)] 
gccrs: nr2.0: Remove accidental copies of resolver

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc
(CompileExpr::generate_closure_function): Take
NameResolutionContext by reference instead of by value.
* backend/rust-compile-item.cc
(CompileItem::visit): Likewise.
* backend/rust-compile-resolve-path.cc
(ResolvePathRef::resolve): Likewise.
* checks/lints/rust-lint-marklive.cc
(MarkLive::find_ref_node_id): Likewise.
* typecheck/rust-hir-type-check-enumitem.cc
(TypeCheckEnumItem::visit): Likewise.
* typecheck/rust-hir-type-check-implitem.cc
(TypeCheckImplItem::visit): Likewise.
* typecheck/rust-hir-type-check-item.cc
(TypeCheckItem::visit): Likewise.
* typecheck/rust-hir-type-check-path.cc
(TypeCheckExpr::resolve_root_path): Likewise.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::resolve_root_path): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: ast: builder: Add Return expression builder
Arthur Cohen [Thu, 23 Jan 2025 11:42:38 +0000 (11:42 +0000)] 
gccrs: ast: builder: Add Return expression builder

gcc/rust/ChangeLog:

* ast/rust-ast-builder.h: Declare it.
* ast/rust-ast-builder.cc (Builder::return_expr): Define it.

4 months agogccrs: derive(Debug): Add stub implementation.
Arthur Cohen [Wed, 29 Jan 2025 18:10:01 +0000 (18:10 +0000)] 
gccrs: derive(Debug): Add stub implementation.

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.

4 months agogccrs: derive(Clone, Copy): Cleanup using new method from DeriveVisitor
Arthur Cohen [Thu, 30 Jan 2025 10:01:33 +0000 (11:01 +0100)] 
gccrs: derive(Clone, Copy): Cleanup using new method from DeriveVisitor

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc: Cleanup using DeriveVisitor::setup_impl_generics.
* expand/rust-derive-copy.cc: Likewise.

4 months agogccrs: derive-visitor: Add method for setting up derived impl generics
Arthur Cohen [Thu, 30 Jan 2025 09:50:30 +0000 (10:50 +0100)] 
gccrs: derive-visitor: Add method for setting up derived impl generics

gcc/rust/ChangeLog:

* expand/rust-derive.cc (DeriveVisitor::setup_impl_generics): New method.
* expand/rust-derive.h: Declare it, define DeriveVisitor::ImplGenerics struct.