aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/hir
AgeCommit message (Collapse)AuthorFilesLines
2025-08-05gccrs: Call base class's accept_vis methodRyutaro Okada1-4/+4
gcc/rust/ChangeLog: * hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Call base class's accept_vis method Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05gccrs: Add check before calling `get_trait_ref()`Ryutaro Okada1-1/+2
gcc/rust/ChangeLog: * hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Add check before calling `get_trait_ref()` Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05gccrs: Fix object copying issue causing pointer inconsistencyRyutaro Okada1-1/+1
gcc/rust/ChangeLog: * hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit): Fix object copying issue causing pointer inconsistency Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05gccrs: Parse expression instead of literal in attributesPierre-Emmanuel Patry2-2/+2
gcc/rust/ChangeLog: * ast/rust-ast.cc (AttributeParser::parse_path_meta_item): Parse expression instead of literal. Update variant name. (MetaItemPathLit::to_attribute): Remove function. (AttributeParser::parse_path_meta_item): Update name. (MetaItemPathLit::check_cfg_predicate): Likewise. (MetaItemPathExpr::check_cfg_predicate): Likewise. (MetaItemPathLit::accept_vis): Likewise. (MetaItemPathExpr::accept_vis): Likewise. * ast/rust-ast-collector.h: Update prototype and adapt code to new expression. * ast/rust-ast-collector.cc: Update code to expr. * ast/rust-ast-full-decls.h (class MetaItemPathLit): Likewise. (class MetaItemPathExpr): Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.h: Likewise. * ast/rust-ast.h (class MetaItemPathLit): Rename class from here... (class MetaItemPathExpr): ... to here. * ast/rust-expr.h (class MetaItemPathLit): Rename class from here... (class MetaItemPathExpr): ...to here. * expand/rust-derive.h: Update class name. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h: Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h: Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. * resolve/rust-early-name-resolver.h: Likewise. * util/rust-attributes.cc (AttributeChecker::visit): Likewise. * util/rust-attributes.h: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Initialize boolean flag correctlyPierre-Emmanuel Patry1-1/+1
Flag was left uninitialized within default constructor. gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::Dump): Initialize flag. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Initialize boolean flag correctlyPierre-Emmanuel Patry1-1/+3
gcc/rust/ChangeLog: * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::ASTLoweringPattern): flag was not initialized in the constructor. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Prevent used after move on self paramPierre-Emmanuel Patry1-8/+9
gcc/rust/ChangeLog: * hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit): Remove use after move. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Add rest pattern support for AST::SlicePatternYap Zhi Heng3-3/+28
The main change can be found in ast/rust-pattern.h, which introduces 2 item types for AST::SlicePattern - one without rest pattern (SlicePatternItemsNoRest) & the other with it (SlicePatternItemsHasRest). This led to a number of cascading changes as seen in the changelog. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc: Add support for the 2 new classes. * ast/rust-ast-collector.h: Header file update for above. * ast/rust-ast-full-decls.h: Add forward decls for the 2 new classes. * ast/rust-ast-visitor.cc: Add visit support for the 2 new classes. * ast/rust-ast-visitor.h: Header file update for above. * ast/rust-pattern.cc: Implementation of certain methods for the 2 new classes. * ast/rust-pattern.h: Define the 2 new classes. Update SlicePattern to be able to hold 2 kinds of items - SlicePatternItemsNoRest or SlicePatternItemsRest. * expand/rust-cfg-strip.cc: Add support for the 2 new classes. * expand/rust-cfg-strip.h: Header file update for above. * expand/rust-derive.h: Add visits for the 2 new classes. * hir/rust-ast-lower-base.cc: Add visits for the 2 new classes. * hir/rust-ast-lower-base.h: Header file update for above. * hir/rust-ast-lower-pattern.cc: Update lowering of SlicePattern to support SlicePatternItemsNoRest. * parse/rust-parse-impl.h (parse_slice_pattern()): Add support for parsing DOT_DOT into respective SlicePatternItems. * resolve/rust-ast-resolve-base.cc: Add visits for the 2 new classes. * resolve/rust-ast-resolve-base.h: Header file update for above. * resolve/rust-ast-resolve-pattern.cc: Update SlicePattern resolution to support new classes. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05gccrs: Fix ICE during hir dump of deferred anon constantPhilip Herron2-2/+8
gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::visit): check for expression * hir/tree/rust-hir.cc (AnonConst::as_string): likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Add initial support for const genericsPhilip Herron2-2/+6
In order to support const generics we map the declarations to a ConstType this means we reuse all our existing type coercion, unification code and generic substitutions code to support this with minimal impact. This patch adds support for: 1. Default const generics 2. Infer const generics 3. ADTType suport 4. unconstrained checks 5. ensure types of the const generic and default 6. validation if passing a const argument to a type argument Lots of test cases now work and new ones added. More work is needed to support this on functions and method resolution of impls like Foo<1> vs Foo<2> once thats in we can look to support some of the const generic array impls next. gcc/rust/ChangeLog: * backend/rust-compile-base.cc: useful debug * backend/rust-compile-stmt.cc (CompileStmt::visit): likewise * backend/rust-compile-type.cc (TyTyResolveCompile::visit): fold the capacity into ConstType * hir/tree/rust-hir-generic-param.h: make const * hir/tree/rust-hir-path.h: take into account const arguments now * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): needs const * typecheck/rust-hir-type-check-base.h: add error handling for const supported locations * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): const type the arrays * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): update (TypeCheckImplItem::visit): likewise * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): likewise (TypeCheckItem::resolve_impl_block_substitutions): likewise * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): wrap up const type * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise (TypeResolveGenericParam::visit): likewise (TypeResolveGenericParam::apply_trait_bounds): remove HIR::Generic from Param * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): cleanup * typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::SubstitutionParamMapping): handle const generics (SubstitutionParamMapping::get_type_representation): likewise (SubstitutionParamMapping::param_has_default_ty): likewise (SubstitutionParamMapping::get_default_ty): likewise (SubstitutionRef::infer_substitions): likewise * typecheck/rust-tyty-subst.h: likewise * typecheck/rust-tyty-util.cc (TyVar::get_implicit_const_infer_var): new helper * typecheck/rust-tyty-util.h (class ConstType): likewise * typecheck/rust-tyty.cc (BaseType::is_concrete): check for array const concrete (ArrayType::as_string): update to const (ArrayType::handle_substitions): likewise (ParamType::ParamType): likewise (ParamType::get_generic_param): likewise (ParamType::clone): likewise (ConstType::ConstType): likewise (ConstType::set_value): likewise (ConstType::clone): likewise (ConstType::get_generic_param): likewise (generate_tree_str): new helper to pretty print gimple (ConstType::get_name): uses the generate_tree_str (ConstType::handle_substitions): handle const infer's * typecheck/rust-tyty.h (RUST_TYTY): likewise * typecheck/rust-unify.cc (UnifyRules::expect_array): likewise (UnifyRules::expect_const): likewise gcc/testsuite/ChangeLog: * rust/compile/const_generics_3.rs: this works now * rust/compile/const_generics_5.rs: likewise * rust/compile/const_generics_8.rs: move the failure to another test case * rust/compile/const_generics_10.rs: New test. * rust/compile/const_generics_11.rs: New test. * rust/compile/const_generics_12.rs: New test. * rust/compile/const_generics_13.rs: New test. * rust/compile/const_generics_14.rs: New test. * rust/compile/const_generics_15.rs: New test. * rust/compile/const_generics_16.rs: New test. * rust/compile/const_generics_9.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: lower: Add assertions for desugared nodesArthur Cohen6-27/+25
gcc/rust/ChangeLog: * hir/rust-ast-lower-base.cc: Add rust_unreachable() when lowering desugared exprs. * hir/rust-ast-lower-base.h: Mention this. * hir/rust-ast-lower-block.h: Remove existing definitions. * hir/rust-ast-lower-expr.cc: Likewise. * hir/rust-ast-lower-expr.h: Likewise. * hir/rust-ast-lower.cc: Likewise.
2025-08-05gccrs: hir: Add OffsetOf nodeArthur Cohen9-2/+107
gcc/rust/ChangeLog: * hir/tree/rust-hir-expr.h (class OffsetOf): New. * hir/tree/rust-hir-expr.cc: Define its methods. * hir/tree/rust-hir-expr-abstract.h: Add ExprType::OffsetOf. * hir/tree/rust-hir-full-decls.h (class OffsetOf): Declare it. * backend/rust-compile-block.h: Add handling for OffsetOf. * 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 (RUST_BIR_BUILDER_EXPR_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 (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. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/rust-hir-dump.h: Likewise. * hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Likewise. * hir/tree/rust-hir-visitor.h: Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-expr.h (RUST_HIR_TYPE_CHECK_EXPR): Likewise. gcc/testsuite/ChangeLog: * rust/compile/offset_of2.rs: New test.
2025-08-05gccrs: ast: Add OffsetOf nodeArthur Cohen4-1/+17
gcc/rust/ChangeLog: * ast/rust-ast.h: Add OffsetOf expression kind. * ast/rust-builtin-ast-nodes.h (class OffsetOf): Add node. * ast/rust-ast.cc: Define it. * ast/rust-ast-collector.cc: Add visitor for OffsetOf. * ast/rust-ast-collector.h: Likewise. * ast/rust-ast-visitor.cc: Likewise. * ast/rust-ast-visitor.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h: Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-expr.h: Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h: Likewise. * resolve/rust-early-name-resolver-2.0.cc: Likewise. * expand/rust-derive.h:
2025-08-05gccrs: Add pretty hir dump for inline assemblyPierre-Emmanuel Patry3-11/+90
gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::visit): Dump inline assembly fields * hir/tree/rust-hir-expr.h: Add non const getter and avoid operand copy from getters. * hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Use non const reference. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: hir: Handle deferred const inference variablesArthur Cohen4-15/+56
gcc/rust/ChangeLog: * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Handle defered consts. * hir/tree/rust-hir-expr.cc (AnonConst::AnonConst): Likewise. (AnonConst::operator=): Likewise. * hir/tree/rust-hir-expr.h: Likewise. * hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. gcc/testsuite/ChangeLog: * rust/compile/deferred_const_inference.rs: New test.
2025-08-05gccrs: Add initial support for deffered operator overload resolutionPhilip Herron3-9/+45
In the test case: fn test (len: usize) -> u64 { let mut i = 0; let mut out = 0; if i + 3 < len { out = 123; } out } The issue is to determine the correct type of 'i', out is simple because it hits a coercion site in the resturn position for u64. But 'i + 3', 'i' is an integer infer variable and the same for the literal '3'. So when it comes to resolving the type for the Add expression we hit the resolve the operator overload code and because of this: macro_rules! add_impl { ($($t:ty)*) => ($( impl Add for $t { type Output = $t; #[inline] #[rustc_inherit_overflow_checks] fn add(self, other: $t) -> $t { self + other } } )*) } add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 } This means the resolution for 'i + 3' is ambigious because it could be any of these Add implementations. But because we unify against the '< len' where len is defined as usize later in the resolution we determine 'i' is actually a usize. Which means if we defer the resolution of this operator overload in the ambigious case we can simply resolve it at the end. Fixes Rust-GCC#3916 gcc/rust/ChangeLog: * hir/tree/rust-hir-expr.cc (OperatorExprMeta::OperatorExprMeta): track the rhs * hir/tree/rust-hir-expr.h: likewise * hir/tree/rust-hir-path.h: get rid of old comments * typecheck/rust-hir-trait-reference.cc (TraitReference::get_trait_substs): return references instead of copy * typecheck/rust-hir-trait-reference.h: update header * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::ResolveOpOverload): write ambigious operator overloads to a table and try to resolve it at the end * typecheck/rust-hir-type-check-expr.h: new static helper * typecheck/rust-hir-type-check.h (struct DeferredOpOverload): new model to defer resolution * typecheck/rust-typecheck-context.cc (TypeCheckContext::lookup_operator_overload): new (TypeCheckContext::compute_ambigious_op_overload): likewise (TypeCheckContext::compute_inference_variables): likewise gcc/testsuite/ChangeLog: * rust/compile/issue-3916.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Parse try expressionsOwen Avery2-0/+4
This doesn't do anything beyond creating TryExpr and parsing them, so try expressions shouldn't be able to make it past AST lowering yet. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Add visitor for TryExpr. * ast/rust-ast-collector.h (TokenCollector::visit): Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.h (ASTVisitor::visit): Likewise. (DefaultASTVisitor::visit): Likewise. * expand/rust-derive.h (DeriveVisitor::visit): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h (ASTLoweringBase::visit): Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h (ResolverBase::visit): Likewise. * ast/rust-ast-full-decls.h (class TryExpr): New forward class declaration. * ast/rust-ast.cc (TryExpr::as_string): New function. (TryExpr::accept_vis): Likewise. * ast/rust-expr.h (class TryExpr): New class. * parse/rust-parse.h (Parser::parse_try_expr): New function. * parse/rust-parse-impl.h (Parser::parse_try_expr): Likewise. (Parser::null_denotation_not_path): Use parse_try_expr to parse try expressions. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: Add locus gettersPierre-Emmanuel Patry2-0/+4
gcc/rust/ChangeLog: * ast/rust-expr.h: Add getter to locus field. * ast/rust-pattern.h (tokenid_to_rangekind): Likewise. * hir/tree/rust-hir-item.h: Likewise. * hir/tree/rust-hir-visibility.h: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Implement default HIR visitor classRyutaro Okada2-0/+1484
gcc/rust/ChangeLog: * Make-lang.in: Scaffolding new rust-hir-visitor files * hir/tree/rust-hir-visitor.h (DefaultHIRVisitor): Declare default HIR visitor * hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor): Define default HIR visitor Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05gccrs: Add getter for non const lifetime objectRyutaro Okada1-0/+2
gcc/rust/ChangeLog: * hir/tree/rust-hir-item.h (SelfParam::get_lifetime): Add getter for non const lifetime object Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05gccrs: Add getter for outer attributionsRyutaro Okada1-0/+2
gcc/rust/ChangeLog: * hir/tree/rust-hir-expr.h (MatchArm::get_outer_attrs): Add getter for outer attributions Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05gccrs: Fix ICE when constant is missing and expressionPhilip Herron3-2/+7
This is an invalid test case and doesnt work with rustc, we dont fully pick up the errors. Nr2 does handle this and puts out an extra good diagnostic but the old NR doesnt so for now i added this to the exclude list and then when we remove old name resolver this issue goes away. Fixes Rust-GCC#3642 gcc/rust/ChangeLog: * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): check for has_expr * hir/rust-hir-dump.cc (Dump::visit): likewise * hir/tree/rust-hir-item.h: add has_expr helper * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): check for has_expr * resolve/rust-ast-resolve-stmt.h: likewise * typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): likewise gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 puts out an extra error * rust/compile/issue-3642.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Adjust external crate lowering and type checkingOwen Avery2-0/+20
The 2.0 name resolver is provided through ImmutableNameResolutionContext after it is done being mutated. The typechecker attempts to use ImmutableNameResolutionContext, so it needs to be run after ImmutableNameResolutionContext has been initialized (after all name resolution has been completed). Additionally, although I haven't seen any issues with lowering AST to HIR before name resolution 2.0 is complete, it makes sense to perform all lowering in lockstep as well. gcc/rust/ChangeLog: * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Add visitor for ExternCrate. * hir/rust-ast-lower-item.h (ASTLoweringItem::visit): Likewise. * rust-session-manager.cc (Session::load_extern_crate): Avoid lowering or type resolving external crates here. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Add visitor for ExternCrate. * typecheck/rust-hir-type-check-item.h (TypeCheckItem::visit): Replace empty definition with a declaration. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: Rename get_pattern_to_bind to get_subpatternZhi Heng1-1/+1
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc: Rename get_pattern_to_bind to get_subpattern * ast/rust-ast-visitor.cc: Ditto. * ast/rust-pattern.h: Ditto. * expand/rust-cfg-strip.cc: Ditto. * hir/rust-ast-lower-pattern.cc: Ditto. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05gccrs: Improve HIR dumps for patternsZhi Heng1-2/+2
gcc/rust/ChangeLog: * hir/rust-hir-dump.cc: Change pattern dumps to use visit_field. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05gccrs: Rename IdentifierPattern's to_bind to subpatternZhi Heng4-18/+18
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: Add new function ClosureExpr::get_definition_exprOwen Avery1-1/+1
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: 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: Make ConstantItem use IdentifierOwen Avery1-1/+1
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: hir: Add const blocksArthur Cohen10-43/+250
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: ast: Add ConstBlock and AnonConst nodesArthur Cohen3-4/+12
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: Reindent using last clang-format configurationMarc Poulhiès7-25/+40
It changes declaration and switch case indentation to follow GNU coding style. gcc/rust/ChangeLog: * ast/rust-ast-builder-type.cc (ASTTypeBuilder::visit): Reindent. * ast/rust-ast-builder.cc (Builder::new_generic_args): Likewise. * ast/rust-ast-collector.cc (TokenCollector::visit): Likewise. * ast/rust-ast-dump.h (debug): Likewise. * ast/rust-ast-formatting.h (indent_spaces): Likewise. (get_string_in_delims): Likewise. (get_mode_dump_desc): Likewise. (append_attributes): Likewise. (unquote_string): Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast.cc (Attribute::get_traits_to_derive): Likewise. (UseTreeGlob::as_string): Likewise. (UseTreeList::as_string): Likewise. (AttributeParser::parse_path_meta_item): Likewise. (FormatArgs::set_outer_attrs): Likewise. * ast/rust-ast.h (operator<<): Likewise. * ast/rust-cond-compilation.h: Likewise. * ast/rust-desugar-apit.cc: Likewise. * ast/rust-fmt.h (collect_pieces): Likewise. (clone_pieces): Likewise. * ast/rust-pattern.h (tokenid_to_rangekind): Likewise. * backend/rust-compile-context.cc (Context::type_hasher): Likewise. * backend/rust-compile-expr.cc (CompileExpr::visit): Likewise. * backend/rust-compile-intrinsic.cc (get_identifier): Likewise. (offset_handler): Likewise. (sizeof_handler): Likewise. (transmute_handler): Likewise. (rotate_handler): Likewise. (wrapping_op_handler_inner): Likewise. (op_with_overflow_inner): Likewise. (uninit_handler): Likewise. (move_val_init_handler): Likewise. (assume_handler): Likewise. (discriminant_value_handler): Likewise. (variant_count_handler): Likewise. (prefetch_data_handler): Likewise. (atomic_store_handler_inner): Likewise. (atomic_load_handler_inner): Likewise. (unchecked_op_inner): Likewise. (copy_handler_inner): Likewise. (expect_handler_inner): Likewise. (try_handler_inner): Likewise. * backend/rust-compile-pattern.cc (compile_range_pattern_bound): Likewise. (CompilePatternCheckExpr::visit): Likewise. (CompilePatternBindings::visit): Likewise. (CompilePatternLet::visit): Likewise. * backend/rust-compile-var-decl.h: Likewise. * backend/rust-constexpr.cc (verify_constant): Likewise. (find_array_ctor_elt): Likewise. (array_index_cmp): Likewise. (potential_constant_expression_1): Likewise. (unshare_constructor): Likewise. (maybe_save_constexpr_fundef): Likewise. (returns): Likewise. (breaks): Likewise. (continues): Likewise. (switches): Likewise. (constant_value_1): Likewise. (decl_constant_value): Likewise. (non_const_var_error): Likewise. (eval_constant_expression): Likewise. (constexpr_fn_retval): Likewise. (eval_store_expression): Likewise. (eval_call_expression): Likewise. (eval_binary_expression): Likewise. (get_function_named_in_call): Likewise. (eval_statement_list): Likewise. (extract_string_elt): Likewise. (eval_conditional_expression): Likewise. (eval_bit_field_ref): Likewise. (eval_loop_expr): Likewise. (eval_switch_expr): Likewise. (eval_unary_expression): Likewise. (get_or_insert_ctor_field): Likewise. (eval_and_check_array_index): Likewise. * backend/rust-constexpr.h (maybe_save_constexpr_fundef): Likewise. * backend/rust-mangle-v0.cc (v0_path): Likewise. (v0_complex_type_prefix): Likewise. * backend/rust-mangle.h (legacy_mangle_item): Likewise. (v0_mangle_item): Likewise. * backend/rust-tree.cc (convert_to_void): Likewise. (find_parameter_packs_r): Likewise. (rs_tree_equal): Likewise. (publicly_uniquely_derived_p): Likewise. (instantiation_dependent_expression_p): Likewise. (type_has_nontrivial_copy_init): Likewise. (is_normal_capture_proxy): Likewise. (is_bitfield_expr_with_lowered_type): Likewise. (undeduced_auto_decl): Likewise. (require_deduced_type): Likewise. (gt_pch_nx): Likewise. (lvalue_kind): Likewise. * backend/rust-tree.h (LANG_DECL_MIN_CHECK): Likewise. (LANG_DECL_FN_CHECK): Likewise. (LANG_DECL_NS_CHECK): Likewise. (LANG_DECL_PARM_CHECK): Likewise. (LANG_DECL_DECOMP_CHECK): Likewise. (resort_type_member_vec): Likewise. (convert_to_void): Likewise. (mark_discarded_use): Likewise. (mark_exp_read): Likewise. (mark_use): Likewise. (mark_rvalue_use): Likewise. (mark_lvalue_use): Likewise. (mark_lvalue_use_nonread): Likewise. (convert_from_reference): Likewise. (maybe_warn_nodiscard): Likewise. (expr_loc_or_loc): Likewise. (expr_loc_or_input_loc): Likewise. (get_fndecl_from_callee): Likewise. (pointer_offset_expression): Likewise. (is_empty_class): Likewise. (is_really_empty_class): Likewise. (rs_type_quals): Likewise. (init_modules): Likewise. (lookup_add): Likewise. (ovl_make): Likewise. (struct c_fileinfo): Likewise. (get_fileinfo): Likewise. (cxx_make_type): Likewise. (build_cplus_array_type): Likewise. (comptypes): Likewise. (rs_build_qualified_type_real): Likewise. (vector_targets_convertible_p): Likewise. (get_class_binding_direct): Likewise. (lang_check_failed): Likewise. (check_for_uninitialized_const_var): Likewise. (cp_fold_maybe_rvalue): Likewise. (fold_offsetof): Likewise. (fold_non_dependent_expr): Likewise. (in_immediate_context): Likewise. (cxx_mark_addressable): Likewise. (decl_constant_value): Likewise. (is_class_type): Likewise. (fold_builtin_is_pointer_inverconvertible_with_class): Likewise. (c_common_type_for_mode): Likewise. (next_common_initial_seqence): Likewise. (fold_builtin_is_corresponding_member): Likewise. (maybe_constant_value): Likewise. (rs_walk_subtrees): Likewise. (make_tree_vector): Likewise. (release_tree_vector): Likewise. (location_of): Likewise. (maybe_constant_init): Likewise. (explain_invalid_constexpr_fn): Likewise. (literal_type_p): Likewise. (maybe_constexpr_fn): Likewise. (fold_non_dependent_init): Likewise. * checks/errors/borrowck/polonius/rust-polonius.h (polonius_run): Likewise. (FFIVector__new): Likewise. (FFIVector__new_vec_pair): Likewise. (FFIVector__new_vec_triple): Likewise. (FFIVector__push): Likewise. (FFIVector__push_vec_triple): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-pattern.cc (PatternBindingBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-dump.cc (Dump::visit): Likewise. * checks/errors/borrowck/rust-bir-fact-collector.h (points): Likewise. * checks/errors/borrowck/rust-bir-place.h: Likewise. * checks/errors/borrowck/rust-bir-visitor.h: Likewise. * checks/errors/privacy/rust-privacy-check.cc (saw_errors): Likewise. * checks/errors/privacy/rust-privacy-ctx.h (rust_privacy_ctx_test): Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_for_privacy_violation): Likewise. (PrivacyReporter::check_base_type_privacy): Likewise. (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit): Likewise. * checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::resolve_visibility): Likewise. * checks/errors/rust-hir-pattern-analysis.cc (Constructor::is_covered_by): Likewise. (PlaceInfo::specialize): Likewise. (WitnessPat::to_string): Likewise. (WitnessMatrix::apply_constructor): Likewise. (lower_pattern): Likewise. (lower_tuple_pattern): Likewise. (lower_struct_pattern): Likewise. * checks/errors/rust-hir-pattern-analysis.h (check_match_usefulness): Likewise. * expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_generic_args): Likewise. * expand/rust-derive-eq.cc (DeriveEq::visit_enum): Likewise. * expand/rust-derive.cc: Likewise. * expand/rust-expand-format-args.cc (expand_format_args): Likewise. * expand/rust-expand-visitor.h (is_derive): Likewise. (is_builtin): Likewise. * expand/rust-macro-builtins-asm.cc (expand_inline_asm_strings): Likewise. * expand/rust-macro-builtins-asm.h (parse_asm): Likewise. (check_identifier): Likewise. (check_and_set): Likewise. (parse_label): Likewise. (parse_llvm_outputs): Likewise. (parse_llvm_inputs): Likewise. (parse_llvm_clobbers): Likewise. (parse_llvm_options): Likewise. * expand/rust-macro-builtins-helpers.h (make_macro_path_str): Likewise. (make_token): Likewise. (make_string): Likewise. (macro_end_token): Likewise. (parse_single_string_literal): Likewise. (source_relative_path): Likewise. (load_file_bytes): Likewise. * expand/rust-macro-expand.cc (MacroExpander::match_fragment): Likewise. (MacroExpander::match_matcher): Likewise. (MacroExpander::match_n_matches): Likewise. * expand/rust-macro-substitute-ctx.cc (SubstituteCtx::substitute_token): Likewise. * expand/rust-proc-macro.h (load_macros): Likewise. (generate_proc_macro_decls_symbol): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_generic_args): Likewise. (ASTLoweringBase::lower_range_pattern_bound): Likewise. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Likewise. * hir/rust-ast-lower.h (struct_field_name_exists): Likewise. (translate_visibility): Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/rust-hir-dump.h (debug): Likewise. * hir/tree/rust-hir.cc (UseTreeGlob::as_string): Likewise. (UseTreeList::as_string): Likewise. * lex/rust-lex.cc (Lexer::parse_escape): Likewise. (Lexer::parse_utf8_escape): Likewise. * lex/rust-lex.h (rust_input_source_test): Likewise. * lex/rust-token.cc (RS_TOKEN_KEYWORD_2015): Likewise. * lex/rust-token.h (get_token_description): Likewise. (token_id_to_str): Likewise. (token_id_is_keyword): Likewise. (token_id_keyword_string): Likewise. (get_type_hint_string): Likewise. (nfc_normalize_token_string): Likewise. * metadata/rust-export-metadata.cc (PublicInterface::write_to_path): Likewise. * metadata/rust-import-archive.cc: Likewise. * metadata/rust-imports.h (add_search_path): Likewise. * parse/rust-cfg-parser.h (parse_cfg_option): Likewise. (rust_cfg_parser_test): Likewise. * parse/rust-parse-impl.h (Parser::skip_generics_right_angle): Likewise. (Parser::parse_attr_input): Likewise. (Parser::parse_macro_match): Likewise. (Parser::parse_visibility): Likewise. (Parser::parse_module): Likewise. (Parser::parse_use_tree): Likewise. (Parser::parse_generic_param): Likewise. (Parser::parse_struct): Likewise. (Parser::parse_enum_item): Likewise. (Parser::parse_inherent_impl_item): Likewise. (Parser::parse_external_item): Likewise. (Parser::parse_generic_arg): Likewise. (Parser::parse_type_path_segment): Likewise. (Parser::parse_expr_stmt): Likewise. (Parser::parse_if_expr): Likewise. (Parser::parse_if_let_expr): Likewise. (Parser::parse_type): Likewise. (Parser::parse_for_prefixed_type): Likewise. (Parser::parse_slice_or_array_type): Likewise. (Parser::parse_type_no_bounds): Likewise. (Parser::parse_range_pattern_bound): Likewise. (Parser::parse_pattern_no_alt): Likewise. (Parser::parse_grouped_or_tuple_pattern): Likewise. (Parser::parse_ident_leading_pattern): Likewise. (Parser::parse_tuple_struct_items): Likewise. (Parser::parse_stmt_or_expr): Likewise. (Parser::parse_struct_expr_field): Likewise. (Parser::null_denotation): Likewise. (Parser::left_denotation): Likewise. (Parser::parse_closure_expr_pratt): Likewise. * parse/rust-parse.cc (peculiar_fragment_match_compatible): Likewise. (is_match_compatible): Likewise. * parse/rust-parse.h (extract_module_path): Likewise. (is_match_compatible): Likewise. * resolve/rust-ast-resolve-expr.cc (translate_operand): Likewise. * resolve/rust-ast-resolve-item.cc (flatten_glob): Likewise. (flatten_rebind): Likewise. (flatten_list): Likewise. (flatten): Likewise. * resolve/rust-ast-resolve-item.h (rust_simple_path_resolve_test): Likewise. * resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit): Likewise. (resolve_range_pattern_bound): Likewise. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. (ResolveTypeToCanonicalPath::visit): Likewise. * resolve/rust-ast-resolve.cc (saw_errors): Likewise. * resolve/rust-early-name-resolver-2.0.cc (Early::finalize_rebind_import): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (flatten_glob): Likewise. * rust-backend.h (init): Likewise. (debug): Likewise. (get_identifier_node): Likewise. (wchar_type): Likewise. (get_pointer_size): Likewise. (raw_str_type): Likewise. (integer_type): Likewise. (float_type): Likewise. (pointer_type): Likewise. (reference_type): Likewise. (immutable_type): Likewise. (function_type): Likewise. (function_type_variadic): Likewise. (function_ptr_type): Likewise. (struct_type): Likewise. (union_type): Likewise. (array_type): Likewise. (named_type): Likewise. (type_field_offset): Likewise. (var_expression): Likewise. (float_constant_expression): Likewise. (string_constant_expression): Likewise. (char_constant_expression): Likewise. (wchar_constant_expression): Likewise. (boolean_constant_expression): Likewise. (convert_expression): Likewise. (struct_field_expression): Likewise. (compound_expression): Likewise. (conditional_expression): Likewise. (negation_expression): Likewise. (arithmetic_or_logical_expression): Likewise. (arithmetic_or_logical_expression_checked): Likewise. (comparison_expression): Likewise. (lazy_boolean_expression): Likewise. (constructor_expression): Likewise. (array_constructor_expression): Likewise. (array_initializer): Likewise. (array_index_expression): Likewise. (call_expression): Likewise. (init_statement): Likewise. (assignment_statement): Likewise. (return_statement): Likewise. (if_statement): Likewise. (loop_expression): Likewise. (exit_expression): Likewise. (statement_list): Likewise. (exception_handler_statement): Likewise. (block): Likewise. (block_add_statements): Likewise. (global_variable): Likewise. (global_variable_set_init): Likewise. (local_variable): Likewise. (parameter_variable): Likewise. (static_chain_variable): Likewise. (temporary_variable): Likewise. (label): Likewise. (function): Likewise. (function_defer_statement): Likewise. (function_set_parameters): Likewise. (write_global_definitions): Likewise. (fill_in_fields): Likewise. * rust-diagnostics.cc (expand_format): Likewise. (expand_message): Likewise. (va_constructor): Likewise. * rust-diagnostics.h (RUST_ATTRIBUTE_GCC_DIAG): Likewise. (rust_open_quote): Likewise. (rust_close_quote): Likewise. (rust_debug_loc): Likewise. * rust-gcc.cc (non_zero_size_type): Likewise. * rust-object-export.h (rust_field_alignment): Likewise. (rust_read_export_data): Likewise. (rust_write_export_data): Likewise. * rust-session-manager.cc (saw_errors): Likewise. (rust_get_linemap): Likewise. (validate_crate_name): Likewise. (Session::load_extern_crate): Likewise. * rust-session-manager.h (rust_crate_name_validation_test): Likewise. * rust-system.h (rust_preserve_from_gc): Likewise. (rust_localize_identifier): Likewise. * rust-target.h (rust_add_target_info): Likewise. * typecheck/rust-autoderef.cc: * typecheck/rust-casts.cc (TypeCastRules::cast_rules): Likewise. * typecheck/rust-coercion.cc (TypeCoercionRules::do_coercion): Likewise. (TypeCoercionRules::coerce_unsafe_ptr): Likewise. (TypeCoercionRules::coerce_borrowed_pointer): Likewise. * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): Likewise. (TraitItemReference::is_object_safe): Likewise. * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. (typecheck_inline_asm_operand): Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): Likewise. (TypeCheckImplItemWithTrait::visit): Likewise. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise. * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::visit): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeResolveGenericParam::apply_trait_bounds): Likewise. (ResolveWhereClauseItem::visit): Likewise. * typecheck/rust-hir-type-check.cc (saw_errors): Likewise. (TraitItemReference::get_type_from_fn): Likewise. * typecheck/rust-type-util.h (query_type): Likewise. (types_compatable): Likewise. (unify_site): Likewise. (unify_site_and): Likewise. (coercion_site): Likewise. (try_coercion): Likewise. (cast_site): Likewise. * typecheck/rust-tyty-bounds.cc: * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Likewise. * typecheck/rust-tyty-cmp.h: * typecheck/rust-tyty-variance-analysis.h (query_field_regions): Likewise. * typecheck/rust-tyty.cc (BaseType::is_unit): Likewise. (BaseType::has_substitutions_defined): Likewise. (BaseType::needs_generic_substitutions): Likewise. (BaseType::get_subst_argument_mappings): Likewise. (InferType::default_type): Likewise. (InferType::apply_primitive_type_hint): Likewise. * typecheck/rust-tyty.h (is_primitive_type_kind): Likewise. * typecheck/rust-unify.cc (UnifyRules::expect_inference_variable): Likewise. (UnifyRules::expect_adt): Likewise. (UnifyRules::expect_str): Likewise. (UnifyRules::expect_reference): Likewise. (UnifyRules::expect_pointer): Likewise. (UnifyRules::expect_param): Likewise. (UnifyRules::expect_array): Likewise. (UnifyRules::expect_slice): Likewise. (UnifyRules::expect_fndef): Likewise. (UnifyRules::expect_fnptr): Likewise. (UnifyRules::expect_tuple): Likewise. (UnifyRules::expect_bool): Likewise. (UnifyRules::expect_char): Likewise. (UnifyRules::expect_int): Likewise. (UnifyRules::expect_uint): Likewise. (UnifyRules::expect_float): Likewise. (UnifyRules::expect_isize): Likewise. (UnifyRules::expect_usize): Likewise. (UnifyRules::expect_never): Likewise. (UnifyRules::expect_placeholder): Likewise. (UnifyRules::expect_projection): Likewise. (UnifyRules::expect_dyn): Likewise. (UnifyRules::expect_closure): Likewise. (UnifyRules::expect_opaque): Likewise. * util/rust-abi.h (get_abi_from_string): Likewise. (get_string_from_abi): Likewise. * util/rust-attributes.cc (check_doc_attribute): Likewise. * util/rust-base62.h (base62_integer): Likewise. * util/rust-dir-owner.h (get_file_subdir): Likewise. * util/rust-edition.h (get_rust_edition): Likewise. * util/rust-punycode.h (encode_punycode): Likewise. (rust_punycode_encode_test): Likewise. * util/rust-token-converter.cc (convert): Likewise. (from_tokenstream): Likewise. * util/rust-token-converter.h (convert): Likewise. (convert_literal): Likewise. * util/rust-unicode.h (is_alphabetic): Likewise. (is_ascii_only): Likewise. (is_numeric): Likewise. (is_nfc_qc_no): Likewise. (is_nfc_qc_maybe): Likewise. (nfc_quick_check): Likewise. (rust_nfc_qc_test): Likewise. (rust_utf8_normalize_test): Likewise. (rust_utf8_property_test): Likewise. * util/rust-unwrap-segment.h (unwrap_segment_node_id): Likewise. libgrust/ChangeLog: * libproc_macro_internal/ffistring.h (FFIString__new): Likewise. (FFIString__drop): Likewise. * libproc_macro_internal/ident.h (Ident__new): Likewise. (Ident__new_raw): Likewise. (Ident__drop): Likewise. (Ident__clone): Likewise. * libproc_macro_internal/literal.h (Literal__from_string): Likewise. * libproc_macro_internal/proc_macro.h (bridge_is_available): Likewise. * libproc_macro_internal/tokenstream.h (TokenStream__new): Likewise. (TokenStream__with_capacity): Likewise. (TokenSream__push): Likewise. (TokenStream__from_string): Likewise. (TokenStream__clone): Likewise. (TokenStream__drop): Likewise.
2025-08-05gccrs: Fix test same_field_name.rsOwen Avery1-1/+1
gcc/rust/ChangeLog: * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Keep going after a duplicate field is found. gcc/testsuite/ChangeLog: * rust/execute/same_field_name.rs: Move to... * rust/compile/same_field_name.rs: ...here and adjust expected errors. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: ast: collector: visit InlineAsm node during ast dump0xn4utilus2-4/+4
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.
2025-08-05gccrs: Prevent passing generic arguments to impl traits in argument positionPhilip Herron3-14/+14
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>
2025-08-05gccrs: desugar APIT impl traitsPhilip Herron1-1/+1
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>
2025-08-05gccrs: Emit error diagnostic for bad impl type usagePhilip Herron4-24/+52
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-04-28gccrs: Remove error state for GenericArgPierre-Emmanuel Patry1-1/+1
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-28gccrs: Parse and lower llvm asm nodePierre-Emmanuel Patry9-0/+140
Add a new HIR LlvmInlineAsm HIR node as well as some structures to represent it's options and operands. Lower AST::LlvmInlineAsm node to it and then create a tree from that node. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove unreachable code. * ast/rust-expr.h (struct LlvmOperand): Add LlvmOperand struct to represent input and outputs. (class LlvmInlineAsm): Add input, output and clobber operands. (struct TupleTemplateStr): Add locus getter. * backend/rust-compile-block.h: Add visit for LlvmInlineAsm. * backend/rust-compile-expr.cc (CompileExpr::visit): Add llvm inline asm stmt compilation. * backend/rust-compile-expr.h: Add function prototype. * backend/rust-compile-asm.h (class CompileLlvmAsm): Add llvm asm hir not to gimple. * backend/rust-compile-asm.cc (CompileLlvmAsm::CompileLlvmAsm): Add constructor. (CompileLlvmAsm::construct_operands): Add function to construct operand tree. (CompileLlvmAsm::construct_clobbers): Add function to construct clobber tree. (CompileLlvmAsm::tree_codegen_asm): Generate the whole tree for a given llvm inline assembly node. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Add visit function. * checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Add function prototype. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Add visit function. * 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: Add visit function prototype. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Add visit function. * checks/errors/rust-const-checker.h: Add visit function prototype. * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit): Add visit function. * checks/errors/rust-hir-pattern-analysis.h: Add visit function prototype. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Add visit function. * checks/errors/rust-unsafe-checker.h: Add function prototype. * expand/rust-macro-builtins-asm.cc (parse_llvm_templates): Parse templates. (parse_llvm_arguments): Add function to parse non template tokens. (parse_llvm_operands): Add function to parse operands, either input or output. (parse_llvm_outputs): Add function to parse and collect llvm asm outputs. (parse_llvm_inputs): Likewise with inputs. (parse_llvm_clobbers): Add function to parse llvm asm clobbers. (parse_llvm_options): Add function to parse llvm asm options. (parse_llvm_asm): Add function to parse llvm asm. * expand/rust-macro-builtins-asm.h (class LlvmAsmContext): Add context for llvm asm parser. (parse_llvm_outputs): Add function prototype. (parse_llvm_inputs): Likewise. (parse_llvm_clobbers): Likewise. (parse_llvm_options): Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Lower AST llvm asm node to HIR. * hir/rust-ast-lower-expr.h: Add function prototype. * hir/rust-hir-dump.cc (Dump::visit): Add visit function. * hir/rust-hir-dump.h: Add function prototype. * hir/tree/rust-hir-expr-abstract.h: Add HIR llvm asm node kind. * hir/tree/rust-hir-expr.h (struct LlvmOperand): Add LlvmOperand type to represent input and outputs. (class LlvmInlineAsm): Add LlvmInlineAsm hir node. * hir/tree/rust-hir-full-decls.h (class LlvmInlineAsm): Add LlvmInlineAsm hir node forward declaration. * hir/tree/rust-hir-visitor.h: Add visit functions for LlvmInlineAsm hir node. * hir/tree/rust-hir.cc (LlvmInlineAsm::accept_vis): Add hir node visitor related functions. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Type check input and output operands. * typecheck/rust-hir-type-check-expr.h: Add function prototype. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit input and output operand expressions. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Resolve input and output expressions. * resolve/rust-ast-resolve-expr.h: Add function prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-28gccrs: Add llvmInlineAsm nodePierre-Emmanuel Patry2-0/+5
InlineAsm node does not support memory clobbers. gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Make visitor unreachable. * ast/rust-ast-collector.h: Add visit for LlvmInlineAsmNode. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Add visit function for the default ast visitor. * ast/rust-ast-visitor.h: Add function prototype. * ast/rust-ast.cc (LlvmInlineAsm::accept_vis): Add accept_vis to LlvmInlineAsm node. * ast/rust-ast.h: Add LlvmInlineAsm node kind. * ast/rust-expr.h (class LlvmInlineAsm): Add LlvmInlineAsm node. * expand/rust-derive.h: Add visit function for LlvmInlineAsm node. * expand/rust-macro-builtins-asm.cc (MacroBuiltin::llvm_asm_handler): Add handler for llvm inline assembly nodes. (parse_llvm_asm): Add function to parse llvm assembly nodes. * expand/rust-macro-builtins-asm.h (parse_llvm_asm): Add function prototypes. * expand/rust-macro-builtins.cc (inline_llvm_asm_maker): Add macro transcriber. * expand/rust-macro-builtins.h: Add transcriber function prototype. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add visit function for LlvmInlineAsm node. * hir/rust-ast-lower-base.h: Add visit function prototype. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add visit function for LlvmInlineAsm node. * resolve/rust-ast-resolve-base.h: Add visit function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-28gccrs: Fix crash in hir dump as labels are optionalPhilip Herron1-1/+3
gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::visit): add guard for optional label Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-28gccrs: Fix segv in unsafe chckerPhilip Herron1-0/+2
Trait constants were missing type resolution step, this adds that as if it was a normal constant. The unsafe checker was missing a null check. Fixes Rust-GCC#3612 gcc/rust/ChangeLog: * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): add null check * hir/tree/rust-hir-item.h: add has_type helper * typecheck/rust-hir-trait-resolve.cc (TraitItemReference::resolve_item): add missing type checking gcc/testsuite/ChangeLog: * rust/compile/issue-3612.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-08gccrs: Rename label getter to uncheckedPierre-Emmanuel Patry1-1/+1
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-08gccrs: Rename label getter in ContinueExprPierre-Emmanuel Patry1-1/+1
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-08gccrs: Migrate error state to optionalsPierre-Emmanuel Patry16-144/+137
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-08gccrs: Resolve labelsPierre-Emmanuel Patry4-20/+31
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-08gccrs: hir: Add default qualifier to function, lower it properlyArthur Cohen4-6/+31
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-08gccrs: Fix ICE on raw referencePhilip Herron3-10/+9
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-03-31gccrs: FIX ICE when working with HIR::BareFunctionTypePhilip Herron2-2/+5
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-31gccrs: Fix ICE when compiling path which resolves to trait constantPhilip Herron1-1/+3
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>