aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2025-04-10rust: Use FLOAT_TYPE_P instead of manual checkingAndrew Pinski1-4/+4
This moves is_floating_point over to using FLOAT_TYPE_P instead of manually checking. Note before it would return true for all COMPLEX_TYPE but complex types' inner type could be integral. Also fixes up the comment to be in more of the GNU style. Bootstrapped and tested on x86_64-linux-gnu. gcc/rust/ChangeLog: * rust-gcc.cc (is_floating_point): Use FLOAT_TYPE_P instead of manually checking the type. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
2025-04-07nr2.0: Adjust test macro6.rsOwen Avery2-2/+1
gcc/testsuite/ChangeLog: * rust/compile/macros/mbe/macro6.rs: Remove call of undefined function. * rust/compile/nr2/exclude: Remove macros/mbe/macro6.rs. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-07nr2.0: Adjust test issue-2812.rsOwen Avery2-3/+2
gcc/testsuite/ChangeLog: * rust/compile/issue-2812.rs: Avoid multiple definition error. * rust/compile/nr2/exclude: Remove issue-2812.rs. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-07gccrs: fix ICE segfault with empty feature gateMatty Kuhn3-0/+12
This patch fixes an issue where an empty feature gate would segfault, instead of reporting a syntax error to the user. gcc/rust/ChangeLog: * ast/rust-ast.h: (AST::Attribute): add empty_input function * checks/errors/rust-feature-gate.cc: (FeatureGate::visit): check for empty feature gate gcc/testsuite/ChangeLog: * rust/compile/feature.rs: add an invalid empty feature to produce an error Signed-off-by: Matty Kuhn <matty.kuhn.1@gmail.com>
2025-04-07Rename label getter to uncheckedPierre-Emmanuel Patry7-8/+11
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Update label getter call. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast.cc (BreakExpr::as_string): Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise. * ast/rust-expr.h: Add optional getter and rename label getter to get_label_unchecked. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Rename label getter in ContinueExprPierre-Emmanuel Patry7-10/+13
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Call unchecked getter. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast.cc (ContinueExpr::as_string): Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise. * ast/rust-expr.h: Add new getter for the optional and rename getter to get_label_unchecked. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Change optional to expected for parse_loop_labelPierre-Emmanuel Patry2-7/+19
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_loop_label): Change function return type to expected. (Parser::parse_labelled_loop_expr): Adapt call location to new return type. * parse/rust-parse.h (enum class): Update function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Adapt testcase to name resolution 2.0Pierre-Emmanuel Patry1-0/+4
Name resolution 2.0 behavior matches more closely rustc's behavior and trying to prevent undeclared label error emission would break some other test. gcc/testsuite/ChangeLog: * rust/compile/invalid_label_name.rs: Adapt test to nr2. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Resolve labels within break or continue expressionsPierre-Emmanuel Patry3-11/+29
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add call to label resolution if there is one label. (Late::resolve_label): Look for labels and emit an error message on failure. * resolve/rust-late-name-resolver-2.0.h: Add function prototypes. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Fix unresolved label error messagePierre-Emmanuel Patry2-6/+6
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Change error message to match rustc. gcc/testsuite/ChangeLog: * rust/compile/undeclared_label.rs: Change test expected string. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Migrate error state to optionalsPierre-Emmanuel Patry31-266/+283
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::self_ref_param): Remove error state and use optional. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check label before visiting. * ast/rust-ast.cc (ContinueExpr::as_string): Retrieve label value. (Lifetime::as_string): Retrieve lifetime value. (ReferenceType::as_string): Likewise. (SelfParam::as_string): Likewise. * ast/rust-ast.h: Remove lifetime and LifetimeParam error state. * ast/rust-desugar-for-loops.cc (DesugarForLoops::DesugarCtx::make_break_arm): Use optional instead of error state. * ast/rust-expr.h (class ContinueExpr): Make label optional. * ast/rust-item.h (class SelfParam): Make lifetime optional. * ast/rust-type.h (class ReferenceType): Likewise. * backend/rust-compile-base.cc: Use optional for self param instead of error state. * backend/rust-compile-base.h: Update function prototype. * expand/rust-derive-clone.cc (DeriveClone::clone_fn): Use optional. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): Lower lifetime only if it exists. * hir/rust-ast-lower-block.h: Lower loop label only if it exists. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::visit): Remove references to error state. (ASTLowerTraitItem::visit): Lower self param only if it exists. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Use nullopt for default value instead of SelfParam error state. * hir/rust-ast-lower.cc (ASTLoweringExprWithBlock::visit): Lower label only if it exists. * hir/rust-hir-dump.cc (Dump::do_traitfunctiondecl): Print self only if it exists. (Dump::visit): Liewise. * hir/tree/rust-hir-bound.h: Remove error state. * hir/tree/rust-hir-expr.cc (ContinueExpr::ContinueExpr): Use optional in constructor for loop label. (BreakExpr::BreakExpr): Likewise. * hir/tree/rust-hir-expr.h (class ContinueExpr): Remove error state implementation. (class BreakExpr): Likewise. * hir/tree/rust-hir-generic-param.h: Likewise. * hir/tree/rust-hir-item.cc (SelfParam::SelfParam): Make lifetime optional. (Function::Function): Make self param optional. * hir/tree/rust-hir-item.h (class Function): Likewise. * hir/tree/rust-hir-type.cc (ReferenceType::ReferenceType): Make lifetime optional. * hir/tree/rust-hir-type.h (class ReferenceType): Likewise. * hir/tree/rust-hir.cc (ContinueExpr::as_string): Use new getter. (BreakExpr::as_string): Likewise. (Lifetime::as_string): Likewise. (ReferenceType::as_string): Likewise. (TraitFunctionDecl::as_string): Likewise. (SelfParam::as_string): Remove error state checking. * parse/rust-parse-impl.h (Parser::parse_generic_param): Adapt to optional. (Parser::parse_lifetime_params): Likewise. (Parser::parse_lifetime_params_objs): Likewise. (Parser::parse_lifetime_param): Likewise. (Parser::parse_lifetime_where_clause_item): Likewise. (Parser::parse_type_param_bound): Likewise. (Parser::parse_lifetime_bounds): Likewise. (Parser::parse_path_generic_args): Likewise. (Parser::parse_self_param): Likewise. (Parser::parse_break_expr): Likewise. (Parser::parse_continue_expr): Likewise. (Parser::parse_reference_type_inner): Likewise. * parse/rust-parse.h (class ParseLifetimeParamError): Add new class for lifetime param parsing errors. (class ParseLifetimeError): Add new class for lifetime parsing errors. (enum ParseSelfError): Add new class for self param parsing errors. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): Use unchecked getter in checked context. And make anonymous region. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Update ast visitor with proper check for looplabelPierre-Emmanuel Patry1-1/+2
The visitor was visiting loop label even when they did not exist. gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Add check for loop label before visiting it. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Remove unused error constructor and getterPierre-Emmanuel Patry1-5/+0
These constructor for eroneous state are not in use anymore since we replaced this error state with an optional in the parent nodes. gcc/rust/ChangeLog: * ast/rust-expr.h: Remove error getter and constructor. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Make loop label truly optionalPierre-Emmanuel Patry9-78/+77
A loop label error state was in use to represent missing loop label but this may be easily forgotten and the optional nature of the label was misrepresented. gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::block): Call with a nullopt instead of an error loop label. (WhileLetLoopExpr::as_string): Use getter function and adapt to newtype. * ast/rust-ast.cc (WhileLoopExpr::as_string): Likewise. (LoopExpr::as_string): Likewise. (BreakExpr::as_string): Likewise. (ForLoopExpr::as_string): Likewise. * ast/rust-expr.h (class BlockExpr): Make loop label optional. (class BreakExpr): Likewise. * expand/rust-derive-clone.cc (DeriveClone::clone_fn): Use nullopt. * expand/rust-derive-debug.cc (DeriveDebug::stub_debug_fn): Likewise. * expand/rust-derive-default.cc (DeriveDefault::default_fn): Likewise. * expand/rust-derive-eq.cc: Likewise. * parse/rust-parse-impl.h (Parser::parse_block_expr): Use optional for arguments. (Parser::parse_loop_expr): Likewise. (Parser::parse_while_loop_expr): Likewise. (Parser::parse_while_let_loop_expr): Likewise. (Parser::parse_for_loop_expr): Likewise. (Parser::parse_labelled_loop_expr): Likewise. (Parser::parse_loop_label): Return an optional. * parse/rust-parse.h: Update function prototype and use nullopt for default values. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Visit loop label before predicate expressionPierre-Emmanuel Patry2-3/+1
If the label is referenced within the while predicate expression it has to be resolved before the latter. gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Change default visit order. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove test from exclusion list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Add check for labelPierre-Emmanuel Patry2-3/+2
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit loop label only if it exists. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove passing test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Resolve labelsPierre-Emmanuel Patry6-20/+51
gcc/rust/ChangeLog: * hir/rust-ast-lower.cc (ASTLoweringBlock::visit): Lower label only if it exists. * hir/tree/rust-hir-expr.cc (BlockExpr::BlockExpr): Make loop label optional. (BaseLoopExpr::BaseLoopExpr): Likewise. (LoopExpr::LoopExpr): Likewise. (WhileLoopExpr::WhileLoopExpr): Likewise. * hir/tree/rust-hir-expr.h: Use optional for lifetime and labels. * hir/tree/rust-hir.cc (WhileLoopExpr::as_string): Use getter. (WhileLetLoopExpr::as_string): Likewise. (LoopExpr::as_string): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Resolve labels. * resolve/rust-late-name-resolver-2.0.h: Add visit function prototype for loop labels. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Revert part of 44ffe1193269Pierre-Emmanuel Patry1-3/+1
This commit got rid of msvc specific code and remove the else clause, this triggered warning with tl::expected::value function. gcc/rust/ChangeLog: * util/expected.h: Use gcc_unreachable within gcc context. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-04gccrs: refactoring rust_error_at "redefined multiple times"Sri Ganesh Thota5-37/+41
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-base.h (redefined_error): created a function for rust_error_at for redefined at multiple times. * resolve/rust-ast-resolve-implitem.h: changed rust_error_at to redefined_error. * resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): changed rust_error_at to redefined_error. * resolve/rust-ast-resolve-stmt.h: changed rust_error_at to redefined_error. * resolve/rust-ast-resolve-toplevel.h: changed rust_error_at to redefined_error. Signed-off-by: Sri Ganesh Thota <sriganeshthota12345@gmail.com>
2025-04-04nr2.0: Improve test scriptOwen Avery1-14/+18
gcc/testsuite/ChangeLog: * rust/compile/nr2/compile.exp: Avoid absolute paths in output, adjust phrasing of output, and avoid false XPASS output when tests are run in parallel. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-04nr2.0: Remove duplicate self visitOwen Avery2-3/+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 Herron2-1/+17
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 Cohen7-11/+53
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 Herron9-2/+53
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 Herron10-22/+53
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 Herron2-2/+29
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 Herron13-218/+144
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 Herron10-22/+30
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 Herron2-2/+8
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 Herron2-0/+12
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 Avery5-51/+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 Okada2-0/+9
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 Herron2-0/+25
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 Herron2-2/+24
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 Herron2-1/+6
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 Herron2-0/+9
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 Herron3-2/+12
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 Herron2-4/+19
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-28nr2.0: Fix test macros/mbe/macro43.rsOwen Avery2-5/+11
gcc/testsuite/ChangeLog: * rust/compile/macros/mbe/macro43.rs: Adjust test to pass with name resolution 2.0. * rust/compile/nr2/exclude: Remove macros/mbe/macro43.rs. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-27gccrs: Fix ICE during const expr eval on array expressionsPhilip Herron3-1/+11
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 Herron3-1/+38
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-27Add new test to highlight namespace for self importPierre-Emmanuel Patry1-0/+14
gcc/testsuite/ChangeLog: * rust/compile/self_import_namespace.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-27Update exclusion listPierre-Emmanuel Patry1-6/+0
gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove now passing tests from exclusion list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.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 Herron3-2/+31
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 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>