]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
6 days agogccrs: fix bad monomophization of generic paths
Philip Herron [Sun, 20 Jul 2025 20:48:18 +0000 (21:48 +0100)] 
gccrs: fix bad monomophization of generic paths

When we have generic paths like T::foobar during codegen sometimes we need
to enforce an extra lookup for this generic parameter type to the mono
morphized underlying type.

Fixes Rust-GCC#3915
Fixes Rust-GCC#1247

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): do another lookup

gcc/testsuite/ChangeLog:

* rust/compile/issue-3915.rs: New test.
* rust/execute/torture/sip-hasher.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Use MacroInvocLexer in AttributeParser
Owen Avery [Tue, 8 Jul 2025 21:03:49 +0000 (17:03 -0400)] 
gccrs: Use MacroInvocLexer in AttributeParser

This should make it easier for us to handle attribute meta items of the
form <SimplePath> '=' <Expression> where the expression isn't a literal.
Some low hanging fruit remains here, but I think I should keep this
patch small as I had some trouble debugging it as-is (see:
Rust::Token::as_string vs Rust::Token::get_str vs
Rust::AST::Token::as_string).

gcc/rust/ChangeLog:

* ast/rust-ast.cc: Include "rust-macro-invoc-lexer.h".
(AttributeParser::~AttributeParser): Move function definition
here.
(AttributeParser::AttributeParser): Likewise and adjust member
initialization.
(AttributeParser::parse_meta_item_inner): Handle changes to
peek_token.
(AttributeParser::parse_literal): Likewise.
(AttributeParser::parse_simple_path_segment): Likewise.
(AttributeParser::parse_meta_item_seq): Handle changes to
AttributeParser fields.
(AttributeParser::peek_token): Move function definition here and
wrap MacroInvocLexer.
(AttributeParser::skip_token): Likewise.
* ast/rust-macro.h (class MacroInvocLexer): Forward declare.
(class Parser): Likewise.
(AttributeParser::token_stream): Remove field.
(AttributeParser::stream_pos): Likewise.
(AttributeParser::lexer): New field.
(AttributeParser::parser): Likewise.
(AttributeParser::AttributeParser): Move definition to
"rust-ast.cc".
(AttributeParser::~AttributeParser): Likewise.
(AttributeParser::peek_token): Likewise.
(AttributeParser::skip_token): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: return error node when this fails during constexpr case
Philip Herron [Fri, 18 Jul 2025 15:44:36 +0000 (16:44 +0100)] 
gccrs: return error node when this fails during constexpr case

Not adding the test case here we emit more errors than rustc for the error
type node so its just noisy and dejagnu is being a pain.

Fixes Rust-GCC#3933

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): return error_mark_node

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Add initial support for deffered operator overload resolution
Philip Herron [Fri, 18 Jul 2025 14:46:59 +0000 (15:46 +0100)] 
gccrs: Add initial support for deffered operator overload resolution

In the test case:

  fn test (len: usize) -> u64 {
     let mut i = 0;
     let mut out = 0;
     if i + 3 < len {
        out = 123;
     }
     out
  }

The issue is to determine the correct type of 'i', out is simple because it hits a
coercion site in the resturn position for u64. But 'i + 3', 'i' is an integer infer
variable and the same for the literal '3'. So when it comes to resolving the type for
the Add expression we hit the resolve the operator overload code and because of this:

  macro_rules! add_impl {
      ($($t:ty)*) => ($(
          impl Add for $t {
              type Output = $t;

              #[inline]
              #[rustc_inherit_overflow_checks]
              fn add(self, other: $t) -> $t { self + other }
          }
      )*)
  }

  add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 }

This means the resolution for 'i + 3' is ambigious because it could be any of these Add
implementations. But because we unify against the '< len' where len is defined as usize
later in the resolution we determine 'i' is actually a usize. Which means if we defer the
resolution of this operator overload in the ambigious case we can simply resolve it at the
end.

Fixes Rust-GCC#3916

gcc/rust/ChangeLog:

* hir/tree/rust-hir-expr.cc (OperatorExprMeta::OperatorExprMeta): track the rhs
* hir/tree/rust-hir-expr.h: likewise
* hir/tree/rust-hir-path.h: get rid of old comments
* typecheck/rust-hir-trait-reference.cc (TraitReference::get_trait_substs): return
references instead of copy
* typecheck/rust-hir-trait-reference.h: update header
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::ResolveOpOverload): write ambigious
operator overloads to a table and try to resolve it at the end
* typecheck/rust-hir-type-check-expr.h: new static helper
* typecheck/rust-hir-type-check.h (struct DeferredOpOverload): new model to defer resolution
* typecheck/rust-typecheck-context.cc (TypeCheckContext::lookup_operator_overload): new
(TypeCheckContext::compute_ambigious_op_overload): likewise
(TypeCheckContext::compute_inference_variables): likewise

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Fix ICE with duplicate root item main function
Philip Herron [Fri, 18 Jul 2025 15:22:44 +0000 (16:22 +0100)] 
gccrs: Fix ICE with duplicate root item main function

Rust seems to allow duplicate HIR::Item 'main' functions but it needs
to be a root item to be the true main entry point. This means we can
use the canonical path to determine if this is a root one where
its CrateName::main or CrateName::Module::main.

Fixes Rust-GCC#3978

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: check the canonical path

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Improve parsing of simple paths
Owen Avery [Tue, 15 Jul 2025 02:47:07 +0000 (22:47 -0400)] 
gccrs: Improve parsing of simple paths

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_simple_path): Be more
careful about skipping SCOPE_RESOLUTION tokens.
(Parser::parse_simple_path_segment): Allow parsing from a
starting offset.
(Parser::parse_use_tree): Handle a non-skipped SCOPE_RESOLUTION
token.
* parse/rust-parse.h (Parser::parse_simple_path_segment): Add
parameter for parsing from a starting offset.

gcc/testsuite/ChangeLog:

* rust/compile/parse_simple_path_fail_1.rs: New test.
* rust/compile/parse_simple_path_fail_2.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 days agogccrs: Add test case to show issue is fixed
Philip Herron [Fri, 18 Jul 2025 15:11:59 +0000 (16:11 +0100)] 
gccrs: Add test case to show issue is fixed

Fixes Rust-GCC#3524

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Reject loop in const/static context
lishin [Wed, 16 Jul 2025 00:39:48 +0000 (01:39 +0100)] 
gccrs: Reject loop in const/static context

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Add a catch for const/static.

gcc/testsuite/ChangeLog:

* rust/compile/loop_constant_context.rs: New test.
* rust/compile/issue-3618.rs:

Signed-off-by: lishin <lishin1008@gmail.com>
6 days agogccrs: Implement compilation for SlicePattern matching against ArrayType scrutinee
Yap Zhi Heng [Thu, 17 Jul 2025 14:13:32 +0000 (22:13 +0800)] 
gccrs: Implement compilation for SlicePattern matching against ArrayType scrutinee

Example GIMPLE output from compiling testsuite/rust/compile/match-pattern-array.rs:

  ...
  a[0] = 0;
  a[1] = 1;
  RUSTTMP.3 = a;
  _1 = RUSTTMP.3[0];
  _2 = _1 == 0;
  _3 = RUSTTMP.3[1];
  _4 = _3 == 1;
  _5 = _2 & _4;
  if (_5 != 0) goto <D.122>; else goto <D.123>;
  <D.122>:
  {
    {

}
}
  goto <D.117>;
  }
  <D.123>:
...

gcc/rust/ChangeLog:

* rust-backend.h: New size_constant_expression function.
* rust-gcc.cc: Implementation of size_constant_expression function to generate tree node
for array access.
* backend/rust-compile-pattern.h: Remove empty visits for SlicePattern.
* backend/rust-compile-pattern.cc: Implement SlicePattern check expression & binding
compilation against ArrayType scrutinee.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: Add size checking to SlicePattern
Yap Zhi Heng [Fri, 11 Jul 2025 14:29:31 +0000 (22:29 +0800)] 
gccrs: Add size checking to SlicePattern

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc(TypeCheckPattern::visit(SlicePattern)):
Implement size checking for SlicePattern when type checking against array parent

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: Add test case showing all derives working on enum
Philip Herron [Fri, 11 Jul 2025 12:51:10 +0000 (13:51 +0100)] 
gccrs: Add test case showing all derives working on enum

We have more complex test cases already but this will close out this issue.

Fixes Rust-GCC#2005

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: attributes: Add #[test] and #[simd_test]
Arthur Cohen [Fri, 4 Jul 2025 14:19:44 +0000 (16:19 +0200)] 
gccrs: attributes: Add #[test] and #[simd_test]

gcc/rust/ChangeLog:

* util/rust-attribute-values.h: Add declarations for them.
* util/rust-attributes.cc: Add definitions.

6 days agogccrs: Add test case to show issue is fixed
Philip Herron [Fri, 11 Jul 2025 11:20:04 +0000 (12:20 +0100)] 
gccrs: Add test case to show issue is fixed

Fixes Rust-GCC#1048

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Add test case to show we emit better errors now
Philip Herron [Fri, 11 Jul 2025 09:35:38 +0000 (10:35 +0100)] 
gccrs: Add test case to show we emit better errors now

Fixes Rust-GCC#3144

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: add test case to show issue is fixed
Philip Herron [Fri, 11 Jul 2025 09:16:36 +0000 (10:16 +0100)] 
gccrs: add test case to show issue is fixed

Fixes Rust-GCC#3599

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Fix ICE when handling bad constructor
Philip Herron [Thu, 10 Jul 2025 21:58:21 +0000 (22:58 +0100)] 
gccrs: Fix ICE when handling bad constructor

We just had a typo returning ok true when it should have been false.

Fixes Rust-GCC#3876

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::visit): fix typo

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Fix cast rules logic to try simple casts then fall back to coercions
Philip Herron [Thu, 10 Jul 2025 18:24:37 +0000 (19:24 +0100)] 
gccrs: Fix cast rules logic to try simple casts then fall back to coercions

This case:

    let i = 1;
    let j = i as i64;

'i' is meant to default to i32 but the inference was making both of these
i64 because the code was prefering coercion logic which can end up with a
default unify which causes the ?integer to unify with i64 making them both
i64.

But all we need to do is allow the simple cast rules to run first then
fallback to coercions but special consideration has to be made to ensure
that if there are dyn objects needed then this needs a unsize coercion, but
also we need to ensure the underlying types are a valid simple cast too
otherwise these also need to fallback to the coercion code.

Fixes Rust-GCC#2680

gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::resolve): optional emit_error flag
(TypeCastRules::check): try the simple cast rules then fallback to coercions
(TypeCastRules::check_ptr_ptr_cast): ensure the underlying's
(TypeCastRules::emit_cast_error): make this a static helper
* typecheck/rust-casts.h: new emit_error prototype

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: nr2.0: Check before visiting a for-loop's label
Arthur Cohen [Wed, 9 Jul 2025 09:46:10 +0000 (11:46 +0200)] 
gccrs: nr2.0: Check before visiting a for-loop's label

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Check for a label
before visiting it.

6 days agogccrs: Fix bad bounds checking for PartialOrd
Philip Herron [Fri, 27 Jun 2025 16:13:29 +0000 (17:13 +0100)] 
gccrs: Fix bad bounds checking for PartialOrd

This was a nasty issue to debug, the issue was very eager type bounds
checking. So for example:

  pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs>

The super trait of PartialEq<Rhs> is a generic substitution and we reuse
our bounds code here for normal generic bounds and generics an invalid
bounds check was occuring when PartialEq<Rhs> was getting substituted becase
this is a trait doing proper bounds checking is not valid here because this
is telling us about the bounds in this case.

Fixes Rust-GCC#3836

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): track is super trait
* typecheck/rust-hir-type-bounds.h: refactor bounds scan
* typecheck/rust-hir-type-check-base.h: track from super trait
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::is_bound_satisfied_for_type): refactor
(TypeBoundsProbe::scan): likewise
(TypeBoundPredicate::apply_generic_arguments): likewise
* typecheck/rust-tyty-subst.cc: optional bounds checking on parm subst
* typecheck/rust-tyty-subst.h: likewise
* typecheck/rust-tyty.h: likewise

gcc/testsuite/ChangeLog:

* rust/compile/derive_partial_ord1.rs: this is now fully supported
* rust/execute/torture/basic_partial_ord1.rs: add missing i32 impl
* rust/execute/torture/basic_partial_ord2.rs: likewise
* rust/compile/issue-3836.rs: New test.
* rust/execute/torture/issue-3836.rs: New test.
* rust/execute/torture/partial-ord-6.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
6 days agogccrs: Fix narrowing of Loan (size_t) into LoanId (uint32)
Marc Poulhiès [Thu, 3 Jul 2025 21:29:48 +0000 (23:29 +0200)] 
gccrs: Fix narrowing of Loan (size_t) into LoanId (uint32)

Fix narrowing:

  -../../gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc:145:46:
  warning: narrowing conversion of ‘loan’ from ‘Rust::Polonius::Loan’ {aka
  ‘long unsigned int’} to ‘uint32_t’ {aka ‘unsigned int’} [-Wnarrowing]

gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-place.h (LoanId::value): Make
it size_t to match Loan's base type.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
6 days agogccrs: Improve LiteralPattern type checking
Yap Zhi Heng [Tue, 8 Jul 2025 14:15:09 +0000 (22:15 +0800)] 
gccrs: Improve LiteralPattern type checking

This change is made to ensure that LiteralPatterns in SlicePattern are type-checked
against the scrutinee array/slice's element type properly.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc(TypeCheckPattern::visit(LiteralPattern)):
Check LiteralPattern's type against its parent.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
6 days agogccrs: Add type checking for SlicePattern
Yap Zhi Heng [Tue, 8 Jul 2025 14:10:46 +0000 (22:10 +0800)] 
gccrs: Add type checking for SlicePattern

This commit implements basic type checking support for SlicePattern, based on rustc's
check_pat_slice function.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit(SlicePattern)):
Implement initial type checking for SlicePattern.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
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>