Commit graph

207521 commits

Author SHA1 Message Date
Pierre-Emmanuel Patry
e112189800 gccrs: libproc_macro: Put all structures in a namespace
Put all functions and structures in a Procmacro namespace to avoid
spilling names in any other namespace.

libgrust/ChangeLog:

	* libproc_macro/group.cc (Group::drop): Add Procmacro
	namespace.
	* libproc_macro/group.h: Likewise.
	* libproc_macro/ident.cc (Ident::drop): Likewise.
	* libproc_macro/ident.h (Ident__clone): Likewise.
	* libproc_macro/literal.cc (Literal::make_isize):
	Likewise.
	* libproc_macro/literal.h (Literal__from_string):
	Likewise.
	* libproc_macro/punct.cc (Punct::make_punct): Likewise.
	* libproc_macro/punct.h: Likewise.
	* libproc_macro/tokenstream.cc (TokenStream__drop):
	Likewise.
	* libproc_macro/tokenstream.h (TokenStream__drop):
	Likewise.
	* libproc_macro/tokentree.cc (TokenTree::drop):
	Likewise.
	* libproc_macro/tokentree.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:15 +01:00
Pierre-Emmanuel Patry
1ca5d5f84c gccrs: cli: Add frust-extern option
Add a new option to gather extern crates location.

gcc/rust/ChangeLog:

	* lang.opt: Add frust-extern option.
	* rust-session-manager.cc (Session::handle_extern_option): Add
	frust-extern option handler.
	* rust-session-manager.h (struct Session): Add an unordered map
	to store library name and locations.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:15 +01:00
Owen Avery
582accedb7 gccrs: Fix infinite loop with parsing invalid generic parameters
gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h
	(Parser::parse_generic_params):
	Handle parameter parsing error.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16 18:34:15 +01:00
Philip Herron
68a0eb254f gccrs: Improve operator overload check for recursive overload
This is a case in #2019 where you have the default Add impl for i32 for
example which has:

  impl Add for i32 {
    fn add(self, other:i32) { self + other }
  }

This function will do a check for operator overload which then is able to
find multiple candidates such as:

  impl<'a> Add<i32> for &'a i32 {
    type Output = <i32 as Add<i32>>::Output;

    fn add(self, other: i32) -> <i32 as Add<i32>>::Output {
        Add::add(*self, other)
    }
  }

This initial operator overload will resolve to this as it looks like a
valid candidate. This patch adds another level of checks to ensure the
candidate does not equal the current context DefId.

Addresses #2019

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-expr.cc: update for op overload

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:15 +01:00
Philip Herron
04877f1096 gccrs: qualified path syntax is used to disambiguate predicates
When resolving a qualified path we need to use the predicate to lookup the
relevant assoicated impl block where possible. The issue here is that
it might not have one due to a valid error in the impl block or it might
be used within a trait this is a valid case. Generally we will be able to
resolve to an impl block then it can grab that type and move on.

Fixes #2135

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): use the predicate
	(TypeCheckExpr::resolve_segments): cleanup

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:15 +01:00
Philip Herron
0a0b51c5dc gccrs: Extract helper lookup_associated_impl_block
This will look for a specified predicate that is associated with it so we
might have the predicate Foo<u16, i32> which would refer to:

  impl Foo<i32> for u16 {}

This is a general helper which can be used in several places.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-trait-reference.cc (AssociatedImplTrait::AssociatedImplTrait):
	bind the predicate
	(AssociatedImplTrait::get_trait): remove
	(AssociatedImplTrait::get_predicate): new getter
	* typecheck/rust-hir-trait-reference.h: bind predicate
	* typecheck/rust-hir-type-check-item.cc: update ctor
	* typecheck/rust-type-util.cc (lookup_associated_impl_block): new function
	* typecheck/rust-type-util.h (class BaseType): remove unused forward decl
	(lookup_associated_impl_block): new helper
	* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::is_equal): new
	* typecheck/rust-tyty-subst.cc (SubstitutionRef::lookup_associated_impl): use new helper
	(SubstitutionRef::monomorphize): update usage/error handling
	* typecheck/rust-tyty-subst.h: remove old prototype
	* typecheck/rust-tyty.h: add is_equal decl

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:15 +01:00
Owen Avery
46eb2b751f gccrs: Type check StructPatternFieldIdentPat
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-pattern.cc
	(TypeCheckPattern::visit): Type check StructPatternFieldIdentPat.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16 18:34:15 +01:00
Owen Avery
532d74c192 gccrs: Lower StructPatternFieldIdentPat
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-pattern.cc
	(ASTLoweringPattern::visit): Lower StructPatternFieldIdentPat.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16 18:34:15 +01:00
Philip Herron
255d22ea90 gccrs: resolve the associated_predicate when mapping Fn traits
This is required to solve #2105

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_fn_trait_call):
	return the assoicated predicate
	* typecheck/rust-hir-type-check-expr.h: update prototype

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:15 +01:00
Philip Herron
6182a28496 gccrs: Add missing where clause lowering for Impl functions
Fixes #2106

gcc/rust/ChangeLog:

	* hir/rust-ast-lower-implitem.h: add missing where clause lowering

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2106.rs: New test.
	* rust/compile/issue-1524.rs: regression (placeholder generic)

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:14 +01:00
Philip Herron
bee0c8a1d4 gccrs: Add missing TypeBoundWhereClauseItem::get_locus
gcc/rust/ChangeLog:

	* hir/tree/rust-hir-item.h: add get_locus() const

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:14 +01:00
Owen Avery
829785bb69 gccrs: Add accessors to HIR::StructPatternFieldIdentPat
gcc/rust/ChangeLog:

	* hir/tree/rust-hir-pattern.h
	(StructPatternFieldIdentPat::get_identifier): New.
	(StructPatternFieldIdentPat::get_pattern): New.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16 18:34:14 +01:00
Marc Poulhiès
98142ce7cc gccrs: Minor tuning in AST dump
Use parentheses to remove any ambiguities when dumping expressions with
unary ! and -.

gcc/rust/ChangeLog:
	* ast/rust-ast-dump.cc (Dump::visit): print parentheses around
	unique expression operand.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2024-01-16 18:34:14 +01:00
Owen Avery
8b7ab6f2f2 gccrs: Fix -frust-dump-* error messages
gcc/rust/ChangeLog:

	* rust-session-manager.cc
	(Session::enable_dump): Fix error messages.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16 18:34:14 +01:00
Philip Herron
dd8fb58695 gccrs: Add missing ABI checking on function types
Addresses #2304

gcc/rust/ChangeLog:

	* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
	(UnifyRules::expect_fndef): add ABI check
	* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:14 +01:00
Philip Herron
a92d1cc9b5 gccrs: Add missing ABI mapping
gcc/rust/ChangeLog:

	* util/rust-abi.cc (get_abi_from_string): add ABI mapping

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:14 +01:00
Philip Herron
1b810614f1 gccrs: Add mechanism use pattern information to improve type info
When we have an untyped closure we assumed all parameters were inference
variables but we can use the pattern type to try and improve the type info
so if we have a reference pattern it must be a reference to an inference
variables '&_'. This patch adds a new visitor to figure this out for
untyped closure parameters.

Note this test case does fully type resolve into the gimple:

    bool test::main::{{closure}}
        (struct test::main::{{closure}} $closure, struct (& u8) args)
    { ... }

Though the Rustc version does fail type-resolution but we make some
assumptions during comparison expressions here that they resolve to a bool
this will change when we implement the comparison lang items.

Fixes #2142

gcc/rust/ChangeLog:

	* hir/tree/rust-hir-pattern.h: add missing get_mutability
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
	use new ClosureParamInfer on untyped parameters
	* typecheck/rust-hir-type-check-pattern.cc (ClosureParamInfer::Resolve): interface
	(ClosureParamInfer::ClosureParamInfer): constructor
	(ClosureParamInfer::visit): visitors for each pattern
	* typecheck/rust-hir-type-check-pattern.h (class ClosureParamInfer): new visitor

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:14 +01:00
Philip Herron
d264dcc70c gccrs: remove unused header
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-pattern.h: cleanup

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:14 +01:00
Philip Herron
73ed16c0f8 gccrs: Fix ICE when we dont get a reference type
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
	return so we dont hit undefined behaviour

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:13 +01:00
Philip Herron
6700154ff7 gccrs: remove unused includes
gcc/rust/ChangeLog:

	* backend/rust-compile-implitem.h: remove includes

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:13 +01:00
Philip Herron
91a86375d9 gccrs: fix ICE with recursive function calls
Fixes #2136

gcc/rust/ChangeLog:

	* backend/rust-compile-item.cc (CompileItem::visit): remove bad checks

gcc/testsuite/ChangeLog:

	* rust/compile/issue-2136-1.rs: New test.
	* rust/compile/issue-2136-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:13 +01:00
Philip Herron
50c549ef3d gccrs: enable -Winfinite-recursion warnings by default
gcc/rust/ChangeLog:

	* lang.opt: add lang option flag
	* rust-lang.cc (grs_langhook_init_options_struct): enable by default

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:13 +01:00
Philip Herron
cd587fbc1d gccrs: Fix ICE in assignment of error type bound predicates
gcc/rust/ChangeLog:

	* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::operator=):
	we are done if other is in an error state

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:13 +01:00
Philip Herron
b237dcd81a gccrs: Fix ICE during method resolution
We were missing a check for trait item selection to ensure they are
actually methods and remove assertion to check if the trait item is a
function this is a valid error check not an assertion.

Fixes #2139

gcc/rust/ChangeLog:

	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): verify it is a method

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:13 +01:00
Philip Herron
b39ecbfec9 gccrs: Track Self properly with TypePredicateBounds
When we handle generic trait bounds we never tracked its associated Self
type. Its important to remember a Trait Predicate is associated with a type
this means we end up missing a lot of helpful type information down the
line relating to higher ranked trait bounds and associated types
compuations. Remember traits have an implict Generic Type Parameter of Self
we use this in computing trait defintions so in that case no associated
type is specified which is to be expected but in all other cases we do
even if it is generic its still useful type information to keep track of.

There is one regression here with compile/issue-1893.rs this testcase
mostly worked out as a fluke rather than a proper fix so its no suprise
here it has regressed the other two test cases one where the number
generic arguments has changed, Rustc gets around this and has a seperate
error message for this case.

We need to solve this patch in order to solve #2019

gcc/rust/ChangeLog:

	* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): use new interface
	* typecheck/rust-hir-type-check-base.h: update prototype to include Self
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): lifewise
	* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::resolve_impl_block_substitutions):
	likewise
	* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): likewise
	(TypeCheckExpr::resolve_segments): likewise
	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
	(TypeResolveGenericParam::visit): likewise
	(ResolveWhereClauseItem::visit): likewise
	* typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): likewise
	(TypeBoundPredicate::apply_generic_arguments): likewise
	(TypeBoundsMappings::lookup_predicate): likewise
	* typecheck/rust-tyty-bounds.h: likewise
	* typecheck/rust-tyty.h:likewise

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1893.rs: regression
	* rust/compile/traits12.rs: rustc uses a custom error message here
	* rust/compile/unconstrained_type_param.rs: extra error message

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:13 +01:00
Philip Herron
b18533466c gccrs: add error state to TypeCheckContextItem and missing copy ctor's
When checking current context we might be in the const or static context
which does not have a current function or impl or trait context associated
with it. So this allows us to represent the an error state for that case.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check.h: New error state and missing copy implementations
	* typecheck/rust-typecheck-context.cc (TypeCheckContextItem::TypeCheckContextItem):
	missing copy ctor
	(TypeCheckContextItem::operator=): missing copy implementation
	(TypeCheckContextItem::get_error): new static function
	(TypeCheckContextItem::is_error): new method
	(TypeCheckContextItem::get_context_type): handle error state
	(TypeCheckContextItem::get_defid): handle error state

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:13 +01:00
Philip Herron
0c6338ddb6 gccrs: add helper to check for a const or static context
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check.h: new helper
	* typecheck/rust-typecheck-context.cc (TypeCheckContext::have_function_context):
	implementation

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:12 +01:00
Philip Herron
e3a2f3b193 gccrs: Add get_defid helper to TypeCheckContextItem
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check.h: Add prototype
	* typecheck/rust-typecheck-context.cc (TypeCheckContextItem::get_defid): implementation

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:12 +01:00
Philip Herron
8e8c56392e gccrs: minor refactor to reuse a variable instead of recreating it later
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-expr.cc: refactor

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:12 +01:00
Philip Herron
e755e6e407 gccrs: Fix memory corruption at peek_context
When working in the resolve_operator_overload it was found that we got
memory corruption as method resolution will use the query system and
therefore resolve new methods and the current function context info will
change and due to the fact the peek_context interface returns a reference
to the element which was now safe from a vector which can change and all
you need is the current function context at that moment in time.

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: don't take a reference
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
	* typecheck/rust-hir-type-check.h: remove reference
	* typecheck/rust-typecheck-context.cc (TypeCheckContext::pop_return_type): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:12 +01:00
Arthur Cohen
315e267e8b gccrs: patterns: Add execution testcases to verify proper pattern matching
These testcases are similar to the ones added in #2072 but regarding
execution. One more issue was opened from them - #2144

gcc/testsuite/ChangeLog:

	* rust/execute/torture/issue-1852-1.rs: New test.
	* rust/execute/torture/issue-1852.rs: New test.
2024-01-16 18:34:12 +01:00
Owen Avery
14ab22c46e gccrs: Resolve identifier-pattern struct pattern fields
gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-pattern.cc
	(PatternDeclaration::visit): Handle StructPatternFieldIdentPat.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16 18:34:12 +01:00
Pierre-Emmanuel Patry
2698707419 gccrs: libproc_macro: Fix literal drop function
Fix drop function by changing the delete operator to delete[] in order
to avoid undefined behaviors.

libgrust/ChangeLog:

	* libproc_macro/literal.cc (Literal::drop): Change
	delete operator to delete[].

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:12 +01:00
Pierre-Emmanuel Patry
98b779a83c gccrs: libproc_macro: Implement Drop for TokenStream
TokenStream did not have any drop implementation, the memory could not
have been freed correctly.

libgrust/ChangeLog:

	* libproc_macro/rust/bridge/token_stream.rs: Implement
	drop.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:12 +01:00
Pierre-Emmanuel Patry
b44757f836 gccrs: libproc_macro: Add remaining drop functions
Remaining structures from the rust bridge that missed a drop function
now have one.

libgrust/ChangeLog:

	* libproc_macro/group.cc (Group::drop): Add drop
	implementation.
	* libproc_macro/group.h: Add drop prototype.
	* libproc_macro/tokenstream.cc (TokenStream::drop): Add
	drop implementation.
	(TokenStream__drop): Change to a call to TokenStream::drop.
	* libproc_macro/tokenstream.h: Add drop prototype.
	* libproc_macro/tokentree.cc (TokenTree::drop): Add
	drop implementation.
	* libproc_macro/tokentree.h: Add drop prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:12 +01:00
Pierre-Emmanuel Patry
2fa0bbc3ee gccrs: libproc_macro: Add drop function to Literal struct
Add a drop function to clean internal fields of a Literal struct.

libgrust/ChangeLog:

	* libproc_macro/literal.cc (Literal__drop): Replace
	implementation by a call to Literal::drop.
	(Literal::drop): Add drop implementation.
	* libproc_macro/literal.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
c9534eb5d9 gccrs: libproc_macro: Add drop function on Ident struct
Add a drop function that cleans internal fields of a given Ident struct.

libgrust/ChangeLog:

	* libproc_macro/ident.cc (Ident__drop): Replace by call
	to Ident::drop.
	(Ident::drop): Add drop function.
	* libproc_macro/ident.h: Add drop prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
d9473a5b55 gccrs: libproc_macro: Add remaining tokenstream structs.
Add remaining missing tokenstream structures. Most are interdependent.

libgrust/ChangeLog:

	* libproc_macro/group.cc: New file.
	* libproc_macro/group.h: New file.
	* libproc_macro/tokenstream.cc: New file.
	* libproc_macro/tokenstream.h: New file.
	* libproc_macro/tokentree.cc: New file.
	* libproc_macro/tokentree.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
TieWay59
747d9a92dd gccrs: Fix translation mistakes 2023 in GCC/Rust [PR108890]
In https://gcc.gnu.org/PR108890 "Translation mistakes 2023"
@rillig lists several issues with GCC/Rust diagnostics and
option help texts (but also a few non-GCC/Rust).

This commit fix mistakes only related to GCC/Rust,
specifically to the file `gcc/rust/lang.opt`.

closes https://github.com/Rust-GCC/gccrs/issues/1916

	PR translation/108890
	gcc/rust/
	* lang.opt: Fix translation mistakes 2023 in
	GCC/Rust [PR108890]
	(line 67): change the inconsistent tab to spaces
	(line 75): wrap bare placeholder `integer`
	(line 79): remove redundant text of `Choose which`
	(line 96): remove redundant text of `Choose which`
	(line 112): remove redundant `Flag to`
	(line 124): correct the exclusive term `When to stop`
	(line 124): correct typo of `copimlation`

Signed-off-by: Tieway59 <tieway59@foxmail.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
27f298c1dd gccrs: libproc_macro: Add Punct struct
Add Punct struct for rust interface as well as a basic named
constructor.

libgrust/ChangeLog:

	* libproc_macro/punct.cc: New file.
	* libproc_macro/punct.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
6a569f5c6c gccrs: libproc_macro: Add namespace to Ident
Add a new Ident namespace to group Ident related enumeration and
structures.

libgrust/ChangeLog:

	* libproc_macro/ident.cc (Ident::make_ident): Add Ident
	namespace.
	* libproc_macro/ident.h (Ident__clone): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
f4b2b28f32 gccrs: libproc_macro: Add named constructor
Add named constructor directly in Ident struct.

libgrust/ChangeLog:

	* libproc_macro/ident.cc (Ident__new): Use named
	constructor.
	(Ident__new_raw): Use named constructor.
	(Ident__clone): Use clone member function.
	(Ident::clone): Make clone const.
	(Ident::make_ident): Add named construcot.
	* libproc_macro/ident.h (struct Ident): Add named
	constructor prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
d2c9c8cf39 gccrs: libproc_macro: Change drop rust interface
Change rust interface on drop function to take a mut pointer instead.
This will match the drop trait interface more closely.

libgrust/ChangeLog:

	* libproc_macro/rust/bridge/ident.rs: Change drop
	function interface.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
e8c656ff6e gccrs: libproc_macro: Add ident implementation
Add implementation and representation for ident cpp structure as well as
a high level wrapper interface.

libgrust/ChangeLog:

	* libproc_macro/ident.cc: New file.
	* libproc_macro/ident.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
M V V S Manoj Kumar
f395ed80ce gccrs: Deleted the as_string ASR and HIR dumps
Fixes #2021, #2022
Deleted Parser::debug_dump_ast_output, removed any functions that called
it i.e Session::dump_ast and Session::dump_ast_expanded, and any
associated items.

Made it so that when you use the dump option "expanded" it dumps the
pretty ast only.

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::debug_dump_ast_output): Removed this funtion.
	* rust-session-manager.cc (Session::enable_dump): Removed else if (arg == "parse").
	(Session::compile_crate): Removed calls of dump_ast and dump_ast_expanded.
	(Session::dump_ast): Removed this function.
	(Session::dump_ast_expanded): Removed this function.
	* rust-session-manager.h (struct CompileOptions): Removed the PARSER_AST_DUMP option.

Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
2024-01-16 18:34:11 +01:00
Arthur Cohen
94f2a1ce4b gccrs: parser: Parse reference patterns correctly
Reference patterns cannot contain AltPatterns per the Rust reference,
so we should not call into `parse_pattern` to parse the referenced pattern,
but rather the more restrictive `parse_pattern_no_alt`.

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_reference_pattern): Do not
	call into `parse_pattern` anymore.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-1807.rs: New test.
2024-01-16 18:34:10 +01:00
Owen Avery
0b48fddeee gccrs: Add error message for AltPattern in let statements
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-pattern.cc
	(ASTLoweringPattern::translate): Add is_let_top_level parameter.
	(ASTLoweringPattern::visit): Handle is_let_top_level.
	* hir/rust-ast-lower-pattern.h
	(class ASTLoweringPattern): Add is_let_top_level.
	* hir/rust-ast-lower-stmt.cc
	(ASTLoweringStmt::visit): Set is_let_top_level.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16 18:34:10 +01:00
Zheyuan Chen
3ddfc58b25 gccrs: Implement Dump:visit() function for QualifiedPathInType argument.
gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc: fix bad formatting for associated type.

Signed-off-by: Zheyuan Chen <sephirotheca17@gmail.com>
2024-01-16 18:34:10 +01:00
Philip Herron
c1da49edb8 gccrs: Add testcase to show matching of enum variants
Fixes #852

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16 18:34:10 +01:00
Sergey Bugaev
18cd9a240d gccrs: Lower ErrorPropagationExpr from AST to HIR
gcc/rust/ChangeLog:
	* hir/rust-ast-lower-expr.h, hir/rust-ast-lower-expr.cc:
	Lower AST::ErrorPropagationExpr to HIR::ErrorPropagationExpr

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2024-01-16 18:34:10 +01:00