aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve
AgeCommit message (Collapse)AuthorFilesLines
2025-05-27ast: Add ConstBlock and AnonConst nodesArthur Cohen4-1/+27
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-05-27nr2.0: Fix IfLet pattern handlingOwen Avery5-10/+29
gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit_if_let_patterns): New function definition. (DefaultResolver::visit): New IfLetExpr visitor definition. * resolve/rust-default-resolver.h (DefaultResolver::visit_if_let_patterns): New function declaration. (DefaultResolver::visit): New IfLetExpr visitor declaration. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove IfLetExpr visitor definition. (Late::visit_if_let_patterns): New function definition. * resolve/rust-late-name-resolver-2.0.h (Late::visit): Remove IfLetExpr visitor declaration. (Late::visit_if_let_patterns): New function declaration. * resolve/rust-name-resolution-context.h (BindingSource::IfLet): New enumerator. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-05-19gccrs: Fix NR2 ICE in visit_attributesTom Schollenberger1-1/+2
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>
2025-05-15Small improvements to DefaultASTVisitor and nr2.0Owen Avery2-7/+7
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>
2025-05-08nr2.0: Adjust resolution of impl itemsOwen Avery6-35/+53
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>
2025-05-07nr2.0: Adjust enum item visitorsOwen Avery1-0/+8
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>
2025-05-07Improve canonical path handling for impl itemsOwen Avery1-11/+2
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>
2025-05-07gccrs: 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-04-29nr2.0: late: Correctly initialize funny_error memberArthur Cohen1-1/+3
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::Late): False initialize the funny_error field.
2025-04-28Some assorted tweaks and bug fixesOwen Avery2-4/+4
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit the loop labels of WhileLetLoopExpr instances before visiting their scrutinee expressions. * resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Pass the glob import's path directly to NameResolutionContext::resolve_path. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Remove unnecessary call to Identifier::as_string. (flatten_glob): Improve handling of cases where a glob use tree has no path. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-24Use specialized param visit function for paramsPierre-Emmanuel Patry2-26/+8
This commit introduce a new public function to visit function parameters in the default visitor. It allows visitors derived from DefaultVisitor to override only a small part of the default visitor. gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit_function_params): Add specialized function to visit function parameters. (DefaultASTVisitor::visit): Remove parameter visit and call specialized function instead. * ast/rust-ast-visitor.h: Add function prototye. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove function. (Late::visit_function_params): Override specialized visit function. * resolve/rust-late-name-resolver-2.0.h: Add overriden function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Use stacked context for nested bindings.Pierre-Emmanuel Patry3-70/+105
Binding context may be stacked when a new binding group is introduced within a const expression. gcc/rust/ChangeLog: * resolve/rust-name-resolution-context.h: Use BindingLayer instead. * resolve/rust-name-resolution-context.cc (BindingLayer::BindingLayer): Add new constructor for binding layer. (BindingLayer::bind_test): Add a function to test a binding constraint. (BindingLayer::push): Push a new binding group. (BindingLayer::and_binded): Add function to test and-binding constraint. (BindingLayer::or_binded): Add function to test or-binding constraints. (BindingLayer::insert_ident): Insert a new identifier in the current binding group. (BindingLayer::merge): Merge current binding group with it's parent. (BindingLayer::get_source): Get the source of the current binding group. * resolve/rust-late-name-resolver-2.0.cc: Use stacked context for binding group. * util/rust-stacked-contexts.h: Add mutable peek function. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Add pattern bindingsPierre-Emmanuel Patry3-5/+156
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add binding creation in visitor. * resolve/rust-late-name-resolver-2.0.h: Add function prototypes. * resolve/rust-name-resolution-context.h: Add binding context. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Add binding context classPierre-Emmanuel Patry1-0/+81
We need to differentiate bindings types, so the same binding cannot be reused multiple time in a product binding. gcc/rust/ChangeLog: * resolve/rust-name-resolution-context.h (struct Binding): Add Binding struct to differentiate Or and Product bindings in patterns. (enum class): Add Binding kind. (class BindingContext): Add binding context with Binding stack. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Prevent forward declaration in type parametersPierre-Emmanuel Patry4-0/+33
gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Add visit function for TypeParam. * resolve/rust-default-resolver.h: Add function prototype. * resolve/rust-forever-stack.h: Add function to check for forward declaration ban. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Check forward declarations. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-24Remove error state for GenericArgPierre-Emmanuel Patry1-2/+2
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove error kind and change function call. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Change call name. * ast/rust-path.cc (ConstGenericParam::as_string): Likewise. * ast/rust-path.h: Remove error kind. * hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): Change call name. * parse/rust-parse-impl.h (Parser::parse_generic_param): Use optional on parsing failure. (Parser::parse_generic_arg): Likewise. (Parser::parse_path_generic_args): Likewise. * parse/rust-parse.h: Likewise. * resolve/rust-ast-resolve-type.h: Change call name. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-23Change error message to match expected test outputPierre-Emmanuel Patry1-2/+2
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Change error message. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove passing test from exclusion list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-22nr2.0: Improve error handlingOwen Avery5-48/+115
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::build_import_mapping): Avoid outputting an "unresolved import" error if other errors are outputted during resolution. * resolve/rust-early-name-resolver-2.0.h (Early::resolve_path_in_all_ns): Collect path resolution errors while avoiding duplicate errors for resolutions in each namespace. * resolve/rust-forever-stack.h (ForeverStack::resolve_path): Add parameter for collecting errors. (ForeverStack::find_starting_point): Likewise. (ForeverStack::resolve_segments): Likewise. * resolve/rust-forever-stack.hxx (check_leading_kw_at_start): Likewise. (ForeverStack::find_starting_point): Likewise. (ForeverStack::resolve_segments): Likewise. (ForeverStack::resolve_path): Likewise. * resolve/rust-name-resolution-context.h (NameResolutionContext::resolve_path): Add optional parameter for collecting errors. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entry. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-18Adjust segment start position errorsOwen Avery3-10/+8
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Adjust error messages. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. * resolve/rust-forever-stack.hxx (check_leading_kw_at_start): Likewise. gcc/testsuite/ChangeLog: * rust/compile/issue-3568.rs: Adjust expected errors. * rust/compile/name_resolution9.rs: Likewise. * rust/compile/self-path2.rs: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-18nr2.0: Remove unnecessary copy of NodeOwen Avery1-1/+1
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx (ForeverStack::resolve_path): Pass instance of Node to lambda by reference instead of by value. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-18nr2.0: Handle StructPatternFieldIdentOwen Avery2-0/+9
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Handle StructPatternFieldIdent. * resolve/rust-late-name-resolver-2.0.h (Late::visit): Likewise. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entry. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-04-17Parse and lower llvm asm nodePierre-Emmanuel Patry2-0/+12
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-17Add 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-14nr2.0: Only insert derive macros if they existArthur Cohen1-4/+3
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.
2025-04-14Fix const checking of enum discriminantsOwen Avery1-0/+2
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>
2025-04-14nr2.0: Do not resolve modules this run if they are unloadedArthur Cohen1-1/+11
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.
2025-04-07Rename label getter to uncheckedPierre-Emmanuel Patry2-2/+2
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Update label getter call. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast.cc (BreakExpr::as_string): Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise. * ast/rust-expr.h: Add optional getter and rename label getter to get_label_unchecked. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Rename label getter in ContinueExprPierre-Emmanuel Patry2-4/+4
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-07Resolve labels within break or continue expressionsPierre-Emmanuel Patry2-10/+29
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add call to label resolution if there is one label. (Late::resolve_label): Look for labels and emit an error message on failure. * resolve/rust-late-name-resolver-2.0.h: Add function prototypes. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Fix unresolved label error messagePierre-Emmanuel Patry1-4/+4
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Change error message to match rustc. gcc/testsuite/ChangeLog: * rust/compile/undeclared_label.rs: Change test expected string. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-04-07Resolve labelsPierre-Emmanuel Patry2-0/+20
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-04gccrs: refactoring rust_error_at "redefined multiple times"Sri Ganesh Thota5-37/+41
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-base.h (redefined_error): created a function for rust_error_at for redefined at multiple times. * resolve/rust-ast-resolve-implitem.h: changed rust_error_at to redefined_error. * resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): changed rust_error_at to redefined_error. * resolve/rust-ast-resolve-stmt.h: changed rust_error_at to redefined_error. * resolve/rust-ast-resolve-toplevel.h: changed rust_error_at to redefined_error. Signed-off-by: Sri Ganesh Thota <sriganeshthota12345@gmail.com>
2025-04-04gccrs: Fix ICE when hitting invalid types for genericsPhilip Herron1-1/+1
We need to check upfront if the type is valid or not. Then error with a decent message. Fixes Rust-GCC#3643 Fixes Rust-GCC#3646 Fixes Rust-GCC#3654 Fixes Rust-GCC#3663 Fixes Rust-GCC#3671 gcc/rust/ChangeLog: * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): fix error msg * typecheck/rust-substitution-mapper.cc (SubstMapper::Resolve): add validation (SubstMapper::valid_type): new check (SubstMapper::visit): check if can resolve * typecheck/rust-substitution-mapper.h: new prototype gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 is missing type path error * rust/compile/issue-3643.rs: New test. * rust/compile/issue-3646.rs: New test. * rust/compile/issue-3654.rs: New test. * rust/compile/issue-3663.rs: New test. * rust/compile/issue-3671.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-04-01nr2.0: Handle global pathsOwen Avery4-49/+96
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h (ForeverStack::ForeverStack): Initialize extern_prelude. (ForeverStack::resolve_path): Add parameter has_opening_scope_resolution. (ForeverStack::extern_prelude): Add field. * resolve/rust-forever-stack.hxx: Include rust-edition.h. (ForeverStacl::resolve_path): Handle global paths (paths with an opening scope resolution operator). * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Handle global paths. * resolve/rust-name-resolution-context.h (NameResolutionContext::resolve_path): Handle global paths. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-28nr2.0: Rename prelude to lang_preludeOwen Avery3-13/+14
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h (ForeverStack::get_prelude): Rename to... (ForeverStack::get_lang_prelude): ...here. (ForeverStack::prelude): Rename to... (ForeverStack::lang_prelude): ...here. (ForeverStack::ForeverStack): Handle renames. * resolve/rust-forever-stack.hxx (ForeverStack::push_inner): Likewise. (ForeverStack::resolve_segments): Likewise. (ForeverStack::resolve_path): Likewise. (ForeverStack::get_prelude): Rename to... (ForeverStack::get_lang_prelude): ...here and handle renames. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Handle renames. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-27Resolve module final self segment in use declsPierre-Emmanuel Patry3-8/+42
Lowercase self suffix with path was not resolved properly, this should point to the module right before. gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx: Add a new specialized function to retrieve the last "real" segment depending on the namespace. * resolve/rust-forever-stack.h: Add new function prototype. * resolve/rust-early-name-resolver-2.0.cc (Early::finalize_rebind_import): Set declared name according to the selected segment, if there is a self suffix in the use declaration then select the previous segment. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-27gccrs: Fix ICE when using super mid way though pathPhilip Herron1-0/+6
Fixes Rust-GCC#3568 gcc/rust/ChangeLog: * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): check for super mid path gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 puts out a different error multiple times * rust/compile/issue-3568.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-03-25name-resolution: Handle let-else properlyArthur Cohen2-3/+7
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-stmt.h: Add handling for diverging else. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise.
2025-03-21nr2.0: Fix StructExprFieldIdentifier handlingOwen Avery2-0/+29
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add visitor for StructExprFieldIdentifier. * resolve/rust-late-name-resolver-2.0.h (Late::visit): Likewise. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-21nr2.0: Adjust indentifier expression handlingOwen Avery1-9/+17
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Make sure to return early after a resolution error, improve the resolution error message, fix a typo, handle ambiguous resolutions, and remove an old comment. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-21Modify multiple definition errorOwen Avery6-41/+41
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Modify error message. * resolve/rust-ast-resolve-implitem.h (ResolveToplevelImplItem::visit): Likewise. (ResolveTopLevelTraitItems::visit): Likewise. (ResolveToplevelExternItem::visit): Likewise. * resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): Likewise. * resolve/rust-ast-resolve-stmt.h (ResolveStmt::visit): Likewise. * resolve/rust-ast-resolve-toplevel.h (ResolveTopLevel::visit): Likewise. * resolve/rust-ast-resolve-type.h (ResolveGenericParams::visit): Likewise. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. * rust/compile/redef_error2.rs: Modify expected error. * rust/compile/redef_error5.rs: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-20nr2.0: Adjust visitors for struct expressionsOwen Avery1-3/+17
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Make sure to always visit the struct name. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Avoid visiting the struct name twice. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-19Prevent multiple resolution insertionOwen Avery4-51/+249
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::clone_impl): Avoid using the same node id multiple times. (DeriveClone::clone_enum_identifier): Likewise. (DeriveClone::clone_enum_tuple): Likewise. * expand/rust-derive-copy.cc (DeriveCopy::copy_impl): Likewise. * resolve/rust-ast-resolve-item.cc (flatten_list): Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Prevent reinsertion of resolutions. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_fn_trait_call): Likewise. * resolve/rust-name-resolver.cc (Resolver::insert_resolved_name): Catch multiple resolution insertions. (Resolver::insert_resolved_type): Likewise. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-19nr2.0: Fix test self-path2.rsOwen Avery2-4/+4
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Adjust the error message for a lower self segment in the middle of a path. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove self-path2.rs * rust/compile/self-path2.rs: Adjust expected errors. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-03-18Fix modules with same name as builtins causing ICE (#3315)Liam Naddell5-25/+111
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h (ForeverStack): Add a dedicated prelude node for the Language prelude * resolve/rust-forever-stack.hxx (ForeverStack): Add support code for the prelude node * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Move language prelude builtins to the prelude context * resolve/rust-name-resolution-context.cc (NameResolutionContext::scoped): Add code for handling the prelude corner case * resolve/rust-rib.h (Rib::Kind): Add a special Prelude rib type gcc/testsuite/ChangeLog: * rust/compile/issue-3315-1.rs: Add test for module with same name as builtin * rust/compile/issue-3315-2.rs: Test with utilization of i32 type * rust/compile/nr2/exclude: issue-3315-2.rs Does not work with NR2.0 Signed-off-by: Liam Naddell <liamnprg@gmail.com>
2025-03-17Fix canonical path parent resolutionPierre-Emmanuel Patry1-1/+1
The algorithm was comparing using the wrong id, this lead to some mangling errors as an erroneous parent was selected. gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx: Fix the id comparison. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17Insert crate name in canonical pathPierre-Emmanuel Patry1-1/+6
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx: Insert a new segment with the crate's name as canonical's path prefix. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17Remove finalize import visitorPierre-Emmanuel Patry2-75/+0
This visitor is not used anymore. gcc/rust/ChangeLog: * resolve/rust-finalize-imports-2.0.cc (FinalizeImports::FinalizeImports): Remove constructor. (FinalizeImports::go): Remove function. (FinalizeImports::visit): Likewise. * resolve/rust-finalize-imports-2.0.h (class FinalizeImports): Remove FinalizeImports class. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-17Move import mapping resolution to in tree visitPierre-Emmanuel Patry5-90/+105
Import mapping was relying on resolve_path which in turn relies on the cursor function. This means the mapping resolver should be called from the correct scope instead of being called from the crate scope. gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::Early): Move the top level visitor from the function scope to attributes. (Early::go): Remove top level visitor creation and adapt calling code. Remove call to mapping resolution and import finalization. (Early::finalize_simple_import): Move the finalization from it's visitor. (Early::finalize_glob_import): Likewise. (Early::finalize_rebind_import): Likewise. (Early::visit): Add mapping resolution and finalization in UseDeclaration visitor function. * resolve/rust-finalize-imports-2.0.cc (finalize_simple_import): Move function. (finalize_glob_import): Likewise. (finalize_rebind_import): Likewise. (FinalizeImports::visit): Remove call to finalizers. * resolve/rust-early-name-resolver-2.0.h (class Early): Add top level attribute. * resolve/rust-finalize-imports-2.0.h: Add function prototypes. * resolve/rust-toplevel-name-resolver-2.0.h: Change getter return type to reference. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-03-11Add enum variant string information to definitionPierre-Emmanuel Patry1-0/+2
New enum variant status now appears in the string representation of the resolver's definition. gcc/rust/ChangeLog: * resolve/rust-rib.cc (Rib::Definition::to_string): Add enum variant status. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>