aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
10 daysgccrs: Adapt attribute lang hook and do some cleanupdevel/rust/masterMarc Poulhiès2-47/+134
Since r14-6076, the LANG_HOOKS_COMMON_ATTRIBUTE_TABLE should not be used and LANG_HOOKS_ATTRIBUTE_TABLE replaces it. Add the "cold" attribute to fix PR120018 (and the matching "hot" attribute). Replace some gcc_assert() by explicit warnings (same as D frontend). Add some clang-format off/on comment around code that's not correctly formatted. gcc/rust/ChangeLog: PR rust/120018 * rust-attribs.cc (handle_noreturn_attribute): Reindent declaration. (handle_leaf_attribute): Likewise. (handle_const_attribute): Likewise. (handle_malloc_attribute): Likewise. (handle_pure_attribute): Likewise. (handle_novops_attribute): Likewise. (handle_nonnull_attribute): Likewise. (handle_nothrow_attribute): Likewise. (handle_type_generic_attribute): Likewise. (handle_transaction_pure_attribute): Likewise. (handle_returns_twice_attribute): Likewise. (handle_fnspec_attribute): Likewise. (handle_omp_declare_simd_attribute): Likewise. (handle_cold_attribute): New. (handle_hot_attribute): New. (attribute_spec::exclusions attr_cold_hot_exclusions): New. (grs_langhook_common_attributes): Make it static. (grs_langhook_common_attribute_table): New. (grs_langhook_gnu_attributes): New. (grs_langhook_gnu_attribute_table): New. (handle_malloc_attribute): Make it static. (handle_fnspec_attribute): Likewise. (handle_pure_attribute): Replace gcc_assert by explicit warning. (handle_novops_attribute): Likewise. (handle_nothrow_attribute): Likewise. (handle_returns_twice_attribute): Likewise. (handle_omp_declare_simd_attribute): Likewise and make it static. * rust-lang.cc (grs_langhook_gnu_attribute_table): New. (grs_langhook_common_attribute_table): Adjust type to new hook. (LANG_HOOKS_COMMON_ATTRIBUTE_TABLE): Remove. (LANG_HOOKS_ATTRIBUTE_TABLE): New. Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
11 daysnr2.0: Adjust resolution of impl itemsOwen Avery9-37/+76
gcc/rust/ChangeLog: * ast/rust-path.cc (TypePath::make_debug_string): Add definition. * ast/rust-path.h (TypePath::make_debug_string): Add declaration. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Adjust InherentImpl and TraitImpl visitors to better handle associated item scope. * resolve/rust-default-resolver.h (DefaultResolver::maybe_insert_big_self): Add. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Adjust type path resolution errors. * resolve/rust-rib.h (Rib::Kind): Add Generics kind. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Remove InherentImpl and TraitImpl visitor overrides. (TopLevel::maybe_insert_big_self): Add override in order to add a definition of 'Self'. * resolve/rust-toplevel-name-resolver-2.0.h (TopLevel::visit): Remove InherentImpl and TraitImpl visitor overrides. (TopLevel::maybe_insert_big_self): Add override. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
11 daysast: collector: visit InlineAsm node during ast dump0xn4utilus8-47/+143
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Implement for InlineAsm. * ast/rust-ast-full-decls.h (enum class): Move InlineAsmOption enum inside InlineAsm. * ast/rust-expr.h (enum class): Likewise. (class InlineAsm): Likewise. * expand/rust-macro-builtins-asm.cc (check_and_set): Likewise. (parse_options): Likewise. * expand/rust-macro-builtins-asm.h (check_and_set): Likewise. * hir/tree/rust-hir-expr.cc (InlineAsm::InlineAsm): Likewise. * hir/tree/rust-hir-expr.h: Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
11 daysgccrs: fix ICE on empty constexpr loopsTom Schollenberger2-0/+4
Empty loops have no body which means this is a NULL_TREE during const evaluation which needs a check. Fixes Rust-GCC #3618. gcc/rust/ChangeLog: * backend/rust-constexpr.cc (eval_constant_expression): Check if t is a NULL_TREE gcc/testsuite/ChangeLog: * rust/compile/issue-3618.rs: Test empty loops error properly. Signed-off-by: Tom Schollenberger <tss2344@g.rit.edu>
11 daysgccrs: Prevent passing generic arguments to impl traits in argument positionPhilip Herron9-33/+73
When using impl traits in argument position (APIT), they are desugared into generics, and supplying explicit generic arguments is not allowed. This commit adds the error diagnostic E0632 for attempting to pass generic arguments to impl traits, completing the implementation of the APIT feature. gcc/rust/ChangeLog: * ast/rust-desugar-apit.cc: track if this is a impl-trait generic * ast/rust-item.h (class TypeParam): add field to track if from impl trait * hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): likewise * hir/tree/rust-hir-item.cc (TypeParam::TypeParam): upate hir as well (TypeParam::operator=): likewise * hir/tree/rust-hir-item.h (class TypeParam): likewise * typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_generic_param): add error * typecheck/rust-tyty-subst.h: add const getter for the associated TypeParm gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this * rust/compile/impl_trait_generic_arg.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
12 daysnr2.0: Adjust enum item visitorsOwen Avery4-3/+38
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Make call to EnumItem visitor from EnumItem derived class visitors non-virtual. * ast/rust-collect-lang-items.cc (CollectLangItems::visit): Handle visitation of classes derived from EnumItem. * ast/rust-collect-lang-items.h (CollectLangItems::visit): Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Call DefaultResolver::visit on EnumItem instances. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
12 daysImprove struct pattern compilationOwen Avery3-29/+30
gcc/rust/ChangeLog: * backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): Fix GENERIC generation in light of enum layout changes since this code was written. (CompilePatternBindings::handle_struct_pattern_ident_pat): Delegate handling of child patterns to another CompilePatternBindings::Compile call. (CompilePatternBindings::make_struct_access): Make field name parameter const qualified. * backend/rust-compile-pattern.h (CompilePatternBindings::make_struct_access): Likewise. gcc/testsuite/ChangeLog: * rust/execute/torture/struct-pattern-match.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
12 daysRevert "backend: Remove checks on StructFieldIdentPattern"Owen Avery1-7/+25
This reverts commit 92323dd3bb16f21194891ce463fc865598c6980f.
12 daysImprove canonical path handling for impl itemsOwen Avery2-13/+8
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Use the return values of CanonicalPath::inherent_impl_seg and CanonicalPath::trait_impl_projection_seg more directly. * util/rust-canonical-path.h (CanonicalPath::trait_impl_projection_seg): Append "<impl " instead of "<" to the beginning of the returned path segment. (CanonicalPath::inherent_impl_seg): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
12 daysgccrs: desugar APIT impl traitsPhilip Herron21-34/+866
Argument position impl traits are simply syntatic sugar for generics. This adds a new desugar pass to do this. So for example: fn foo(a: impl Value, b: impl Value) -> i32 Is desugared into: fn foo<T: Value, U: Value> (a: T, b: U) -> i32 So it just works like any normal generic function. There are more complex cases such as: fn foo(_value: impl Bar<Baz = impl Foo>) -> i32 Which has a generic argument binding which needs to be turned into a where constraint: fn foo<T, U>(_value: T) -> i32 where T: Bar<Baz = U>, U: Foo, Fixes Rust-GCC#2015 Fixes Rust-GCC#1487 Fixes Rust-GCC#3454 Fixes Rust-GCC#1482 gcc/rust/ChangeLog: * Make-lang.in: new desugar file * ast/rust-ast.cc (ImplTraitTypeOneBound::as_string): its a unique_ptr now (FormatArgs::set_outer_attrs): reformat * ast/rust-path.h: remove has_generic_args assertion (can be empty because of desugar) * ast/rust-type.h (class ImplTraitTypeOneBound): add copy ctor and use unique_ptr * hir/rust-ast-lower-type.cc (ASTLoweringType::visit): update to use unique_ptr * parse/rust-parse-impl.h (Parser::parse_type): reuse the existing unique_ptr instead (Parser::parse_type_no_bounds): likewise (Parser::parse_pattern): likewise * resolve/rust-ast-resolve-type.cc (ResolveType::visit): its a unique_ptr now * rust-session-manager.cc (Session::compile_crate): call desugar * ast/rust-desugar-apit.cc: New file. * ast/rust-desugar-apit.h: New file. gcc/testsuite/ChangeLog: * rust/compile/issue-2015.rs: fully supported now * rust/compile/nr2/exclude: nr2 cant handle some of these * rust/compile/issue-1487.rs: New test. * rust/compile/issue-3454.rs: New test. * rust/execute/torture/impl_desugar-2.rs: New test. * rust/execute/torture/impl_desugar.rs: New test. * rust/execute/torture/impl_trait1.rs: New test. * rust/execute/torture/impl_trait2.rs: New test. * rust/execute/torture/impl_trait3.rs: New test. * rust/execute/torture/impl_trait4.rs: New test. * rust/execute/torture/issue-1482.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
12 daysgccrs: Emit error diagnostic for bad impl type usagePhilip Herron6-24/+85
Rust only allows impl traits to be used in the return position of functions. Fixes Rust-GCC#1485 gcc/rust/ChangeLog: * hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): allow impl type * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): likewise * hir/rust-ast-lower-type.cc (ASTLoweringType::ASTLoweringType): new flag for impl trait (ASTLoweringType::translate): pass flag (ASTLoweringType::visit): track impl trait tag (ASTLoweringType::emit_impl_trait_error): new diagnostic * hir/rust-ast-lower-type.h: add new field gcc/testsuite/ChangeLog: * rust/compile/impl_trait_diag.rs: New test. * rust/compile/issue-1485.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-05-02derive(PartialEq): Fix raw strings in testCohenArthur1-2/+2
gcc/testsuite/ChangeLog: * rust/execute/torture/derive-partialeq2.rs: Add missing terminating nul char. Co-authored-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-05-02derive(PartialEq): Allow deriving enum structsArthur Cohen2-14/+118
gcc/rust/ChangeLog: * expand/rust-derive-partial-eq.cc (DerivePartialEq::match_enum_tuple): Remove debug call. (DerivePartialEq::match_enum_struct): Add proper implementation. (DerivePartialEq::visit_enum): Call it. gcc/testsuite/ChangeLog: * rust/execute/torture/derive-partialeq2.rs: New test.
2025-05-02ast: builder: Allow building struct ident patternsArthur Cohen2-0/+12
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::struct_pattern_ident_pattern): New. * ast/rust-ast-builder.h: New declaration.
2025-04-30backend: Remove checks on StructFieldIdentPatternArthur Cohen1-25/+7
gcc/rust/ChangeLog: * backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): Remove old invalid checks.
2025-04-30backend: Compile struct rebinding patternsArthur Cohen3-18/+77
Allow matching on a struct instance and rebinding its fields to new names: match X { Foo { field0: new_name0, field1: new_name1, } => { do_something(new_name0, new_name1); }, } This will enable us to finish derives for PartialEq and PartialOrd but isn't a complete implementation of these patterns yet. gcc/rust/ChangeLog: * backend/rust-compile-pattern.cc (CompilePatternBindings::make_struct_access): New function. (CompilePatternBindings::visit): Properly implement patterns mentioned above and call make_struct_accesss. * backend/rust-compile-pattern.h: New declaration. gcc/testsuite/ChangeLog: * rust/execute/torture/struct_pattern1.rs: New test.
2025-04-30backend: Refactor struct pattern compilationArthur Cohen2-46/+68
gcc/rust/ChangeLog: * backend/rust-compile-pattern.h: Split struct pattern compilation into three functions. * backend/rust-compile-pattern.cc: Implement them.
2025-04-29nr2.0: late: Correctly initialize funny_error memberArthur Cohen1-1/+3
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::Late): False initialize the funny_error field.
2025-04-28Fix narrowing conversion warningsOwen Avery2-23/+29
Fixes PR#119641 gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-place.h (IndexVec::size_type): Add. (IndexVec::MAX_INDEX): Add. (IndexVec::size): Change the return type to the type of the internal value used by the index type. (PlaceDB::lookup_or_add_variable): Use the return value from the PlaceDB::add_place call. * checks/errors/borrowck/rust-bir.h (struct BasicBlockId): Move this definition before the definition of the struct Function. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-28Visit visibility in UseDeclarationPierre-Emmanuel Patry1-0/+1
Default visitor should visit all it's children. gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit visibility. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-28Some assorted tweaks and bug fixesOwen Avery3-5/+5
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit the loop labels of WhileLetLoopExpr instances before visiting their scrutinee expressions. * resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Pass the glob import's path directly to NameResolutionContext::resolve_path. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Remove unnecessary call to Identifier::as_string. (flatten_glob): Improve handling of cases where a glob use tree has no path. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-28Completely duplicate path nodePierre-Emmanuel Patry2-2/+7
Both nodes had the same id, this led to a resolution conflict. gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::clone_enum_struct): Clone path to avoid using the same nodeid. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove now passing test from exclusion list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Use specialized param visit function for paramsPierre-Emmanuel Patry4-28/+20
This commit introduce a new public function to visit function parameters in the default visitor. It allows visitors derived from DefaultVisitor to override only a small part of the default visitor. gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit_function_params): Add specialized function to visit function parameters. (DefaultASTVisitor::visit): Remove parameter visit and call specialized function instead. * ast/rust-ast-visitor.h: Add function prototye. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove function. (Late::visit_function_params): Override specialized visit function. * resolve/rust-late-name-resolver-2.0.h: Add overriden function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Remove passing test from exclusion listPierre-Emmanuel Patry1-2/+0
gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove passing test from exclusion list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Use stacked context for nested bindings.Pierre-Emmanuel Patry4-71/+113
Binding context may be stacked when a new binding group is introduced within a const expression. gcc/rust/ChangeLog: * resolve/rust-name-resolution-context.h: Use BindingLayer instead. * resolve/rust-name-resolution-context.cc (BindingLayer::BindingLayer): Add new constructor for binding layer. (BindingLayer::bind_test): Add a function to test a binding constraint. (BindingLayer::push): Push a new binding group. (BindingLayer::and_binded): Add function to test and-binding constraint. (BindingLayer::or_binded): Add function to test or-binding constraints. (BindingLayer::insert_ident): Insert a new identifier in the current binding group. (BindingLayer::merge): Merge current binding group with it's parent. (BindingLayer::get_source): Get the source of the current binding group. * resolve/rust-late-name-resolver-2.0.cc: Use stacked context for binding group. * util/rust-stacked-contexts.h: Add mutable peek function. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Add pattern bindingsPierre-Emmanuel Patry3-5/+156
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add binding creation in visitor. * resolve/rust-late-name-resolver-2.0.h: Add function prototypes. * resolve/rust-name-resolution-context.h: Add binding context. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Add binding context classPierre-Emmanuel Patry1-0/+81
We need to differentiate bindings types, so the same binding cannot be reused multiple time in a product binding. gcc/rust/ChangeLog: * resolve/rust-name-resolution-context.h (struct Binding): Add Binding struct to differentiate Or and Product bindings in patterns. (enum class): Add Binding kind. (class BindingContext): Add binding context with Binding stack. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Add hash function for IdentifiersPierre-Emmanuel Patry1-0/+13
gcc/rust/ChangeLog: * ast/rust-ast.h: Add hash function. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Add equality operator for identifiersPierre-Emmanuel Patry1-0/+5
gcc/rust/ChangeLog: * ast/rust-ast.h: Add equality operator. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Add fn_once and Sized lang items to the testPierre-Emmanuel Patry1-10/+19
gcc/testsuite/ChangeLog: * rust/compile/multiple_bindings1.rs: Add missing lang items. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Change expected error output to match nr2Pierre-Emmanuel Patry2-5/+5
Name resolution 2.0 message describes the context around the unresolved items and should therefore be kept. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove test from exclusion list. * rust/compile/use_1.rs: Change expected output and remove test from nr1. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Update generics9 expected error messagePierre-Emmanuel Patry2-2/+2
gcc/testsuite/ChangeLog: * rust/compile/generics9.rs: Change expected error message. * rust/compile/nr2/exclude: Remove test from exclusion list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Prevent forward declaration in type parametersPierre-Emmanuel Patry4-0/+33
gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Add visit function for TypeParam. * resolve/rust-default-resolver.h: Add function prototype. * resolve/rust-forever-stack.h: Add function to check for forward declaration ban. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Check forward declarations. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Remove error state for GenericArgPierre-Emmanuel Patry8-45/+35
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove error kind and change function call. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Change call name. * ast/rust-path.cc (ConstGenericParam::as_string): Likewise. * ast/rust-path.h: Remove error kind. * hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): Change call name. * parse/rust-parse-impl.h (Parser::parse_generic_param): Use optional on parsing failure. (Parser::parse_generic_arg): Likewise. (Parser::parse_path_generic_args): Likewise. * parse/rust-parse.h: Likewise. * resolve/rust-ast-resolve-type.h: Change call name. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-23Change error message to match expected test outputPierre-Emmanuel Patry2-4/+2
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Change error message. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove passing test from exclusion list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-22nr2.0: Improve error handlingOwen Avery6-49/+115
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::build_import_mapping): Avoid outputting an "unresolved import" error if other errors are outputted during resolution. * resolve/rust-early-name-resolver-2.0.h (Early::resolve_path_in_all_ns): Collect path resolution errors while avoiding duplicate errors for resolutions in each namespace. * resolve/rust-forever-stack.h (ForeverStack::resolve_path): Add parameter for collecting errors. (ForeverStack::find_starting_point): Likewise. (ForeverStack::resolve_segments): Likewise. * resolve/rust-forever-stack.hxx (check_leading_kw_at_start): Likewise. (ForeverStack::find_starting_point): Likewise. (ForeverStack::resolve_segments): Likewise. (ForeverStack::resolve_path): Likewise. * resolve/rust-name-resolution-context.h (NameResolutionContext::resolve_path): Add optional parameter for collecting errors. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entry. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-22nr2.0: Fix derive-debug1.rsOwen Avery2-2/+1
gcc/testsuite/ChangeLog: * rust/compile/derive-debug1.rs: Adjust a path. * rust/compile/nr2/exclude: Remove derive-debug1.rs. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-19Disable parallel testing for 'rust/compile/nr2/compile.exp' [PR119508]Thomas Schwinge1-0/+11
..., using the standard idiom. This '*.exp' file doesn't adhere to the parallel testing protocol as defined in 'gcc/testsuite/lib/gcc-defs.exp'. This also restores proper behavior for '*.exp' files executing after (!) this one, which erroneously caused hundreds or even thousands of individual test cases get duplicated vs. skipped, randomly, depending on the '-jN' level. PR testsuite/119508 gcc/testsuite/ * rust/compile/nr2/compile.exp: Disable parallel testing. (cherry picked from commit 79d2c3089f480738613b7d338d86d8be710f8158)
2025-04-19gccrs: prealloc the initilizer vectorPhilip Herron1-0/+4
There are two cases when initilizing an array, this is the const context which means we need to build the array ctor, which means using lots of memory, its super inefficient because we are using a big wrapper over the GCC internals here but preallocating the vectors here causes a: terminate called after throwing an instance of 'std::bad_alloc' So this is a handy error condition to rely on for this senario. Fixes Rust-GCC#3713 Fixes Rust-GCC#3727 gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::array_copied_expr): prealloc the vector Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-18gccrs: Fix ICE with empty generic argumentsPhilip Herron4-2/+7
We have an assertion when accessing generic args if there are any which is really useful so this adds the missing guards for the case where they are specified but empty. Fixes Rust-GCC#3649 gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): add guard * expand/rust-expand-visitor.cc (ExpandVisitor::visit): add guard gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 is missing error for this * rust/compile/issue-3649.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-18Adjust segment start position errorsOwen Avery6-15/+13
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Adjust error messages. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. * resolve/rust-forever-stack.hxx (check_leading_kw_at_start): Likewise. gcc/testsuite/ChangeLog: * rust/compile/issue-3568.rs: Adjust expected errors. * rust/compile/name_resolution9.rs: Likewise. * rust/compile/self-path2.rs: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-18gccrs: Fix ICE when handling case of unknown field in HIR::FieldAccessPhilip Herron4-11/+30
We were wrongly adding the assertion that this must not be an enum but this is a pointless assertion we only care that there are variant in the ADT and if the field exists in the first variant. Fixes Rust-GCC#3581 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): fix bad assertion gcc/testsuite/ChangeLog: * rust/compile/nonexistent-field.rs: fix bad error message * rust/compile/issue-3581-1.rs: New test. * rust/compile/issue-3581-2.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-18gccrs: Add test case to show ice is fixedPhilip Herron2-0/+8
Fixes Rust-GCC#3652 gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 does not error on the T it should require Self::T * rust/compile/issue-3652.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-18nr2.0: Remove unnecessary copy of NodeOwen Avery1-1/+1
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx (ForeverStack::resolve_path): Pass instance of Node to lambda by reference instead of by value. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-18gccrs: Fix ICE in struct expressionsPhilip Herron5-33/+45
The error handling here was done long ago when we didnt know how to do any error handling very well. This removed bad fatal_errors and adds in some nice rich_location error diagnostics instead. Fixes Rust-GCC#3628 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-struct-field.h: keep reference to parent expression * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::TypeCheckStructExpr): update ctor (TypeCheckStructExpr::resolve): remove bad rust_fatal_errors (TypeCheckStructExpr::visit): cleanup errors gcc/testsuite/ChangeLog: * rust/compile/macros/mbe/macro-issue2983_2984.rs: cleanup error diagnotics * rust/compile/struct_init1.rs: likewise * rust/compile/issue-3628.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-18nr2.0: Handle StructPatternFieldIdentOwen Avery3-1/+9
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Handle StructPatternFieldIdent. * resolve/rust-late-name-resolver-2.0.h (Late::visit): Likewise. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entry. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-18gccrs: Add test case to show ICE is fixedPhilip Herron1-0/+8
Fixes Rust-GCC#3662 gcc/testsuite/ChangeLog: * rust/compile/issue-3662.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-18gccrs: Add test case to show issue is fixedPhilip Herron1-0/+17
This was already fixed in: bb01719f0e1 but we require fn_once lang item to be defined as we are working on libcore support still. Fixes Rust-GCC#3711 gcc/testsuite/ChangeLog: * rust/compile/issue-3711.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-17Add gimple test for black box intrinsicPierre-Emmanuel Patry1-0/+28
gcc/testsuite/ChangeLog: * rust/compile/black_box.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-17Add execute test for black_box intrinsicPierre-Emmanuel Patry1-0/+30
gcc/testsuite/ChangeLog: * rust/execute/black_box.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>