aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2025-02-20derive(PartialEq): Add partial implementationArthur Cohen8-4/+519
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-02-20derive(Clone): chore: CleanupArthur Cohen2-25/+17
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc: Cleanup implementation, avoid repetitions. * expand/rust-derive-clone.h: Likewise.
2025-02-20ast-builder: Add new methods for creating operator expressionsArthur Cohen2-0/+66
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::literal_bool): New method. (Builder::comparison_expr): Likewise. (Builder::boolean_operation): Likewise. * ast/rust-ast-builder.h: Declare them.
2025-02-20ast-builder: Improve function generation.Arthur Cohen2-17/+17
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::block): Change return type. (Builder::loop): Use new APIs. * ast/rust-ast-builder.h: Change return type of block functions.
2025-02-20derive(Eq): Add implementation.Arthur Cohen5-0/+337
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-02-19nr2.0: Run DefaultResolver::visit on PathInExpressionOwen Avery2-11/+2
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-02-19nr2.0: Fix issue with external cratesOwen Avery2-4/+10
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-02-19Add comments to resolve_segmentsOwen Avery1-0/+11
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx (ForeverStack::resolve_segments): Add comments explaining the behaviour of a while loop. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-02-17Add type check on if-exprBenjamin Thos4-5/+27
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-02-17nr2.0: Resolve paths which start with SelfOwen Avery3-64/+56
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-02-16gccrs: initial setup for new OpaqueType to represent Impl typesPhilip Herron18-14/+372
This completes the initial setup and boilerplate for the new type in the typesystem. This is not functional yet but its a big patch already. gcc/rust/ChangeLog: * backend/rust-compile-type.cc (TyTyResolveCompile::visit): new tyty::OpaqueType * backend/rust-compile-type.h: likewise * checks/errors/borrowck/rust-bir-fact-collector.h: likewise * checks/errors/borrowck/rust-bir-place.h: likewise * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy): likewise * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise * typecheck/rust-hir-type-check-type.h: likewise * typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): likewise * typecheck/rust-substitution-mapper.h: likewise * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_sized_builtin): likewise * typecheck/rust-tyty-call.h: likewise * typecheck/rust-tyty-cmp.h (class OpaqueCmp): likewise * typecheck/rust-tyty-variance-analysis-private.h: likewise * typecheck/rust-tyty-visitor.h: likewise * typecheck/rust-tyty.cc (TypeKindFormat::to_string): likewise (BaseType::is_unit): likewise (BaseType::destructure): likewise (BaseType::has_substitutions_defined): likewise (BaseType::needs_generic_substitutions): likewise (OpaqueType::OpaqueType): likewise (OpaqueType::can_resolve): likewise (OpaqueType::accept_vis): likewise (OpaqueType::as_string): likewise (OpaqueType::get_name): likewise (OpaqueType::can_eq): likewise (OpaqueType::clone): likewise (OpaqueType::resolve): likewise (OpaqueType::is_equal): likewise (OpaqueType::handle_substitions): likewise * typecheck/rust-tyty.h (enum TypeKind): likewise (class OpaqueType): likewise * typecheck/rust-unify.cc (UnifyRules::go): likewise (UnifyRules::expect_inference_variable): likewise (UnifyRules::expect_adt): likewise (UnifyRules::expect_str): likewise (UnifyRules::expect_reference): likewise (UnifyRules::expect_pointer): likewise (UnifyRules::expect_param): likewise (UnifyRules::expect_array): likewise (UnifyRules::expect_slice): likewise (UnifyRules::expect_fndef): likewise (UnifyRules::expect_fnptr): likewise (UnifyRules::expect_tuple): likewise (UnifyRules::expect_bool): likewise (UnifyRules::expect_char): likewise (UnifyRules::expect_int): likewise (UnifyRules::expect_uint): likewise (UnifyRules::expect_float): likewise (UnifyRules::expect_isize): likewise (UnifyRules::expect_usize): likewise (UnifyRules::expect_placeholder): likewise (UnifyRules::expect_projection): likewise (UnifyRules::expect_dyn): likewise (UnifyRules::expect_opaque): likewise * typecheck/rust-unify.h: likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-02-15gccrs: Add name resolution and HIR lowering for ImplTraitType'sPhilip Herron19-135/+103
Our AST has ImplTraitType for multiple bounds and a singular ImplTraitTypeOneBound, this patch desugars these into a simple HIR::ImplTraitType. It also does the name resolution for this. gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-builder-struct.h: remove HIR::ImplTraitTypeOneBound * checks/errors/borrowck/rust-function-collector.h: likewise * checks/errors/rust-const-checker.cc (ConstChecker::visit): likewise * checks/errors/rust-const-checker.h: likewise * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit): likewise * checks/errors/rust-hir-pattern-analysis.h: likewise * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): likewise * checks/errors/rust-unsafe-checker.h: likewise * hir/rust-ast-lower-type.cc (ASTLoweringType::translate): likewise (ASTLoweringType::visit): likewise * hir/rust-ast-lower-type.h: cleanup * hir/rust-hir-dump.cc (Dump::visit): remove ImplTraitTypeOneBound * hir/rust-hir-dump.h: likewise * hir/tree/rust-hir-full-decls.h (class ImplTraitTypeOneBound): likewise * hir/tree/rust-hir-type.h (class ImplTraitTypeOneBound): likewise * hir/tree/rust-hir-visitor.h: likewise * hir/tree/rust-hir.cc (ImplTraitTypeOneBound::as_string): likewise (ImplTraitTypeOneBound::accept_vis): likewise * resolve/rust-ast-resolve-type.cc (ResolveType::go): likewise (ResolveType::visit): likewise * resolve/rust-ast-resolve-type.h: add name resolution * typecheck/rust-hir-type-check-type.h: likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-02-14gccrs: improve error diagnostic for bad type-resolution in CallExprPhilip Herron6-8/+19
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-02-13gccrs: self paths are patterns but we dont have mappings for itPhilip Herron3-1/+23
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-02-13gccrs: fix name resolution for generics where type param is declared laterPhilip Herron3-75/+86
Rust allows you to use generics within type bounds when they are declared later on. This changes the name resolution to walk the genric params in two passes to ensure the type parameters are setup before drilling down into the type parameters This issue has exposed another type checking issue which needs fixed in a subseqent patch. Addresses Rust-GCC#3022 gcc/rust/ChangeLog: * resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): use new api (ResolveItem::visit): likewise (ResolveExternItem::visit): likewise * resolve/rust-ast-resolve-stmt.h: likewise * resolve/rust-ast-resolve-type.h (class ResolveGenericParam): remove (class ResolveGenericParams): added new api Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-02-13gccrs: fix unconstrained generics check to handle recursive genericsPhilip Herron4-18/+82
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-02-12gccrs: add diagnostic for E0229 no associated type arguments allowed herePhilip Herron4-4/+43
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-02-12gccrs: remove name resolution inserts from type-pathPhilip Herron2-135/+16
We resolve path segments and inserted their resolution into the name resolution space which was an old hack to use this as information in code-gen/check-passes in order to help things move forward but this is not nessecary gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): remove name resolution info (TypeCheckType::resolve_root_path): likewise * typecheck/rust-hir-type-check-type.h: likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-02-11gccrs: enum type layout needs to respect the enum repr typePhilip Herron2-14/+5
Addresses Rust-GCC#3352 gcc/rust/ChangeLog: * backend/rust-compile-type.cc (TyTyResolveCompile::get_implicit_enumeral_node_type): use repr (TyTyResolveCompile::visit): update prototype * backend/rust-compile-type.h: likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-02-11gccrs: add variant_count intrinsicPhilip Herron2-1/+80
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-02-11gccrs: add discriminant value intrinsicPhilip Herron11-62/+235
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-02-08Get rid of duplicate interface #3396GS-GOAT5-11/+4
gcc/rust/ChangeLog: * typecheck/rust-autoderef.cc (insert_implicit_type): Update single-parameter call to pass explicit HirId. * typecheck/rust-hir-type-check-expr.cc: Same. * typecheck/rust-hir-type-check-pattern.cc: Same. * typecheck/rust-hir-type-check.h: Removed call to the duplicate interface. * typecheck/rust-typecheck-context.cc (TypeCheckContext::insert_implicit_type): Removed the interface with no HirId field. Signed-off-by: Guransh Singh <guransh766@gmail.com>
2025-02-04gccrs: remove bad type checking diagnosticPhilip Herron3-20/+40
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-02-04session manager: Call into DesugarForLoopsArthur Cohen1-0/+4
gcc/rust/ChangeLog: * rust-session-manager.cc (Session::compile_crate): Call the visitor.
2025-02-04ast: Add DesugarForLoop classArthur Cohen9-1/+2493
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-02-04ast: builder: Fix arguments of Builder::letArthur Cohen2-5/+5
gcc/rust/ChangeLog: * ast/rust-ast-builder.h: Mark all arguments as &&. * ast/rust-ast-builder.cc (Builder::let): Likewise.
2025-02-04nr2.0: Resolve instances of TypePath more accuratelyOwen Avery7-36/+170
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-02-04inline-asm: Fix some warningsArthur Cohen2-7/+21
gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (strip_double_quotes): Special case empty strings ("\"\""). (parse_reg_operand): Remove use of the `struct` keyword. (parse_reg_operand_in): Likewise. (parse_reg_operand_out): Likewise. * expand/rust-macro-builtins.cc: Add llvm_asm! built-in macro as an alias to asm!.
2025-02-04Add warning about default visitor usagePierre-Emmanuel Patry1-0/+4
We already lost some time on this unusual pattern, a comment will hopefully prevent this from happening again. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add warning about current code. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-02-04gccrs: Add test case to show issue is fixedPhilip Herron3-0/+48
This was fixed as part of: c63ecb2f032 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-02-04derive(Default): Add implementationArthur Cohen7-0/+290
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-02-04ast-builder: Add methods for QualifiedPathInExpressionsArthur Cohen3-10/+42
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::qualified_path_in_expression): New. (Builder::function): Change the return type. * ast/rust-ast-builder.h: Declare qualified_path_in_expression functions. * expand/rust-derive-debug.cc (DeriveDebug::stub_debug_fn): Adapt to new APIs.
2025-02-04gccrs: Fix compilation of trait-items which map to impl itemsPhilip Herron9-46/+129
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-02-03gccrs: Fix bad generic substitution error on fn/adt typesPhilip Herron3-2/+68
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-02-03gccrs: Fix crash in privay reporter for placeholder typesPhilip Herron1-4/+6
This guards against a crash but i think this should actually be treated as if its a generic type like below. But for now this addresses a crash which can occur. gcc/rust/ChangeLog: * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy): Add guard for placeholder Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-02-03gccrs: coercion sites allow for type inference as well.Philip Herron2-3/+5
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-02-03gccrs: Fix ICE during path probePhilip Herron1-6/+6
It is valid for the query to fail here so its valid to not assert here. gcc/rust/ChangeLog: * typecheck/rust-hir-path-probe.cc (PathProbeType::visit): remove assertion Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-02-03gccrs: Fix ICE when fn_once and fn_once_output lang item is not definedPhilip Herron1-5/+17
We needed to check for the optional has a value here or not it leads to an ICE. gcc/rust/ChangeLog: * typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): add checks for lang items Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-02-03Fix bug in type resolution of pathsOwen Avery9-72/+128
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-02-03nr2.0: Remove accidental copies of resolverOwen Avery9-19/+19
gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::generate_closure_function): Take NameResolutionContext by reference instead of by value. * backend/rust-compile-item.cc (CompileItem::visit): Likewise. * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::find_ref_node_id): Likewise. * typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit): Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): Likewise. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-02-02ast: builder: Add Return expression builderArthur Cohen2-0/+11
gcc/rust/ChangeLog: * ast/rust-ast-builder.h: Declare it. * ast/rust-ast-builder.cc (Builder::return_expr): Define it.
2025-02-02derive(Debug): Add stub implementation.Arthur Cohen6-0/+234
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-02-02derive(Clone, Copy): Cleanup using new method from DeriveVisitorArthur Cohen2-163/+11
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc: Cleanup using DeriveVisitor::setup_impl_generics. * expand/rust-derive-copy.cc: Likewise.
2025-02-02derive-visitor: Add method for setting up derived impl genericsArthur Cohen2-0/+97
gcc/rust/ChangeLog: * expand/rust-derive.cc (DeriveVisitor::setup_impl_generics): New method. * expand/rust-derive.h: Declare it, define DeriveVisitor::ImplGenerics struct.
2025-02-02ast-builder: Add new methods for functions, traits and tuples.Arthur Cohen2-2/+96
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc: New methods. * ast/rust-ast-builder.h: Declare them.
2025-02-02ast-builder: Add new functions to create type paths.Arthur Cohen2-1/+24
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::type_path): New functions. * ast/rust-ast-builder.h: Declare them.
2025-02-02scan-deadcode: Do not warn unused fields if they start with '_'Arthur Cohen1-2/+3
gcc/rust/ChangeLog: * checks/lints/rust-lint-scan-deadcode.h: Check if the field name starts with an underscore before warning.
2025-02-02lang-items: Add structural_{peq, teq}Arthur Cohen3-0/+15
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-02-02nr2.0: late: Add proper handling for lang item PathInExpressionsArthur Cohen1-1/+7
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Special case lang item paths.
2025-02-02Fix an issue with ForeverStack::dfs_ribOwen Avery1-3/+2
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx (ForeverStack::dfs_rib): Fix const implementation. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>