aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2025-03-27gccrs: Fix ICE when using super mid way though pathPhilip Herron3-0/+14
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 Herron5-1/+59
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 Herron4-3/+95
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 Herron2-0/+15
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-26Fix core library test with proper canonical pathPierre-Emmanuel Patry1-4/+4
Import from core library was wrong, it misses several crate directives since we're no longer dealing with multiple files. gcc/testsuite/ChangeLog: * rust/compile/issue-2905-2.rs: Import from core library into a single file misses the crate directives. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-26gccrs: fix unconstrained infer vars on generic associated typePhilip Herron4-11/+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 Avery3-1/+9
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-26testsuite: Add more testcases for cfg() in coreArthur Cohen2-0/+24
gcc/testsuite/ChangeLog: * rust/compile/cfg-core1.rs: New test. * rust/compile/cfg-core2.rs: New test.
2025-03-26Lower raw string literalsOwen Avery2-2/+5
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 Cohen10-170/+41
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-25nr2.0: Fix test const_generics_3.rsOwen Avery2-4/+5
gcc/testsuite/ChangeLog: * rust/compile/const_generics_3.rs: Modify test to run with name resolution 2.0 only and to handle the absence of a bogus resolution error. * rust/compile/nr2/exclude: Remove const_generics_3.rs. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
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-24Remove now passing test from exclusion listPierre-Emmanuel Patry1-5/+0
Those tests were malformed and failed with the new name resolution because of it. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove test from exclusion list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24Fix testcase module pathPierre-Emmanuel Patry9-137/+139
Those tests are coming from libcore and module inlining was wrong, in libcore there was a use declaration to import those modules which was missing here. gcc/testsuite/ChangeLog: * rust/compile/issue-2330.rs: Use complete path from crate root. * rust/compile/issue-1901.rs: Likewise. * rust/compile/issue-1981.rs: Likewise. * rust/compile/iterators1.rs: Likewise. * rust/compile/sizeof-stray-infer-var-bug.rs: Likewise. * rust/compile/for-loop1.rs: Likewise. * rust/compile/for-loop2.rs: Likewise. * rust/compile/torture/builtin_abort.rs: Likewise. * rust/compile/torture/uninit-intrinsic-1.rs: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24Fix function name to printfPierre-Emmanuel Patry2-2/+5
Function could not be found and triggered an error message. gcc/testsuite/ChangeLog: * rust/compile/feature_rust_attri0.rs: Add extern function declaration and change name to printf. * rust/compile/nr2/exclude: Remove now passing test from exclusion list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24ci: disable networkSam James2-3/+5
Disable network access via 'unshare' in two CI workflows to catch issues like PR119333 where importing polonius meant bootstrap tried to pull crates from the internet. ChangeLog: PR rust/119333 * .github/workflows/bootstrap.yml: Disable network via 'unshare'. * .github/workflows/ccpp.yml: Ditto.
2025-03-23gccrs: support generic super traits recursivelyPhilip Herron10-60/+166
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 Avery3-8/+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 Avery2-12/+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 Avery9-45/+43
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 Avery3-8/+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 Avery8-81/+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 Avery4-7/+6
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 Okada2-0/+19
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 Naddell8-25/+127
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-18nr2.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-17Remove 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-17Fix canonical path parent resolutionPierre-Emmanuel Patry1-1/+1
The algorithm was comparing using the wrong id, this lead to some mangling errors as an erroneous parent was selected. gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx: Fix the id comparison. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17Insert crate name in canonical pathPierre-Emmanuel Patry1-1/+6
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx: Insert a new segment with the crate's name as canonical's path prefix. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17Add a function to get the crate number from node idPierre-Emmanuel Patry2-7/+14
gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::lookup_crate_num): Add function to retrieve crate number from it's node id. (Mappings::node_is_crate): change function with call to lookup_crate_num to avoid looping through all crates. (Mappings::insert_ast_crate): Populate node id to crate number map. * util/rust-hir-map.h: Change function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17Remove finalize import visitorPierre-Emmanuel Patry2-75/+0
This visitor is not used anymore. gcc/rust/ChangeLog: * resolve/rust-finalize-imports-2.0.cc (FinalizeImports::FinalizeImports): Remove constructor. (FinalizeImports::go): Remove function. (FinalizeImports::visit): Likewise. * resolve/rust-finalize-imports-2.0.h (class FinalizeImports): Remove FinalizeImports class. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17Remove 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-17Move import mapping resolution to in tree visitPierre-Emmanuel Patry5-90/+105
Import mapping was relying on resolve_path which in turn relies on the cursor function. This means the mapping resolver should be called from the correct scope instead of being called from the crate scope. gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::Early): Move the top level visitor from the function scope to attributes. (Early::go): Remove top level visitor creation and adapt calling code. Remove call to mapping resolution and import finalization. (Early::finalize_simple_import): Move the finalization from it's visitor. (Early::finalize_glob_import): Likewise. (Early::finalize_rebind_import): Likewise. (Early::visit): Add mapping resolution and finalization in UseDeclaration visitor function. * resolve/rust-finalize-imports-2.0.cc (finalize_simple_import): Move function. (finalize_glob_import): Likewise. (finalize_rebind_import): Likewise. (FinalizeImports::visit): Remove call to finalizers. * resolve/rust-early-name-resolver-2.0.h (class Early): Add top level attribute. * resolve/rust-finalize-imports-2.0.h: Add function prototypes. * resolve/rust-toplevel-name-resolver-2.0.h: Change getter return type to reference. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-14gccrs: check for recursion trait cycle with bounds checksPhilip Herron6-5/+78
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-14gccrs: track DefId on ADT Types this could be useful informationPhilip Herron3-29/+65
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): track DefId of origin * typecheck/rust-tyty.cc (BaseType::monomorphized_clone): likewise (ADTType::ADTType): likewise (ADTType::get_id): likewise (ADTType::clone): likewise * typecheck/rust-tyty.h: likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-14gccrs: remove visitor which is not needed herePhilip Herron2-46/+20
Just a small refactor to remove a visitor which is not needed. gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (ResolvePathRef::Compile): remove visitor (ResolvePathRef::ResolvePathRef): likewise (ResolvePathRef::visit): likewise * backend/rust-compile-resolve-path.h (class ResolvePathRef): likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-14Fix some small issuesOwen Avery2-2/+2
gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (assume_handler): Fix copy/paste error. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Fix spelling mistake. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-11Add 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-11Remove 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-11Add enum variant string information to definitionPierre-Emmanuel Patry1-0/+2
New enum variant status now appears in the string representation of the resolver's definition. gcc/rust/ChangeLog: * resolve/rust-rib.cc (Rib::Definition::to_string): Add enum variant status. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-11Keep definition provenance to skip enum variantsPierre-Emmanuel Patry8-26/+106
Enum variants shouldn't be accessed directly even from within an enum. This commit keeps the provenance for enum variants definition so we can skip them when resolving a value within an enum definition. gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Add new function to insert enum variants and add argument to resolver's get function to explicitely skip enum variants. * resolve/rust-forever-stack.hxx: Update function definitions. * resolve/rust-name-resolution-context.cc (NameResolutionContext::insert_variant): Add function to insert enum variants. * resolve/rust-name-resolution-context.h: Add function's prototype. * resolve/rust-rib.cc (Rib::Definition::Definition): Add new boolean to hint at enum variant provenance. (Rib::Definition::is_variant): New getter for variant status. (Rib::Definition::Shadowable): Update constructor to opt out of enum variants. (Rib::Definition::Globbed): Likewise. (Rib::Definition::NonShadowable): Change constructor to forward enum variant provenance status. * resolve/rust-rib.h: Update function prototypes. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::insert_enum_variant_or_error_out): Add function to insert enum variants in the name resolver. (TopLevel::visit): Update several enum variant's visitor function with the new enum variant name resolving code. * resolve/rust-toplevel-name-resolver-2.0.h: Update function prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-11Add rib kind debug representationPierre-Emmanuel Patry2-3/+36
Rib kind had no string representation, and thus were not used in the debug string representation. gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx: Output rib kind. * resolve/rust-rib.h: Add function to get string representation from a rib kind. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-10nr2.0: Set the node id of the root nodeOwen Avery3-10/+6
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-06expansion: Correctly expand $crate metavarArthur Cohen8-17/+115
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.