]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
6 days agogccrs: Fix ice with invalid borrow expression
Philip Herron [Tue, 8 Jul 2025 21:33:02 +0000 (22:33 +0100)] 
gccrs: Fix ice with invalid borrow expression

This is an invalid test case but we just need a guard for the missing
borrow expression.

Fixes Rust-GCC#3874

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): check for missing borrow
* ast/rust-expr.h: add helper

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Do proper const folding during typechecking for array capacities
Philip Herron [Tue, 8 Jul 2025 20:13:48 +0000 (21:13 +0100)] 
gccrs: Do proper const folding during typechecking for array capacities

This patch adds proper folding to the const expression for array capacity we
already have the const folding mechanics and the query system needed to handle cases
where the capacity is a function call in a const context. This leverages and pulls the
gcc tree capacity into the TyTy::ArrayType so it can be used for more typechecking and
eventually doing more const generics work.

Addresses Rust-GCC#3885
Fixes Rust-GCC#3882

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::query_compile_const_expr): new wrapper
* backend/rust-compile-base.h: add prototype
* backend/rust-compile-context.cc (Context::get): singleton helper
* backend/rust-compile-context.h: likewise
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): handle infer's that can default
* rust-session-manager.cc (Session::compile_crate): create the gcc context earlier for tychk
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): const fold it
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
* typecheck/rust-tyty.cc (BaseType::monomorphized_clone): fix constructor call
(ArrayType::as_string): print capacity
(ArrayType::clone): fix constructor call
* typecheck/rust-tyty.h: track capacity
* typecheck/rust-unify.cc (UnifyRules::expect_array): check the capacities

gcc/testsuite/ChangeLog:

* rust/compile/all-cast.rs: shows array capacity now
* rust/compile/arrays2.rs: likewise
* rust/compile/const3.rs: fix error message
* rust/compile/const_generics_3.rs: disable until typecheck we get proper errors now!
* rust/compile/usize1.rs: proper capacity error message

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: nr2.0: Add proper handling for WhileLet loops.
Arthur Cohen [Fri, 4 Jul 2025 13:40:02 +0000 (15:40 +0200)] 
gccrs: nr2.0: Add proper handling for WhileLet loops.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): New visitor.
* resolve/rust-late-name-resolver-2.0.h: Declare it.
* resolve/rust-name-resolution-context.h (enum class): New binding context.

6 days agogccrs: ast: Check before visiting a while-let's label
Arthur Cohen [Mon, 19 May 2025 10:27:17 +0000 (12:27 +0200)] 
gccrs: ast: Check before visiting a while-let's label

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check that the WhileLet has a label
before visiting it.

gcc/testsuite/ChangeLog:

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

6 days agogccrs: Parse try expressions
Owen Avery [Wed, 2 Jul 2025 22:48:07 +0000 (18:48 -0400)] 
gccrs: Parse try expressions

This doesn't do anything beyond creating TryExpr and parsing them, so
try expressions shouldn't be able to make it past AST lowering yet.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Add visitor
for TryExpr.
* ast/rust-ast-collector.h (TokenCollector::visit): Likewise.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* ast/rust-ast-visitor.h (ASTVisitor::visit): Likewise.
(DefaultASTVisitor::visit): Likewise.
* expand/rust-derive.h (DeriveVisitor::visit): Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h (ASTLoweringBase::visit): Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit):
Likewise.
* resolve/rust-ast-resolve-base.h (ResolverBase::visit):
Likewise.
* ast/rust-ast-full-decls.h (class TryExpr): New forward class
declaration.
* ast/rust-ast.cc (TryExpr::as_string): New function.
(TryExpr::accept_vis): Likewise.
* ast/rust-expr.h (class TryExpr): New class.
* parse/rust-parse.h (Parser::parse_try_expr): New function.
* parse/rust-parse-impl.h (Parser::parse_try_expr): Likewise.
(Parser::null_denotation_not_path): Use parse_try_expr to parse
try expressions.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Allow format_args to accept a raw string literal
Owen Avery [Tue, 1 Jul 2025 17:47:59 +0000 (13:47 -0400)] 
gccrs: Allow format_args to accept a raw string literal

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-format-args.cc
(format_args_parse_arguments): Accept a RAW_STRING_LITERAL token
as the first argument.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Change enum to enum class
Pierre-Emmanuel Patry [Mon, 7 Jul 2025 11:03:10 +0000 (13:03 +0200)] 
gccrs: Change enum to enum class

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h: Add enum prefix.
* parse/rust-parse.h (enum ParseSelfError): Change from enum...
(enum class): To enum class.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 days agogccrs: Remove reinterpret_cast usages in DefaultASTVisitor
Owen Avery [Tue, 1 Jul 2025 21:18:28 +0000 (17:18 -0400)] 
gccrs: Remove reinterpret_cast usages in DefaultASTVisitor

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Replace
usages of reinterpret_cast with static_cast.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Remove Late visitor override for StructStruct
Owen Avery [Tue, 1 Jul 2025 19:54:27 +0000 (15:54 -0400)] 
gccrs: Remove Late visitor override for StructStruct

DefaultResolver already handles StructStruct in a more correct fashion.

gcc/rust/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: nr1.0: Remove rust/backend support
Owen Avery [Thu, 3 Jul 2025 21:48:11 +0000 (17:48 -0400)] 
gccrs: nr1.0: Remove rust/backend support

This is the first patch in a set intended to fully remove name
resolution 1.0. As such, it should leave name resolution 1.0 technically
available but broken.

gcc/rust/ChangeLog:

* backend/rust-compile-context.cc (Context::Context): Remove
initialization of resolver field.
* backend/rust-compile-context.h (Context::get_resolver): Remove
function.
(Context::resolver): Remove field.
* backend/rust-compile-expr.cc (CompileExpr::visit): Assume name
resolution 2.0 is always enabled.
(CompileExpr::generate_closure_function): Likewise.
* backend/rust-compile-implitem.cc (CompileTraitItem::visit):
Likewise.
* backend/rust-compile-item.cc (CompileItem::visit): Likewise.
* backend/rust-compile-resolve-path.cc
(ResolvePathRef::resolve): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Remove -frust-name-resolution-2.0 usage in tests
Owen Avery [Thu, 3 Jul 2025 21:43:55 +0000 (17:43 -0400)] 
gccrs: Remove -frust-name-resolution-2.0 usage in tests

gcc/testsuite/ChangeLog:

* rust/compile/additional-trait-bounds2nr2.rs: Remove
-frust-name-resolution-2.0 usage.
* rust/compile/const_generics_3.rs: Likewise.
* rust/compile/enum_variant_name.rs: Likewise.
* rust/compile/generics9.rs: Likewise.
* rust/compile/invalid_label_name.rs: Likewise.
* rust/compile/issue-3304.rs: Likewise.
* rust/compile/macros/mbe/macro-issue3708.rs: Likewise.
* rust/compile/macros/mbe/macro-issue3709-2.rs: Likewise.
* rust/compile/name_resolution10.rs: Likewise.
* rust/compile/name_resolution11.rs: Likewise.
* rust/compile/name_resolution12.rs: Likewise.
* rust/compile/name_resolution13.rs: Likewise.
* rust/compile/name_resolution14.rs: Likewise.
* rust/compile/name_resolution15.rs: Likewise.
* rust/compile/name_resolution16.rs: Likewise.
* rust/compile/name_resolution17.rs: Likewise.
* rust/compile/name_resolution18.rs: Likewise.
* rust/compile/name_resolution20.rs: Likewise.
* rust/compile/name_resolution22.rs: Likewise.
* rust/compile/name_resolution23.rs: Likewise.
* rust/compile/name_resolution24.rs: Likewise.
* rust/compile/name_resolution25.rs: Likewise.
* rust/compile/name_resolution6.rs: Likewise.
* rust/compile/name_resolution7.rs: Likewise.
* rust/compile/name_resolution8.rs: Likewise.
* rust/compile/name_resolution9.rs: Likewise.
* rust/compile/nested_macro_definition.rs: Likewise.
* rust/compile/pub_restricted_1.rs: Likewise.
* rust/compile/pub_restricted_2.rs: Likewise.
* rust/compile/self-in-impl.rs: Likewise.
* rust/compile/self_import_namespace.rs: Likewise.
* rust/compile/use_1.rs: Likewise.
* rust/compile/xfail/name_resolution21.rs: Likewise.
* rust/execute/torture/name_resolution.rs: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: nr2.0: Enable by default
Owen Avery [Fri, 9 May 2025 21:50:22 +0000 (17:50 -0400)] 
gccrs: nr2.0: Enable by default

gcc/rust/ChangeLog:

* lang.opt (frust-name-resolution-2.0): Enable by default.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/compile.exp: Removed.
* rust/compile/nr2/exclude: Removed.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Implement compilation support for TuplePatternItems::RANGED
Zhi Heng [Sun, 29 Jun 2025 02:44:31 +0000 (10:44 +0800)] 
gccrs: Implement compilation support for TuplePatternItems::RANGED

Example GIMPLE output of the match statement for match-restpattern-tuple-1.rs:

...
RUSTTMP.2 = x;
_1 = RUSTTMP.2.__0;
_2 = _1 == 1;
_3 = RUSTTMP.2.__3;
_4 = _3 == 4;
_5 = _2 & _4;
if (_5 != 0) goto <D.109>; else goto <D.110>;
<D.109>:
{
    {

    }
    goto <D.104>;
}
<D.110>:
if (1 != 0) goto <D.111>; else goto <D.112>;
<D.111>:
{
    {

    }
    goto <D.104>;
}
<D.112>:
<D.104>:
...

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit(TuplePattern)):
Implement check expression compilation for TuplePatternItems::RANGED.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: Fix type checking logic for TuplePattern
Zhi Heng [Sat, 28 Jun 2025 12:59:54 +0000 (20:59 +0800)] 
gccrs: Fix type checking logic for TuplePattern

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (visit(TuplePattern)): Fix
incorrect logic for field size checking.

gcc/testsuite/ChangeLog:

* rust/compile/tuple_mismatch.rs: Include RestPattern in test.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: chore: ast: Fix formatting and includes
Arthur Cohen [Fri, 13 Jun 2025 08:04:41 +0000 (10:04 +0200)] 
gccrs: chore: ast: Fix formatting and includes

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc: Remove extra include, fix new formatting.

6 days agogccrs: reconstruct_vec: Allocate size when creating the vector
Arthur Cohen [Mon, 26 May 2025 09:31:40 +0000 (11:31 +0200)] 
gccrs: reconstruct_vec: Allocate size when creating the vector

gcc/rust/ChangeLog:

* ast/rust-ast.h (reconstruct_vec): Pre-allocate size of vector.

6 days agogccrs: ast: builder: Remove ASTTypeBuilder
Arthur Cohen [Tue, 20 May 2025 13:08:06 +0000 (15:08 +0200)] 
gccrs: ast: builder: Remove ASTTypeBuilder

gcc/rust/ChangeLog:

* Make-lang.in: Remove object file for ASTTypeBuilder.
* ast/rust-ast-builder.h: Remove function.
* ast/rust-ast-builder.cc (Builder::new_type): Likewise.
(Builder::new_const_param): Use reconstruct_type() instead.
(Builder::new_generic_args): Likewise.
* expand/rust-derive-default.cc (DeriveDefault::visit_struct): Likewise.
(DeriveDefault::visit_tuple): Likewise.
* expand/rust-derive-eq.cc (DeriveEq::visit_tuple): Likewise.
(DeriveEq::visit_struct): Likewise.
(DeriveEq::visit_enum): Likewise.
(DeriveEq::visit_union): Likewise.
* ast/rust-ast-builder-type.cc: Removed.
* ast/rust-ast-builder-type.h: Removed.

6 days agogccrs: ast: Add reconstruct() method for Type nodes
Arthur Cohen [Tue, 20 May 2025 12:59:28 +0000 (14:59 +0200)] 
gccrs: ast: Add reconstruct() method for Type nodes

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add reconstruct() and reconstruct_impl() for Type nodes.
* ast/rust-type.h: Implement them.
* ast/rust-macro.h: Likewise.
* ast/rust-path.h: Likewise.

6 days agogccrs: ast: reconstruct: Add base for reconstructing and asserting different IDs
Arthur Cohen [Tue, 20 May 2025 12:25:07 +0000 (14:25 +0200)] 
gccrs: ast: reconstruct: Add base for reconstructing and asserting different IDs

gcc/rust/ChangeLog:

* ast/rust-ast.h (reconstruct): New function for calling the `reconstruct_*_impl` method
and asserting that the new NodeId is different, and then wrap it in a unique_ptr<T>.
(reconstruct_vec): Likewise, but for vectors of unique_ptr<T>

6 days agogccrs: nr2.0: Adjust resolution of modules
Owen Avery [Thu, 29 May 2025 21:04:46 +0000 (17:04 -0400)] 
gccrs: nr2.0: Adjust resolution of modules

This prioritizes resolution in the language prelude over resolution as a
module.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx (ForeverStack::resolve_path):
Resolve final segments which point to modules.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Avoid inserting module names into ribs in the type namespace.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove issue-3315-2.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: nr2.0: Add more checks for alternate patterns
Owen Avery [Sat, 24 May 2025 15:51:29 +0000 (11:51 -0400)] 
gccrs: nr2.0: Add more checks for alternate patterns

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(visit_identifier_as_pattern): Handle is_ref and is_mut.
(Late::visit): Likewise.
* resolve/rust-name-resolution-context.cc
(BindingLayer::insert_ident): Likewise.
(BindingLayer::bind_test): Handle changes to BindingLayer
fields.
(BindingLayer::merge): Likewise and emit more error messages.
* resolve/rust-name-resolution-context.h
(struct IdentifierMode): New.
(Binding::has_expected_bindings): New field.
(Binding::set): Rename field to...
(Binding::idents): ...here and convert from a set to a map.
(Binding::Binding): Initialize has_expected_bindings.
(BindingLayer::insert_ident): Adjust parameters.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove torture/alt_patterns1.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Add locus getters
Pierre-Emmanuel Patry [Fri, 27 Jun 2025 11:31:17 +0000 (13:31 +0200)] 
gccrs: Add locus getters

gcc/rust/ChangeLog:

* ast/rust-expr.h: Add getter to locus field.
* ast/rust-pattern.h (tokenid_to_rangekind): Likewise.
* hir/tree/rust-hir-item.h: Likewise.
* hir/tree/rust-hir-visibility.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
6 days agogccrs: nr2.0: Adjust resolution of external crates
Owen Avery [Mon, 16 Jun 2025 21:05:09 +0000 (17:05 -0400)] 
gccrs: nr2.0: Adjust resolution of external crates

This ensures Session::load_extern_crate doesn't try to use the old name
resolver when nr2.0 is enabled, while also ensuring that nr2.0 handles
external crates.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc
(DefaultResolver::visit_extern_crate): New function.
(DefaultResolver::visit): New visitor function for ExternCrate.
* resolve/rust-default-resolver.h
(DefaultResolver::visit_extern_crate): New function.
(DefaultResolver::visit): New visitor function for ExternCrate.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Adjust ExternCrate visitor and rename to...
(TopLevel::visit_extern_crate): ...here.
* resolve/rust-toplevel-name-resolver-2.0.h (TopLevel::visit):
Remove ExternCrate visitor override.
(TopLevel::visit_extern_crate): New function.
* rust-session-manager.cc (Session::load_extern_crate): Only run
name resolution 1.0 if name resolution 2.0 is disabled.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Implement type checking for ItemType::RANGED in TuplePattern
Zhi Heng [Thu, 26 Jun 2025 14:33:15 +0000 (22:33 +0800)] 
gccrs: Implement type checking for ItemType::RANGED in TuplePattern

This patch implements the previously unimplemented type checking for RANGED item
type for TuplePattern, which serves as the start for implementing compilation of
RestPattern.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit(TuplePattern)):
Implement type checking for ItemType::RANGED.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: Update C++ version check in rust-lang.cc
Owen Avery [Tue, 24 Jun 2025 03:10:34 +0000 (23:10 -0400)] 
gccrs: Update C++ version check in rust-lang.cc

gcc/rust/ChangeLog:

* rust-lang.cc: Move version check from C++11 to C++14.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Implement default HIR visitor class
Ryutaro Okada [Tue, 24 Jun 2025 05:03:09 +0000 (22:03 -0700)] 
gccrs: Implement default HIR visitor class

gcc/rust/ChangeLog:

* Make-lang.in: Scaffolding new rust-hir-visitor files
* hir/tree/rust-hir-visitor.h (DefaultHIRVisitor): Declare default HIR visitor
* hir/tree/rust-hir-visitor.cc  (DefaultHIRVisitor): Define default HIR visitor

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
6 days agogccrs: Create Rust::GGC::Ident
Owen Avery [Tue, 24 Jun 2025 00:27:36 +0000 (20:27 -0400)] 
gccrs: Create Rust::GGC::Ident

This should make it easier for us to hand identifiers off to the
back end.

gcc/rust/ChangeLog:

* Make-lang.in (GRS_OBJS): Add rust-ggc.o.
* backend/rust-compile-base.cc
(HIRCompileBase::compile_function): Adjust call to
Backend::function.
(HIRCompileBase::compile_constant_item): Likewise and adjust
initialization of Backend::typed_identifier.
* backend/rust-compile-expr.cc (CompileExpr::visit): Adjust call
to Backend::label.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit):
Adjust initialization of Backend::typed_identifier.
* rust-backend.h: Add includes.
(Backend::GGC::Ident): Use Rust::GGC::Ident.
(struct typed_identifier): Store name as a GGC::Ident rather
than a std::string and adjust constructors.
(named_type): Take GGC::Ident/tl::optional<GGC::Ident> rather
than std::string.
(global_variable): Likewise.
(local_variable): Likewise.
(parameter_variable): Likewise.
(static_chain_variable): Likewise.
(label): Likewise.
(function): Likewise.
* rust-gcc.cc (named_type): Likewise.
(global_variable): Likewise.
(local_variable): Likewise.
(parameter_variable): Likewise.
(static_chain_variable): Likewise.
(label): Likewise.
(function): Likewise.
(function_defer_statement): Adjust call to Backend::label.
(get_identifier_from_string): Remove function.
(fill_in_fields): Handle adjustments to typed_identifier.
* util/rust-ggc.cc: New file.
* util/rust-ggc.h: New file.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Add getter for non const lifetime object
Ryutaro Okada [Tue, 24 Jun 2025 05:28:59 +0000 (22:28 -0700)] 
gccrs: Add getter for non const lifetime object

gcc/rust/ChangeLog:

* hir/tree/rust-hir-item.h (SelfParam::get_lifetime): Add getter
for non const lifetime object

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
6 days agogccrs: Add getter for outer attributions
Ryutaro Okada [Tue, 24 Jun 2025 05:25:57 +0000 (22:25 -0700)] 
gccrs: Add getter for outer attributions

gcc/rust/ChangeLog:

* hir/tree/rust-hir-expr.h (MatchArm::get_outer_attrs): Add getter for outer attributions

Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
6 days agogccrs: Fix scan-assembler regexp in recurse2.rs
Owen Avery [Mon, 23 Jun 2025 16:33:54 +0000 (12:33 -0400)] 
gccrs: Fix scan-assembler regexp in recurse2.rs

gcc/testsuite/ChangeLog:

* rust/compile/macros/builtin/recurse2.rs: Match "abheyho\0" as
well as "abheyho", to handle slight differences in assembly
output for null-terminated strings.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Fix bug with non compiled const decl
Philip Herron [Mon, 23 Jun 2025 11:59:33 +0000 (12:59 +0100)] 
gccrs: Fix bug with non compiled const decl

There was a sily bug where if you reorder this test case to declare A before B
this test would work but its meant to work in any order. So this fixes the bug
during code gen to fall back to our query compile system if this is needed.

Fixes Rust-GCC#3525

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc: if this fails fall back to query compile

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: check for invalid const calls during code-gen
Philip Herron [Mon, 23 Jun 2025 10:21:02 +0000 (11:21 +0100)] 
gccrs: check for invalid const calls during code-gen

Closure calls are not const so this is invalid. This patch fixes two bugs

  1. Make the look at the parent context optional for generics
  2. Ensure we look for non const calls during call expr code-gen

Fixes Rust-GCC#3551

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): add const call check
* backend/rust-compile-item.cc (CompileItem::visit): ensure we upfront compile types where
possible
* backend/rust-compile-item.h: update header
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): make parent ctx optional

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Fix TupleStructPattern compilation throwing error
Zhi Heng [Sun, 22 Jun 2025 09:38:06 +0000 (17:38 +0800)] 
gccrs: Fix TupleStructPattern compilation throwing error

Code for TupleStructPattern compilation previously only assumes that it is derived from
an enum. This commit adds a check for that, and compiles non-enum TupleStructPatterns
similarly to TuplePatterns if it is not an enum.

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc(CompilePatternCheckExpr::visit(TupleStructPattern)):
Fix error thrown when compiling non-enum TupleStructPattern.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: nr2.0: Fix resolution of constant items
Owen Avery [Fri, 20 Jun 2025 16:04:29 +0000 (12:04 -0400)] 
gccrs: nr2.0: Fix resolution of constant items

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit):
Call DefaultASTVisitor::visit even on ConstantItem instances
without expressions.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove issue-3642.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Add unify rules for fnptr and closures
Philip Herron [Sat, 21 Jun 2025 15:08:28 +0000 (16:08 +0100)] 
gccrs: Add unify rules for fnptr and closures

Its valid to unify a closure to an fnptr as we are working on the
fn traits. There are still other issues but this is part of the patch set.

gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::expect_fnptr): add unify rules

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Fix silly ordering bug in trait reference resolution
Philip Herron [Fri, 20 Jun 2025 17:21:30 +0000 (18:21 +0100)] 
gccrs: Fix silly ordering bug in trait reference resolution

Ensure proper ordering when resolving trait references to prevent
incorrect type resolution in certain contexts.

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.cc (TraitReference::on_resolved): ensure associated
types are done first
* typecheck/rust-hir-type-check-type.cc: Update call site.

gcc/testsuite/ChangeLog:

* rust/compile/silly-order-bug.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Fix bug with bad type bindings not looking at super traits
Philip Herron [Sat, 21 Jun 2025 13:58:49 +0000 (14:58 +0100)] 
gccrs: Fix bug with bad type bindings not looking at super traits

When resolving type bounds, we need to examine super traits to properly
determine if type bindings are valid in the current context.

gcc/rust/ChangeLog:

* typecheck/rust-tyty-bounds.cc: Check super traits for type bindings.
* typecheck/rust-tyty.h: Add helper methods for bound checking.

6 days agogccrs: Refactor marker builtin trait assembly
Philip Herron [Sat, 21 Jun 2025 14:40:50 +0000 (15:40 +0100)] 
gccrs: Refactor marker builtin trait assembly

Rename assemble_sized_builtin to assemble_marker_builtins and reorganize
the type matching to properly handle function pointers and closures with
their associated traits (Fn, FnMut, FnOnce).

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-bounds.h: Rename method.
* typecheck/rust-tyty-bounds.cc: Refactor marker trait assembly
and add proper Fn trait handling for function types.

6 days agogccrs: Cleanup and refactor method resolution
Philip Herron [Tue, 17 Jun 2025 19:22:34 +0000 (20:22 +0100)] 
gccrs: Cleanup and refactor method resolution

Refactor the dot operator implementation to improve code organization
and maintainability while preserving existing functionality.

gcc/rust/ChangeLog:

* typecheck/rust-hir-dot-operator.cc: Major refactoring and cleanup.
* typecheck/rust-hir-dot-operator.h: Add new helper methods.

6 days agogccrs: Fix cyclical projection to placeholder
Philip Herron [Sat, 21 Jun 2025 13:22:04 +0000 (14:22 +0100)] 
gccrs: Fix cyclical projection to placeholder

Prevent infinite loops when projecting associated types by properly
handling cyclical references with placeholder types.

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc: Add cyclical projection
protection.

6 days agogccrs: Ensure we look at the bounds behind a reference
Philip Herron [Fri, 20 Jun 2025 16:49:32 +0000 (17:49 +0100)] 
gccrs: Ensure we look at the bounds behind a reference

When type checking expressions that involve references, we need to
examine the bounds of the referenced type to properly resolve traits
and methods.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc: Look at bounds behind
references.
* typecheck/rust-hir-type-check-expr.h: Add helper method.

6 days agogccrs: Move AST desugaring into expansion phase
Owen Avery [Sat, 24 May 2025 18:32:10 +0000 (14:32 -0400)] 
gccrs: Move AST desugaring into expansion phase

This fixes some issues with name resolution 2.0.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Move
AST desugaring to...
(Session::expansion): ...here and add a final TopLevel pass
afterwards.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Add test case showing RPIT working to close issue
Philip Herron [Thu, 19 Jun 2025 18:37:10 +0000 (19:37 +0100)] 
gccrs: Add test case showing RPIT working to close issue

Fixes Rust-GCC#1486

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Fix ICE when constant is missing and expression
Philip Herron [Wed, 18 Jun 2025 17:25:14 +0000 (18:25 +0100)] 
gccrs: Fix ICE when constant is missing and expression

This is an invalid test case and doesnt work with rustc, we dont fully pick
up the errors. Nr2 does handle this and puts out an extra good diagnostic
but the old NR doesnt so for now i added this to the exclude list and then
when we remove old name resolver this issue goes away.

Fixes Rust-GCC#3642

gcc/rust/ChangeLog:

* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): check for has_expr
* hir/rust-hir-dump.cc (Dump::visit): likewise
* hir/tree/rust-hir-item.h: add has_expr helper
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): check for has_expr
* resolve/rust-ast-resolve-stmt.h: likewise
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): likewise

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 puts out an extra error
* rust/compile/issue-3642.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Adjust external crate lowering and type checking
Owen Avery [Mon, 16 Jun 2025 21:04:22 +0000 (17:04 -0400)] 
gccrs: Adjust external crate lowering and type checking

The 2.0 name resolver is provided through
ImmutableNameResolutionContext after it is done being mutated. The
typechecker attempts to use ImmutableNameResolutionContext, so it needs
to be run after ImmutableNameResolutionContext has been initialized
(after all name resolution has been completed). Additionally, although I
haven't seen any issues with lowering AST to HIR before name resolution
2.0 is complete, it makes sense to perform all lowering in lockstep as
well.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Add
visitor for ExternCrate.
* hir/rust-ast-lower-item.h (ASTLoweringItem::visit): Likewise.
* rust-session-manager.cc (Session::load_extern_crate): Avoid
lowering or type resolving external crates here.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
Add visitor for ExternCrate.
* typecheck/rust-hir-type-check-item.h (TypeCheckItem::visit):
Replace empty definition with a declaration.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Fix execute testsuite
Owen Avery [Tue, 17 Jun 2025 14:42:05 +0000 (10:42 -0400)] 
gccrs: Fix execute testsuite

Our non-torture execute tests haven't actually been running.

gcc/testsuite/ChangeLog:

* rust/execute/black_box.rs: Return 0 from main.
* rust/execute/match-identifierpattern-enum.rs: Move to...
* rust/execute/xfail/match-identifierpattern-enum.rs: ...here.
* rust/execute/execute.exp: New file.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Fix issues around PartialEq Eq Ord Partial Ord
Philip Herron [Tue, 17 Jun 2025 10:32:21 +0000 (11:32 +0100)] 
gccrs: Fix issues around PartialEq Eq Ord Partial Ord

There is still an issue with derive on PartialOrd but this adds good tests
and fixes a bug we had handling the default Rhs = Self generic type param
substitutions on the comparison traits.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (ParamType::handle_substitions): make this consistent

gcc/testsuite/ChangeLog:

* rust/compile/bug-with-default-generic.rs: New test.
* rust/execute/torture/partial-eq-1.rs: New test.
* rust/execute/torture/partial-eq-2.rs: New test.
* rust/execute/torture/partial-eq-3.rs: New test.
* rust/execute/torture/partial-eq-4.rs: New test.
* rust/execute/torture/partial-ord-1.rs: New test.
* rust/execute/torture/partial-ord-2.rs: New test.
* rust/execute/torture/partial-ord-3.rs: New test.
* rust/execute/torture/partial-ord-4.rs: New test.
* rust/execute/torture/partial-ord-5.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: nr2.0: Update IdentifierPattern's subpattern name resolution
Zhi Heng [Mon, 16 Jun 2025 13:30:44 +0000 (21:30 +0800)] 
gccrs: nr2.0: Update IdentifierPattern's subpattern name resolution

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit(IdentifierPattern)):
Remove redundant subpattern check.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: Implement compilation of IdentifierPattern's subpattern bindings
Zhi Heng [Fri, 13 Jun 2025 14:45:23 +0000 (22:45 +0800)] 
gccrs: Implement compilation of IdentifierPattern's subpattern bindings

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc: Add support for IdentifierPattern's
subpattern under CompilePatternBindings.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: Implement name resolution for IdentifierPattern's subpattern
Zhi Heng [Fri, 13 Jun 2025 14:19:33 +0000 (22:19 +0800)] 
gccrs: Implement name resolution for IdentifierPattern's subpattern

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-pattern.cc: Implement name resolution for
IdentifierPattern's subpattern.
* resolve/rust-late-name-resolver-2.0.cc: Ditto, but for nr2.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: Rename get_pattern_to_bind to get_subpattern
Zhi Heng [Wed, 11 Jun 2025 13:48:32 +0000 (21:48 +0800)] 
gccrs: Rename get_pattern_to_bind to get_subpattern

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc: Rename get_pattern_to_bind to get_subpattern
* ast/rust-ast-visitor.cc: Ditto.
* ast/rust-pattern.h: Ditto.
* expand/rust-cfg-strip.cc: Ditto.
* hir/rust-ast-lower-pattern.cc: Ditto.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: nr2.0: Adjust lookup of associated items
Owen Avery [Fri, 9 May 2025 18:37:55 +0000 (14:37 -0400)] 
gccrs: nr2.0: Adjust lookup of associated items

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit):
Adjust scoping of trait definitions and their generic
parameters.
* resolve/rust-forever-stack.hxx (ForeverStack::get): Prevent
lookups inside TraitOrImpl ribs.
(ForeverStack::resolve_segments): Prevent lookups of the first
segment inside TraitOrImpl ribs.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Improve HIR dumps for patterns
Zhi Heng [Sun, 15 Jun 2025 07:07:54 +0000 (15:07 +0800)] 
gccrs: Improve HIR dumps for patterns

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc: Change pattern dumps to use visit_field.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: chore: Fix formatting
Arthur Cohen [Wed, 11 Jun 2025 09:12:55 +0000 (11:12 +0200)] 
gccrs: chore: Fix formatting

gcc/rust/ChangeLog:

* expand/rust-derive.cc: Fix formatting after fork update.

6 days agogccrs: derive(Ord, Eq): Use different node IDs for variant paths
Arthur Cohen [Tue, 10 Jun 2025 13:03:03 +0000 (15:03 +0200)] 
gccrs: derive(Ord, Eq): Use different node IDs for variant paths

gcc/rust/ChangeLog:

* expand/rust-derive-cmp-common.cc (EnumMatchBuilder::tuple): Create two different
variant paths.
(EnumMatchBuilder::strukt): Likewise.
* expand/rust-derive-cmp-common.h: Change API.
* expand/rust-derive-ord.cc (DeriveOrd::visit_enum): Use new EnumMatchBuilder API.
* expand/rust-derive-partial-eq.cc (DerivePartialEq::visit_enum): Likewise.

gcc/testsuite/ChangeLog:

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

6 days agogccrs: derive(Ord): Handle unit structs properly
Arthur Cohen [Tue, 27 May 2025 12:23:39 +0000 (14:23 +0200)] 
gccrs: derive(Ord): Handle unit structs properly

gcc/rust/ChangeLog:

* expand/rust-derive-ord.cc (DeriveOrd::make_cmp_arms): Use new make_equal function.
(DeriveOrd::make_equal): New function.
(DeriveOrd::recursive_match): Handle the unit struct/tuple case.
* expand/rust-derive-ord.h: Declare make_equal.

6 days agogccrs: derive(Ord): Fix cmp call to use references instead of values
Arthur Cohen [Mon, 28 Apr 2025 09:35:53 +0000 (11:35 +0200)] 
gccrs: derive(Ord): Fix cmp call to use references instead of values

gcc/rust/ChangeLog:

* expand/rust-derive-ord.cc (DeriveOrd::cmp_call): Use references.

6 days agogccrs: derive(Ord): Fix condition for matching on Option::Some instead
Arthur Cohen [Wed, 23 Apr 2025 10:37:57 +0000 (12:37 +0200)] 
gccrs: derive(Ord): Fix condition for matching on Option::Some instead

gcc/rust/ChangeLog:

* expand/rust-derive-ord.cc (DeriveOrd::make_cmp_arms): Fix condition.

6 days agogccrs: derive(Ord, PartialOrd): Finish implementation
Arthur Cohen [Tue, 22 Apr 2025 20:22:29 +0000 (22:22 +0200)] 
gccrs: derive(Ord, PartialOrd): Finish implementation

gcc/rust/ChangeLog:

* expand/rust-derive-ord.cc: Finish implementation for enums.
* expand/rust-derive-ord.h: Likewise.

6 days agogccrs: derive(PartialEq): Implement proper discriminant comparison
Arthur Cohen [Tue, 22 Apr 2025 20:21:01 +0000 (22:21 +0200)] 
gccrs: derive(PartialEq): Implement proper discriminant comparison

And use the new EnumMatchBuilder class to do so.

gcc/rust/ChangeLog:

* expand/rust-derive-partial-eq.cc (DerivePartialEq::eq_fn): Change signature.
(DerivePartialEq::visit_tuple): Use new eq_fn API.
(DerivePartialEq::visit_struct): Likewise.
(DerivePartialEq::visit_enum): Implement proper discriminant comparison.
* expand/rust-derive-partial-eq.h: Change eq_fn signature.

gcc/testsuite/ChangeLog:

* rust/execute/torture/derive-partialeq2.rs: Add declaration for
discriminant_value.

6 days agogccrs: derive-cmp: Add EnumMatchBuilder class
Arthur Cohen [Tue, 22 Apr 2025 20:17:18 +0000 (22:17 +0200)] 
gccrs: derive-cmp: Add EnumMatchBuilder class

gcc/rust/ChangeLog:

* expand/rust-derive-cmp-common.h (class EnumMatchBuilder): New helper class.
* expand/rust-derive-cmp-common.cc (EnumMatchBuilder::tuple): New function.
(EnumMatchBuilder::strukt): New function.

6 days agogccrs: ast-builder: Make location public
Arthur Cohen [Tue, 22 Apr 2025 20:18:01 +0000 (22:18 +0200)] 
gccrs: ast-builder: Make location public

gcc/rust/ChangeLog:

* ast/rust-ast-builder.h: Put `loc` member in public.

6 days agogccrs: derive(Ord): Add handling for ordering of discriminant values
Arthur Cohen [Tue, 22 Apr 2025 18:03:16 +0000 (20:03 +0200)] 
gccrs: derive(Ord): Add handling for ordering of discriminant values

gcc/rust/ChangeLog:

* expand/rust-derive-ord.cc (DeriveOrd::cmp_call): New function.
(DeriveOrd::recursive_match): Use it.
(DeriveOrd::visit_enum): Likewise.
* expand/rust-derive-ord.h: Declare it.

6 days agogccrs: derive(Hash): Use new Builder API
Arthur Cohen [Tue, 22 Apr 2025 18:02:56 +0000 (20:02 +0200)] 
gccrs: derive(Hash): Use new Builder API

gcc/rust/ChangeLog:

* expand/rust-derive-hash.cc (DeriveHash::visit_enum): Use new APIs.

6 days agogccrs: builder: Add Builder::discriminant_value
Arthur Cohen [Tue, 22 Apr 2025 18:02:47 +0000 (20:02 +0200)] 
gccrs: builder: Add Builder::discriminant_value

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::discriminant_value): New function.
* ast/rust-ast-builder.h: Declare it.

6 days agogccrs: derive(Ord, PartialOrd): Handle tuples properly
Arthur Cohen [Fri, 18 Apr 2025 16:30:46 +0000 (18:30 +0200)] 
gccrs: derive(Ord, PartialOrd): Handle tuples properly

gcc/rust/ChangeLog:

* expand/rust-derive-ord.cc (is_last): Remove.
(DeriveOrd::visit_tuple): Fix implementation.

6 days agogccrs: derive(PartialEq): chore: Refactor using new SelfOther APIs
Arthur Cohen [Fri, 18 Apr 2025 16:30:19 +0000 (18:30 +0200)] 
gccrs: derive(PartialEq): chore: Refactor using new SelfOther APIs

gcc/rust/ChangeLog:

* expand/rust-derive-cmp-common.cc (SelfOther::indexes): Fix formatting.
(SelfOther::fields): Make iterator const.
* expand/rust-derive-cmp-common.h (struct SelfOther): New declaration for indexes.
* expand/rust-derive-partial-eq.cc (DerivePartialEq::visit_tuple): Use the new API.
(DerivePartialEq::visit_struct): Likewise.

6 days agogccrs: derive(Ord, PartialOrd): Implement proper recursive match logic
Arthur Cohen [Fri, 18 Apr 2025 16:19:31 +0000 (18:19 +0200)] 
gccrs: derive(Ord, PartialOrd): Implement proper recursive match logic

gcc/rust/ChangeLog:

* expand/rust-derive-ord.cc (DeriveOrd::make_cmp_arms): New function.
(is_last): Likewise.
(recursive_match): Likewise.
(DeriveOrd::recursive_match): Likewise.
(DeriveOrd::visit_struct): Add proper implementation.
(DeriveOrd::visit_union): Likewise.
* expand/rust-derive-ord.h: Declare these new functions.

6 days agogccrs: derive(PartialEq): Use that common class
Arthur Cohen [Fri, 18 Apr 2025 16:19:18 +0000 (18:19 +0200)] 
gccrs: derive(PartialEq): Use that common class

gcc/rust/ChangeLog:

* expand/rust-derive-partial-eq.cc (DerivePartialEq::tuple_indexes): Remove.
(DerivePartialEq::field_acccesses): Remove.
(DerivePartialEq::visit_tuple): Use new API.
(DerivePartialEq::visit_struct): Likewise.
* expand/rust-derive-partial-eq.h: Remove declarations.

6 days agogccrs: derive: Add common comparison derive class
Arthur Cohen [Fri, 18 Apr 2025 16:18:40 +0000 (18:18 +0200)] 
gccrs: derive: Add common comparison derive class

gcc/rust/ChangeLog:

* expand/rust-derive-cmp-common.cc: New file.
* expand/rust-derive-cmp-common.h: New file.
* Make-lang.in: Compile them.

6 days agogccrs: builder: Add match_case() function and new block() one
Arthur Cohen [Fri, 18 Apr 2025 16:18:06 +0000 (18:18 +0200)] 
gccrs: builder: Add match_case() function and new block() one

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::block): New function.
(Builder::match_case): Likewise.
* ast/rust-ast-builder.h: Declare them.

6 days agogccrs: derive: Add const generics when deriving impls
Arthur Cohen [Wed, 9 Apr 2025 09:18:06 +0000 (11:18 +0200)] 
gccrs: derive: Add const generics when deriving impls

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::new_const_param): New function.
* ast/rust-ast-builder.h (vec): New function for creating 3 elts vector.
* expand/rust-derive.cc: Use the new_const_param builder.
* ast/rust-path.h: Add get_default_value() method.

6 days agogccrs: derive(Ord, PartialOrd): Add base for deriving them.
Arthur Cohen [Fri, 7 Mar 2025 17:08:34 +0000 (17:08 +0000)] 
gccrs: derive(Ord, PartialOrd): Add base for deriving them.

gcc/rust/ChangeLog:

* Make-lang.in: Compile it.
* expand/rust-derive.cc (DeriveVisitor::derive): Call them.
* expand/rust-derive-ord.cc: New file.
* expand/rust-derive-ord.h: New file.

6 days agogccrs: derive: chore: Add missing override qualifiers
Arthur Cohen [Fri, 7 Mar 2025 14:31:38 +0000 (14:31 +0000)] 
gccrs: derive: chore: Add missing override qualifiers

gcc/rust/ChangeLog:

* expand/rust-derive-clone.h: Add missing override qualifiers to DeriveVisitor methods.
* expand/rust-derive-copy.h: Likewise.
* expand/rust-derive-eq.h: Likewise.
* expand/rust-derive-hash.h: Likewise.
* expand/rust-derive-partial-eq.h: Likewise.

6 days agogccrs: rib: Add all kinds of Ribs to pretty-printing
Arthur Cohen [Tue, 27 May 2025 11:25:01 +0000 (13:25 +0200)] 
gccrs: rib: Add all kinds of Ribs to pretty-printing

gcc/rust/ChangeLog:

* resolve/rust-rib.h: Add missing switch cases.

6 days agogccrs: Fix bug in query type stopping PartialOrd
Philip Herron [Sat, 14 Jun 2025 19:34:33 +0000 (20:34 +0100)] 
gccrs: Fix bug in query type stopping PartialOrd

There was a complex recurisve type query hierarchy here but the type was
resolved so we can just do an early return here

gcc/rust/ChangeLog:

* typecheck/rust-type-util.cc (query_type): early return.

gcc/testsuite/ChangeLog:

* rust/execute/torture/basic_partial_ord1.rs: New test.
* rust/execute/torture/basic_partial_ord2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Fix bad type canonicalization on ARRAY_TYPES
Philip Herron [Tue, 27 May 2025 12:47:04 +0000 (13:47 +0100)] 
gccrs: Fix bad type canonicalization on ARRAY_TYPES

Fixes Rust-GCC#3660

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): reuse GCC's build_array_type

gcc/testsuite/ChangeLog:

* rust/compile/const_generics_3.rs:
* rust/compile/issue-3660.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: nr2.0: Adjust alternate identifier handling
Owen Avery [Fri, 23 May 2025 20:29:59 +0000 (16:29 -0400)] 
gccrs: nr2.0: Adjust alternate identifier handling

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(visit_identifier_as_pattern): Make sure to map identifiers
inside or-bindings to prior identifiers.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Rename IdentifierPattern's to_bind to subpattern
Zhi Heng [Mon, 9 Jun 2025 12:18:28 +0000 (20:18 +0800)] 
gccrs: Rename IdentifierPattern's to_bind to subpattern

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc: Rename to_bind to subpattern.
* ast/rust-ast-visitor.cc: Ditto.
* ast/rust-pattern.cc: Ditto.
* ast/rust-pattern.h: Ditto.
* backend/rust-compile-pattern.cc: Ditto.
* expand/rust-cfg-strip.cc: Ditto.
* hir/rust-ast-lower-pattern.cc: Ditto.
* hir/rust-hir-dump.cc: Ditto.
* hir/tree/rust-hir-pattern.h: Ditto.
* hir/tree/rust-hir.cc: Ditto.
* typecheck/rust-hir-type-check-pattern.cc: Ditto.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: Support compilation of IdentifierPattern's subpatterns
Zhi Heng [Sat, 7 Jun 2025 14:24:03 +0000 (22:24 +0800)] 
gccrs: Support compilation of IdentifierPattern's subpatterns

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc: Add CheckExpr compilation for
IdentifierPattern with subpattern.
* backend/rust-compile-pattern.h: Modify IdentifierPattern's
visit func to support the above.
* typecheck/rust-hir-type-check-pattern.cc: Add typechecking
support for the changes above.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: nr2.0: Fix closure parameter scoping
Owen Avery [Thu, 15 May 2025 01:40:04 +0000 (21:40 -0400)] 
gccrs: nr2.0: Fix closure parameter scoping

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc
(DefaultResolver::visit_closure_params): New member function
definition.
(DefaultResolver::visit): New visiting function definition for
ClosureExpr called from visiting functions for ClosureExprInner
and ClosureExprInnerTyped.
* resolve/rust-default-resolver.h
(DefaultResolver::visit_closure_params): New member function
declaration.
(DefaultResolver::visit): New visiting function declaration for
ClosureExpr.
* resolve/rust-late-name-resolver-2.0.cc (add_captures): Remove
function.
(Late::visit): New visiting function definition for ClosureExpr,
remove visiting function definitions for ClosureExprInner and
ClosureExprInnerTyped.
(Late::visit_closure_params): New member function definition.
* resolve/rust-late-name-resolver-2.0.h (Late::visit): New
visiting function declaration for ClosureExpr, remove visiting
function declarations for ClosureExprInner and
ClosureExprInnerTyped.
(Late::visit_closure_params): New member function declaration.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: nr2.0: Improve handling of single segment paths
Owen Avery [Sat, 29 Mar 2025 23:50:28 +0000 (19:50 -0400)] 
gccrs: nr2.0: Improve handling of single segment paths

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx (ForeverStack::resolve_path):
Handle single segment paths "crate", "self", and "super".

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: nr2.0: Adjust pub_restricted tests
Owen Avery [Sun, 18 May 2025 02:26:20 +0000 (22:26 -0400)] 
gccrs: nr2.0: Adjust pub_restricted tests

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.
* rust/compile/pub_restricted_1.rs: Adjust expected error
messages and only run with name resolution 2.0 enabled.
* rust/compile/pub_restricted_2.rs: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: nr2.0: Improve StructPatternFieldIdent handling
Owen Avery [Fri, 23 May 2025 20:19:59 +0000 (16:19 -0400)] 
gccrs: nr2.0: Improve StructPatternFieldIdent handling

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Use
visit_identifier_as_pattern to handle IdentifierPattern and
StructPatternFieldIdent.
(visit_identifier_as_pattern): New function.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Add new function ClosureExpr::get_definition_expr
Owen Avery [Mon, 9 Jun 2025 21:11:39 +0000 (17:11 -0400)] 
gccrs: Add new function ClosureExpr::get_definition_expr

gcc/rust/ChangeLog:

* ast/rust-expr.h (ClosureExpr::get_definition_expr): New
virtual member function.
(ClosureExprInner::get_definition_expr): Add override specifier.
(ClosureExprInnerTyped::get_definition_block): Rename to...
(ClosureExprInnerTyped::get_definition_expr): ...here and add
override specifier.

* ast/rust-ast-collector.cc (TokenCollector::visit): Handle
rename of ClosureExprInnerTyped::get_definition_block to
ClosureExprInnerTyped::get_definition_expr.
* 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-expr.cc (ASTLoweringExpr::visit): Likewise.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit):
Likewise.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit):
Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: nr2.0: Separate out canonical path handling
Owen Avery [Fri, 2 May 2025 22:38:50 +0000 (18:38 -0400)] 
gccrs: nr2.0: Separate out canonical path handling

This should improve our canonical path handling, without requiring
further tweaks to ForeverStack. This may also help if, in the future, we
have to move canonical path calculation to later compilation phases for
proper handling of generics.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc
(HIRCompileBase::compile_function): Since canonical paths
returned from nr2.0 now include the crate name, avoid prepending
the crate name again.

* backend/rust-compile-implitem.cc (CompileTraitItem::visit):
Use NameResolutionContext::to_canonical_path instead of
ForeverStack::to_canonical_path.
* backend/rust-compile-item.cc (CompileItem::visit): 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.cc
(TraitItemReference::get_type_from_fn): Likewise.

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Add
Crate and EnumItem instance visitors, handle canonical path
context scoping.
* resolve/rust-default-resolver.h (DefaultResolver::visit): Add
Crate and EnumItem instance visitors.
* resolve/rust-early-name-resolver-2.0.cc (Early::go): Visit
instances of Crate using the virtual member function visit.
* resolve/rust-forever-stack.h
(ForeverStack::to_canonical_path): Remove function declaration.
* resolve/rust-forever-stack.hxx
(ForeverStack::to_canonical_path): Remove function definition.
* resolve/rust-late-name-resolver-2.0.cc (Late::go): Visit
instances of Crate using the virtual member function visit.
* resolve/rust-name-resolution-context.cc
(CanonicalPathRecordCrateRoot::as_path): New function definition.
(CanonicalPathRecordNormal::as_path): Likewise.
(CanonicalPathRecordLookup::as_path): Likewise.
(CanonicalPathRecordImpl::as_path): Likewise.
(CanonicalPathRecordTraitImpl::as_path): Likewise.
(NameResolutionContext::NameResolutionContext): Initialize
member variable canonical_ctx.
* resolve/rust-name-resolution-context.h: Include "rust-item.h".
(class NameResolutionContext): Forward declare class.
(class CanonicalPathRecord): New class.
(class CanonicalPathRecordWithParent): Likewise.
(class CanonicalPathRecordCrateRoot): Likewise.
(class CanonicalPathRecordNormal): Likewise.
(class CanonicalPathRecordLookup): Likewise.
(class CanonicalPathRecordImpl): Likewise.
(class CanonicalPathRecordTraitImpl): Likewise.
(class CanonicalPathCtx): Likewise.
(NameResolutionContext::canonical_ctx): New member variable.
(NameResolutionContext::to_canonical_path): New member function.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::go):
Visit instances of Crate with the virtual member function visit.
(TopLevel::visit): Handle canonical path context scoping for
external crates, use DefaultResolver::visit when visiting
instances of StructStruct.
* util/rust-canonical-path.h (CanonicalPath::new_seg): Take path
parameter by-value, as a duplicate instance will be constructed
regardless.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove canonical_paths1.rs.

6 days agogccrs: Lower IdentifierPattern's to_bind to HIR
Zhi Heng [Sat, 7 Jun 2025 14:30:25 +0000 (22:30 +0800)] 
gccrs: Lower IdentifierPattern's to_bind to HIR

gcc/rust/ChangeLog:

* hir/rust-ast-lower-pattern.cc: Lower of IdentifierPattern's to_bind to HIR.
* hir/rust-hir-dump.cc: Update IdentifierPattern's dump to properly show to_bind's full
full properties.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: fix: ICE when parsing unterminated raw byte strings
Vishruth-Thimmaiah [Wed, 28 May 2025 17:33:27 +0000 (23:03 +0530)] 
gccrs: fix: ICE when parsing unterminated raw byte strings

Fixes an ICE when a raw byte string is not terminated

Fixes Rust-GCC#3731

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::parse_raw_byte_string):
Fix infinite looping when a raw byte string is not terminated.

gcc/testsuite/ChangeLog:

* rust/compile/torture/unended-raw-byte-string.rs:
New test to ensure correct error message for unended raw byte string.

Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
6 days agogccrs: nr2.0: Catch Self in impl block self types
Owen Avery [Fri, 16 May 2025 02:04:34 +0000 (22:04 -0400)] 
gccrs: nr2.0: Catch Self in impl block self types

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Use
visit_impl_type to visit the self types of impl blocks.
* resolve/rust-default-resolver.h
(DefaultResolver::visit_impl_type): New member function
declaration.
* resolve/rust-late-name-resolver-2.0.cc (Late::Late):
Initialize member variable block_big_self.
(Late::visit_impl_type): New member function definition.
(Late::visit): Check for Self while inside impl block self
types.
* resolve/rust-late-name-resolver-2.0.h (Late::visit_impl_type):
New member function.
(Late::block_big_self): New member variable.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3671.rs: Remove usage of Self.
* rust/compile/nr2/exclude: Remove issue-3671.rs.
* rust/compile/self-in-impl.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: nr2.0: Improve visibility path handling
Owen Avery [Fri, 9 May 2025 00:44:47 +0000 (20:44 -0400)] 
gccrs: nr2.0: Improve visibility path handling

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h
(enum ResolutionMode): New.
(ForeverStack::get): Add a private overload that takes a
starting node as a parameter.
(ForeverStack::resolve_path): Replace boolean parameter
has_opening_scope_resolution with ResolutionMode parameter mode.
* resolve/rust-forever-stack.hxx
(ForeverStack::resolve_path): Likewise.
(ForeverStack::get): Add a private overload that takes a
starting node as a parameter.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Add Visibility visitor.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::resolve_path): Rework overloading a bit
and accept ResolutionMode parameter.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: parser: fix ICE std::out_of_range with path attrs to nonexisting path
Vishruth-Thimmaiah [Tue, 22 Apr 2025 14:34:22 +0000 (20:04 +0530)] 
gccrs: parser: fix ICE std::out_of_range with path attrs to nonexisting path

Stops an ICE from occuring when path attribute is empty

Fixes Rust-GCC#3607.

gcc/rust/ChangeLog:

* parse/rust-parse.cc (Rust::extract_module_path):
Handle empty or whitespace-only path attributes.

gcc/testsuite/ChangeLog:

* rust/compile/torture/extern_mod2.rs:
New test to ensure an error is emitted for empty path attributes.

Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
6 days agogccrs: Make ConstantItem use Identifier
Owen Avery [Wed, 4 Jun 2025 05:06:06 +0000 (01:06 -0400)] 
gccrs: Make ConstantItem use Identifier

The change to ASTLoweringExternItem is necessary, since with this patch
Identifier can be implicitly converted to std::string.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Handle
changed type of ConstantItem::identifier.
* ast/rust-ast.cc (ConstantItem::as_string): Likewise.
* ast/rust-ast.h (operator const std::string &): New member
function.
* ast/rust-item.h (ConstantItem::identifier): Change type from
std::string to Identifier.
(ConstantItem::ConstantItem): Handle changed type of identifier
field.
(ConstantItem::is_unnamed): Likewise.
(ConstantItem::get_identifier): Likewise.
* hir/rust-ast-lower-extern.h (ASTLoweringExternItem::visit):
Avoid discarding location of wildcard patterns.
* lex/rust-token.cc: Include "rust-ast.h".
(Token::make_identifier): Add overload accepting an Identifier
instance.
* lex/rust-token.h (class Identifier): Add forward declaration
in order to...
(Token::make_identifier): ...declare an overload for this static
member function.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: const-block: Add testcase
Arthur Cohen [Tue, 15 Apr 2025 11:41:41 +0000 (13:41 +0200)] 
gccrs: const-block: Add testcase

gcc/testsuite/ChangeLog:

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

6 days agogccrs: hir: Add const blocks
Arthur Cohen [Tue, 15 Apr 2025 11:34:38 +0000 (13:34 +0200)] 
gccrs: hir: Add const blocks

gcc/rust/ChangeLog:

* hir/tree/rust-hir-expr.h: New classes.
* hir/tree/rust-hir-full-decls.h: Likewise.
* hir/tree/rust-hir.cc: Handle AnonConst and ConstBlock.
* backend/rust-compile-block.cc: Likewise.
* backend/rust-compile-block.h: Likewise.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-expr.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
* checks/errors/borrowck/rust-function-collector.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: 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-expr.cc (ASTLoweringExpr::visit): Likewise.
(translate_operand_out): Likewise.
(translate_operand_inout): Likewise.
(translate_operand_const): Likewise.
* hir/rust-ast-lower-expr.h: Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/rust-hir-dump.h: Likewise.
* hir/tree/rust-hir-expr-abstract.h: Likewise.
* hir/tree/rust-hir-expr.cc (AnonConst::AnonConst): Likewise.
(AnonConst::operator=): Likewise.
(ConstBlock::ConstBlock): Likewise.
(ConstBlock::operator=): Likewise.
* hir/tree/rust-hir-visitor.h:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
(typecheck_inline_asm_operand): Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.

6 days agogccrs: parser: Add base for parsing const blocks
Arthur Cohen [Tue, 15 Apr 2025 15:33:11 +0000 (17:33 +0200)] 
gccrs: parser: Add base for parsing const blocks

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_const_block_expr): New function.
* parse/rust-parse.h: Declare it.

6 days agogccrs: ast: Add ConstBlock and AnonConst nodes
Arthur Cohen [Wed, 9 Apr 2025 16:18:30 +0000 (18:18 +0200)] 
gccrs: ast: Add ConstBlock and AnonConst nodes

gcc/rust/ChangeLog:

* ast/rust-expr.h: Declare AnonConst and ConstBlock and use them.
* ast/rust-ast-full-decls.h: Likewise.
* ast/rust-ast.cc: Add implementation for AnonConst and ConstBlock.
* ast/rust-ast.h: Likewise.
* ast/rust-ast-collector.cc (TokenCollector::visit): Likewise.
* ast/rust-ast-collector.h: Likewise.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* ast/rust-ast-visitor.h: 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-expr.cc (translate_operand_const): Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.
* resolve/rust-ast-resolve-expr.h: Likewise.
* resolve/rust-ast-resolve-expr.cc: Likewise.

6 days agogccrs: Always emit the error highest in the type hierarchy
Philip Herron [Tue, 20 May 2025 17:44:57 +0000 (18:44 +0100)] 
gccrs: Always emit the error highest in the type hierarchy

The unify code was a bit dumb here where we always set emit_error to false for any
subtypes for example in comparing tuples we always emitted the whole tuple didnt
match the other tuple but really its much better to say expected bool got i32 because
the element types didn't match.

gcc/rust/ChangeLog:

* typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsized): dont emit error here
* typecheck/rust-unify.cc (UnifyRules::resolve_subtype): new helper to handle emit error
(UnifyRules::expect_adt): call resolve_subtype
(UnifyRules::expect_reference): likewise
(UnifyRules::expect_pointer): likewise
(UnifyRules::expect_array): likewise
(UnifyRules::expect_slice): likewise
(UnifyRules::expect_fndef): likewise
(UnifyRules::expect_fnptr): likewise
(UnifyRules::expect_tuple): likewise
(UnifyRules::expect_closure): likewise
(UnifyRules::expect_opaque): likeiwse
* typecheck/rust-unify.h: add new helper to header

gcc/testsuite/ChangeLog:

* rust/compile/traits9.rs: update errors
* rust/compile/unify-errors1.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: nr2.0: Fix IfLet pattern handling
Owen Avery [Thu, 15 May 2025 00:03:01 +0000 (20:03 -0400)] 
gccrs: nr2.0: Fix IfLet pattern handling

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc
(DefaultResolver::visit_if_let_patterns): New function
definition.
(DefaultResolver::visit): New IfLetExpr visitor definition.
* resolve/rust-default-resolver.h
(DefaultResolver::visit_if_let_patterns): New function
declaration.
(DefaultResolver::visit): New IfLetExpr visitor declaration.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove
IfLetExpr visitor definition.
(Late::visit_if_let_patterns): New function definition.
* resolve/rust-late-name-resolver-2.0.h (Late::visit): Remove
IfLetExpr visitor declaration.
(Late::visit_if_let_patterns): New function declaration.
* resolve/rust-name-resolution-context.h (BindingSource::IfLet):
New enumerator.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Initial support for Return Position Impl Trait
Philip Herron [Mon, 19 May 2025 17:02:13 +0000 (18:02 +0100)] 
gccrs: Initial support for Return Position Impl Trait

This is the initial patch for RPIT, we can build on this to handle the
more complex cases but there are enough distinct changes going on here
that it should just get merged now.

RPIT is really a sneaky generic so for example:

  fn foo() -> impl Bar {
      Baz
  }

This is represented as: fn () -> OpaqueType Bar. But when we handle the
coercion site for Baz on impl Bar when we type resolve the function we
know that the underlying type  is Baz. Note this function is _not_ generic
so its using this special OpaqueType and keeping track of the underlying type
in its ty_ref reference hir-id which will resolve to Baz.

This also means if we have a case where maybe this was in an if statement:

  fn foo(a: i32) -> impl Bar {
      if a > 10 {
        Baz
      } else {
        Qux
      }
  }

The rules of impl Bar is that Baz is handled but Baz and Qux are different
underlying types so this is not allowed. The reason is impl traits are not
generic and although from a programmer perspective the callers dont know what
the underlying type is, the compiler _knows_ what it is. So really when
you call a function and get its return position impl trait the compiler knows
what to do and does all whats nessecary to handle calling functions using that
type etc.

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): we need to resolve the
underlying type
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): just clone
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit):
ensure we monomphize to get the underlying
* typecheck/rust-tyty.cc (BaseType::destructure): handle opaque types
(OpaqueType::resolve): this is much simpler now
(OpaqueType::handle_substitions): no longer needed
* typecheck/rust-tyty.h: update header
* typecheck/rust-unify.cc (UnifyRules::expect_opaque): unify rules for opaque

gcc/testsuite/ChangeLog:

* rust/compile/bad-rpit1.rs: New test.
* rust/execute/torture/impl_rpit1.rs: New test.
* rust/execute/torture/impl_rpit2.rs: New test.
* rust/execute/torture/impl_rpit3.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Fix non canonical type bug with tuples
Philip Herron [Mon, 26 May 2025 18:30:45 +0000 (19:30 +0100)] 
gccrs: Fix non canonical type bug with tuples

When working on rpit we needed to change to use a monomorphized clone of
the result of function calls. This ended up causing a verify gimple issue
with tuples because:

  fn test<A, B>(a: A, b: B) -> (A, B)

When passing for example:

  let a = test::<i32, i32> (123, 456) -> (A=i32, B=i32)

The resulting gimple types became:

  const struct (A=i32, B=i32) vs struct (i32, i32)

We removed the VIEW_CONVERT_EXPR support to auto fix this stuff a good
while ago because it hides these kinds of issues because the type hasher
included the A=i32, B=i32 vs the i32, i32 name so updating this to use
get_name instead keeps the naming the same as well as the fields meaning
these types are 100% equivilant and therefore no conversion is required.
This only occurs because tuples are not named types we should really add
more rust specific info on our gimple TYPES.

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc (TyTyResolveCompile::visit): use get_name
* typecheck/rust-tyty.cc (TupleType::get_name): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>