aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust
AgeCommit message (Collapse)AuthorFilesLines
2025-03-24gccrs: nr2.0: Adjust visitors for struct expressionsOwen Avery1-5/+0
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Make sure to always visit the struct name. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Avoid visiting the struct name twice. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: Prevent multiple resolution insertionOwen Avery1-6/+0
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::clone_impl): Avoid using the same node id multiple times. (DeriveClone::clone_enum_identifier): Likewise. (DeriveClone::clone_enum_tuple): Likewise. * expand/rust-derive-copy.cc (DeriveCopy::copy_impl): Likewise. * resolve/rust-ast-resolve-item.cc (flatten_list): Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Prevent reinsertion of resolutions. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_fn_trait_call): Likewise. * resolve/rust-name-resolver.cc (Resolver::insert_resolved_name): Catch multiple resolution insertions. (Resolver::insert_resolved_type): Likewise. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: nr2.0: Fix test self-path2.rsOwen Avery2-3/+2
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Adjust the error message for a lower self segment in the middle of a path. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove self-path2.rs * rust/compile/self-path2.rs: Adjust expected errors. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: emit an error for type or const parameters on foreign itemsRyutaro Okada1-0/+8
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): emit an error for type or const parameters on foreign items gcc/testsuite/ChangeLog: * rust/compile/extern_generics.rs: New test. Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-03-24gccrs: Fix modules with same name as builtins causing ICE (#3315)Liam Naddell3-0/+16
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h (ForeverStack): Add a dedicated prelude node for the Language prelude * resolve/rust-forever-stack.hxx (ForeverStack): Add support code for the prelude node * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Move language prelude builtins to the prelude context * resolve/rust-name-resolution-context.cc (NameResolutionContext::scoped): Add code for handling the prelude corner case * resolve/rust-rib.h (Rib::Kind): Add a special Prelude rib type gcc/testsuite/ChangeLog: * rust/compile/issue-3315-1.rs: Add test for module with same name as builtin * rust/compile/issue-3315-2.rs: Test with utilization of i32 type * rust/compile/nr2/exclude: issue-3315-2.rs Does not work with NR2.0 Signed-off-by: Liam Naddell <liamnprg@gmail.com>
2025-03-24gccrs: nr2.0: Check compile/torture/*.rs testsOwen Avery2-4/+19
gcc/testsuite/ChangeLog: * rust/compile/nr2/compile.exp: Adjust to cover tests in the torture subdirectory. * rust/compile/nr2/exclude: Add entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: Remove mangling tests from exclusion listPierre-Emmanuel Patry1-2/+0
Those tests are now passing. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove two mangling tests from exclusion file. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: Remove tests from exclusion listPierre-Emmanuel Patry1-2/+0
gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove issue-1786 and issue-3033 from exclusion list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: check for recursion trait cycle with bounds checksPhilip Herron1-0/+52
We need to be careful when doing bounds check as to not create a recusive trait resolution. This patch checks for that case and fixes a bad type is equal check on ADT Types which was caught with a regression here. Fixes Rust-GCC#3126 gcc/rust/ChangeLog: * typecheck/rust-hir-trait-resolve.cc (TraitResolver::ResolveHirItem): new helper * typecheck/rust-hir-trait-resolve.h: add helper prototype * typecheck/rust-type-util.cc (query_type): add debug * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): check for recursion * typecheck/rust-tyty.cc (VariantDef::is_equal): fix is equal check gcc/testsuite/ChangeLog: * rust/execute/torture/issue-3126.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: Add a test for enum variant name resolutionPierre-Emmanuel Patry1-0/+12
Highlight the fact that a value inside an enum definition refers to a struct outside of the enum and not to the enum variant's name directly. gcc/testsuite/ChangeLog: * rust/compile/enum_variant_name.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: Remove nr2 exhaustiveness test from exclusion listPierre-Emmanuel Patry1-1/+0
gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: nr2.0: Set the node id of the root nodeOwen Avery1-2/+0
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h (ForeverStack::ForeverStack): Set the node id of the root node to that of the current crate. * resolve/rust-forever-stack.hxx (ForeverStack::find_starting_point): Use the node id of the root node during resolution of crate segments. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: expansion: Correctly expand $crate metavarArthur Cohen2-0/+25
gcc/rust/ChangeLog: * expand/rust-macro-expand.cc: Use new SubstituteCtx API. * expand/rust-macro-expand.h: Likewise. * expand/rust-macro-substitute-ctx.cc: Implement proper expansion of $crate. * expand/rust-macro-substitute-ctx.h: Adapt APIs to take macro definition when substituting. * util/rust-hir-map.cc (Mappings::insert_macro_def): Store crate information when inserting macro definition in mappings. (Mappings::lookup_macro_def_crate): New. * util/rust-hir-map.h: Adapt mappings to store crate in which macros were defined. gcc/testsuite/ChangeLog: * rust/execute/crate-metavar1.rs: New test. * rust/compile/crate-metavar1.rs: New test.
2025-03-24gccrs: nr2.0: Make sure PathInExpression is default resolvedOwen Avery1-5/+0
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Call DefaultResolver::visit earlier, in order to ensure it is called even if Late::visit returns early. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: ast: Add base for desugaring try expressionsArthur Cohen1-0/+84
gcc/rust/ChangeLog: * Make-lang.in: Compile it. * ast/rust-desugar-question-mark.cc: New file. * ast/rust-desugar-question-mark.h: New file. gcc/testsuite/ChangeLog: * rust/compile/try-expr1.rs: New test.
2025-03-24gccrs: Adjust unknown macro error messageOwen Avery4-5/+3
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::visit): Adjust error produced when macro resolution fails. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. gcc/testsuite/ChangeLog: * rust/compile/macros/mbe/macro43.rs: Adjust expected errors. * rust/compile/macros/mbe/macro44.rs: Likewise. * rust/compile/nested_macro_use2.rs: Likewise. * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: nr2.0: Handle lang item type path segmentsOwen Avery1-5/+0
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx (ForeverStack::find_starting_point): Stop when hitting a lang item segment. (ForeverStack::resolve_segments): Resolve lang item segments. (ForeverStacl::resolve_path): Handle single segment lang item paths and add comment. * util/rust-unwrap-segment.cc (unwrap_segment_get_lang_item): Add. * util/rust-unwrap-segment.h (unwrap_segment_get_lang_item): Add. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: expansion: Expand generic args in generic type path segmentsArthur Cohen1-0/+19
gcc/rust/ChangeLog: * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Correctly visit the generic args of a generic type path segment. gcc/testsuite/ChangeLog: * rust/compile/issue-2015.rs: New test.
2025-03-24gccrs: nr2.0: Implement macro_use for modulesOwen Avery1-3/+0
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc: Include rust-attribute-values.h. (Early::visit): If a module has a macro_use attribute, avoid pushing a new textual macro scope. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: Adjust type path resolution error messageOwen Avery9-22/+16
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Adjust error message to match the 2.0 name resolver. gcc/testsuite/ChangeLog: * rust/compile/additional-trait-bounds2.rs: Adjust expected errors. * rust/compile/const_generics_4.rs: Likewise. * rust/compile/const_generics_7.rs: Likewise. * rust/compile/generic-default1.rs: Likewise. * rust/compile/generics5.rs: Likewise. * rust/compile/generics9.rs: Likewise. * rust/compile/issue-2423.rs: Likewise. * rust/compile/method2.rs: Likewise. * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: derive(Hash): Add implementation.Arthur Cohen2-0/+92
gcc/rust/ChangeLog: * Make-lang.in: Compile it. * expand/rust-derive.cc (DeriveVisitor::derive): Call it. * expand/rust-derive-hash.cc: New file. * expand/rust-derive-hash.h: New file. gcc/testsuite/ChangeLog: * rust/compile/derive-hash1.rs: New test. * rust/compile/nr2/exclude: Add testcase to exclusion list.
2025-03-24gccrs: Fix expansion of macros inside modulesOwen Avery1-0/+11
gcc/rust/ChangeLog: * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Override DefaultASTVisitor in order to expand a module's items, rather than directly visit them. * expand/rust-expand-visitor.h (ExpandVisitor::visit): Add override. gcc/testsuite/ChangeLog: * rust/compile/macros/mbe/macro-expand-module.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: derive(PartialEq): Also derive StructuralPartialEqArthur Cohen3-0/+12
gcc/rust/ChangeLog: * expand/rust-derive-partial-eq.cc: Adapt signatures to generate two impls. * expand/rust-derive-partial-eq.h: Likewise. * expand/rust-derive.cc (DeriveVisitor::derive): Adapt to multiple item generation. gcc/testsuite/ChangeLog: * rust/compile/derive-eq-invalid.rs: Declare StructuralPartialEq. * rust/compile/derive-partialeq1.rs: Likewise. * rust/execute/torture/derive-partialeq1.rs: Likewise.
2025-03-24gccrs: derive(PartialEq): Add partial implementationArthur Cohen4-4/+127
We are still missing some deriving for enums, as part of our codegen and nameres for rebinding struct field patterns is missing. gcc/rust/ChangeLog: * expand/rust-derive-partial-eq.cc: New file. * expand/rust-derive-partial-eq.h: New file. * expand/rust-derive.cc (DeriveVisitor::derive): Call them. * Make-lang.in: Compile them. gcc/testsuite/ChangeLog: * rust/compile/derive-eq-invalid.rs: Mark PartialEq def as a lang item. * rust/compile/derive-partialeq1.rs: New test. * rust/execute/torture/derive-partialeq1.rs: New test. * rust/compile/nr2/exclude: Exclude all of them.
2025-03-24gccrs: derive(Eq): Add implementation.Arthur Cohen1-0/+45
gcc/rust/ChangeLog: * expand/rust-derive.cc (DeriveVisitor::derive): Call into DeriveEq. * expand/rust-derive-eq.cc: New file. * expand/rust-derive-eq.h: New file. * Make-lang.in: Compile them. gcc/testsuite/ChangeLog: * rust/compile/derive-eq-invalid.rs: New test.
2025-03-24gccrs: nr2.0: Run DefaultResolver::visit on PathInExpressionOwen Avery1-11/+0
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): When visiting a PathInExpression instance, call into DefaultResolver::visit, ensuring generic arguments are visited. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: nr2.0: Fix issue with external cratesOwen Avery1-3/+0
gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): When visiting an external crate declaration, handle failed crate name lookups. This can happen when Session::load_extern_crate fails to load a crate during the CfgStrip phase. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: Add type check on if-exprBenjamin Thos3-3/+16
Check if an if-expr returns void type or a coercible type like an early return. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Add check on if-expr. gcc/testsuite/ChangeLog: * rust/compile/implicit_returns_err3.rs: Change test to be valid. * rust/compile/torture/if.rs: Likewise. * rust/compile/if-without-else.rs: New test. Signed-off-by: Benjamin Thos <benjamin.thos@epita.fr>
2025-03-24gccrs: nr2.0: Resolve paths which start with SelfOwen Avery1-35/+0
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx (ForeverStack::find_starting_point): Be more careful about applying ForeverStack::find_closest_module. (ForeverStack::resolve_segments): Allow traversal into parent nodes when not in a module node or root node, which ForeverStack::find_starting_point previously made moot through use of ForeverStack::find_closest_module. Also, when a child node lookup fails when resolving in the type namespace, attempt a rib lookup as a fallback. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Avoid throwing a resolution error for type paths when the typechecker may be able to finish the resolution. Also, throw an error when a resolution is ambiguous. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: improve error diagnostic for bad type-resolution in CallExprPhilip Herron5-4/+10
We have the type information for the resolved call lets tell the user about it in the diagnostic and apply the correct error code. Fixes Rust-GCC#2035 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): improve error diag gcc/testsuite/ChangeLog: * rust/compile/generics4.rs: cleanup * rust/compile/generics6.rs: likewise * rust/compile/type-bindings1.rs: likewise * rust/compile/unconstrained_type_param.rs: likewise * rust/compile/issue-2035.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: self paths are patterns but we dont have mappings for itPhilip Herron1-0/+18
With simple patterns we dont introduce any more inference varaibles as they are already declared in a specific way. This would only lead to more unconstrained inference varaibles than is required. Fixes Rust-GCC#3022 gcc/rust/ChangeLog: * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): add location mappings * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): check for self gcc/testsuite/ChangeLog: * rust/compile/issue-3022.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: fix unconstrained generics check to handle recursive genericsPhilip Herron1-0/+15
Generics can be constrained within other generic types so this check needs to be recursive. Fixes Rust-GCC#3031 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc (walk_types_to_constrain): recursive walker * typecheck/rust-tyty.cc (BaseType::get_subst_argument_mappings): new helper * typecheck/rust-tyty.h: prototype gcc/testsuite/ChangeLog: * rust/compile/issue-3031.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: add diagnostic for E0229 no associated type arguments allowed herePhilip Herron1-0/+21
It seems bounds in qualified paths are not allowed to specify associated type bindings because its going to be associated with the impl block anyway. Fixes Rust-GCC#2369 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.h: add flag * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise * typecheck/rust-tyty-bounds.cc: new diagnostic gcc/testsuite/ChangeLog: * rust/compile/issue-2369.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: add variant_count intrinsicPhilip Herron1-0/+25
Addresses Rust-GCC#3348 gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (variant_count_handler): new intrinsic gcc/testsuite/ChangeLog: * rust/execute/torture/enum_intrinsics2.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: add discriminant value intrinsicPhilip Herron1-0/+48
This is pretty nasty piece of rust in my opinion the return type of this intrinsic results into a lang item associated type: <T as DiscriminantKind>::Discriminant This is a special case which needs to support mapping onto the repr type of the associated ADT that is passed in, but defaults to iszie otherwise. This patch assumes we only come accross this case in a HIR::CALL_EXPR, so and makes assumutions that its always of this function signiture. I will do some checking in libcore to verify that assumption. More work is needed to parse the repr type on enums but the code is there to support this when its in to change the types etc. Addresses Rust-GCC#3348 gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (discriminant_value_handler): new handler * typecheck/rust-hir-trait-resolve.cc (TraitItemReference::resolve_item): track the defid * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): default isize * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): special case CallExpr * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): parse repr options enum * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): remove bad diagnostic * typecheck/rust-tyty.cc (PlaceholderType::PlaceholderType): track defid (PlaceholderType::clone): likewise (PlaceholderType::get_def_id): likeiwse * typecheck/rust-tyty.h: placeholder track defid * util/rust-lang-item.cc: add new lang items * util/rust-lang-item.h: likewise gcc/testsuite/ChangeLog: * rust/execute/torture/enum_intrinsics1.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: remove bad type checking diagnosticPhilip Herron2-0/+39
This was a bad diagnostic added when I was working on slices and iterators also the name of the function is also bad. This is all about setting up associated types based on the current context of the bounds assocated with the associated trait bounds on this function. The tell tale is that this didnt have an associated rust error code so this is most definetly not the correct error diagnostic. Fixes Rust-GCC#3403 gcc/rust/ChangeLog: * typecheck/rust-tyty-subst.cc (SubstitutionRef::monomorphize): remove diagnostic gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this * rust/compile/issue-3403.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: ast: Add DesugarForLoop classArthur Cohen5-0/+2179
gcc/rust/ChangeLog: * ast/rust-desugar-for-loops.cc: New file. * ast/rust-desugar-for-loops.h: New file. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Make lowering of for-loops an unreachable. * Make-lang.in: Compile it. gcc/testsuite/ChangeLog: * rust/compile/for-loop1.rs: New test. * rust/compile/for-loop2.rs: New test. * rust/execute/torture/for-loop1.rs: New test. * rust/execute/torture/for-loop2.rs: New test. * rust/compile/nr2/exclude: Exclude for-loop1.rs
2025-03-24gccrs: nr2.0: Resolve instances of TypePath more accuratelyOwen Avery1-5/+0
gcc/rust/ChangeLog: * util/rust-unwrap-segment.cc: New file. * util/rust-unwrap-segment.h: New file. * Make-lang.in: Add rust-unwrap-segment.o to the object list. * resolve/rust-forever-stack.hxx: Include rust-unwrap-segment.h. (ForeverStack::find_starting_point): Use unwrap_type_segment. (ForeverStack::resolve_segments): Likewise. (ForeverStack::resolve_path): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Resolve type paths using NameResolutionContext::resolve_path. * resolve/rust-name-resolution-context.h (NameResolutionContext::resolve_path): Use unwrap_segment_node_id. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: Add test case to show issue is fixedPhilip Herron3-0/+48
This was fixed as part of: "gccrs: Fix compilation of trait-items which map to impl items" Fixes Rust-GCC#3402 gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this * rust/compile/issue-3402-1.rs: New test. * rust/compile/issue-3402-2.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: derive(Default): Add implementationArthur Cohen3-0/+56
gcc/rust/ChangeLog: * expand/rust-derive.cc (DeriveVisitor::derive): Call DeriveDefault. * expand/rust-derive-default.cc: New file. * expand/rust-derive-default.h: New file. * Make-lang.in: Compile them. gcc/testsuite/ChangeLog: * rust/compile/derive-default1.rs: New test. * rust/execute/torture/derive-default1.rs: New test. * rust/compile/nr2/exclude: Exclude them.
2025-03-24gccrs: Fix compilation of trait-items which map to impl itemsPhilip Herron1-0/+90
When we have paths such as Try::from_error the Try references the Trait and then from_error references the from_error trait item. So this resolves directly to a trait implementation which has the type: fn <Self> (v: placeholder) -> Self Remember that a path such as: Try::from_error gets handled by doing a clever substitution: <T? as Try>::from_error The main piece here is that we resolve this function type and for monomoprhization we know this is a trait call but we know that all trait's have an implicit Self type param which in this case is Result<i32, i32> so when it comes to knowing which impl block this is we got rid of the old bad insert/lookup receiver hack and use the specified type to know which impl block we are talking about to generate the function. The hard part here is inside rust-compil-item.cc, where we have the 'concete' type which is the trait item fntype of: fn <Result<i32, i32>> (v : i32) -> Result<i32,i32> This does not really match the signiture of the impl item for Result which is: fn <T, E> (v: i32) -> Result<T, E> So what we need to do is actually infer this by inputing inference variables on the impl fntype then unify'ing the trait object to this to compute the types of this to monomorphize this. Fixes Rust-GCC#3381 gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): remove receiver interface * backend/rust-compile-item.cc (CompileItem::visit): monomorphize trait to impl item * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): use trait item Self * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): remove receiver interface (TypeCheckExpr::resolve_fn_trait_call): likewise * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): likewise (TypeCheckExpr::resolve_segments): likewise * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise * typecheck/rust-hir-type-check.h: likewise * typecheck/rust-typecheck-context.cc (TypeCheckContext::insert_receiver): remove (TypeCheckContext::lookup_receiver): remove gcc/testsuite/ChangeLog: * rust/execute/torture/issue-3381.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: Fix bad generic substitution error on fn/adt typesPhilip Herron2-0/+62
When passing generics around we try to adjust them because there are cases where the names are adjusted from other generics this can fail for traits because of the implicit Self and we just need to continue on without adjustment. Fxies Rust-GCC#3382 gcc/rust/ChangeLog: * typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): continue on for trait item mode. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this. * rust/compile/issue-3382.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: coercion sites allow for type inference as well.Philip Herron1-1/+1
Addresses Rust-GCC#3382 and Rust-GCC#3381 gcc/rust/ChangeLog: * typecheck/rust-type-util.cc (coercion_site): allow inference vars gcc/testsuite/ChangeLog: * rust/compile/reference1.rs: fix error message Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: Fix bug in type resolution of pathsOwen Avery1-29/+0
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Use NameResolutionContext::resolve_path instead of ForeverStack::resolve_path. (Early::visit): Likewise. (Early::visit_attributes): Likewise. * resolve/rust-early-name-resolver-2.0.h (Early::resolve_path_in_all_ns): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise, insert segment resolutions not handled by NameResolutionContext::resolve_path, and avoid throwing an error when path resolution could be finished by the typechecker. * resolve/rust-name-resolution-context.h (NameResolutionContext::resolve_path): Add. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): Use segment node ids instead of the path node id to look up segment resolutions when using the 2.0 resolver, as is done with the 1.0 resolver. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. * resolve/rust-forever-stack.h (ForeverStack::resolve_path): Add callback parameter for inserting segment resolutions. (ForeverStack::find_starting_point): Likewise. (ForeverStack::resolve_segments): Likewise. * resolve/rust-forever-stack.hxx (ForeverStack::find_starting_point): Likewise. (ForeverStack::resolve_segments): Likewise. (ForeverStack::resolve_path): Likewise and avoid resolving inside TraitOrImpl ribs. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: derive(Debug): Add stub implementation.Arthur Cohen2-0/+42
gcc/rust/ChangeLog: * expand/rust-derive-debug.cc: New file. * expand/rust-derive-debug.h: New file. * Make-lang.in: Compile them. * expand/rust-derive.cc (DeriveVisitor::derive): Call into DeriveDebug. gcc/testsuite/ChangeLog: * rust/compile/derive-debug1.rs: New test. * rust/compile/nr2/exclude: Exclude it.
2025-03-24gccrs: lang-items: Add structural_{peq, teq}Arthur Cohen1-0/+9
These lang items are used when deriving Eq and PartialEq, and will be checked when compiling pattern matching. gcc/rust/ChangeLog: * util/rust-lang-item.cc: New items. * util/rust-lang-item.h: Likewise. gcc/testsuite/ChangeLog: * rust/compile/structural-eq-peq.rs: New test.
2025-03-24gccrs: Add option_env! supportLiam Naddell4-0/+149
gcc/rust/ChangeLog: * expand/rust-macro-builtins-utility.cc: Add macro expansion for option_env with eager expansion * expand/rust-macro-builtins.cc: Add option_env to builtin list * expand/rust-macro-builtins.h: Add option_env handler to header file * resolve/rust-late-name-resolver-2.0.cc: Prevent NR2.0 from recursing into lang-item segments gcc/testsuite/ChangeLog: * rust/compile/macros/builtin/option_env1.rs: Add success case for option_env * rust/compile/macros/builtin/option_env2.rs: Add failure case for option_env * rust/execute/torture/builtin_macro_option_env.rs: Add execution case for option_env
2025-03-24gccrs: add support for ref literal patternsPhilip Herron2-0/+29
Fixes Rust-GCC#3174 gcc/rust/ChangeLog: * backend/rust-compile-pattern.cc (CompilePatternBindings::visit): make recursive * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): handle ref flag gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this * rust/compile/issue-3174.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: Remove some passing test from exclude filePierre-Emmanuel Patry1-5/+2
Those tests are now passing. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove some tests. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: Remove some tests from nr2 exclusion filePierre-Emmanuel Patry1-11/+0
Those test are now passing. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove passing tests. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>