]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
6 weeks agoconst-block: Add testcase devel/rust/master
Arthur Cohen [Tue, 15 Apr 2025 11:41:41 +0000 (13:41 +0200)] 
const-block: Add testcase

gcc/testsuite/ChangeLog:

* rust/execute/torture/const_block1.rs: New test.

6 weeks agohir: Add const blocks
Arthur Cohen [Tue, 15 Apr 2025 11:34:38 +0000 (13:34 +0200)] 
hir: Add const blocks

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.

6 weeks agoparser: Add base for parsing const blocks
Arthur Cohen [Tue, 15 Apr 2025 15:33:11 +0000 (17:33 +0200)] 
parser: Add base for parsing const blocks

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_const_block_expr): New function.
* parse/rust-parse.h: Declare it.

6 weeks agoast: Add ConstBlock and AnonConst nodes
Arthur Cohen [Wed, 9 Apr 2025 16:18:30 +0000 (18:18 +0200)] 
ast: Add ConstBlock and AnonConst nodes

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.

6 weeks agogccrs: Always emit the error highest in the type hierarchy
Philip Herron [Tue, 20 May 2025 17:44:57 +0000 (18:44 +0100)] 
gccrs: Always emit the error highest in the type hierarchy

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>
6 weeks agonr2.0: Fix IfLet pattern handling
Owen Avery [Thu, 15 May 2025 00:03:01 +0000 (20:03 -0400)] 
nr2.0: Fix IfLet pattern handling

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>
6 weeks agoAdjust included headers in rust-lang.cc
Owen Avery [Mon, 26 May 2025 21:11:19 +0000 (17:11 -0400)] 
Adjust included headers in rust-lang.cc

This was upstreamed as part of ea34614225d4d255e58f63206eb12178b870cb4c
but never made it to our downstream repo. I've added Philip as a
co-author, since he wrote the upstream commit.

gcc/rust/ChangeLog:

* rust-lang.cc: Remove direct inclusion of "config.h" and
"system.h", move inclusion of "rust-system.h" upwards.

Co-authored-by: Philip Herron <herron.philip@googlemail.com>
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
6 weeks agogccrs: Initial support for Return Position Impl Trait
Philip Herron [Mon, 19 May 2025 17:02:13 +0000 (18:02 +0100)] 
gccrs: Initial support for Return Position Impl Trait

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>
6 weeks agogccrs: Fix non canonical type bug with tuples
Philip Herron [Mon, 26 May 2025 18:30:45 +0000 (19:30 +0100)] 
gccrs: Fix non canonical type bug with tuples

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>
6 weeks agogccrs: Remove unneeded clones untill we have an arena allocator for these tmps
Philip Herron [Mon, 19 May 2025 16:42:17 +0000 (17:42 +0100)] 
gccrs: Remove unneeded clones untill we have an arena allocator for these tmps

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>
6 weeks agogccrs: refactor default infer vars to be its own function
Philip Herron [Mon, 19 May 2025 16:55:53 +0000 (17:55 +0100)] 
gccrs: refactor default infer vars to be its own function

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>
7 weeks agonr2.0: Fix some paths in test files
Owen Avery [Wed, 14 May 2025 22:22:33 +0000 (18:22 -0400)] 
nr2.0: Fix some paths in test files

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>
7 weeks agonr2.0: Fix test builtin_abort.rs
Owen Avery [Thu, 15 May 2025 00:05:55 +0000 (20:05 -0400)] 
nr2.0: Fix test builtin_abort.rs

gcc/testsuite/ChangeLog:

* rust/execute/torture/builtin_abort.rs: Fix path to
intrinsics::abort.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 weeks agogccrs: Fix NR2 ICE in visit_attributes
Tom Schollenberger [Mon, 12 May 2025 02:57:28 +0000 (22:57 -0400)] 
gccrs: Fix NR2 ICE in visit_attributes

Undefined attribute macros have no proc macro definition, which results
in a failing `rust_assert`. This changes that assert to an if statement,
that returns early if there is no proc macro definition. Fixes #3661.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes): rust_assert to if

gcc/testsuite/ChangeLog:

* rust/compile/issue-3661.rs: Test NR2 has expected behavior

Signed-off-by: Tom Schollenberger <tss2344@g.rit.edu>
7 weeks agoRemove rvalue reference binding
Owen Avery [Tue, 13 May 2025 22:01:33 +0000 (18:01 -0400)] 
Remove rvalue reference binding

This should be unnecessary, since even C++11 has implicit move.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_expr_stmt): Avoid
reference binding and remove std::move in return statements.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
8 weeks agoSmall improvements to DefaultASTVisitor and nr2.0
Owen Avery [Thu, 8 May 2025 21:32:05 +0000 (17:32 -0400)] 
Small improvements to DefaultASTVisitor and nr2.0

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Only visit the path of an instance
of Visibility if the instance has a path.
* ast/rust-ast.h
(SimplePath::SimplePath): Make sure constructors are explicit.
* resolve/rust-early-name-resolver-2.0.cc
(Early::visit_attributes): Pass entire paths to
NameResolutionContext::resolve_path.
(Early::visit): Likewise and avoid copying a path.
* resolve/rust-forever-stack.hxx
(ForeverStack::resolve_path): Assert that at least one path
segment has been passed in.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
8 weeks agogccrs: remove unused file
Marc Poulhiès [Tue, 13 May 2025 19:21:18 +0000 (21:21 +0200)] 
gccrs: remove unused file

gcc/rust/ChangeLog:

* Make-lang.in (GRS_OBJS): Remove rust-macro.o.
* ast/rust-macro.cc: Removed.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
8 weeks agoFix Attr metavariable binding
Owen Avery [Sat, 10 May 2025 02:17:55 +0000 (22:17 -0400)] 
Fix Attr metavariable binding

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_attr_input): Handle more delimeter tokens and the
END_OF_FILE token.
(Parser::skip_after_end_attribute): Handle the END_OF_FILE
token.

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/meta-param.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
8 weeks agoFix test same_field_name.rs
Owen Avery [Sat, 10 May 2025 00:48:18 +0000 (20:48 -0400)] 
Fix test same_field_name.rs

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>
8 weeks agonr2.0: Fix borrow checking
Owen Avery [Fri, 9 May 2025 22:02:29 +0000 (18:02 -0400)] 
nr2.0: Fix borrow checking

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-internal.h: Include
"rust-immutable-name-resolution-context.h" and "options.h".
(AbstractBuilder::resolve_label): Use the 2.0 name resolver when
it's enabled.
(AbstractBuilder::resolve_variable): Likewise.
(AbstractBuilder::resolve_variable_or_fn): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
8 weeks agogccrs: We cant clone types as it will dup the node-id
Philip Herron [Sun, 11 May 2025 14:03:05 +0000 (15:03 +0100)] 
gccrs: We cant clone types as it will dup the node-id

This patch ensuers we reuse the Builder for new type to
ensure we create a new type from scratch ensuring consistent
new node-ids.

gcc/rust/ChangeLog:

* expand/rust-derive-default.cc (DeriveDefault::visit_struct): use builder
(DeriveDefault::visit_tuple): likewise
* expand/rust-derive-eq.cc (DeriveEq::visit_tuple): likewise
(DeriveEq::visit_struct): likewise
(DeriveEq::visit_enum): likewise
(DeriveEq::visit_union): likewise

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: these are fixed now

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: Adapt attribute lang hook and do some cleanup
Marc Poulhiès [Fri, 9 May 2025 09:09:58 +0000 (11:09 +0200)] 
gccrs: Adapt attribute lang hook and do some cleanup

Since r14-6076, the LANG_HOOKS_COMMON_ATTRIBUTE_TABLE should not be used and
LANG_HOOKS_ATTRIBUTE_TABLE replaces it.

Add the "cold" attribute to fix PR120018 (and the matching "hot" attribute).

Replace some gcc_assert() by explicit warnings (same as D frontend).

Add some clang-format off/on comment around code that's not correctly
formatted.

gcc/rust/ChangeLog:
PR rust/120018

* rust-attribs.cc (handle_noreturn_attribute): Reindent declaration.
(handle_leaf_attribute): Likewise.
(handle_const_attribute): Likewise.
(handle_malloc_attribute): Likewise.
(handle_pure_attribute): Likewise.
(handle_novops_attribute): Likewise.
(handle_nonnull_attribute): Likewise.
(handle_nothrow_attribute): Likewise.
(handle_type_generic_attribute): Likewise.
(handle_transaction_pure_attribute): Likewise.
(handle_returns_twice_attribute): Likewise.
(handle_fnspec_attribute): Likewise.
(handle_omp_declare_simd_attribute): Likewise.
(handle_cold_attribute): New.
(handle_hot_attribute): New.
(attribute_spec::exclusions attr_cold_hot_exclusions): New.
(grs_langhook_common_attributes): Make it static.
(grs_langhook_common_attribute_table): New.
(grs_langhook_gnu_attributes): New.
(grs_langhook_gnu_attribute_table): New.
(handle_malloc_attribute): Make it static.
(handle_fnspec_attribute): Likewise.
(handle_pure_attribute): Replace gcc_assert by explicit warning.
(handle_novops_attribute): Likewise.
(handle_nothrow_attribute): Likewise.
(handle_returns_twice_attribute): Likewise.
(handle_omp_declare_simd_attribute): Likewise and make it static.
* rust-lang.cc (grs_langhook_gnu_attribute_table): New.
(grs_langhook_common_attribute_table): Adjust type to new hook.
(LANG_HOOKS_COMMON_ATTRIBUTE_TABLE): Remove.
(LANG_HOOKS_ATTRIBUTE_TABLE): New.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2 months agonr2.0: Adjust resolution of impl items
Owen Avery [Fri, 25 Apr 2025 22:06:41 +0000 (18:06 -0400)] 
nr2.0: Adjust resolution of impl items

gcc/rust/ChangeLog:

* ast/rust-path.cc
(TypePath::make_debug_string): Add definition.
* ast/rust-path.h
(TypePath::make_debug_string): Add declaration.
* resolve/rust-default-resolver.cc
(DefaultResolver::visit): Adjust InherentImpl and TraitImpl
visitors to better handle associated item scope.
* resolve/rust-default-resolver.h
(DefaultResolver::maybe_insert_big_self): Add.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Adjust type path resolution errors.
* resolve/rust-rib.h
(Rib::Kind): Add Generics kind.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Remove InherentImpl and TraitImpl visitor
overrides.
(TopLevel::maybe_insert_big_self): Add override in order to add
a definition of 'Self'.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Remove InherentImpl and TraitImpl visitor
overrides.
(TopLevel::maybe_insert_big_self): Add override.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agoast: collector: visit InlineAsm node during ast dump
0xn4utilus [Wed, 7 May 2025 16:51:10 +0000 (22:21 +0530)] 
ast: collector: visit InlineAsm node during ast dump

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.

2 months agogccrs: fix ICE on empty constexpr loops
Tom Schollenberger [Thu, 8 May 2025 11:26:07 +0000 (07:26 -0400)] 
gccrs: fix ICE on empty constexpr loops

Empty loops have no body which means this is a NULL_TREE during const
evaluation which needs a check. Fixes Rust-GCC #3618.

gcc/rust/ChangeLog:

* backend/rust-constexpr.cc (eval_constant_expression):  Check if t is a NULL_TREE

gcc/testsuite/ChangeLog:

* rust/compile/issue-3618.rs: Test empty loops error properly.

Signed-off-by: Tom Schollenberger <tss2344@g.rit.edu>
2 months agogccrs: Prevent passing generic arguments to impl traits in argument position
Philip Herron [Wed, 7 May 2025 15:07:43 +0000 (16:07 +0100)] 
gccrs: Prevent passing generic arguments to impl traits in argument position

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>
2 months agonr2.0: Adjust enum item visitors
Owen Avery [Fri, 2 May 2025 22:37:45 +0000 (18:37 -0400)] 
nr2.0: Adjust enum item visitors

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Make call to EnumItem visitor from
EnumItem derived class visitors non-virtual.
* ast/rust-collect-lang-items.cc
(CollectLangItems::visit): Handle visitation of classes derived
from EnumItem.
* ast/rust-collect-lang-items.h
(CollectLangItems::visit): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Call DefaultResolver::visit on EnumItem
instances.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agoImprove struct pattern compilation
Owen Avery [Thu, 1 May 2025 01:54:53 +0000 (21:54 -0400)] 
Improve struct pattern compilation

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc
(CompilePatternCheckExpr::visit): Fix GENERIC generation in
light of enum layout changes since this code was written.
(CompilePatternBindings::handle_struct_pattern_ident_pat):
Delegate handling of child patterns to another
CompilePatternBindings::Compile call.
(CompilePatternBindings::make_struct_access): Make field name
parameter const qualified.
* backend/rust-compile-pattern.h
(CompilePatternBindings::make_struct_access): Likewise.

gcc/testsuite/ChangeLog:

* rust/execute/torture/struct-pattern-match.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agoRevert "backend: Remove checks on StructFieldIdentPattern"
Owen Avery [Wed, 30 Apr 2025 20:20:53 +0000 (16:20 -0400)] 
Revert "backend: Remove checks on StructFieldIdentPattern"

This reverts commit 92323dd3bb16f21194891ce463fc865598c6980f.

2 months agoImprove canonical path handling for impl items
Owen Avery [Sat, 3 May 2025 00:28:15 +0000 (20:28 -0400)] 
Improve canonical path handling for impl items

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-item.cc
(ResolveItem::visit): Use the return values of
CanonicalPath::inherent_impl_seg and
CanonicalPath::trait_impl_projection_seg more directly.
* util/rust-canonical-path.h
(CanonicalPath::trait_impl_projection_seg): Append "<impl "
instead of "<" to the beginning of the returned path segment.
(CanonicalPath::inherent_impl_seg): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: desugar APIT impl traits
Philip Herron [Wed, 30 Apr 2025 13:37:49 +0000 (14:37 +0100)] 
gccrs: desugar APIT impl traits

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>
2 months agogccrs: Emit error diagnostic for bad impl type usage
Philip Herron [Mon, 5 May 2025 20:07:20 +0000 (21:07 +0100)] 
gccrs: Emit error diagnostic for bad impl type usage

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>
2 months agoderive(PartialEq): Fix raw strings in test
CohenArthur [Thu, 24 Apr 2025 16:41:11 +0000 (18:41 +0200)] 
derive(PartialEq): Fix raw strings in test

gcc/testsuite/ChangeLog:

* rust/execute/torture/derive-partialeq2.rs: Add missing terminating nul char.

Co-authored-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoderive(PartialEq): Allow deriving enum structs
Arthur Cohen [Wed, 16 Apr 2025 15:38:27 +0000 (17:38 +0200)] 
derive(PartialEq): Allow deriving enum structs

gcc/rust/ChangeLog:

* expand/rust-derive-partial-eq.cc (DerivePartialEq::match_enum_tuple): Remove debug call.
(DerivePartialEq::match_enum_struct): Add proper implementation.
(DerivePartialEq::visit_enum): Call it.

gcc/testsuite/ChangeLog:

* rust/execute/torture/derive-partialeq2.rs: New test.

2 months agoast: builder: Allow building struct ident patterns
Arthur Cohen [Wed, 16 Apr 2025 15:37:31 +0000 (17:37 +0200)] 
ast: builder: Allow building struct ident patterns

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::struct_pattern_ident_pattern): New.
* ast/rust-ast-builder.h: New declaration.

2 months agobackend: Remove checks on StructFieldIdentPattern
Arthur Cohen [Wed, 16 Apr 2025 15:39:28 +0000 (17:39 +0200)] 
backend: Remove checks on StructFieldIdentPattern

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): Remove old invalid
checks.

2 months agobackend: Compile struct rebinding patterns
Arthur Cohen [Wed, 16 Apr 2025 14:32:35 +0000 (16:32 +0200)] 
backend: Compile struct rebinding patterns

Allow matching on a struct instance and rebinding its fields to new names:

match X {
Foo {
field0: new_name0,
field1: new_name1,
} => {
do_something(new_name0, new_name1);
},
}

This will enable us to finish derives for PartialEq and PartialOrd but
isn't a complete implementation of these patterns yet.

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc (CompilePatternBindings::make_struct_access):
New function.
(CompilePatternBindings::visit): Properly implement patterns mentioned above
and call make_struct_accesss.
* backend/rust-compile-pattern.h: New declaration.

gcc/testsuite/ChangeLog:

* rust/execute/torture/struct_pattern1.rs: New test.

2 months agobackend: Refactor struct pattern compilation
Arthur Cohen [Wed, 16 Apr 2025 14:03:26 +0000 (16:03 +0200)] 
backend: Refactor struct pattern compilation

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.h: Split struct pattern compilation into three functions.
* backend/rust-compile-pattern.cc: Implement them.

2 months agonr2.0: late: Correctly initialize funny_error member
Arthur Cohen [Mon, 28 Apr 2025 19:45:13 +0000 (21:45 +0200)] 
nr2.0: late: Correctly initialize funny_error member

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::Late): False initialize the
funny_error field.

2 months agoFix narrowing conversion warnings
Owen Avery [Thu, 17 Apr 2025 02:53:18 +0000 (22:53 -0400)] 
Fix narrowing conversion warnings

Fixes PR#119641

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h
(IndexVec::size_type): Add.
(IndexVec::MAX_INDEX): Add.
(IndexVec::size): Change the return type to the type of the
internal value used by the index type.
(PlaceDB::lookup_or_add_variable): Use the return value from the
PlaceDB::add_place call.
* checks/errors/borrowck/rust-bir.h
(struct BasicBlockId): Move this definition before the
definition of the struct Function.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agoVisit visibility in UseDeclaration
Pierre-Emmanuel Patry [Mon, 28 Apr 2025 11:05:49 +0000 (13:05 +0200)] 
Visit visibility in UseDeclaration

Default visitor should visit all it's children.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit visibility.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoSome assorted tweaks and bug fixes
Owen Avery [Sat, 11 Jan 2025 05:15:05 +0000 (00:15 -0500)] 
Some assorted tweaks and bug fixes

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Visit the loop labels of
WhileLetLoopExpr instances before visiting their scrutinee
expressions.
* resolve/rust-early-name-resolver-2.0.cc
(Early::resolve_glob_import): Pass the glob import's path
directly to NameResolutionContext::resolve_path.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Remove unnecessary call to
Identifier::as_string.
(flatten_glob): Improve handling of cases where a glob use tree
has no path.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agoCompletely duplicate path node
Pierre-Emmanuel Patry [Fri, 25 Apr 2025 14:02:12 +0000 (16:02 +0200)] 
Completely duplicate path node

Both nodes had the same id, this led to a resolution conflict.

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::clone_enum_struct): Clone
path to avoid using the same nodeid.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove now passing test from exclusion
list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoUse specialized param visit function for params
Pierre-Emmanuel Patry [Sat, 19 Apr 2025 12:14:25 +0000 (14:14 +0200)] 
Use specialized param visit function for params

This commit introduce a new public function to visit function parameters
in the default visitor. It allows visitors derived from DefaultVisitor
to override only a small part of the default visitor.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit_function_params):
Add specialized function to visit function parameters.
(DefaultASTVisitor::visit): Remove parameter visit and call specialized
function instead.
* ast/rust-ast-visitor.h: Add function prototye.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove
function.
(Late::visit_function_params): Override specialized visit function.
* resolve/rust-late-name-resolver-2.0.h: Add overriden function
prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoRemove passing test from exclusion list
Pierre-Emmanuel Patry [Sun, 6 Apr 2025 17:54:06 +0000 (19:54 +0200)] 
Remove passing test from exclusion list

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove passing test from exclusion list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoUse stacked context for nested bindings.
Pierre-Emmanuel Patry [Sun, 6 Apr 2025 16:49:11 +0000 (18:49 +0200)] 
Use stacked context for nested bindings.

Binding context may be stacked when a new binding group is introduced
within a const expression.

gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.h: Use BindingLayer instead.
* resolve/rust-name-resolution-context.cc (BindingLayer::BindingLayer):
Add new constructor for binding layer.
(BindingLayer::bind_test): Add a function to test a binding constraint.
(BindingLayer::push): Push a new binding group.
(BindingLayer::and_binded): Add function to test and-binding
constraint.
(BindingLayer::or_binded): Add function to test or-binding constraints.
(BindingLayer::insert_ident): Insert a new identifier in the current
binding group.
(BindingLayer::merge): Merge current binding group with it's parent.
(BindingLayer::get_source): Get the source of the current binding
group.
* resolve/rust-late-name-resolver-2.0.cc: Use stacked context for
binding group.
* util/rust-stacked-contexts.h: Add mutable peek function.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoAdd pattern bindings
Pierre-Emmanuel Patry [Sun, 6 Apr 2025 16:17:41 +0000 (18:17 +0200)] 
Add pattern bindings

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add binding
creation in visitor.
* resolve/rust-late-name-resolver-2.0.h: Add function prototypes.
* resolve/rust-name-resolution-context.h: Add binding context.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoAdd binding context class
Pierre-Emmanuel Patry [Sun, 6 Apr 2025 15:09:42 +0000 (17:09 +0200)] 
Add binding context class

We need to differentiate bindings types, so the same binding cannot be
reused multiple time in a product binding.

gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.h (struct Binding): Add Binding
struct to differentiate Or and Product bindings in patterns.
(enum class): Add Binding kind.
(class BindingContext): Add binding context with Binding stack.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoAdd hash function for Identifiers
Pierre-Emmanuel Patry [Sat, 5 Apr 2025 23:44:18 +0000 (01:44 +0200)] 
Add hash function for Identifiers

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add hash function.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoAdd equality operator for identifiers
Pierre-Emmanuel Patry [Sat, 5 Apr 2025 23:43:20 +0000 (01:43 +0200)] 
Add equality operator for identifiers

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add equality operator.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoAdd fn_once and Sized lang items to the test
Pierre-Emmanuel Patry [Fri, 4 Apr 2025 13:35:15 +0000 (15:35 +0200)] 
Add fn_once and Sized lang items to the test

gcc/testsuite/ChangeLog:

* rust/compile/multiple_bindings1.rs: Add missing lang items.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoChange expected error output to match nr2
Pierre-Emmanuel Patry [Thu, 24 Apr 2025 12:28:59 +0000 (14:28 +0200)] 
Change expected error output to match nr2

Name resolution 2.0 message describes the context around the unresolved
items and should therefore be kept.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove test from exclusion list.
* rust/compile/use_1.rs: Change expected output and remove test from
nr1.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoUpdate generics9 expected error message
Pierre-Emmanuel Patry [Wed, 23 Apr 2025 12:41:24 +0000 (14:41 +0200)] 
Update generics9 expected error message

gcc/testsuite/ChangeLog:

* rust/compile/generics9.rs: Change expected error message.
* rust/compile/nr2/exclude: Remove test from exclusion list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoPrevent forward declaration in type parameters
Pierre-Emmanuel Patry [Wed, 23 Apr 2025 12:40:22 +0000 (14:40 +0200)] 
Prevent forward declaration in type parameters

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Add visit
function for TypeParam.
* resolve/rust-default-resolver.h: Add function prototype.
* resolve/rust-forever-stack.h: Add function to check for forward
declaration ban.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Check forward
declarations.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoRemove error state for GenericArg
Pierre-Emmanuel Patry [Mon, 7 Apr 2025 13:59:15 +0000 (15:59 +0200)] 
Remove error state for GenericArg

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>
2 months agoChange error message to match expected test output
Pierre-Emmanuel Patry [Wed, 23 Apr 2025 15:24:04 +0000 (17:24 +0200)] 
Change error message to match expected test output

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Change error
message.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove passing test from exclusion list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agonr2.0: Improve error handling
Owen Avery [Thu, 17 Apr 2025 17:51:43 +0000 (13:51 -0400)] 
nr2.0: Improve error handling

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc
(Early::build_import_mapping): Avoid outputting an "unresolved
import" error if other errors are outputted during resolution.
* resolve/rust-early-name-resolver-2.0.h
(Early::resolve_path_in_all_ns): Collect path resolution errors
while avoiding duplicate errors for resolutions in each
namespace.
* resolve/rust-forever-stack.h
(ForeverStack::resolve_path): Add parameter for collecting
errors.
(ForeverStack::find_starting_point): Likewise.
(ForeverStack::resolve_segments): Likewise.
* resolve/rust-forever-stack.hxx
(check_leading_kw_at_start): Likewise.
(ForeverStack::find_starting_point): Likewise.
(ForeverStack::resolve_segments): Likewise.
(ForeverStack::resolve_path): Likewise.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::resolve_path): Add optional parameter
for collecting errors.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entry.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agonr2.0: Fix derive-debug1.rs
Owen Avery [Sun, 6 Apr 2025 22:48:58 +0000 (18:48 -0400)] 
nr2.0: Fix derive-debug1.rs

gcc/testsuite/ChangeLog:

* rust/compile/derive-debug1.rs: Adjust a path.
* rust/compile/nr2/exclude: Remove derive-debug1.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agoDisable parallel testing for 'rust/compile/nr2/compile.exp' [PR119508]
Thomas Schwinge [Sat, 19 Apr 2025 13:49:34 +0000 (15:49 +0200)] 
Disable parallel testing for 'rust/compile/nr2/compile.exp' [PR119508]

..., using the standard idiom.  This '*.exp' file doesn't adhere to the
parallel testing protocol as defined in 'gcc/testsuite/lib/gcc-defs.exp'.

This also restores proper behavior for '*.exp' files executing after (!) this
one, which erroneously caused hundreds or even thousands of individual test
cases get duplicated vs. skipped, randomly, depending on the '-jN' level.

PR testsuite/119508
gcc/testsuite/
* rust/compile/nr2/compile.exp: Disable parallel testing.

(cherry picked from commit 79d2c3089f480738613b7d338d86d8be710f8158)

2 months agogccrs: prealloc the initilizer vector
Philip Herron [Thu, 17 Apr 2025 15:19:35 +0000 (16:19 +0100)] 
gccrs: prealloc the initilizer vector

There are two cases when initilizing an array, this is the
const context which means we need to build the array ctor,
which means using lots of memory, its super inefficient
because we are using a big wrapper over the GCC internals here
but preallocating the vectors here causes a:

  terminate called after throwing an instance of 'std::bad_alloc'

So this is a handy error condition to rely on for this senario.

Fixes Rust-GCC#3713
Fixes Rust-GCC#3727

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::array_copied_expr): prealloc the vector

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: Fix ICE with empty generic arguments
Philip Herron [Thu, 17 Apr 2025 14:53:58 +0000 (15:53 +0100)] 
gccrs: Fix ICE with empty generic arguments

We have an assertion when accessing generic args if there are any which
is really useful so this adds the missing guards for the case where
they are specified but empty.

Fixes Rust-GCC#3649

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): add guard
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): add guard

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 is missing error for this
* rust/compile/issue-3649.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agoAdjust segment start position errors
Owen Avery [Thu, 17 Apr 2025 20:51:21 +0000 (16:51 -0400)] 
Adjust segment start position errors

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-path.cc
(ResolvePath::resolve_path): Adjust error messages.
* resolve/rust-ast-resolve-type.cc
(ResolveRelativeTypePath::go): Likewise.
* resolve/rust-forever-stack.hxx
(check_leading_kw_at_start): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3568.rs: Adjust expected errors.
* rust/compile/name_resolution9.rs: Likewise.
* rust/compile/self-path2.rs: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: Fix ICE when handling case of unknown field in HIR::FieldAccess
Philip Herron [Thu, 17 Apr 2025 12:50:55 +0000 (13:50 +0100)] 
gccrs: Fix ICE when handling case of unknown field in HIR::FieldAccess

We were wrongly adding the assertion that this must not be an enum but
this is a pointless assertion we only care that there are variant in the
ADT and if the field exists in the first variant.

Fixes Rust-GCC#3581

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): fix bad assertion

gcc/testsuite/ChangeLog:

* rust/compile/nonexistent-field.rs: fix bad error message
* rust/compile/issue-3581-1.rs: New test.
* rust/compile/issue-3581-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: Add test case to show ice is fixed
Philip Herron [Fri, 18 Apr 2025 10:37:55 +0000 (11:37 +0100)] 
gccrs: Add test case to show ice is fixed

Fixes Rust-GCC#3652

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 does not error on the T it should require Self::T
* rust/compile/issue-3652.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agonr2.0: Remove unnecessary copy of Node
Owen Avery [Thu, 17 Apr 2025 23:23:12 +0000 (19:23 -0400)] 
nr2.0: Remove unnecessary copy of Node

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx
(ForeverStack::resolve_path): Pass instance of Node to lambda by
reference instead of by value.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: Fix ICE in struct expressions
Philip Herron [Thu, 17 Apr 2025 13:38:04 +0000 (14:38 +0100)] 
gccrs: Fix ICE in struct expressions

The error handling here was done long ago when we didnt know how to do
any error handling very well. This removed bad fatal_errors and adds in
some nice rich_location error diagnostics instead.

Fixes Rust-GCC#3628

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-struct-field.h: keep reference to parent expression
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::TypeCheckStructExpr):
update ctor
(TypeCheckStructExpr::resolve): remove bad rust_fatal_errors
(TypeCheckStructExpr::visit): cleanup errors

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/macro-issue2983_2984.rs: cleanup error diagnotics
* rust/compile/struct_init1.rs: likewise
* rust/compile/issue-3628.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agonr2.0: Handle StructPatternFieldIdent
Owen Avery [Thu, 17 Apr 2025 18:02:45 +0000 (14:02 -0400)] 
nr2.0: Handle StructPatternFieldIdent

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Handle StructPatternFieldIdent.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entry.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agogccrs: Add test case to show ICE is fixed
Philip Herron [Thu, 17 Apr 2025 15:29:05 +0000 (16:29 +0100)] 
gccrs: Add test case to show ICE is fixed

Fixes Rust-GCC#3662

gcc/testsuite/ChangeLog:

* rust/compile/issue-3662.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: Add test case to show issue is fixed
Philip Herron [Thu, 17 Apr 2025 15:04:55 +0000 (16:04 +0100)] 
gccrs: Add test case to show issue is fixed

This was already fixed in: bb01719f0e1 but we require fn_once lang item
to be defined as we are working on libcore support still.

Fixes Rust-GCC#3711

gcc/testsuite/ChangeLog:

* rust/compile/issue-3711.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agoAdd gimple test for black box intrinsic
Pierre-Emmanuel Patry [Thu, 17 Apr 2025 16:28:52 +0000 (18:28 +0200)] 
Add gimple test for black box intrinsic

gcc/testsuite/ChangeLog:

* rust/compile/black_box.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoAdd execute test for black_box intrinsic
Pierre-Emmanuel Patry [Thu, 17 Apr 2025 15:53:15 +0000 (17:53 +0200)] 
Add execute test for black_box intrinsic

gcc/testsuite/ChangeLog:

* rust/execute/black_box.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoAdd LlvmInlineAsm node dump
Pierre-Emmanuel Patry [Thu, 17 Apr 2025 12:27:11 +0000 (14:27 +0200)] 
Add LlvmInlineAsm node dump

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Dump llvm inline
asm tokens.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agoParse and lower llvm asm node
Pierre-Emmanuel Patry [Tue, 15 Apr 2025 09:38:29 +0000 (11:38 +0200)] 
Parse and lower llvm asm node

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>
2 months agoAdd llvmInlineAsm node
Pierre-Emmanuel Patry [Thu, 10 Apr 2025 11:05:15 +0000 (13:05 +0200)] 
Add llvmInlineAsm node

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>
2 months agoEmit error with old asm syntax in new asm blocks
Pierre-Emmanuel Patry [Wed, 9 Apr 2025 15:41:24 +0000 (17:41 +0200)] 
Emit error with old asm syntax in new asm blocks

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_asm_arg): Emit error
message.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 months agogccrs: Add check for placeholder (infer) type in return position
Philip Herron [Wed, 16 Apr 2025 19:38:17 +0000 (20:38 +0100)] 
gccrs: Add check for placeholder (infer) type in return position

It is not allowed to have a declared inference variable in the return
position of a function as this may never get infered you need good points
of truth.

Ideally if we get a student for GSoC 25 we will get the Default Hir Visitor
so that we can grab the HIR::InferredType locus instead of using the ref
location lookups.

Fixes Rust-GCC#402

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): add diagnostic
* typecheck/rust-tyty.cc (BaseType::contains_infer): new helper to grab first infer var
* typecheck/rust-tyty.h: prototype

gcc/testsuite/ChangeLog:

* rust/compile/issue-402.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: Fix ICE when checking shift's which are behind array refs
Philip Herron [Wed, 16 Apr 2025 16:13:04 +0000 (17:13 +0100)] 
gccrs: Fix ICE when checking shift's which are behind array refs

I copied a bad form of this check from the c front-end this updates it
to ensure the rhs is an INTEGER_CST and the lhs needs checked in the first
place.

Fixes Rust-GCC#3664

gcc/rust/ChangeLog:

* rust-gcc.cc (arithmetic_or_logical_expression): Ensure this is an integer

gcc/testsuite/ChangeLog:

* rust/compile/issue-3664.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: Fix crash in hir dump as labels are optional
Philip Herron [Wed, 16 Apr 2025 16:00:28 +0000 (17:00 +0100)] 
gccrs: Fix crash in hir dump as labels are optional

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): add guard for optional label

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2 months agogccrs: Update comments in repr parsing code
Yap Zhi Heng [Fri, 4 Apr 2025 11:37:03 +0000 (19:37 +0800)] 
gccrs: Update comments in repr parsing code

gcc/rust/ChangeLog:

* typecheck/rust-tyty.h: Remove extra redundant comment.
* typecheck/rust-hir-type-check-base.cc: Update comment on repr
handling.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2 months agogccrs: Implement integer representation for enums
Zhi Heng [Thu, 3 Apr 2025 15:02:59 +0000 (23:02 +0800)] 
gccrs: Implement integer representation for enums

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-base.cc: Set enum representing
type properly if repr is an integer type.
* typecheck/rust-hir-type-check-item.cc: Update comments.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2 months agogccrs: Implement typecheck for zero-variant enums
Zhi Heng [Thu, 3 Apr 2025 12:23:46 +0000 (20:23 +0800)] 
gccrs: Implement typecheck for zero-variant enums

gcc/rust/ChangeLog:

* typecheck/rust-tyty.h: Add new `ReprKind` enum to
`ReprOptions`.
* typecheck/rust-hir-type-check-base.cc: Handle setting of
`repr_kind`.
* typecheck/rust-hir-type-check-item.cc: New check for
zero-variant enums.

Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2 months agogccrs: Fix segv in unsafe chcker
Philip Herron [Fri, 4 Apr 2025 15:35:13 +0000 (16:35 +0100)] 
gccrs: Fix segv in unsafe chcker

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>
2 months agolang-items: Add ManuallyDrop<T>
Arthur Cohen [Tue, 8 Apr 2025 15:04:09 +0000 (17:04 +0200)] 
lang-items: Add ManuallyDrop<T>

gcc/rust/ChangeLog:

* util/rust-lang-item.h: Add new manually_drop lang item.
* util/rust-lang-item.cc: Likewise.

2 months agoattributes: Handle external tool annotations like rustfmt::
Arthur Cohen [Wed, 9 Apr 2025 13:17:38 +0000 (15:17 +0200)] 
attributes: Handle external tool annotations like rustfmt::

gcc/rust/ChangeLog:

* util/rust-attribute-values.h: Add RUSTFMT value.
* util/rust-attributes.cc: Define the attribute.
* util/rust-attributes.h (enum CompilerPass): Add EXTERNAL variant.
* expand/rust-macro-builtins.cc: Fix formatting.

2 months agonr2.0: Only insert derive macros if they exist
Arthur Cohen [Wed, 9 Apr 2025 12:48:55 +0000 (14:48 +0200)] 
nr2.0: Only insert derive macros if they exist

This causes an assertion failure when compiling core with nr2.0, but should
probably be improved. I'm not sure how this code enables built-in derive
macros to be resolved so this is a temporary fix.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes): Remove assertion.

2 months agoattributes: Add missing attributes used in `core`
Arthur Cohen [Fri, 4 Apr 2025 12:20:04 +0000 (14:20 +0200)] 
attributes: Add missing attributes used in `core`

gcc/rust/ChangeLog:

* util/rust-attribute-values.h: Add missing attributes.
* util/rust-attributes.cc: Likewise.
* util/rust-attributes.h (enum CompilerPass): Mention adding something for const
functions.

2 months agoAdd `#[track_caller]` as known attribute
beamandala [Thu, 20 Mar 2025 22:34:48 +0000 (17:34 -0500)] 
Add `#[track_caller]` as known attribute

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc (MacroBuiltin::builtin_transcribers):
Add entry for track_caller.
* util/rust-attribute-values.h: add `TRACK_CALLER` attribute.
* util/rust-attributes.cc: add `track_caller` attribute definition.

gcc/testsuite/ChangeLog:

* rust/compile/track_caller.rs: New test.

Signed-off-by: Bhavesh Mandalapu <mandalapubhavesh@gmail.com>
2 months agoci: Update warnings for new location in install.texi
Arthur Cohen [Mon, 14 Apr 2025 08:58:25 +0000 (10:58 +0200)] 
ci: Update warnings for new location in install.texi

ChangeLog:

* .github/glibcxx_ubuntu64b_log_expected_warnings: Change line number
for warning from 2230 to 2236.
* .github/log_expected_warnings: Likewise.

2 months agoinstall.texi: Mention Rust requirement for building gccrs
Arthur Cohen [Tue, 1 Apr 2025 11:00:56 +0000 (13:00 +0200)] 
install.texi: Mention Rust requirement for building gccrs

Addresses PR#117869

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117869

gcc/ChangeLog:

* doc/install.texi: Add requirements for building gccrs.

2 months agoFix const checking of enum discriminants
Owen Avery [Sat, 5 Apr 2025 21:20:44 +0000 (17:20 -0400)] 
Fix const checking of enum discriminants

gcc/rust/ChangeLog:

* checks/errors/rust-const-checker.cc
(ConstChecker::visit): Visit the enum items of enums.
* resolve/rust-ast-resolve-item.cc
(ResolveItem::visit): Resolve enum discriminants during nr1.0.

gcc/testsuite/ChangeLog:

* rust/compile/enum_discriminant2.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 months agoformat_args: Allow extraneous commas, improve safety
Arthur Cohen [Wed, 9 Apr 2025 12:42:08 +0000 (14:42 +0200)] 
format_args: Allow extraneous commas, improve safety

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-format-args.cc (format_args_parse_arguments): Improve safety,
allow extra commas after end of argument list.

gcc/testsuite/ChangeLog:

* rust/compile/format_args_extra_comma.rs: New test.

2 months agoexpansion: Desugar doc comments into attributes before expansion
Arthur Cohen [Tue, 8 Apr 2025 14:20:18 +0000 (16:20 +0200)] 
expansion: Desugar doc comments into attributes before expansion

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc (MacroExpander::expand_decl_macro): Call into
TokenTreeDesugar.
* expand/rust-token-tree-desugar.cc: New file.
* expand/rust-token-tree-desugar.h: New file.
* Make-lang.in: Compile them.

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/macro-issue3709-1.rs: New test.
* rust/compile/macros/mbe/macro-issue3709-2.rs: New test.

2 months agoexpansion: Only add fragments if the matcher succeeded
Arthur Cohen [Tue, 8 Apr 2025 12:41:16 +0000 (14:41 +0200)] 
expansion: Only add fragments if the matcher succeeded

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc (MacroExpander::match_n_matches): Do not
insert fragments and substack fragments if the matcher failed.

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/macro-issue3708.rs: New test.

2 months agosession: Desugar question mark operator after expansion instead.
Arthur Cohen [Fri, 4 Apr 2025 12:21:00 +0000 (14:21 +0200)] 
session: Desugar question mark operator after expansion instead.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Call the visitor later in the pipeline.

2 months agoast: Add get_locus() to DelimTokenTree
Arthur Cohen [Wed, 9 Apr 2025 12:44:11 +0000 (14:44 +0200)] 
ast: Add get_locus() to DelimTokenTree

gcc/rust/ChangeLog:

* ast/rust-ast.h (DelimTokenTree::get_locus): New function.

2 months agoast: Support outer attributes for AST::RangeExpr
Arthur Cohen [Wed, 9 Apr 2025 12:44:56 +0000 (14:44 +0200)] 
ast: Support outer attributes for AST::RangeExpr

gcc/rust/ChangeLog:

* ast/rust-expr.h (class RangeExpr): Add empty outer attributes and allow getting them
and setting them.

2 months agonr2.0: Do not resolve modules this run if they are unloaded
Arthur Cohen [Fri, 4 Apr 2025 12:18:33 +0000 (14:18 +0200)] 
nr2.0: Do not resolve modules this run if they are unloaded

Instead, mark the visitor as dirty and wait for the next round of the fixed point to take care of
them. This avoids issues with module items being loaded while not being stripped yet.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Return if module
is unloaded.

2 months agotypecheck: Properly select methods when dealing with specialization
Arthur Cohen [Thu, 3 Apr 2025 14:22:10 +0000 (16:22 +0200)] 
typecheck: Properly select methods when dealing with specialization

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (is_default_fn): New.
(emit_ambiguous_resolution_error): New.
(handle_multiple_candidates): Properly handle multiple candidates in
the case of specialization.
(TypeCheckExpr::visit): Call `handle_multiple_candidates`.

gcc/testsuite/ChangeLog:

* rust/execute/torture/min_specialization2.rs: New test.
* rust/execute/torture/min_specialization3.rs: New test.

3 months agorust: Add comment inside block [PR119342]
Andrew Pinski [Thu, 20 Mar 2025 00:30:02 +0000 (17:30 -0700)] 
rust: Add comment inside block [PR119342]

Inside a BLOCK node, all of the variables of the scope/block
are chained together and that connects them to the block.
This just adds a comment to that effect as reading the code
it is not so obvious why they need to be chained together.

gcc/rust/ChangeLog:

PR rust/119342
* rust-gcc.cc (block): Add comment on why chaining
the variables of the scope toether.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
3 months agorust: use range for inside rust-gcc.cc [PR119341]
Andrew Pinski [Thu, 20 Mar 2025 00:30:01 +0000 (17:30 -0700)] 
rust: use range for inside rust-gcc.cc [PR119341]

There are some places inside rust-gcc.cc which are candidates
to use range for instead of iterators directly. This changes
the locations I saw and makes the code slightly more readable.

gcc/rust/ChangeLog:

PR rust/119341
* rust-gcc.cc (function_type): Use range fors.
(function_type_variadic): Likewise.
(fill_in_fields): Likewise.
(statement_list): Likewise.
(block): Likewise.
(block_add_statements): Likewise.
(function_set_parameters): Likewise.
(write_global_definitions): Likewise.

Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>