aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2025-08-05gccrs: derive(Ord, Eq): Use different node IDs for variant pathsArthur Cohen5-23/+496
gcc/rust/ChangeLog: * expand/rust-derive-cmp-common.cc (EnumMatchBuilder::tuple): Create two different variant paths. (EnumMatchBuilder::strukt): Likewise. * expand/rust-derive-cmp-common.h: Change API. * expand/rust-derive-ord.cc (DeriveOrd::visit_enum): Use new EnumMatchBuilder API. * expand/rust-derive-partial-eq.cc (DerivePartialEq::visit_enum): Likewise. gcc/testsuite/ChangeLog: * rust/compile/derive_partial_ord1.rs: New test.
2025-08-05gccrs: derive(Ord): Handle unit structs properlyArthur Cohen2-5/+32
gcc/rust/ChangeLog: * expand/rust-derive-ord.cc (DeriveOrd::make_cmp_arms): Use new make_equal function. (DeriveOrd::make_equal): New function. (DeriveOrd::recursive_match): Handle the unit struct/tuple case. * expand/rust-derive-ord.h: Declare make_equal.
2025-08-05gccrs: derive(Ord): Fix cmp call to use references instead of valuesArthur Cohen1-1/+2
gcc/rust/ChangeLog: * expand/rust-derive-ord.cc (DeriveOrd::cmp_call): Use references.
2025-08-05gccrs: derive(Ord): Fix condition for matching on Option::Some insteadArthur Cohen1-2/+3
gcc/rust/ChangeLog: * expand/rust-derive-ord.cc (DeriveOrd::make_cmp_arms): Fix condition.
2025-08-05gccrs: derive(Ord, PartialOrd): Finish implementationArthur Cohen2-11/+18
gcc/rust/ChangeLog: * expand/rust-derive-ord.cc: Finish implementation for enums. * expand/rust-derive-ord.h: Likewise.
2025-08-05gccrs: derive(PartialEq): Implement proper discriminant comparisonArthur Cohen3-22/+51
And use the new EnumMatchBuilder class to do so. gcc/rust/ChangeLog: * expand/rust-derive-partial-eq.cc (DerivePartialEq::eq_fn): Change signature. (DerivePartialEq::visit_tuple): Use new eq_fn API. (DerivePartialEq::visit_struct): Likewise. (DerivePartialEq::visit_enum): Implement proper discriminant comparison. * expand/rust-derive-partial-eq.h: Change eq_fn signature. gcc/testsuite/ChangeLog: * rust/execute/torture/derive-partialeq2.rs: Add declaration for discriminant_value.
2025-08-05gccrs: derive-cmp: Add EnumMatchBuilder classArthur Cohen2-0/+159
gcc/rust/ChangeLog: * expand/rust-derive-cmp-common.h (class EnumMatchBuilder): New helper class. * expand/rust-derive-cmp-common.cc (EnumMatchBuilder::tuple): New function. (EnumMatchBuilder::strukt): New function.
2025-08-05gccrs: ast-builder: Make location publicArthur Cohen1-1/+1
gcc/rust/ChangeLog: * ast/rust-ast-builder.h: Put `loc` member in public.
2025-08-05gccrs: derive(Ord): Add handling for ordering of discriminant valuesArthur Cohen2-11/+73
gcc/rust/ChangeLog: * expand/rust-derive-ord.cc (DeriveOrd::cmp_call): New function. (DeriveOrd::recursive_match): Use it. (DeriveOrd::visit_enum): Likewise. * expand/rust-derive-ord.h: Declare it.
2025-08-05gccrs: derive(Hash): Use new Builder APIArthur Cohen1-8/+1
gcc/rust/ChangeLog: * expand/rust-derive-hash.cc (DeriveHash::visit_enum): Use new APIs.
2025-08-05gccrs: builder: Add Builder::discriminant_valueArthur Cohen2-3/+24
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::discriminant_value): New function. * ast/rust-ast-builder.h: Declare it.
2025-08-05gccrs: derive(Ord, PartialOrd): Handle tuples properlyArthur Cohen1-10/+8
gcc/rust/ChangeLog: * expand/rust-derive-ord.cc (is_last): Remove. (DeriveOrd::visit_tuple): Fix implementation.
2025-08-05gccrs: derive(PartialEq): chore: Refactor using new SelfOther APIsArthur Cohen3-16/+8
gcc/rust/ChangeLog: * expand/rust-derive-cmp-common.cc (SelfOther::indexes): Fix formatting. (SelfOther::fields): Make iterator const. * expand/rust-derive-cmp-common.h (struct SelfOther): New declaration for indexes. * expand/rust-derive-partial-eq.cc (DerivePartialEq::visit_tuple): Use the new API. (DerivePartialEq::visit_struct): Likewise.
2025-08-05gccrs: derive(Ord, PartialOrd): Implement proper recursive match logicArthur Cohen2-11/+116
gcc/rust/ChangeLog: * expand/rust-derive-ord.cc (DeriveOrd::make_cmp_arms): New function. (is_last): Likewise. (recursive_match): Likewise. (DeriveOrd::recursive_match): Likewise. (DeriveOrd::visit_struct): Add proper implementation. (DeriveOrd::visit_union): Likewise. * expand/rust-derive-ord.h: Declare these new functions.
2025-08-05gccrs: derive(PartialEq): Use that common classArthur Cohen2-33/+3
gcc/rust/ChangeLog: * expand/rust-derive-partial-eq.cc (DerivePartialEq::tuple_indexes): Remove. (DerivePartialEq::field_acccesses): Remove. (DerivePartialEq::visit_tuple): Use new API. (DerivePartialEq::visit_struct): Likewise. * expand/rust-derive-partial-eq.h: Remove declarations.
2025-08-05gccrs: derive: Add common comparison derive classArthur Cohen3-0/+120
gcc/rust/ChangeLog: * expand/rust-derive-cmp-common.cc: New file. * expand/rust-derive-cmp-common.h: New file. * Make-lang.in: Compile them.
2025-08-05gccrs: builder: Add match_case() function and new block() oneArthur Cohen2-1/+16
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::block): New function. (Builder::match_case): Likewise. * ast/rust-ast-builder.h: Declare them.
2025-08-05gccrs: derive: Add const generics when deriving implsArthur Cohen4-15/+48
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::new_const_param): New function. * ast/rust-ast-builder.h (vec): New function for creating 3 elts vector. * expand/rust-derive.cc: Use the new_const_param builder. * ast/rust-path.h: Add get_default_value() method.
2025-08-05gccrs: derive(Ord, PartialOrd): Add base for deriving them.Arthur Cohen4-2/+251
gcc/rust/ChangeLog: * Make-lang.in: Compile it. * expand/rust-derive.cc (DeriveVisitor::derive): Call them. * expand/rust-derive-ord.cc: New file. * expand/rust-derive-ord.h: New file.
2025-08-05gccrs: derive: chore: Add missing override qualifiersArthur Cohen5-24/+24
gcc/rust/ChangeLog: * expand/rust-derive-clone.h: Add missing override qualifiers to DeriveVisitor methods. * expand/rust-derive-copy.h: Likewise. * expand/rust-derive-eq.h: Likewise. * expand/rust-derive-hash.h: Likewise. * expand/rust-derive-partial-eq.h: Likewise.
2025-08-05gccrs: rib: Add all kinds of Ribs to pretty-printingArthur Cohen1-2/+6
gcc/rust/ChangeLog: * resolve/rust-rib.h: Add missing switch cases.
2025-08-05gccrs: Fix bug in query type stopping PartialOrdPhilip Herron3-3/+363
There was a complex recurisve type query hierarchy here but the type was resolved so we can just do an early return here gcc/rust/ChangeLog: * typecheck/rust-type-util.cc (query_type): early return. gcc/testsuite/ChangeLog: * rust/execute/torture/basic_partial_ord1.rs: New test. * rust/execute/torture/basic_partial_ord2.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Fix bad type canonicalization on ARRAY_TYPESPhilip Herron3-6/+12
Fixes Rust-GCC#3660 gcc/rust/ChangeLog: * backend/rust-compile-type.cc (TyTyResolveCompile::visit): reuse GCC's build_array_type gcc/testsuite/ChangeLog: * rust/compile/const_generics_3.rs: * rust/compile/issue-3660.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: nr2.0: Adjust alternate identifier handlingOwen Avery1-2/+3
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (visit_identifier_as_pattern): Make sure to map identifiers inside or-bindings to prior identifiers. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: Rename IdentifierPattern's to_bind to subpatternZhi Heng11-46/+49
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc: Rename to_bind to subpattern. * ast/rust-ast-visitor.cc: Ditto. * ast/rust-pattern.cc: Ditto. * ast/rust-pattern.h: Ditto. * backend/rust-compile-pattern.cc: Ditto. * expand/rust-cfg-strip.cc: Ditto. * hir/rust-ast-lower-pattern.cc: Ditto. * hir/rust-hir-dump.cc: Ditto. * hir/tree/rust-hir-pattern.h: Ditto. * hir/tree/rust-hir.cc: Ditto. * typecheck/rust-hir-type-check-pattern.cc: Ditto. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05gccrs: Support compilation of IdentifierPattern's subpatternsZhi Heng5-4/+36
gcc/rust/ChangeLog: * backend/rust-compile-pattern.cc: Add CheckExpr compilation for IdentifierPattern with subpattern. * backend/rust-compile-pattern.h: Modify IdentifierPattern's visit func to support the above. * typecheck/rust-hir-type-check-pattern.cc: Add typechecking support for the changes above. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05gccrs: nr2.0: Fix closure parameter scopingOwen Avery4-38/+37
gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit_closure_params): New member function definition. (DefaultResolver::visit): New visiting function definition for ClosureExpr called from visiting functions for ClosureExprInner and ClosureExprInnerTyped. * resolve/rust-default-resolver.h (DefaultResolver::visit_closure_params): New member function declaration. (DefaultResolver::visit): New visiting function declaration for ClosureExpr. * resolve/rust-late-name-resolver-2.0.cc (add_captures): Remove function. (Late::visit): New visiting function definition for ClosureExpr, remove visiting function definitions for ClosureExprInner and ClosureExprInnerTyped. (Late::visit_closure_params): New member function definition. * resolve/rust-late-name-resolver-2.0.h (Late::visit): New visiting function declaration for ClosureExpr, remove visiting function declarations for ClosureExprInner and ClosureExprInnerTyped. (Late::visit_closure_params): New member function declaration. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: nr2.0: Improve handling of single segment pathsOwen Avery2-10/+42
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx (ForeverStack::resolve_path): Handle single segment paths "crate", "self", and "super". gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: nr2.0: Adjust pub_restricted testsOwen Avery3-10/+10
gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. * rust/compile/pub_restricted_1.rs: Adjust expected error messages and only run with name resolution 2.0 enabled. * rust/compile/pub_restricted_2.rs: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: nr2.0: Improve StructPatternFieldIdent handlingOwen Avery1-16/+23
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Use visit_identifier_as_pattern to handle IdentifierPattern and StructPatternFieldIdent. (visit_identifier_as_pattern): New function. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: Add new function ClosureExpr::get_definition_exprOwen Avery8-9/+11
gcc/rust/ChangeLog: * ast/rust-expr.h (ClosureExpr::get_definition_expr): New virtual member function. (ClosureExprInner::get_definition_expr): Add override specifier. (ClosureExprInnerTyped::get_definition_block): Rename to... (ClosureExprInnerTyped::get_definition_expr): ...here and add override specifier. * ast/rust-ast-collector.cc (TokenCollector::visit): Handle rename of ClosureExprInnerTyped::get_definition_block to ClosureExprInnerTyped::get_definition_expr. * 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-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. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: nr2.0: Separate out canonical path handlingOwen Avery18-152/+493
This should improve our canonical path handling, without requiring further tweaks to ForeverStack. This may also help if, in the future, we have to move canonical path calculation to later compilation phases for proper handling of generics. gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::compile_function): Since canonical paths returned from nr2.0 now include the crate name, avoid prepending the crate name again. * backend/rust-compile-implitem.cc (CompileTraitItem::visit): Use NameResolutionContext::to_canonical_path instead of ForeverStack::to_canonical_path. * backend/rust-compile-item.cc (CompileItem::visit): 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.cc (TraitItemReference::get_type_from_fn): Likewise. * resolve/rust-default-resolver.cc (DefaultResolver::visit): Add Crate and EnumItem instance visitors, handle canonical path context scoping. * resolve/rust-default-resolver.h (DefaultResolver::visit): Add Crate and EnumItem instance visitors. * resolve/rust-early-name-resolver-2.0.cc (Early::go): Visit instances of Crate using the virtual member function visit. * resolve/rust-forever-stack.h (ForeverStack::to_canonical_path): Remove function declaration. * resolve/rust-forever-stack.hxx (ForeverStack::to_canonical_path): Remove function definition. * resolve/rust-late-name-resolver-2.0.cc (Late::go): Visit instances of Crate using the virtual member function visit. * resolve/rust-name-resolution-context.cc (CanonicalPathRecordCrateRoot::as_path): New function definition. (CanonicalPathRecordNormal::as_path): Likewise. (CanonicalPathRecordLookup::as_path): Likewise. (CanonicalPathRecordImpl::as_path): Likewise. (CanonicalPathRecordTraitImpl::as_path): Likewise. (NameResolutionContext::NameResolutionContext): Initialize member variable canonical_ctx. * resolve/rust-name-resolution-context.h: Include "rust-item.h". (class NameResolutionContext): Forward declare class. (class CanonicalPathRecord): New class. (class CanonicalPathRecordWithParent): Likewise. (class CanonicalPathRecordCrateRoot): Likewise. (class CanonicalPathRecordNormal): Likewise. (class CanonicalPathRecordLookup): Likewise. (class CanonicalPathRecordImpl): Likewise. (class CanonicalPathRecordTraitImpl): Likewise. (class CanonicalPathCtx): Likewise. (NameResolutionContext::canonical_ctx): New member variable. (NameResolutionContext::to_canonical_path): New member function. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::go): Visit instances of Crate with the virtual member function visit. (TopLevel::visit): Handle canonical path context scoping for external crates, use DefaultResolver::visit when visiting instances of StructStruct. * util/rust-canonical-path.h (CanonicalPath::new_seg): Take path parameter by-value, as a duplicate instance will be constructed regardless. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove canonical_paths1.rs.
2025-08-05gccrs: Lower IdentifierPattern's to_bind to HIRZhi Heng2-1/+6
gcc/rust/ChangeLog: * hir/rust-ast-lower-pattern.cc: Lower of IdentifierPattern's to_bind to HIR. * hir/rust-hir-dump.cc: Update IdentifierPattern's dump to properly show to_bind's full full properties. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05gccrs: fix: ICE when parsing unterminated raw byte stringsVishruth-Thimmaiah2-5/+11
Fixes an ICE when a raw byte string is not terminated Fixes Rust-GCC#3731 gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::parse_raw_byte_string): Fix infinite looping when a raw byte string is not terminated. gcc/testsuite/ChangeLog: * rust/compile/torture/unended-raw-byte-string.rs: New test to ensure correct error message for unended raw byte string. Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
2025-08-05gccrs: nr2.0: Catch Self in impl block self typesOwen Avery7-5/+46
gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Use visit_impl_type to visit the self types of impl blocks. * resolve/rust-default-resolver.h (DefaultResolver::visit_impl_type): New member function declaration. * resolve/rust-late-name-resolver-2.0.cc (Late::Late): Initialize member variable block_big_self. (Late::visit_impl_type): New member function definition. (Late::visit): Check for Self while inside impl block self types. * resolve/rust-late-name-resolver-2.0.h (Late::visit_impl_type): New member function. (Late::block_big_self): New member variable. gcc/testsuite/ChangeLog: * rust/compile/issue-3671.rs: Remove usage of Self. * rust/compile/nr2/exclude: Remove issue-3671.rs. * rust/compile/self-in-impl.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: nr2.0: Improve visibility path handlingOwen Avery6-93/+174
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h (enum ResolutionMode): New. (ForeverStack::get): Add a private overload that takes a starting node as a parameter. (ForeverStack::resolve_path): Replace boolean parameter has_opening_scope_resolution with ResolutionMode parameter mode. * resolve/rust-forever-stack.hxx (ForeverStack::resolve_path): Likewise. (ForeverStack::get): Add a private overload that takes a starting node as a parameter. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add Visibility visitor. * resolve/rust-late-name-resolver-2.0.h (Late::visit): Likewise. * resolve/rust-name-resolution-context.h (NameResolutionContext::resolve_path): Rework overloading a bit and accept ResolutionMode parameter. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: parser: fix ICE std::out_of_range with path attrs to nonexisting pathVishruth-Thimmaiah2-4/+17
Stops an ICE from occuring when path attribute is empty Fixes Rust-GCC#3607. gcc/rust/ChangeLog: * parse/rust-parse.cc (Rust::extract_module_path): Handle empty or whitespace-only path attributes. gcc/testsuite/ChangeLog: * rust/compile/torture/extern_mod2.rs: New test to ensure an error is emitted for empty path attributes. Signed-off-by: Vishruth Thimmaiah <vishruththimmaiah@gmail.com>
2025-08-05gccrs: Make ConstantItem use IdentifierOwen Avery7-9/+24
The change to ASTLoweringExternItem is necessary, since with this patch Identifier can be implicitly converted to std::string. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Handle changed type of ConstantItem::identifier. * ast/rust-ast.cc (ConstantItem::as_string): Likewise. * ast/rust-ast.h (operator const std::string &): New member function. * ast/rust-item.h (ConstantItem::identifier): Change type from std::string to Identifier. (ConstantItem::ConstantItem): Handle changed type of identifier field. (ConstantItem::is_unnamed): Likewise. (ConstantItem::get_identifier): Likewise. * hir/rust-ast-lower-extern.h (ASTLoweringExternItem::visit): Avoid discarding location of wildcard patterns. * lex/rust-token.cc: Include "rust-ast.h". (Token::make_identifier): Add overload accepting an Identifier instance. * lex/rust-token.h (class Identifier): Add forward declaration in order to... (Token::make_identifier): ...declare an overload for this static member function. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: const-block: Add testcaseArthur Cohen1-0/+9
gcc/testsuite/ChangeLog: * rust/execute/torture/const_block1.rs: New test.
2025-08-05gccrs: hir: Add const blocksArthur Cohen29-44/+380
gcc/rust/ChangeLog: * hir/tree/rust-hir-expr.h: New classes. * hir/tree/rust-hir-full-decls.h: Likewise. * hir/tree/rust-hir.cc: Handle AnonConst and ConstBlock. * backend/rust-compile-block.cc: Likewise. * backend/rust-compile-block.h: Likewise. * backend/rust-compile-expr.cc (CompileExpr::visit): Likewise. * backend/rust-compile-expr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit): Likewise. * checks/errors/rust-hir-pattern-analysis.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. (translate_operand_out): Likewise. (translate_operand_inout): Likewise. (translate_operand_const): Likewise. * hir/rust-ast-lower-expr.h: Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/rust-hir-dump.h: Likewise. * hir/tree/rust-hir-expr-abstract.h: Likewise. * hir/tree/rust-hir-expr.cc (AnonConst::AnonConst): Likewise. (AnonConst::operator=): Likewise. (ConstBlock::ConstBlock): Likewise. (ConstBlock::operator=): Likewise. * hir/tree/rust-hir-visitor.h: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. (typecheck_inline_asm_operand): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise.
2025-08-05gccrs: parser: Add base for parsing const blocksArthur Cohen2-0/+32
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_const_block_expr): New function. * parse/rust-parse.h: Declare it.
2025-08-05gccrs: ast: Add ConstBlock and AnonConst nodesArthur Cohen16-28/+237
gcc/rust/ChangeLog: * ast/rust-expr.h: Declare AnonConst and ConstBlock and use them. * ast/rust-ast-full-decls.h: Likewise. * ast/rust-ast.cc: Add implementation for AnonConst and ConstBlock. * ast/rust-ast.h: Likewise. * ast/rust-ast-collector.cc (TokenCollector::visit): Likewise. * ast/rust-ast-collector.h: Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.h: Likewise. * expand/rust-derive.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h: Likewise. * hir/rust-ast-lower-expr.cc (translate_operand_const): Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h: Likewise. * resolve/rust-ast-resolve-expr.h: Likewise. * resolve/rust-ast-resolve-expr.cc: Likewise.
2025-08-05gccrs: Always emit the error highest in the type hierarchyPhilip Herron5-75/+110
The unify code was a bit dumb here where we always set emit_error to false for any subtypes for example in comparing tuples we always emitted the whole tuple didnt match the other tuple but really its much better to say expected bool got i32 because the element types didn't match. gcc/rust/ChangeLog: * typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsized): dont emit error here * typecheck/rust-unify.cc (UnifyRules::resolve_subtype): new helper to handle emit error (UnifyRules::expect_adt): call resolve_subtype (UnifyRules::expect_reference): likewise (UnifyRules::expect_pointer): likewise (UnifyRules::expect_array): likewise (UnifyRules::expect_slice): likewise (UnifyRules::expect_fndef): likewise (UnifyRules::expect_fnptr): likewise (UnifyRules::expect_tuple): likewise (UnifyRules::expect_closure): likewise (UnifyRules::expect_opaque): likeiwse * typecheck/rust-unify.h: add new helper to header gcc/testsuite/ChangeLog: * rust/compile/traits9.rs: update errors * rust/compile/unify-errors1.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: nr2.0: Fix IfLet pattern handlingOwen Avery5-10/+29
gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit_if_let_patterns): New function definition. (DefaultResolver::visit): New IfLetExpr visitor definition. * resolve/rust-default-resolver.h (DefaultResolver::visit_if_let_patterns): New function declaration. (DefaultResolver::visit): New IfLetExpr visitor declaration. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove IfLetExpr visitor definition. (Late::visit_if_let_patterns): New function definition. * resolve/rust-late-name-resolver-2.0.h (Late::visit): Remove IfLetExpr visitor declaration. (Late::visit_if_let_patterns): New function declaration. * resolve/rust-name-resolution-context.h (BindingSource::IfLet): New enumerator. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: Initial support for Return Position Impl TraitPhilip Herron10-120/+169
This is the initial patch for RPIT, we can build on this to handle the more complex cases but there are enough distinct changes going on here that it should just get merged now. RPIT is really a sneaky generic so for example: fn foo() -> impl Bar { Baz } This is represented as: fn () -> OpaqueType Bar. But when we handle the coercion site for Baz on impl Bar when we type resolve the function we know that the underlying type is Baz. Note this function is _not_ generic so its using this special OpaqueType and keeping track of the underlying type in its ty_ref reference hir-id which will resolve to Baz. This also means if we have a case where maybe this was in an if statement: fn foo(a: i32) -> impl Bar { if a > 10 { Baz } else { Qux } } The rules of impl Bar is that Baz is handled but Baz and Qux are different underlying types so this is not allowed. The reason is impl traits are not generic and although from a programmer perspective the callers dont know what the underlying type is, the compiler _knows_ what it is. So really when you call a function and get its return position impl trait the compiler knows what to do and does all whats nessecary to handle calling functions using that type etc. gcc/rust/ChangeLog: * backend/rust-compile-type.cc (TyTyResolveCompile::visit): we need to resolve the underlying type * typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): just clone * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): ensure we monomphize to get the underlying * typecheck/rust-tyty.cc (BaseType::destructure): handle opaque types (OpaqueType::resolve): this is much simpler now (OpaqueType::handle_substitions): no longer needed * typecheck/rust-tyty.h: update header * typecheck/rust-unify.cc (UnifyRules::expect_opaque): unify rules for opaque gcc/testsuite/ChangeLog: * rust/compile/bad-rpit1.rs: New test. * rust/execute/torture/impl_rpit1.rs: New test. * rust/execute/torture/impl_rpit2.rs: New test. * rust/execute/torture/impl_rpit3.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Fix non canonical type bug with tuplesPhilip Herron2-2/+2
When working on rpit we needed to change to use a monomorphized clone of the result of function calls. This ended up causing a verify gimple issue with tuples because: fn test<A, B>(a: A, b: B) -> (A, B) When passing for example: let a = test::<i32, i32> (123, 456) -> (A=i32, B=i32) The resulting gimple types became: const struct (A=i32, B=i32) vs struct (i32, i32) We removed the VIEW_CONVERT_EXPR support to auto fix this stuff a good while ago because it hides these kinds of issues because the type hasher included the A=i32, B=i32 vs the i32, i32 name so updating this to use get_name instead keeps the naming the same as well as the fields meaning these types are 100% equivilant and therefore no conversion is required. This only occurs because tuples are not named types we should really add more rust specific info on our gimple TYPES. gcc/rust/ChangeLog: * backend/rust-compile-type.cc (TyTyResolveCompile::visit): use get_name * typecheck/rust-tyty.cc (TupleType::get_name): likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Remove unneeded clones untill we have an arena allocator for these tmpsPhilip Herron2-13/+8
Cloning inference variables is very expensive because it means we are indirectly creating an implicit new inference variable added to the reference chain. gcc/rust/ChangeLog: * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy): no need for unreachable here * typecheck/rust-unify.cc (UnifyRules::commit): dont clone infer vars (UnifyRules::expect_inference_variable): likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: refactor default infer vars to be its own functionPhilip Herron2-32/+39
This is just a simple refactor to pull all the logic outside of the closure which makes it more readable. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check.h: new function * typecheck/rust-typecheck-context.cc (TypeCheckContext::compute_inference_variables): call the new helper (TypeCheckContext::compute_infer_var): refactored code Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Revert 10-second timeout for each testParthib1-4/+1
gcc/testsuite/ChangeLog: * lib/rust.exp: Remove timeout. Signed-off-by: Parthib <parthibdutta02@gmail.com>
2025-08-05gccrs: nr2.0: Fix some paths in test filesOwen Avery3-57/+57
This is similar to 9faba024ef18b9c4d67f22bd3b020b5e445fad0a, but it applies to execute tests. gcc/testsuite/ChangeLog: * rust/execute/torture/for-loop1.rs: Adjust paths. * rust/execute/torture/for-loop2.rs: Likewise. * rust/execute/torture/iter1.rs: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>