aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
AgeCommit message (Collapse)AuthorFilesLines
2025-04-04nr2.0: Remove duplicate self visitOwen Avery1-2/+0
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Remove explicit visitation of a function's self parameter, as if it exists it'll be visited as one of the function parameters. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entry. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-04gccrs: Fix ICE for reserved lifetime namePhilip Herron1-1/+10
This is a reserved name so this changes the assertion to a diagnostic. Fixes Rust-GCC#3647 gcc/rust/ChangeLog: * typecheck/rust-typecheck-context.cc (TypeCheckContext::lookup_lifetime): emit error gcc/testsuite/ChangeLog: * rust/compile/issue-3647.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-04hir: Add default qualifier to function, lower it properlyArthur Cohen6-11/+38
gcc/rust/ChangeLog: * ast/rust-ast.cc (Function::Function): Rename is_default -> has_default. (Function::operator=): Likewise. * ast/rust-item.h (class Function): Add `is_default` method. * hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): Lower default qualifier. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise. * hir/tree/rust-hir-item.cc (Function::Function): Add `is_default` member. (Function::operator=): Likewise. * hir/tree/rust-hir-item.h (enum class Defaultness): New enum. (class Function): Use it. gcc/testsuite/ChangeLog: * rust/compile/min_specialization1.rs: New test.
2025-04-04feature: Add min_specialization featureArthur Cohen2-0/+5
gcc/rust/ChangeLog: * checks/errors/rust-feature.cc (Feature::create): Handle `#![feature(min_specialization)]`. * checks/errors/rust-feature.h: Likewise.
2025-04-04gccrs: Fix ICE when hitting invalid types for genericsPhilip Herron3-2/+29
We need to check upfront if the type is valid or not. Then error with a decent message. Fixes Rust-GCC#3643 Fixes Rust-GCC#3646 Fixes Rust-GCC#3654 Fixes Rust-GCC#3663 Fixes Rust-GCC#3671 gcc/rust/ChangeLog: * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): fix error msg * typecheck/rust-substitution-mapper.cc (SubstMapper::Resolve): add validation (SubstMapper::valid_type): new check (SubstMapper::visit): check if can resolve * typecheck/rust-substitution-mapper.h: new prototype gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 is missing type path error * rust/compile/issue-3643.rs: New test. * rust/compile/issue-3646.rs: New test. * rust/compile/issue-3654.rs: New test. * rust/compile/issue-3663.rs: New test. * rust/compile/issue-3671.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-03gccrs: Fix ICE on raw referencePhilip Herron9-22/+29
This patch adds support for raw references which enforce the pointer type away from a reference type. Fixes Rust-GCC#3667 gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::address_expression): allow optional type * backend/rust-compile-base.h: update prototype * backend/rust-compile-expr.cc (CompileExpr::visit): update borrow expr * backend/rust-compile-extern.h: remove unused debug * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): update usage * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): lower raw ref * hir/tree/rust-hir-expr.cc (BorrowExpr::BorrowExpr): add flag for raw ref * hir/tree/rust-hir-expr.h (class BorrowExpr): add new raw ref field * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): add handle for raw ref gcc/testsuite/ChangeLog: * rust/compile/issue-3667.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-03gccrs: Fix ICE on invalid match armsPhilip Herron1-2/+19
We hit assertions on empty enum or unknown variant, this catches the error and emits a new diagnostic. Fixes Rust-GCC#3656 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): emit error gcc/testsuite/ChangeLog: * rust/compile/issue-3656.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-03gccrs: Fix recusive type query and nullptr on type pathPhilip Herron12-218/+142
This was a small fix to sort out the segfault to check for nullptr on the TypePath cases for query type. But when this happened opened up a few bugs that were hidden under the carpet namely: compile/issue-2905-{1,2}.rs which has a recursive type query which needs to ne handled but now and error message is being output for the type path. This happens because we start resolving a generic struct: struct Wierd<T>(A<(T,)>); So the child field A is also generic and the generic argument of the tuple of T needs to be applied to this generic field. This causes a chunk of code to do bounds checking to ensure the bounds are ok, this is also something that probably might change as generic types will have the bounds secified anyway but thats besides the case right now. So once this bounds checking occurs we endup looking at the impl block for Wierd<i32> which is also grand but we still havent finished resolving the parent type of Wierd which is recusive. But the query type system needs to check for that. The other issue was: compile/issue-3022.rs which is a resolution issue: impl<T: Foo<U>, U> Foo<U> for Bar<T, U> The bound of Foo<T> is added to T before U is resolved but this was hidden before the new error message was added. So now we have a generic arguements handler being used correctly all over the code base apart from 1 last case for Traits but we will deal with that later. This handles the case by setting up the type parameters upfront then sorting out their bounds. Fixes Rust-GCC#3625 gcc/rust/ChangeLog: * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): new argument * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::TypeCheckBase): new helper * typecheck/rust-hir-type-check-base.h: new helper prototype * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): remove comment out code * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): check for null * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): likewise (TypeResolveGenericParam::Resolve): new args (TypeResolveGenericParam::ApplyAnyTraitBounds): new helper (TypeResolveGenericParam::apply_trait_bounds): new field (TypeResolveGenericParam::visit): update * typecheck/rust-hir-type-check-type.h: new args * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): reuse helper * typecheck/rust-type-util.cc (query_type): check for recursive query * typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::SubstitutionParamMapping): remove const (SubstitutionParamMapping::get_generic_param): likewise * typecheck/rust-tyty-subst.h: likewise * typecheck/rust-tyty-variance-analysis.cc (GenericTyVisitorCtx::process_type): likewise gcc/testsuite/ChangeLog: * rust/compile/issue-3625.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-02gccrs: Fix ICE when there are 2 functions named mainPhilip Herron9-22/+22
We need to setup the main_identifier_node for MAIN_DECL_P checks in the middle-end. But it is valid to have a main function/method on impl blocks. So we need to flag if this is a "root" item or not, which is one that is jsut an HIR::Function on part of the Crate::items as oppposed to a HIR::Function which is part of an HIR::ImplBlock as part of the HIR::Crate. Some small cleanups have been added here too. Fixes Rust-GCC#3648 gcc/rust/ChangeLog: * backend/rust-compile-base.cc: new flag is_root_item * backend/rust-compile-base.h: update prototype * backend/rust-compile-implitem.cc (CompileTraitItem::visit): update call * backend/rust-compile-implitem.h: remove old debug internal error * backend/rust-compile-item.cc (CompileItem::visit): update call * backend/rust-compile-item.h: remove old debug * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): update calls * backend/rust-compile.cc: likewise * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait): remove assertion and error gcc/testsuite/ChangeLog: * rust/compile/issue-3648.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-01gccrs: Fix ICE when resolving lifetimes without namePhilip Herron1-2/+0
We dont need to assert here the lifetime code already supports this case. Fixes Rust-GCC#3657 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc: remove assertion gcc/testsuite/ChangeLog: * rust/compile/issue-3657.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-01gccrs: Fix ICE when doing shift checks on const declPhilip Herron1-0/+6
Const decls are just delcarations wrapping the value into the DECL_INITIAL and the shift checks we have assume no decls are involved and its just flat values. This patch simply unwraps the constant values if they exist. Fixes Rust-GCC#3665 gcc/rust/ChangeLog: * rust-gcc.cc (arithmetic_or_logical_expression): unwrap const decls gcc/testsuite/ChangeLog: * rust/compile/issue-3665.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-01nr2.0: Handle global pathsOwen Avery4-49/+96
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h (ForeverStack::ForeverStack): Initialize extern_prelude. (ForeverStack::resolve_path): Add parameter has_opening_scope_resolution. (ForeverStack::extern_prelude): Add field. * resolve/rust-forever-stack.hxx: Include rust-edition.h. (ForeverStacl::resolve_path): Handle global paths (paths with an opening scope resolution operator). * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Handle global paths. * resolve/rust-name-resolution-context.h (NameResolutionContext::resolve_path): Handle global paths. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-31Evaluate the enum's discriminant in a const contextRyutaro Okada1-0/+2
gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc: Evaluate the enum's discriminant in a const context gcc/testsuite/ChangeLog: * rust/compile/enum_discriminant1.rs: New test. Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-03-28gccrs: Fix SEGV when type path resolver fails outrightPhilip Herron1-0/+7
When we resolve paths we resolve to Types first we walk each segment to the last module which has no type but then in the event that the child of a module is not found we have a null root_tyty which needs to be caught and turned into an ErrorType node. Fixes Rust-GCC#3613 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): catch nullptr root_tyty gcc/testsuite/ChangeLog: * rust/compile/issue-3613.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-28gccrs: fix crash in parse repr options and missing delete callPhilip Herron1-2/+18
Fixes Rust-GCC#3606 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): check for null and empty and add missing delete call gcc/testsuite/ChangeLog: * rust/compile/issue-3606.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-28gccrs: fix ice when setting up regionsPhilip Herron1-1/+1
num regions is based on the used arguments of regions which can be less than the substutions requirements. So lets check for that and allow anon regions to be created for them. Fixes Rust-GCC#3605 gcc/rust/ChangeLog: * typecheck/rust-tyty-subst.h: check for min range gcc/testsuite/ChangeLog: * rust/compile/issue-3605.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-28gccrs: FIX ICE for malformed repr attributePhilip Herron1-0/+6
Fixes Rust-GCC#3614 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): check for input gcc/testsuite/ChangeLog: * rust/compile/issue-3614.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-28gccrs: FIX ICE when working with HIR::BareFunctionTypePhilip Herron2-2/+5
Fixes Rust-GCC#3615 gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::visit): check has type * hir/tree/rust-hir-type.cc (BareFunctionType::BareFunctionType): likewise gcc/testsuite/ChangeLog: * rust/compile/issue-3615.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-28gccrs: Fix ICE in array ref constexprPhilip Herron1-4/+2
Since 898d55ad7e2 was fixed to remove the VIEW_CONVERT_EXPR from array expressions we can now turn on the array element access const expr. Fixes Rust-GCC#3563 gcc/rust/ChangeLog: * backend/rust-constexpr.cc (eval_store_expression): turn this back on gcc/testsuite/ChangeLog: * rust/compile/issue-3563.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-28Add ending newline to rust-macro-builtins-log-debug.ccOwen Avery1-1/+1
gcc/rust/ChangeLog: * expand/rust-macro-builtins-log-debug.cc: Add newline to end of file. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-28nr2.0: Rename prelude to lang_preludeOwen Avery3-13/+14
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h (ForeverStack::get_prelude): Rename to... (ForeverStack::get_lang_prelude): ...here. (ForeverStack::prelude): Rename to... (ForeverStack::lang_prelude): ...here. (ForeverStack::ForeverStack): Handle renames. * resolve/rust-forever-stack.hxx (ForeverStack::push_inner): Likewise. (ForeverStack::resolve_segments): Likewise. (ForeverStack::resolve_path): Likewise. (ForeverStack::get_prelude): Rename to... (ForeverStack::get_lang_prelude): ...here and handle renames. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Handle renames. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-27gccrs: Fix ICE during const expr eval on array expressionsPhilip Herron2-1/+6
Array expressions are still getting turned into VIEW_CONVERT_EXPR's becuase TYPE_MAIN_VARIANT is not set so then we might as well reuse the type-hasher to sort this out. Fixes Rust-GCC#3588 gcc/rust/ChangeLog: * backend/rust-compile-context.h: only push named types * backend/rust-compile-type.cc (TyTyResolveCompile::visit): run the type hasher gcc/testsuite/ChangeLog: * rust/compile/issue-3588.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-27gccrs: Fix ICE when compiling path which resolves to trait constantPhilip Herron2-1/+24
Fixes Rust-GCC#3552 gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): check for Expr trait * hir/rust-hir-dump.cc (Dump::visit): expr is optional gcc/testsuite/ChangeLog: * rust/compile/issue-3552.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-27Resolve module final self segment in use declsPierre-Emmanuel Patry3-8/+42
Lowercase self suffix with path was not resolved properly, this should point to the module right before. gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx: Add a new specialized function to retrieve the last "real" segment depending on the namespace. * resolve/rust-forever-stack.h: Add new function prototype. * resolve/rust-early-name-resolver-2.0.cc (Early::finalize_rebind_import): Set declared name according to the selected segment, if there is a self suffix in the use declaration then select the previous segment. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-27gccrs: Give the builtin unit struct an actual locusPhilip Herron5-8/+17
This has been a pet peeve of mine for a while because the gimple never emitted the struct () name properly it was always empty which for record types they always require a real locus or they dont get a proper name. gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::unit_expression): pass ctx * backend/rust-compile-base.h: cant be static * backend/rust-compile-intrinsic.cc (try_handler_inner): pass ctx * backend/rust-compile-type.cc (TyTyResolveCompile::get_unit_type): update to grab the first locus (TyTyResolveCompile::visit): pass ctx * backend/rust-compile-type.h: likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-27gccrs: Fix ICE when doing method resolution on trait predicatesPhilip Herron1-2/+5
We need to ensure we are adding methods to the possible candidates. Fixes Rust-GCC#3554 gcc/rust/ChangeLog: * typecheck/rust-hir-dot-operator.cc: gcc/testsuite/ChangeLog: * rust/compile/issue-3554-1.rs: New test. * rust/compile/issue-3554-2.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-27gccrs: Fix ICE when using super mid way though pathPhilip Herron1-0/+6
Fixes Rust-GCC#3568 gcc/rust/ChangeLog: * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): check for super mid path gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 puts out a different error multiple times * rust/compile/issue-3568.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-27gccrs: Fix ICE when compiling block expressions in array capacityPhilip Herron3-1/+29
We need to reuse the existing compile_constant_item helper which handles the case if this is a simple expression, fn-call or a block expression. The patch extracts out this helper as a static method so this can be used in more places. Fixes Rust-GCC#3566 gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::address_expression): new helper constexpr * backend/rust-compile-base.h: prototype * backend/rust-compile-type.cc (TyTyResolveCompile::visit): call constexpr helper gcc/testsuite/ChangeLog: * rust/compile/issue-3566-1.rs: New test. * rust/compile/issue-3566-2.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-27gccrs: Add check for super traits being implemented by SelfPhilip Herron3-3/+77
We need to recursively check the super traits of the predicate the Self type is trying to implement. Otherwise its cannot implement it. Fixes Rust-GCC#3553 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::resolve_impl_block_substitutions): Track the polarity * typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::validate_type_implements_this): new validator * typecheck/rust-tyty.h: new prototypes gcc/testsuite/ChangeLog: * rust/compile/issue-3553.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-27gccrs: Fix ICE when array elements are not a valuePhilip Herron1-0/+11
We need to check for error_mark_node when doing adjustments from coercion sites otherwise we hit assetions as part of the coercion. That fixes the ICE but the reason for the error_mark_node is because the array element value. Fixes Rust-GCC#3567 gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::array_value_expr): add value chk for array expr gcc/testsuite/ChangeLog: * rust/compile/issue-3567.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-26gccrs: fix unconstrained infer vars on generic associated typePhilip Herron3-10/+9
The trick here is that when Bar::test is resolved it resolves to the trait method: fn <Bar<i32>, T> (placeholder) -> placeholder Which is fine so we need to setup the associated types for Bar<i32> which means looking up the associated impl block then setting up the projection of A = T so it becomes: fn <Bar<i32>, T> (placeholder: projection<T>:T) -> placeholder: projection<T>:T But previously it was auto injecting inference variables so it became: fn <Bar<i32>, T> (placeholder: projection<T>:?T) -> placeholder: projection<T>:?T The issue is that the binding of the generics was still T so this caused inference variables to be injected again but unlinked. A possible tweak would be that we are substituting again with new infer vars to actually just unify them enplace so they are all part of the chain. This still might be needed but lets hold off for now. So basically when we are Path probing we dont allow GAT's to generate new inference vars because they wont be bound to this current segment which just causes confusion. Fixes Rust-GCC#3242 gcc/rust/ChangeLog: * typecheck/rust-hir-trait-reference.h: add default infer arg * typecheck/rust-hir-trait-resolve.cc: dont add new infer vars * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): dont infer gcc/testsuite/ChangeLog: * rust/compile/issue-3242.rs: no longer skip the test Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-26Fix validation of constant itemsOwen Avery1-1/+1
gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Allow constant items lacking expressions if and only if they're associated with a trait definition, not a trait implementation. gcc/testsuite/ChangeLog: * rust/compile/issue-3541-1.rs: New test. * rust/compile/issue-3541-2.rs: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-26Lower raw string literalsOwen Avery1-2/+2
gcc/rust/ChangeLog: * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_literal): Lower raw string literals into normal string literals. gcc/testsuite/ChangeLog: * rust/compile/issue-3549.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-26rust: Lower minimum supported Rust version to 1.49Arthur Cohen5-156/+9
gcc/rust/ChangeLog: * checks/errors/borrowck/ffi-polonius/Cargo.lock: Regenerate. * checks/errors/borrowck/ffi-polonius/Cargo.toml: Update to use source patching instead of vendoring, lower edition to 2018. * checks/errors/borrowck/ffi-polonius/vendor/log/Cargo.toml: Change edition to 2018. * checks/errors/borrowck/ffi-polonius/vendor/log/src/lib.rs: Remove uses of unstable feature. * checks/errors/borrowck/ffi-polonius/.cargo/config.toml: Removed. libgrust/ChangeLog: * libformat_parser/Makefile.am: Avoid using --config as it is unsupported by cargo 1.49. * libformat_parser/Makefile.in: Regenerate. * libformat_parser/generic_format_parser/src/lib.rs: Use extension trait for missing features. * libformat_parser/src/lib.rs: Likewise. * libformat_parser/.cargo/config: Moved to... * libformat_parser/.cargo/config.toml: ...here.
2025-03-25lower: Handle let-else properlyArthur Cohen3-5/+37
gcc/rust/ChangeLog: * hir/tree/rust-hir-stmt.h (class LetStmt): Add optional diverging else expression. * hir/tree/rust-hir-stmt.cc: Likewise. * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Add handling for lowering diverging else.
2025-03-25name-resolution: Handle let-else properlyArthur Cohen2-3/+7
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-stmt.h: Add handling for diverging else. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise.
2025-03-25dump: Handle let-else properlyArthur Cohen1-0/+8
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Add handling for diverging else expression.
2025-03-25parser: Parse let-else statementsArthur Cohen1-1/+5
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_let_stmt): Add new parsing in case of `else` token.
2025-03-25ast: Add optional diverging else to AST::LetStmtArthur Cohen2-2/+30
gcc/rust/ChangeLog: * ast/rust-stmt.h (class LetStmt): Add optional expression for diverging else. * ast/rust-ast-builder.cc (Builder::let): Use new API.
2025-03-23gccrs: support generic super traits recursivelyPhilip Herron9-60/+114
In order to handle generic super traits on any trait bound we need to ensure we track the TypeBoundPredicate as part of the TraitReference instead of just the raw TraitReferences because these will have any applied generics enplace. Then for any TypeBoundPredicate it takes a copy of the super traits because this is the usage of a TraitBound and we can apply generics which then need to be recursively applied up the chain of super predicates. The main tweak is around TypeBoundPredicate::lookup_associated_item because we need to associate the predicate with the item we are looking up so the caller can respect the generics correctly as well. Fixes Rust-GCC#3502 gcc/rust/ChangeLog: * typecheck/rust-hir-path-probe.cc: update call * typecheck/rust-hir-trait-reference.cc (TraitReference::lookup_trait_item): track predicate (TraitReference::is_equal): likewise (TraitReference::is_object_safe): likewise (TraitReference::satisfies_bound): likewise * typecheck/rust-hir-trait-reference.h: likewise * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): likewise * typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::TypeBoundPredicate): track super traits (TypeBoundPredicate::operator=): likewise (TypeBoundPredicate::apply_generic_arguments): ensure we apply to super predicates (TypeBoundPredicateItem::operator=): take copy of parent predicate (TypeBoundPredicateItem::error): pass error instead of nullptr (TypeBoundPredicateItem::is_error): update to no longer check for nullptr (TypeBoundPredicateItem::get_parent): updated (TypeBoundPredicateItem::get_tyty_for_receiver): likewise (TypeBoundPredicate::get_associated_type_items): likewise * typecheck/rust-tyty-bounds.h (class TypeBoundPredicateItem): move * typecheck/rust-tyty-subst.cc: flag to handle placeholder Self on traits * typecheck/rust-tyty-subst.h (class TypeBoundPredicateItem): likewise * typecheck/rust-tyty.h (class TypeBoundPredicateItem): refactored gcc/testsuite/ChangeLog: * rust/execute/torture/issue-3502.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-21nr2.0: Fix StructExprFieldIdentifier handlingOwen Avery2-0/+29
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add visitor for StructExprFieldIdentifier. * resolve/rust-late-name-resolver-2.0.h (Late::visit): Likewise. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-21rust: force cargo to build offlineMarc Poulhiès1-1/+1
gcc/rust/Changelog: PR rust/119333 * Make-lang.in: Force offline mode for cargo Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2025-03-21polonius: Vendor Rust dependenciesArthur Cohen50-0/+10860
This fixes PR #119333 by allowing our borrow-checker interface to be built offline. This was already done for our components in libgrust/, but had never been done for the borrow-checker. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119333 gcc/rust/ChangeLog: * checks/errors/borrowck/ffi-polonius/.cargo/config.toml: New file, force vendored deps. * checks/errors/borrowck/ffi-polonius/vendor/datafrog/.cargo-checksum.json: New file. * checks/errors/borrowck/ffi-polonius/vendor/datafrog/CODE_OF_CONDUCT.md: New file. * checks/errors/borrowck/ffi-polonius/vendor/datafrog/Cargo.toml: New file. * checks/errors/borrowck/ffi-polonius/vendor/datafrog/LICENSE-APACHE: New file. * checks/errors/borrowck/ffi-polonius/vendor/datafrog/LICENSE-MIT: New file. * checks/errors/borrowck/ffi-polonius/vendor/datafrog/README.md: New file. * checks/errors/borrowck/ffi-polonius/vendor/datafrog/RELEASES.md: New file. * checks/errors/borrowck/ffi-polonius/vendor/datafrog/examples/borrow_check.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/datafrog/examples/graspan1.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/datafrog/src/join.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/datafrog/src/lib.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/datafrog/src/map.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/datafrog/src/test.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/datafrog/src/treefrog.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/.cargo-checksum.json: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/CHANGELOG.md: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/Cargo.toml: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/LICENSE-APACHE: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/LICENSE-MIT: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/README.md: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/benches/value.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/src/__private_api.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/src/kv/error.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/src/kv/key.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/src/kv/mod.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/src/kv/source.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/src/kv/value.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/src/lib.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/src/macros.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/src/serde.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/log/triagebot.toml: New file. * checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/.cargo-checksum.json: New file. * checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/Cargo.toml: New file. * checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/README.md: New file. * checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/facts.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/lib.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/output/datafrog_opt.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/output/initialization.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/output/liveness.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/output/location_insensitive.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/output/mod.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/output/naive.rs: New file. * checks/errors/borrowck/ffi-polonius/vendor/rustc-hash/.cargo-checksum.json: New file. * checks/errors/borrowck/ffi-polonius/vendor/rustc-hash/CODE_OF_CONDUCT.md: New file. * checks/errors/borrowck/ffi-polonius/vendor/rustc-hash/Cargo.toml: New file. * checks/errors/borrowck/ffi-polonius/vendor/rustc-hash/LICENSE-APACHE: New file. * checks/errors/borrowck/ffi-polonius/vendor/rustc-hash/LICENSE-MIT: New file. * checks/errors/borrowck/ffi-polonius/vendor/rustc-hash/README.md: New file. * checks/errors/borrowck/ffi-polonius/vendor/rustc-hash/src/lib.rs: New file.
2025-03-21nr2.0: Adjust indentifier expression handlingOwen Avery1-9/+17
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Make sure to return early after a resolution error, improve the resolution error message, fix a typo, handle ambiguous resolutions, and remove an old comment. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-21Modify multiple definition errorOwen Avery6-41/+41
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Modify error message. * resolve/rust-ast-resolve-implitem.h (ResolveToplevelImplItem::visit): Likewise. (ResolveTopLevelTraitItems::visit): Likewise. (ResolveToplevelExternItem::visit): Likewise. * resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): Likewise. * resolve/rust-ast-resolve-stmt.h (ResolveStmt::visit): Likewise. * resolve/rust-ast-resolve-toplevel.h (ResolveTopLevel::visit): Likewise. * resolve/rust-ast-resolve-type.h (ResolveGenericParams::visit): Likewise. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. * rust/compile/redef_error2.rs: Modify expected error. * rust/compile/redef_error5.rs: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-20nr2.0: Adjust visitors for struct expressionsOwen Avery2-3/+19
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-19Prevent multiple resolution insertionOwen Avery7-75/+302
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-19nr2.0: Fix test self-path2.rsOwen Avery2-4/+4
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-19emit an error for type or const parameters on foreign itemsRyutaro Okada1-0/+11
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-18Fix modules with same name as builtins causing ICE (#3315)Liam Naddell5-25/+111
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>