aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite
AgeCommit message (Collapse)AuthorFilesLines
2025-08-05gccrs: desugar: Add base for desugaring while-let loopsArthur Cohen1-0/+109
gcc/rust/ChangeLog: * Make-lang.in: * ast/rust-expression-yeast.cc (ExpressionYeast::dispatch_loops): Call DesugarWhileLet. * ast/rust-desugar-while-let.cc: New file. * ast/rust-desugar-while-let.h: New file. gcc/testsuite/ChangeLog: * rust/compile/while_let1.rs: New test.
2025-08-05gccrs: hir: Add OffsetOf nodeArthur Cohen1-0/+9
gcc/rust/ChangeLog: * hir/tree/rust-hir-expr.h (class OffsetOf): New. * hir/tree/rust-hir-expr.cc: Define its methods. * hir/tree/rust-hir-expr-abstract.h: Add ExprType::OffsetOf. * hir/tree/rust-hir-full-decls.h (class OffsetOf): Declare it. * backend/rust-compile-block.h: Add handling for OffsetOf. * 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 (RUST_BIR_BUILDER_EXPR_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 (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. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/rust-hir-dump.h: Likewise. * hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Likewise. * hir/tree/rust-hir-visitor.h: Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-expr.h (RUST_HIR_TYPE_CHECK_EXPR): Likewise. gcc/testsuite/ChangeLog: * rust/compile/offset_of2.rs: New test.
2025-08-05gccrs: expand: Add parser for offset_of!() and builtin resolution.Arthur Cohen1-0/+11
gcc/rust/ChangeLog: * Make-lang.in: Compile the offset_of handler. * lang.opt: Add -frust-assume-builtin-offset-of option. * ast/rust-ast.h: Add has_str() for const_TokenPtr. * expand/rust-macro-builtins.cc: Map offset_of as builtin. * expand/rust-macro-builtins.h: Declare it. * expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Add hack for calling builtin offset_of!(). * resolve/rust-early-name-resolver-2.0.cc (Early::visit): Likewise. * expand/rust-macro-builtins-offset-of.cc: New file. gcc/testsuite/ChangeLog: * rust/compile/offset_of1.rs: New test.
2025-08-05gccrs: Fix infinite loop with missing commaPierre-Emmanuel Patry1-0/+13
A missing comma between inline assembly templates did not throw an error and looped indefinitely. gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (parse_format_strings): Emit an error when expecting a comma. gcc/testsuite/ChangeLog: * rust/compile/issue-4006.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Add execute test for variable and identifiersPierre-Emmanuel Patry2-0/+47
gcc/testsuite/ChangeLog: * rust/execute/inline_asm_inout_ident.rs: New test. * rust/execute/inline_asm_inout_var.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Implement compilation for SlicePattern against SliceType scrutineeYap Zhi Heng2-0/+34
006t.original output from compiling testsuite/rust/compile/match-slicepattern-slice.rs: ... RUSTTMP.3 = slice; if (RUSTTMP.3.len == 1 && *(RUSTTMP.3.data + 0 * 4) == 1) { { struct () RUSTTMP.4; { } goto <D.129>; } } if (RUSTTMP.3.len == 2 && *(RUSTTMP.3.data + 1 * 4) == 2) { { struct () RUSTTMP.5; { } goto <D.129>; } } if (1) { { struct () RUSTTMP.6; { } goto <D.129>; } } <D.129>:; ... gcc/rust/ChangeLog: * rust-backend.h: New slice_index_expression function. * rust-gcc.cc: Implementation of slice_index_expression to generate tree node for accessing slice elements. * backend/rust-compile-pattern.cc: Implement SlicePattern check expression & binding compilation against SliceType scrutinee. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05gccrs: desugar: Handle try-blocksArthur Cohen1-0/+89
gcc/rust/ChangeLog: * Make-lang.in: Compile it. * ast/rust-expression-yeast.cc (ExpressionYeast::dispatch): Dispatch to try-block desugar. * ast/rust-desugar-try-block.cc: New file. * ast/rust-desugar-try-block.h: New file. gcc/testsuite/ChangeLog: * rust/compile/try_block1.rs: New test.
2025-08-05gccrs: hir: Handle deferred const inference variablesArthur Cohen1-0/+7
gcc/rust/ChangeLog: * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Handle defered consts. * hir/tree/rust-hir-expr.cc (AnonConst::AnonConst): Likewise. (AnonConst::operator=): Likewise. * hir/tree/rust-hir-expr.h: Likewise. * hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. gcc/testsuite/ChangeLog: * rust/compile/deferred_const_inference.rs: New test.
2025-08-05gccrs: nr2.0: Handle glob imports of enum variants.Arthur Cohen1-0/+16
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Adapt for enums. (Early::finalize_glob_import): Likewise. * resolve/rust-early-name-resolver-2.0.h: Likewise. * resolve/rust-finalize-imports-2.0.cc (GlobbingVisitor::go): Likewise. (GlobbingVisitor::visit_module_container): New function. (GlobbingVisitor::visit_enum_container): New function. * resolve/rust-finalize-imports-2.0.h: Declare them. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Insert enums as potential containers. gcc/testsuite/ChangeLog: * rust/compile/glob_import_enum.rs: New test.
2025-08-05gccrs: fix bad monomophization of generic pathsPhilip Herron2-0/+466
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>
2025-08-05gccrs: Add initial support for deffered operator overload resolutionPhilip Herron1-0/+36
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>
2025-08-05gccrs: Fix ICE with duplicate root item main functionPhilip Herron1-0/+8
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>
2025-08-05gccrs: Improve parsing of simple pathsOwen Avery2-0/+12
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>
2025-08-05gccrs: Add test case to show issue is fixedPhilip Herron1-0/+9
Fixes Rust-GCC#3524 gcc/testsuite/ChangeLog: * rust/compile/issue-3524.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Reject loop in const/static contextlishin2-1/+7
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>
2025-08-05gccrs: Implement compilation for SlicePattern matching against ArrayType ↵Yap Zhi Heng2-0/+31
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>
2025-08-05gccrs: Add size checking to SlicePatternYap Zhi Heng1-0/+8
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>
2025-08-05gccrs: Add test case showing all derives working on enumPhilip Herron1-0/+465
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>
2025-08-05gccrs: Add test case to show issue is fixedPhilip Herron1-0/+8
Fixes Rust-GCC#1048 gcc/testsuite/ChangeLog: * rust/compile/issue-1048.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Add test case to show we emit better errors nowPhilip Herron1-0/+29
Fixes Rust-GCC#3144 gcc/testsuite/ChangeLog: * rust/compile/issue-3144.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: add test case to show issue is fixedPhilip Herron1-0/+8
Fixes Rust-GCC#3599 gcc/testsuite/ChangeLog: * rust/compile/issue-3599.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Fix ICE when handling bad constructorPhilip Herron1-0/+8
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>
2025-08-05gccrs: Fix cast rules logic to try simple casts then fall back to coercionsPhilip Herron1-0/+6
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>
2025-08-05gccrs: Fix bad bounds checking for PartialOrdPhilip Herron6-1/+1066
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>
2025-08-05gccrs: Fix ice with invalid borrow expressionPhilip Herron1-0/+4
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>
2025-08-05gccrs: Do proper const folding during typechecking for array capacitiesPhilip Herron5-6/+5
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>
2025-08-05gccrs: ast: Check before visiting a while-let's labelArthur Cohen1-0/+11
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.
2025-08-05gccrs: Remove -frust-name-resolution-2.0 usage in testsOwen Avery34-51/+9
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>
2025-08-05gccrs: nr2.0: Enable by defaultOwen Avery2-150/+0
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>
2025-08-05gccrs: Implement compilation support for TuplePatternItems::RANGEDZhi Heng3-0/+43
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>
2025-08-05gccrs: Fix type checking logic for TuplePatternZhi Heng1-0/+1
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>
2025-08-05gccrs: nr2.0: Adjust resolution of modulesOwen Avery1-1/+0
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>
2025-08-05gccrs: nr2.0: Add more checks for alternate patternsOwen Avery1-1/+0
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>
2025-08-05gccrs: Fix scan-assembler regexp in recurse2.rsOwen Avery1-1/+1
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>
2025-08-05gccrs: Fix bug with non compiled const declPhilip Herron1-0/+6
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>
2025-08-05gccrs: check for invalid const calls during code-genPhilip Herron1-0/+15
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>
2025-08-05gccrs: Fix TupleStructPattern compilation throwing errorZhi Heng2-0/+21
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>
2025-08-05gccrs: nr2.0: Fix resolution of constant itemsOwen Avery1-1/+0
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>
2025-08-05gccrs: Fix silly ordering bug in trait reference resolutionPhilip Herron1-0/+8
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>
2025-08-05gccrs: Move AST desugaring into expansion phaseOwen Avery1-4/+0
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>
2025-08-05gccrs: Add test case showing RPIT working to close issuePhilip Herron1-0/+35
Fixes Rust-GCC#1486 gcc/testsuite/ChangeLog: * rust/execute/torture/issue-1481.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Fix ICE when constant is missing and expressionPhilip Herron2-0/+10
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>
2025-08-05gccrs: Fix execute testsuiteOwen Avery3-1/+35
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>
2025-08-05gccrs: Fix issues around PartialEq Eq Ord Partial OrdPhilip Herron10-0/+2753
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>
2025-08-05gccrs: Implement compilation of IdentifierPattern's subpattern bindingsZhi Heng2-0/+27
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>
2025-08-05gccrs: nr2.0: Adjust lookup of associated itemsOwen Avery1-2/+0
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>
2025-08-05gccrs: derive(Ord, Eq): Use different node IDs for variant pathsArthur Cohen1-0/+464
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.
2025-08-05gccrs: derive(PartialEq): Implement proper discriminant comparisonArthur Cohen1-0/+14
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.
2025-08-05gccrs: Fix bug in query type stopping PartialOrdPhilip Herron2-0/+360
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>
2025-08-05gccrs: Fix bad type canonicalization on ARRAY_TYPESPhilip Herron2-1/+4
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>