aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
AgeCommit message (Collapse)AuthorFilesLines
2025-03-24gccrs: 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-03-24gccrs: coercion sites allow for type inference as well.Philip Herron1-2/+4
Addresses Rust-GCC#3382 and Rust-GCC#3381 gcc/rust/ChangeLog: * typecheck/rust-type-util.cc (coercion_site): allow inference vars gcc/testsuite/ChangeLog: * rust/compile/reference1.rs: fix error message Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: Fix 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-03-24gccrs: 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-03-24gccrs: Fix bug in type resolution of pathsOwen Avery8-43/+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-03-24gccrs: nr2.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-03-24gccrs: ast: 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-03-24gccrs: derive(Debug): Add stub implementation.Arthur Cohen4-0/+192
gcc/rust/ChangeLog: * expand/rust-derive-debug.cc: New file. * expand/rust-derive-debug.h: New file. * Make-lang.in: Compile them. * expand/rust-derive.cc (DeriveVisitor::derive): Call into DeriveDebug. gcc/testsuite/ChangeLog: * rust/compile/derive-debug1.rs: New test. * rust/compile/nr2/exclude: Exclude it.
2025-03-24gccrs: derive(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-03-24gccrs: derive-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-03-24gccrs: ast-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-03-24gccrs: ast-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-03-24gccrs: scan-deadcode: Do not warn unused fields if they start with '_'Arthur Cohen1-1/+2
gcc/rust/ChangeLog: * checks/lints/rust-lint-scan-deadcode.h: Check if the field name starts with an underscore before warning.
2025-03-24gccrs: lang-items: Add structural_{peq, teq}Arthur Cohen2-0/+6
These lang items are used when deriving Eq and PartialEq, and will be checked when compiling pattern matching. gcc/rust/ChangeLog: * util/rust-lang-item.cc: New items. * util/rust-lang-item.h: Likewise. gcc/testsuite/ChangeLog: * rust/compile/structural-eq-peq.rs: New test.
2025-03-24gccrs: nr2.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-03-24gccrs: Fix 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>
2025-03-24gccrs: Add option_env! supportLiam Naddell4-1/+85
gcc/rust/ChangeLog: * expand/rust-macro-builtins-utility.cc: Add macro expansion for option_env with eager expansion * expand/rust-macro-builtins.cc: Add option_env to builtin list * expand/rust-macro-builtins.h: Add option_env handler to header file * resolve/rust-late-name-resolver-2.0.cc: Prevent NR2.0 from recursing into lang-item segments gcc/testsuite/ChangeLog: * rust/compile/macros/builtin/option_env1.rs: Add success case for option_env * rust/compile/macros/builtin/option_env2.rs: Add failure case for option_env * rust/execute/torture/builtin_macro_option_env.rs: Add execution case for option_env
2025-03-24gccrs: ast: Add new Expr::KindsArthur Cohen2-0/+41
Collapses all of the OperatorExprs into Expr instead of first having to check for OperatorExpr and then check for each OperatorExpr::Kind. gcc/rust/ChangeLog: * ast/rust-ast.h: Add new Expr::Kinds. * ast/rust-expr.h: Implement missing get_expr_kind(), Add get_function_expr_ptr()
2025-03-24gccrs: add support for ref literal patternsPhilip Herron2-8/+23
Fixes Rust-GCC#3174 gcc/rust/ChangeLog: * backend/rust-compile-pattern.cc (CompilePatternBindings::visit): make recursive * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): handle ref flag gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this * rust/compile/issue-3174.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: lang-items: Add From::fromArthur Cohen2-0/+5
gcc/rust/ChangeLog: * util/rust-lang-item.h: Declare it. * util/rust-lang-item.cc: Use it.
2025-03-24gccrs: add new -frust-overflow-checks flag to control overflow checksPhilip Herron2-16/+21
This will be crucial for more complex gimple debugging to make it easier to follow the code vs the original rust code. gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): disable overflow checks * lang.opt: new flag Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: Compile unit struct with constructorPierre-Emmanuel Patry1-0/+5
gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Do not use query system for unit struct but compile it's constructor instead. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: Resolved item type shall be differentiated laterPierre-Emmanuel Patry1-2/+4
We need to query all namespaces and error out at a later stage if the retrieved item is wrong. gcc/rust/ChangeLog: * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait): Query all namespaces. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: Make foreverstack debug string constPierre-Emmanuel Patry2-6/+6
Those function should not change anything within the foreverstack, it can therefore be made const. gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Make debug functions const. * resolve/rust-forever-stack.hxx: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: Clone expr instead of taking itPierre-Emmanuel Patry1-4/+5
We're reusing the value, it could therefore not be taken be should be cloned. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit): Clone expr instead of taking it. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: Remove query mode on CompileItemPierre-Emmanuel Patry2-8/+4
Query mode was a hack to catch up some compile errors early, it was deemed to be removed at some time. Recent changes to NR1 highlighted an incompatibility with it hence it's removal. gcc/rust/ChangeLog: * backend/rust-compile-item.h: Remove query mode. * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: Add unit struct to name namespace in old resolverPierre-Emmanuel Patry1-8/+15
We missed the name namespace for unit struct in the old resolver. gcc/rust/ChangeLog: * resolve/rust-ast-resolve-toplevel.h: Add struct to name namespace. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: Add debug dump to old name resolverPierre-Emmanuel Patry1-0/+35
It might be necessary to compare both name resolution' internal states during the transition. This new debug representation could help with that. gcc/rust/ChangeLog: * resolve/rust-name-resolver.h: Add new degug dump for old name resolver. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: Labels shall be pushed within label namespacePierre-Emmanuel Patry4-14/+14
Labels were using the wrong namespace. gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Change label push function from type rib to label rib. * resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise. (ResolveItem::visit): Likewise. (ResolveExternItem::visit): Likewise. * resolve/rust-ast-resolve-stmt.h: Likewise. * resolve/rust-ast-resolve.cc (NameResolution::go): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: backend: Improve handling of lang-item PathInExpressionsArthur Cohen2-48/+84
gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (ResolvePathRef::visit): Call into resolve_path_like instead. (ResolvePathRef::resolve_path_like): New. (ResolvePathRef::resolve): Call into resolve_with_node_id. * backend/rust-compile-resolve-path.h: Declare new functions and document them.
2025-03-24gccrs: ast: Add Path::is_lang_item()Arthur Cohen1-0/+2
gcc/rust/ChangeLog: * ast/rust-path.h: New function.
2025-03-24gccrs: marklive: Fix handling for lang item PathInExpressions.Arthur Cohen1-4/+12
gcc/rust/ChangeLog: * checks/lints/rust-lint-marklive.cc (MarkLive::visit): Adapt to lang items.
2025-03-24gccrs: hir: Adapt visitors to lang item PathInExpressionsArthur Cohen2-15/+85
gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (ResolvePathRef::visit): Adapt visitor to lang item HIR::PathInExpressions. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise.
2025-03-24gccrs: hir: Add LangItem paths to PathPattern classArthur Cohen3-8/+104
gcc/rust/ChangeLog: * hir/tree/rust-hir-path.h: Adapt PathPattern to accept lang-item paths. * hir/tree/rust-hir-path.cc: Assert we are dealing with a segmented path, create lang-item constructors. * hir/tree/rust-hir.cc (PathPattern::convert_to_simple_path): Likewise.
2025-03-24gccrs: ast: More visitors to allow lang item paths in expressionsArthur Cohen7-35/+53
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Adapt visitor to lang item PathInExpressions. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * hir/rust-ast-lower.cc (ASTLoweringExprWithBlock::visit): Likewise. (ASTLowerPathInExpression::visit): Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise.
2025-03-24gccrs: lang-items: Add LangItem::IsEnumVariantArthur Cohen2-1/+13
gcc/rust/ChangeLog: * util/rust-lang-item.cc (LangItem::IsEnumVariant): New function. * util/rust-lang-item.h: Declare it.
2025-03-24gccrs: mappings: Improve error message for get_lang_item_nodeArthur Cohen1-2/+2
gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::get_lang_item_node): Better formatting when a lang item does not exist when it should.
2025-03-24gccrs: lang-items: Collect enum variants as lang itemsArthur Cohen2-0/+10
gcc/rust/ChangeLog: * ast/rust-collect-lang-items.h: Declare visitor. * ast/rust-collect-lang-items.cc (CollectLangItems::visit): New.
2025-03-24gccrs: catch missing guard for optional resultPhilip Herron1-5/+2
When we lookup here it returns an optional which can lead to a crash because it needs a guard if it has a value. gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): add guard gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: these tests now work it seems Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-24gccrs: Infer crate name after file openingDylan Gardner2-29/+34
Fixes #3129. gcc/rust/ChangeLog: * rust-session-manager.cc (Session::handle_crate_name): Remove crate name inference (Session::compile_crate): Add crate name inference and error if inferred name is empty. Remove CompileOptions::get_instance () that returned a local copy of the options. Rename crate_name_changed to crate_name_found to match semantics. (rust_crate_name_validation_test): Test inferring ".rs" name * rust-session-manager.h: Modify handle_crate_name definition to include filename.
2025-03-24gccrs: Add captures for ClosureExprInnerTyped with nr2Pierre-Emmanuel Patry2-2/+16
Captures were only processed for regular ClosureExprInner. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add ClosureExprInnerTyped visit implementation. (add_captures): Add a function to avoid code duplication. * resolve/rust-late-name-resolver-2.0.h: Add function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: Add environment capture to NR2Pierre-Emmanuel Patry6-1/+61
The compiler was still relying on NR1 for closure captures when using nr2 even though the resolver was not used and thus it's state empty. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add environment collection. * resolve/rust-late-name-resolver-2.0.h: Add function prototype. * resolve/rust-name-resolver.cc (Resolver::get_captures): Add assertion to prevent NR2 usage with nr1 capture functions. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Use nr2 captures. * util/rust-hir-map.cc (Mappings::add_capture): Add function to register capture for a given closure. (Mappings::lookup_captures): Add a function to lookup all captures available for a given closure. * util/rust-hir-map.h: Add function prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: Check for type paths nr2.0 can't handle yetOwen Avery1-0/+8
Some of our tests only work with name resolution 2.0 because the latter misinterprets type paths. This change should cause the compiler to error out if it would otherwise misinterpret a type path. A fix for type path resolution isn't included in this comment, since doing so would make it harder to track the meaningfulness of test regressions. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Error out if a type path has multiple segments, as we currently ignore every segment except the last. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Add entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-24gccrs: backend: Allow anything as a match scrutineeArthur Cohen1-5/+1
gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (check_match_scrutinee): Allow anything to be used as a match scrutinee, not just ADTs.
2025-03-24gccrs: lang-items: Add Result and Try lang itemsArthur Cohen2-0/+20
gcc/rust/ChangeLog: * util/rust-lang-item.h: Add handling for Result::Ok, Result::Err, Try, Try::into_result, Try::from_ok, Try::from_err. * util/rust-lang-item.cc: Likewise. gcc/testsuite/ChangeLog: * rust/compile/try-trait.rs: New test.
2025-03-24gccrs: Fix rust breakage with nr2Pierre-Emmanuel Patry6-41/+143
Nr2 did not emit the correct error message for break identifier "rust". gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add "rust" identifier detection akin to nr1. (funny_ice_finalizer): Copy ICE finalizer from nr1. * resolve/rust-late-name-resolver-2.0.h: Add funny_error member context state. * Make-lang.in: Add new translation unit for new ice finalizer. * resolve/rust-ast-resolve-expr.cc: Move ice finalizer to it's own file. * resolve/rust-ice-finalizer.cc: New file. * resolve/rust-ice-finalizer.h: New file. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove break-rust3.rs from exclude list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-24gccrs: derive(Copy): Improve bounds when deriving CopyArthur Cohen1-2/+7
gcc/rust/ChangeLog: * expand/rust-derive-copy.cc: Always add an extra Copy bound on generic Copy impls.
2025-03-24gccrs: derive(Clone): Use lang item bounds on AssertParamIsCopyArthur Cohen1-6/+5
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::visit_union): Use lang items for Copy and Sized bounds. gcc/testsuite/ChangeLog: * rust/compile/derive_macro6.rs: Add lang item attribute to Copy trait.
2025-03-24gccrs: derive(Clone): Add Clone bound on generated impl blocksArthur Cohen1-6/+11
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc: Add extra bound when deriving generic Clone
2025-03-24gccrs: ast-builder: Add extra parameter for TypeParam builderArthur Cohen2-2/+8
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::new_type_param): Add optional extra trait bounds. * ast/rust-ast-builder.h: Likewise.