]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
18 months agogccrs: Handle gengtype annotations in rust-constexpr.cc
Owen Avery [Sat, 12 Aug 2023 15:37:10 +0000 (11:37 -0400)] 
gccrs: Handle gengtype annotations in rust-constexpr.cc

gcc/rust/ChangeLog:

* backend/rust-constexpr.cc:
Include gt-rust-rust-constexpr.h.
(struct constexpr_call_hasher): Rename to ...
(struct rust_constexpr_call_hasher): ... here.
(struct constexpr_fundef_hasher): Rename to ...
(struct rust_constexpr_fundef_hasher): ... here.
* config-lang.in: Add rust-constexpr.cc to gtfiles.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Add punycode encoding to v0 mangling
Raiki Tamura [Mon, 7 Aug 2023 17:08:38 +0000 (02:08 +0900)] 
gccrs: Add punycode encoding to v0 mangling

gcc/rust/ChangeLog:

* backend/rust-mangle.cc (v0_add_identifier): Added punycode encoding
(v0_mangle_item): Likewise.
* lex/rust-lex.cc (assert_source_content): Change type
(test_buffer_input_source): Change type
(test_file_input_source): Change type
* resolve/rust-ast-resolve-toplevel.h: fix typo
* rust-session-manager.cc (Session::load_extern_crate): fix typo
* util/rust-canonical-path.h: fix typo
* util/rust-hir-map.cc (NodeMapping::get_error): fix typo
(Mappings::Mappings): fix typo
* util/rust-mapping-common.h (UNKNOWN_CREATENUM): fix typo
(UNKNOWN_CRATENUM): Change 0 to UINT32_MAX

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: [E0391] Detected type dependency cycle
Muhammad Mahad [Tue, 15 Aug 2023 16:29:03 +0000 (21:29 +0500)] 
gccrs: [E0391] Detected type dependency cycle

This errorcode & message emits when cycle
detected when computing the super predicates
of `x` which requires computing the super
predicates of `y`, which again requires
computing the super predicates of `x`,
completing the cycle.

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait):
Updated errorcode & more userfriendly message.

gcc/testsuite/ChangeLog:

* rust/compile/issue-1589.rs: Updated comment for dejagnu.
* rust/compile/trait-cycle.rs: New relevant test.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Non-allowed default type paramters
Muhammad Mahad [Mon, 14 Aug 2023 12:09:25 +0000 (17:09 +0500)] 
gccrs: Non-allowed default type paramters

gcc/rust/ChangeLog:

* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit):
Added more helpful error message.

gcc/testsuite/ChangeLog:

* rust/compile/generics10.rs: for dejagnu.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0034] found more than one items for method
Muhammad Mahad [Tue, 15 Aug 2023 15:19:36 +0000 (20:19 +0500)] 
gccrs: [E0034] found more than one items for method

Multiple items found with same prototype.
Fixes: https://github.com/Rust-GCC/gccrs/issues/2366
gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.h:
Fixes issue & added rich location message.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Added rich location and error code.

gcc/testsuite/ChangeLog:

* rust/compile/generics6.rs: Updated dejagnu comment.
* rust/compile/generics7.rs: likewise.
* rust/compile/issue-925.rs: likewise.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Add a regression test for decimal lexing
Pierre-Emmanuel Patry [Thu, 3 Aug 2023 13:52:51 +0000 (15:52 +0200)] 
gccrs: Add a regression test for decimal lexing

Issue #2514 fixed by the previous commit highlight a behavior we want to
avoid in the future, hence this regression test.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: fix lexer exponent output on tuple indices
Pierre-Emmanuel Patry [Thu, 3 Aug 2023 13:28:40 +0000 (15:28 +0200)] 
gccrs: fix lexer exponent output on tuple indices

The lexer did output a literal for values such as 42.e wich are invalid
in rust.

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::parse_decimal_int_or_float): Only
accept digits after a dot instead of accepting any float
member.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: [E0164] Neither tuple struct nor tuple variant used as a pattern
Muhammad Mahad [Wed, 16 Aug 2023 12:40:09 +0000 (17:40 +0500)] 
gccrs: [E0164] Neither tuple struct nor tuple variant used as a pattern

Checking if pattern has items, before returing solves ICE.
Added error code and rich location.
Also, fixes https://github.com/Rust-GCC/gccrs/issues/2430

gcc/rust/ChangeLog:

* ast/rust-pattern.h: No need of assertion, we are handling it.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Added check which emits error instead of using assertion.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Added rich location and error code.

gcc/testsuite/ChangeLog:

* rust/compile/match5.rs:
Updated comment for dejagnu.
* rust/compile/pattern-struct.rs: New test for ICE.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0535] Unknown argument given to inline attribute
Muhammad Mahad [Tue, 15 Aug 2023 14:07:52 +0000 (19:07 +0500)] 
gccrs: [E0535] Unknown argument given to inline attribute

The inline attribute only supports two arguments:
 - always
 - never
All other arguments given to the inline attribute will
return error.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::handle_inline_attribute_on_fndecl):
Added rich_location & error code.

gcc/testsuite/ChangeLog:

* rust/compile/inline_2.rs: Added new message.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0380] Use of auto trait with method or associated item
Muhammad Mahad [Thu, 17 Aug 2023 05:25:33 +0000 (10:25 +0500)] 
gccrs: [E0380] Use of auto trait with method or associated item

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_trait):
added errorcode & updated error message.

gcc/testsuite/ChangeLog:

* rust/compile/auto_trait_invalid.rs:
Updated comment.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0753] Use of inner doc comment in invalid context
Muhammad Mahad [Thu, 17 Aug 2023 05:13:00 +0000 (10:13 +0500)] 
gccrs: [E0753] Use of inner doc comment in invalid context

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_outer_attribute):
Added errorcode & updated error function.

gcc/testsuite/ChangeLog:

* rust/compile/bad_inner_doc.rs:
Updated comment to pass testcase.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Support for rich-loc & errorcode in parser error
Muhammad Mahad [Thu, 10 Aug 2023 17:10:09 +0000 (22:10 +0500)] 
gccrs: Support for rich-loc & errorcode in parser error

Added method of binding ErrorCode & rich location to
parser and expansion errors.
Fixes https://github.com/Rust-GCC/gccrs/issues/2385

gcc/rust/ChangeLog:

* rust-diagnostics.cc (va_constructor):
Added constructor for all possible cases.
(Error::Error): Updated error struct
for all possible cases.
* rust-diagnostics.h (struct Error):
Updated error struct to support error
code & rich location support.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0534] inline attribute was malformed
Muhammad Mahad [Tue, 15 Aug 2023 13:52:10 +0000 (18:52 +0500)] 
gccrs: [E0534] inline attribute was malformed

Inline attribute takes one argument, but
more than one argument was found.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::handle_inline_attribute_on_fndecl):
Added rich_location & error code.

gcc/testsuite/ChangeLog:

* rust/compile/inline_2.rs: Added new case.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: diagnostics: Fix mismatch between new[] and free
Arthur Cohen [Thu, 3 Aug 2023 14:40:07 +0000 (16:40 +0200)] 
gccrs: diagnostics: Fix mismatch between new[] and free

We cannot use `free` on a pointer allocated through `new[]`, and this
causes an ASAN failure. This fixes it by using `xcalloc` instead of
`new[]` when creating description buffers for our error codes.

gcc/rust/ChangeLog:

* rust-diagnostics.cc: Switch from new[] to xcalloc

18 months agogccrs: Type annotation for make-unicode-data.py
Raiki Tamura [Sun, 6 Aug 2023 09:49:20 +0000 (18:49 +0900)] 
gccrs: Type annotation for make-unicode-data.py

gcc/rust/ChangeLog:

* util/make-rust-unicode.py: Add type annotation

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: improve name mangling hash
Philip Herron [Sat, 12 Aug 2023 17:18:51 +0000 (18:18 +0100)] 
gccrs: improve name mangling hash

We can endup with duplicate symbol names for different intrinsics with our
current hash setup. This adds in the mappings and extra info to improve
hash uniqueness.

Addresses #1895

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (check_for_cached_intrinsic):
simplify this cached intrinsic check
* backend/rust-mangle.cc (legacy_mangle_item): use new interface
* typecheck/rust-tyty.h: new managle helper

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: simplify matching possible candidates
Philip Herron [Sat, 12 Aug 2023 17:23:06 +0000 (18:23 +0100)] 
gccrs: simplify matching possible candidates

We do extra checking after the fact here to ensure its a valid candidate
and in the case there is only one candidate lets just go for it.

Addresses #1895

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address):
use the single candidate

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Cleanup HIR dump
Marc Poulhiès [Thu, 10 Aug 2023 21:06:32 +0000 (23:06 +0200)] 
gccrs: Cleanup HIR dump

visit_field() correctly handles empty unique_ptr<> and displays "none".

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): Remove useless if/else
already handled by visit_field.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
18 months agogccrs: Add missing CHECKING_P guard to rust-punycode.cc
Owen Avery [Sat, 12 Aug 2023 02:39:57 +0000 (22:39 -0400)] 
gccrs: Add missing CHECKING_P guard to rust-punycode.cc

gcc/rust/ChangeLog:

* util/rust-punycode.cc: Add CHECKING_P guard.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Fix legacy mangling to use Unicode escape
Raiki Tamura [Sat, 12 Aug 2023 07:16:53 +0000 (16:16 +0900)] 
gccrs: Fix legacy mangling to use Unicode escape

gcc/rust/ChangeLog:

* backend/rust-mangle.cc (legacy_mangle_name): Use Unicode escape

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: remove horrible hack in solving complex generics on impl blocks
Philip Herron [Sat, 12 Aug 2023 16:06:37 +0000 (17:06 +0100)] 
gccrs: remove horrible hack in solving complex generics on impl blocks

We hit an assertion with range based iterators here. This code was used
to solve complex generics such as:

  struct Foo<X,Y>(X,Y);
  impl<T> Foo<T, i32> {
    fn test<Y>(self, a: Y) { }
  }

The impl item will have the signiture of:

  fn test<T,Y> (Foo<T, i32> self, a:Y)

So in the case where we have:

  let a = Foo(123f32, 456);
  a.test<bool>(true);

We need to solve the generic argument T from the impl block by infering the
arguments there and applying them so that when we apply the generic
argument bool we dont end up in the case of missing number of generics.

Addresses #1895

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): remove hack

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Use MacroInvocLexerBase in ProcMacroInvocLexer
Owen Avery [Fri, 30 Jun 2023 01:37:33 +0000 (21:37 -0400)] 
gccrs: Use MacroInvocLexerBase in ProcMacroInvocLexer

gcc/rust/ChangeLog:

* expand/rust-proc-macro-invoc-lexer.cc
(ProcMacroInvocLexer::skip_token): Remove.
* expand/rust-proc-macro-invoc-lexer.h:
Include "rust-macro-invoc-lexer.h".
(class ProcMacroInvocLexer):
Extend MacroInvocLexerBase.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: clean up Codepoint and InputSource
Raiki Tamura [Sun, 6 Aug 2023 10:17:17 +0000 (19:17 +0900)] 
gccrs: clean up Codepoint and InputSource

gcc/rust/ChangeLog:

* lex/rust-codepoint.h: Moved to...
* util/rust-codepoint.h: ...here.
* lex/rust-input-source.h: Add missing license
* util/rust-unicode.cc: Add missing license
* util/rust-punycode.cc (extract_basic_string): Remove constant

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: macro-expand: Keep optional references to last_{def, invoc}
Arthur Cohen [Thu, 3 Aug 2023 15:24:14 +0000 (17:24 +0200)] 
gccrs: macro-expand: Keep optional references to last_{def, invoc}

This avoids a use-after-free when reaching the recursion limit.

gcc/rust/ChangeLog:

* expand/rust-macro-expand.h: Keep optional references for last_def
and last_invoc.
* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Store
optional references.
* rust-session-manager.cc (Session::expansion): Use tl::optional's APIs
for better checking.

18 months agogccrs: Adjust HIR dump for IfExpr and IfExprConseqElse
Marc Poulhiès [Thu, 10 Aug 2023 20:45:38 +0000 (22:45 +0200)] 
gccrs: Adjust HIR dump for IfExpr and IfExprConseqElse

Adjust the HIR dump for IfExpr and IfExprConseqElse
to use visit_field() and factor common part.

gcc/rust/ChangeLog:

* hir/rust-hir-dump.h (do_ifexpr): New.
* hir/rust-hir-dump.cc (Dump::do_ifexpr): New.
(Dump::visit): Use do_ifexpr and visit_field

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
18 months agogccrs: [E0054/E0604/E0620/E0606] TypeCasting ErrorCodes
Muhammad Mahad [Sat, 5 Aug 2023 12:28:45 +0000 (17:28 +0500)] 
gccrs: [E0054/E0604/E0620/E0606] TypeCasting ErrorCodes

Added errorcodes according to different conditions
and updated error message according to type casting
type.

gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::emit_cast_error):
Refactored ErrorCodes & error messages.

gcc/testsuite/ChangeLog:

* rust/compile/bad_as_bool_char.rs:
Updated comment to pass test case.
* rust/compile/cast1.rs: likewise.
* rust/compile/cast4.rs: likewise.
* rust/compile/cast5.rs: likewise.
* rust/compile/all-cast.rs: New test for all error codes.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0541] Use of unknown meta item
Muhammad Mahad [Sat, 5 Aug 2023 08:18:16 +0000 (13:18 +0500)] 
gccrs: [E0541] Use of unknown meta item

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc:
Added ErrorCode.

gcc/testsuite/ChangeLog:

* rust/compile/attr_deprecated_2.rs:
Updated comment to pass the testcase.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0703] Use of Invalid ABI
Muhammad Mahad [Thu, 3 Aug 2023 15:46:50 +0000 (20:46 +0500)] 
gccrs: [E0703] Use of Invalid ABI

Added error code support for invalid ABI.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_qualifiers):
called error function.
(ASTLoweringBase::lower_extern_block): likewise.

gcc/testsuite/ChangeLog:

* rust/compile/abi-options1.rs: updated comment for testcase.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Basic formatting/comment fixes
Owen Avery [Wed, 9 Aug 2023 16:55:37 +0000 (12:55 -0400)] 
gccrs: Basic formatting/comment fixes

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc: Adjust formatting.
* checks/errors/rust-feature-gate.cc: Add trailing newline.
* rust-diagnostics.h: Remove old comment.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Remove unneeded references to "this" in backend methods
Owen Avery [Tue, 1 Aug 2023 19:59:14 +0000 (15:59 -0400)] 
gccrs: Remove unneeded references to "this" in backend methods

gcc/rust/ChangeLog:

* rust-gcc.cc
(Gcc_backend::struct_type): Remove references to "this".
(Gcc_backend::union_type): Likewise.
(Gcc_backend::array_type): Likewise.
(Gcc_backend::wchar_constant_expression): Likewise.
(Gcc_backend::convert_expression): Likewise.
(Gcc_backend::constructor_expression): Likewise.
(Gcc_backend::array_initializer): Likewise.
(Gcc_backend::assignment_statement): Likewise.
(Gcc_backend::global_variable): Likewise.
(Gcc_backend::temporary_variable): Likewise.
(Gcc_backend::function_defer_statement): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Add function `Rust::encode_punycode`
Raiki Tamura [Sun, 30 Jul 2023 10:54:36 +0000 (19:54 +0900)] 
gccrs: Add function `Rust::encode_punycode`

gcc/rust/ChangeLog:

* Make-lang.in: Add rust-punycode.o.
* rust-lang.cc (run_rust_tests): Add selftest.
* util/rust-punycode.cc: New file.
* util/rust-punycode.h: New file.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: [E0308] array misamatch types
Muhammad Mahad [Sat, 5 Aug 2023 07:55:36 +0000 (12:55 +0500)] 
gccrs: [E0308] array misamatch types

gcc/rust/ChangeLog:

* backend/rust-compile.cc (HIRCompileBase::verify_array_capacities):
Added ErrorCode.

gcc/testsuite/ChangeLog:

* rust/compile/arrays2.rs: changed comment to pass
testcase.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0282] type annotations needed
Muhammad Mahad [Sat, 5 Aug 2023 06:27:19 +0000 (11:27 +0500)] 
gccrs: [E0282] type annotations needed

type must be known at compile time.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check.cc (TypeResolution::Resolve):
added errorcode.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Move Backend::error_variable to Bvariable::error_variable
Owen Avery [Wed, 2 Aug 2023 19:51:38 +0000 (15:51 -0400)] 
gccrs: Move Backend::error_variable to Bvariable::error_variable

gcc/rust/ChangeLog:

* rust-backend.h
(Backend::error_variable): Remove.
(Gcc_backend::error_variable): Move to ...
* rust-gcc.cc
(Bvariable::error_variable): ... here ...
* rust-gcc.h
(Bvariable::error_variable): ... and declare here.
(Gcc_backend::global_variable): Update error_variable call.
(Gcc_backend::local_variable): Likewise.
(Gcc_backend::parameter_variable): Likewise.
(Gcc_backend::static_chain_variable): Likewise.
(Gcc_backend::temporary_variable): Likewise.
* backend/rust-compile-extern.h
(CompileExternItem::visit): Likewise.
* backend/rust-compile-fnparam.cc
(CompileFnParam::CompileFnParam): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Remove Backend::bool_type and Backend::char_type
Owen Avery [Wed, 2 Aug 2023 19:52:54 +0000 (15:52 -0400)] 
gccrs: Remove Backend::bool_type and Backend::char_type

gcc/rust/ChangeLog:

* backend/rust-compile-type.cc
(TyTyResolveCompile::visit): Inline Backend::bool_type call.
* rust-backend.h
(Backend::bool_type): Remove.
(Backend::char_type): Remove.
(Gcc_backend::bool_type): Remove.
(Gcc_backend::char_type): Remove.
* rust-gcc.cc
(Gcc_backend::char_constant_expression): Inline Backend::char_type call.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Normalize all identifier tokens
Raiki Tamura [Sun, 30 Jul 2023 10:54:36 +0000 (19:54 +0900)] 
gccrs: Normalize all identifier tokens

gcc/rust/ChangeLog:

* lex/rust-lex.cc (assert_source_content): Fix namespace specifier
(test_buffer_input_source): Likewise.
(test_file_input_source): Likewise.
* lex/rust-lex.h: Move InputSource ...
* lex/rust-input-source.h: ... to here. (New file)
* lex/rust-token.cc (nfc_normalize_token_string): New function
* lex/rust-token.h (nfc_normalize_token_string): New function
* rust-lang.cc (run_rust_tests): Modify order of selftests.
* rust-session-manager.cc (validate_crate_name): Modify interface of Utf8String.
* util/rust-unicode.cc (lookup_cc): Modify codepoint_t typedef.
(lookup_recomp): Likewise.
(recursive_decomp_cano): Likewise.
(decomp_cano): Likewise.
(sort_cano): Likewise.
(compose_hangul): Likewise.
(assert_normalize): Likewise.
(Utf8String::nfc_normalize): New function.
* util/rust-unicode.h: Modify interface of Utf8String.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: [E0412] used type name not in scope
Muhammad Mahad [Mon, 7 Aug 2023 11:55:02 +0000 (16:55 +0500)] 
gccrs: [E0412] used type name not in scope

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go):
Added ErrorCode.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Fix a warning about extra semicolon
Pierre-Emmanuel Patry [Mon, 7 Aug 2023 07:29:54 +0000 (09:29 +0200)] 
gccrs: Fix a warning about extra semicolon

This semicolon produces several warning in each TU the header file is
included in.

gcc/rust/ChangeLog:

* util/rust-common.h (enum_to_str): Remove extra semicolon after
the function.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: [E0658] Unstable langauge feature
Muhammad Mahad [Tue, 8 Aug 2023 19:27:08 +0000 (00:27 +0500)] 
gccrs: [E0658] Unstable langauge feature

gcc/rust/ChangeLog:

* checks/errors/rust-const-checker.cc (ConstChecker::visit):
Use of mutable reference in constant functions.
* checks/errors/rust-feature-gate.cc (FeatureGate::gate):
ErrorCode for intrinsics are subject to change.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0015] Use of non-const inside const
Muhammad Mahad [Tue, 8 Aug 2023 13:39:29 +0000 (18:39 +0500)] 
gccrs: [E0015] Use of non-const inside const

gcc/rust/ChangeLog:

* checks/errors/rust-const-checker.cc (ConstChecker::check_function_call):
Added errorcode.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0107] Wrong number of generic argument
Muhammad Mahad [Tue, 8 Aug 2023 13:54:33 +0000 (18:54 +0500)] 
gccrs: [E0107] Wrong number of generic argument

gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args):
Added errorcode.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: nr2.0: Add macros 2.0 resolution testcase.
Arthur Cohen [Wed, 2 Aug 2023 10:56:03 +0000 (12:56 +0200)] 
gccrs: nr2.0: Add macros 2.0 resolution testcase.

gcc/testsuite/ChangeLog:

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

18 months agogccrs: nr2.0: Add macros 2.0 in Ribs in TopLevel visitor
Arthur Cohen [Wed, 2 Aug 2023 10:53:20 +0000 (12:53 +0200)] 
gccrs: nr2.0: Add macros 2.0 in Ribs in TopLevel visitor

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Declare
macros in the current rib if they are macros 2.0.

18 months agogccrs: ast: Add `get_kind` method to `MacroRulesDefinition`
Arthur Cohen [Wed, 2 Aug 2023 10:50:06 +0000 (12:50 +0200)] 
gccrs: ast: Add `get_kind` method to `MacroRulesDefinition`

gcc/rust/ChangeLog:

* ast/rust-macro.h: Add new method to `MacroRulesDefinition` to allow
getting the `MacroKind` contained.

18 months agogccrs: nr2.0: Add complex macro name resolution test cases
Arthur Cohen [Thu, 27 Jul 2023 08:06:37 +0000 (10:06 +0200)] 
gccrs: nr2.0: Add complex macro name resolution test cases

gcc/testsuite/ChangeLog:

* rust/compile/name_resolution6.rs: New test.
* rust/compile/name_resolution7.rs: New test.
* rust/compile/name_resolution8.rs: New test.
* rust/compile/name_resolution9.rs: New test.

18 months agogccrs: session-manager: Run name resolution 2.0 if the option is present
Arthur Cohen [Fri, 23 Jun 2023 14:35:47 +0000 (16:35 +0200)] 
gccrs: session-manager: Run name resolution 2.0 if the option is present

gcc/rust/ChangeLog:

* rust-session-manager.cc
(Session::expansion): Use new `Early` name resolution 2.0 pass

18 months agogccrs: nr2.0: Add Early name resolution visitor
Arthur Cohen [Thu, 27 Jul 2023 08:06:13 +0000 (10:06 +0200)] 
gccrs: nr2.0: Add Early name resolution visitor

This visitor takes care of resolving macro invocations, procedural macros
and imports - it is used in conjunction with the `TopLevel` pass and
the macro expander.

gcc/rust/ChangeLog:

* Make-lang.in: Add new object file.
* resolve/rust-early-name-resolver-2.0.cc: New file.
* resolve/rust-early-name-resolver-2.0.h: New file.

18 months agogccrs: nr2.0: Visit receiver/call expression and arguments in calls/methods
Arthur Cohen [Wed, 2 Aug 2023 09:22:10 +0000 (11:22 +0200)] 
gccrs: nr2.0: Visit receiver/call expression and arguments in calls/methods

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc
(DefaultResolver::visit): Visit CallExpr and MethodCallExpr properly.
* resolve/rust-default-resolver.h: Switch "node" to plural in documentation.

18 months agogccrs: toplevel: Handle macro definitions properly
Arthur Cohen [Fri, 21 Jul 2023 16:23:00 +0000 (18:23 +0200)] 
gccrs: toplevel: Handle macro definitions properly

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::insert_or_error_out): Fix format string.
(is_macro_export): New method.
(TopLevel::visit): Handle macro definitions.

18 months agogccrs: resolver: Resolve macros too.
Arthur Cohen [Sun, 23 Jul 2023 01:19:46 +0000 (03:19 +0200)] 
gccrs: resolver: Resolve macros too.

gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.cc
(Resolver::insert): Do not call into `rust_unreachable` when resolving
macros anymore.

18 months agogccrs: forever stack: Add path resolution
Arthur Cohen [Thu, 20 Jul 2023 15:52:14 +0000 (17:52 +0200)] 
gccrs: forever stack: Add path resolution

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h
(insert_at_root): New method.
(resolve_path): New method.
(reverse_iter): Iterate on `Node`s instead of `Rib`s
* resolve/rust-forever-stack.hxx: Add path resolution.

18 months agogccrs: rib2.0: Add shadowing
Arthur Cohen [Fri, 21 Jul 2023 16:22:43 +0000 (18:22 +0200)] 
gccrs: rib2.0: Add shadowing

gcc/rust/ChangeLog:

* resolve/rust-rib.h: Add shadowing parameter. Make kind field public.
* resolve/rust-rib.cc (Rib::insert): Likewise.

18 months agogccrs: [E0426] Use of undeclared label
Muhammad Mahad [Tue, 1 Aug 2023 10:00:06 +0000 (15:00 +0500)] 
gccrs: [E0426] Use of undeclared label

Refactored error message to print more
userfriendly message and added error
code.

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit):
refactored message and called error function.

gcc/testsuite/ChangeLog:

* rust/compile/undeclared_label.rs: New test for E0426.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0635] Use of Unknown feature.
Muhammad Mahad [Thu, 3 Aug 2023 08:24:13 +0000 (13:24 +0500)] 
gccrs: [E0635] Use of Unknown feature.

Added ErrorCode support for use of unknown
feature.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc (FeatureGate::check):
errorcode support for unknown feature.

gcc/testsuite/ChangeLog:

* rust/compile/feature.rs: Added new unknown feature.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: [E0308] mismatch types on assignment
Muhammad Mahad [Wed, 2 Aug 2023 11:21:15 +0000 (16:21 +0500)] 
gccrs: [E0308] mismatch types on assignment

This errorcode emits when there are
mismatch types between lhs & rhs of
assignment operator & refactored
message. This error code was used
in many test cases, so updated the
error comments.

gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::emit_type_mismatch):
refactored & called error function.

gcc/testsuite/ChangeLog:

* rust/compile/arrays1.rs: changed comment to pass testcase.
* rust/compile/bad_type1.rs: likewise.
* rust/compile/bad_type2.rs: likewise.
* rust/compile/const_generics_6.rs: likewise.
* rust/compile/deadcode_err1.rs: likewise.
* rust/compile/deadcode_err2.rs: likewise.
* rust/compile/func1.rs: likewise.
* rust/compile/func3.rs: likewise.
* rust/compile/func4.rs: likewise.
* rust/compile/func5.rs: likewise.
* rust/compile/generics1.rs: likewise.
* rust/compile/generics2.rs: likewise.
* rust/compile/generics3.rs: likewise.
* rust/compile/implicit_returns_err1.rs: likewise.
* rust/compile/implicit_returns_err2.rs: likewise.
* rust/compile/implicit_returns_err3.rs: likewise.
* rust/compile/implicit_returns_err4.rs: likewise.
* rust/compile/issue-1152.rs: likewise.
* rust/compile/issue-2477.rs: likewise.
* rust/compile/reference1.rs: likewise.
* rust/compile/stmt_with_block_err1.rs: likewise.
* rust/compile/traits1.rs: likewise.
* rust/compile/traits2.rs: likewise.
* rust/compile/tuple_mismatch.rs: likewise.
* rust/compile/tuple_struct3.rs: likewise.
* rust/compile/mismatched-types.rs: New test from rustc.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: better handling of incorrect file loading in include_* builtin macros
Marc Poulhiès [Wed, 12 Jul 2023 17:00:10 +0000 (19:00 +0200)] 
gccrs: better handling of incorrect file loading in include_* builtin macros

When the load_file_bytes() fails to open the file, it emits an error but
returns an empty vector (as if the file is empty).

Instead, return a tl::optional nullopt in case of error and an empty
vector in case of an empty file.

fixes #2421

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc
(load_file_bytes): Return a tl::optional.
(MacroBuiltin::include_byte_handler): Adjust and check file was
correctly opened.
(MacroBuiltin::include_str_handler): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/empty_file: New file.
* rust/compile/issue-2421_str.rs: New test.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
18 months agogccrs: nr2.0: Use DefaultResolver for TopLevel
Arthur Cohen [Thu, 20 Jul 2023 13:15:21 +0000 (15:15 +0200)] 
gccrs: nr2.0: Use DefaultResolver for TopLevel

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.h
(class TopLevel): Inherit from DefaultResolver
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::TopLevel): Remove unecessary methods

18 months agogccrs: nr2.0: Add DefaultResolver visitor
Arthur Cohen [Thu, 20 Jul 2023 13:14:54 +0000 (15:14 +0200)] 
gccrs: nr2.0: Add DefaultResolver visitor

The DefaultResolver class provides a visitor framework for all three resolvers
in the new name resolution algorithm, with things such as scoping or visiting
sub items.

gcc/rust/ChangeLog:

* Make-lang.in: Add new object file.
* resolve/rust-default-resolver.cc: New file.
* resolve/rust-default-resolver.h: New file.

18 months agogccrs: Normalize Hangul to NFC
Raiki Tamura [Mon, 24 Jul 2023 08:29:20 +0000 (17:29 +0900)] 
gccrs: Normalize Hangul to NFC

gcc/rust/ChangeLog:

* util/rust-unicode.cc (decomp_cano): Decompose Hangul.
(sort_cano): Fix bounds check.
(recomp): use `compose_hangul`.
(compose_hangul): Compose Hangul.
(rust_utf8_normalize_test): Add tests.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: forever-stack: Use rust_assert instead of assert
Arthur Cohen [Mon, 31 Jul 2023 14:13:25 +0000 (16:13 +0200)] 
gccrs: forever-stack: Use rust_assert instead of assert

This causes complaints by our GCC 4.8 builder.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: assert() -> rust_assert()

18 months agogccrs: top-level: Add base `TopLevel` visitor
Arthur Cohen [Thu, 20 Jul 2023 12:15:14 +0000 (14:15 +0200)] 
gccrs: top-level: Add base `TopLevel` visitor

The `TopLevel` pass takes care of collecting definitions, placing them
in the proper namespaces, and making them accessible for later resolution
passes like `Early` and `Late`. It is meant to be run in a fixed point
fashion, as import resolution, macro resolution and macro expansion
may generate multiple new definitions.

gcc/rust/ChangeLog:

* Make-lang.in: Add new object file.
* resolve/rust-toplevel-name-resolver-2.0.cc: New file.
* resolve/rust-toplevel-name-resolver-2.0.h: New file.

18 months agogccrs: name resolution 2.0: Add base for our context data structure
Arthur Cohen [Fri, 23 Jun 2023 14:17:51 +0000 (16:17 +0200)] 
gccrs: name resolution 2.0: Add base for our context data structure

This commit adds a first simple `NameResolutionContext` data structure, which will
be used by all passes of the name resolution to store definitions and access
them. Namely, it contains a few instances of `ForeverStack`, for each
namespace we will be using.

gcc/rust/ChangeLog:

* Make-lang.in: Add new object file.
* resolve/rust-name-resolution-context.cc: New file.
* resolve/rust-name-resolution-context.h: New file.

18 months agogccrs: [E0572] return is outside of function context
Muhammad Mahad [Mon, 31 Jul 2023 10:21:58 +0000 (15:21 +0500)] 
gccrs: [E0572] return is outside of function context

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
called error function.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Use MacroInvocLexerBase in MacroInvocLexer
Owen Avery [Fri, 30 Jun 2023 01:28:23 +0000 (21:28 -0400)] 
gccrs: Use MacroInvocLexerBase in MacroInvocLexer

gcc/rust/ChangeLog:

* expand/rust-macro-invoc-lexer.cc
(MacroInvocLexer::skip_token): Remove.
* expand/rust-macro-invoc-lexer.h
(class MacroInvocLexer): Extend MacroInvocLexerBase.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: use tl::optional for macro transcribers
Marc Poulhiès [Wed, 19 Jul 2023 08:54:52 +0000 (10:54 +0200)] 
gccrs: use tl::optional for macro transcribers

refs #2421.

gcc/rust/ChangeLog:

* ast/rust-ast-fragment.cc (Fragment::create_empty): New.
* ast/rust-ast-fragment.h (MacroTranscriberFunc): New.
* ast/rust-macro.h (MacroRulesDefinition): Use MacroTranscriberFunc.
* expand/rust-macro-builtins.cc
(MacroBuiltin::builtin_transcribers): likewise.
(MacroBuiltin::assert_handler): Return optional.
(MacroBuiltin::file_handler): Likewise.
(MacroBuiltin::column_handler): Likewise.
(MacroBuiltin::include_bytes_handler): Likewise.
(MacroBuiltin::include_str_handler): Likewise.
(MacroBuiltin::compile_error_handler): Likewise.
(MacroBuiltin::concat_handler): Likewise.
(MacroBuiltin::env_handler): Likewise.
(MacroBuiltin::cfg_handler): Likewise.
(MacroBuiltin::include_handler): Likewise.
(MacroBuiltin::line_handler): Likewise.
(MacroBuiltin::stringify_handler): Likewise.
(MacroBuiltin::sorry): Likewise.
* expand/rust-macro-builtins.h (builtin_transcribers): Use
MacroTranscriberFunc.
(assert_handler): Return optional.
(file_handler): Likewise.
(column_handler): Likewise.
(include_bytes_handler): Likewise.
(include_str_handler): Likewise.
(compile_error_handler): Likewise.
(concat_handler): Likewise.
(env_handler): Likewise.
(cfg_handler): Likewise.
(include_handler): Likewise.
(line_handler): Likewise.
(stringify_handler): Likewise.
(sorry): Likewise.
* expand/rust-macro-expand.cc (MacroExpander::expand_invoc):
Adjust to transcribers returning optional.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
18 months agogccrs: Fix ICE by adding check for enum candidate's in TypePath resolution
Philip Herron [Sun, 30 Jul 2023 17:59:06 +0000 (18:59 +0100)] 
gccrs: Fix ICE by adding check for enum candidate's in TypePath resolution

Fixes #2479

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitItemReference::resolve_item):
always resolve the type even when its an a mandatory trait item
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path):
Add check for enum candidates otherwise you get undefined behaviour

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Add Unicode check for crate_name attributes
Raiki Tamura [Fri, 14 Jul 2023 05:45:34 +0000 (14:45 +0900)] 
gccrs: Add Unicode check for crate_name attributes

gcc/rust/ChangeLog:

* lex/rust-codepoint.h: Add comment
* lex/rust-lex.h: New method to get decoded characters
* rust-session-manager.cc (validate_crate_name): Modify unicode check
(rust_crate_name_validation_test): Add testcases
* util/rust-unicode.h (RUST_UNICODE_H): New class Utf8String.
(class Utf8String): New class.
* util/rust-unicode.cc (binary_search_sorted_array): Add comment.
(recursive_decomp_cano): Add comment.
(recomp): Remove dead code.
(dump_string): Removed.

gcc/testsuite/ChangeLog:

* rust/compile/bad-crate-name.rs: Moved to...
* rust/compile/bad-crate-name1.rs: ...here.
* rust/compile/bad-crate-name2.rs: New test.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: Add missing CHECKING_P guard to rust-unicode.cc
Owen Avery [Sun, 30 Jul 2023 04:23:00 +0000 (00:23 -0400)] 
gccrs: Add missing CHECKING_P guard to rust-unicode.cc

gcc/rust/ChangeLog:

* util/rust-unicode.cc: Add CHECKING_P guard.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: fix ice when function is outside of context
Philip Herron [Sat, 29 Jul 2023 23:19:15 +0000 (00:19 +0100)] 
gccrs: fix ice when function is outside of context

Fixes #2477

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
We need to check if a function context exists

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Begin enforcing Sized properly and support anti traits like ?Sized
Philip Herron [Tue, 18 Jul 2023 16:46:08 +0000 (17:46 +0100)] 
gccrs: Begin enforcing Sized properly and support anti traits like ?Sized

Sized is implicitly applied to every generic type parameter apart from the
implicit Self type parameter on traits, as that would cause a recursive
bound and would make Traits unable to be appied to unsized types.

In order to keep everything happy this means we also need to support the
anti trait bound '?' so that Sized can be removed properly. The full Sized
rules are not completely implemented here. Slice's and Str's are currently
marked as Sized but there is a small regression here that looks like a more
general bug which should be fixed on its own as part of #2443. There is
a big testsuite update here to pull in the Sized lang item.

Note this lays the bound's ground work so we can start supporting Drop
trait properly which needs tackled very soon.

Fixes: #2375
Addresses: #2443

gcc/rust/ChangeLog:

* expand/rust-proc-macro.cc (literal_from_string): update Lexer constructor
(tokenstream_from_string): likewise
* lex/rust-lex.cc (Lexer::Lexer): likewise
* lex/rust-lex.h: pass through Linemap
* parse/rust-cfg-parser.cc (parse_cfg_option): likewise
* rust-session-manager.cc (Session::load_extern_crate): likewise
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait):
dont apply Sized on self
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::get_marker_predicate): new
* typecheck/rust-hir-type-check-base.h: add prototype
* typecheck/rust-hir-type-check-type.cc (TypeResolveGenericParam::Resolve): apply Sized
(TypeResolveGenericParam::visit): likewise
* typecheck/rust-hir-type-check-type.h: update prototypes
* typecheck/rust-typecheck-context.cc: remove bad assertions
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_sized_builtin): cleanup
(TypeCheckBase::get_predicate_from_bound): apply sized rules properly
* util/rust-hir-map.cc (Mappings::lookup_trait_item_lang_item): helpers
(Mappings::get_lang_item): likewise
* util/rust-hir-map.h: likewise
* util/rust-token-converter.cc (from_ident): update lexer ctor
(from_punct): likewise

gcc/testsuite/ChangeLog:

* rust/compile/bounds1.rs: Apply sized trait
* rust/compile/canonical_paths1.rs: likewise
* rust/compile/cast_generics.rs: likewise
* rust/compile/closure_no_type_anno.rs: likewise
* rust/compile/complex_qualified_path_in_expr.rs: likewise
* rust/compile/const-issue1440.rs: likewise
* rust/compile/const_generics_1.rs: likewise
* rust/compile/const_generics_8.rs: likewise
* rust/compile/derive_macro1.rs: likewise
* rust/compile/derive_macro3.rs: likewise
* rust/compile/derive_macro4.rs: likewise
* rust/compile/derive_macro6.rs: likewise
* rust/compile/expected_type_args2.rs: likewise
* rust/compile/expected_type_args3.rs: likewise
* rust/compile/generics1.rs: likewise
* rust/compile/generics11.rs: likewise
* rust/compile/generics12.rs: likewise
* rust/compile/generics2.rs: likewise
* rust/compile/generics3.rs: likewise
* rust/compile/generics4.rs: likewise
* rust/compile/generics6.rs: likewise
* rust/compile/generics7.rs: likewise
* rust/compile/generics8.rs: likewise
* rust/compile/if_let_expr.rs: likewise
* rust/compile/issue-1005.rs: likewise
* rust/compile/issue-1019.rs: likewise
* rust/compile/issue-1031.rs: likewise
* rust/compile/issue-1034.rs: likewise
* rust/compile/issue-1128.rs: likewise
* rust/compile/issue-1129-2.rs: likewise
* rust/compile/issue-1130.rs: likewise
* rust/compile/issue-1131.rs: likewise
* rust/compile/issue-1165.rs: likewise
* rust/compile/issue-1173.rs: likewise
* rust/compile/issue-1235.rs: likewise
* rust/compile/issue-1237.rs: likewise
* rust/compile/issue-1289.rs: likewise
* rust/compile/issue-1383.rs: likewise
* rust/compile/issue-1447.rs: likewise
* rust/compile/issue-1589.rs: likewise
* rust/compile/issue-1725-1.rs: likewise
* rust/compile/issue-1725-2.rs: likewise
* rust/compile/issue-1773.rs: likewise
* rust/compile/issue-1786.rs: likewise
* rust/compile/issue-1893.rs: likewise
* rust/compile/issue-1901.rs: likewise
* rust/compile/issue-1930.rs: likewise
* rust/compile/issue-1981.rs: likewise
* rust/compile/issue-2019-1.rs: likewise
* rust/compile/issue-2019-2.rs: likewise
* rust/compile/issue-2019-3.rs: likewise
* rust/compile/issue-2036.rs: likewise
* rust/compile/issue-2037.rs: likewise
* rust/compile/issue-2070.rs: likewise
* rust/compile/issue-2105.rs: likewise
* rust/compile/issue-2106.rs: likewise
* rust/compile/issue-2135.rs: likewise
* rust/compile/issue-2136-1.rs: likewise
* rust/compile/issue-2136-2.rs: likewise
* rust/compile/issue-2139.rs: likewise
* rust/compile/issue-2142.rs: likewise
* rust/compile/issue-2165.rs: likewise
* rust/compile/issue-2166.rs: likewise
* rust/compile/issue-2190-1.rs: likewise
* rust/compile/issue-2190-2.rs: likewise
* rust/compile/issue-2195.rs: likewise
* rust/compile/issue-2238.rs: likewise
* rust/compile/issue-2304.rs: likewise
* rust/compile/issue-850.rs: likewise
* rust/compile/issue-855.rs: likewise
* rust/compile/issue-925.rs: likewise
* rust/compile/macro-issue1400.rs: likewise
* rust/compile/macro20.rs: likewise
* rust/compile/macro23.rs: likewise
* rust/compile/macro40.rs: likewise
* rust/compile/macro54.rs: likewise
* rust/compile/name_resolution2.rs: likewise
* rust/compile/name_resolution4.rs: likewise
* rust/compile/nested_generic.rs: likewise
* rust/compile/parse_associated_type_as_generic_arg.rs: likewise
* rust/compile/parse_associated_type_as_generic_arg2.rs: likewise
* rust/compile/parse_associated_type_as_generic_arg3.rs: likewise
* rust/compile/parse_complex_generic_application.rs: likewise
* rust/compile/parse_complex_generic_application2.rs: likewise
* rust/compile/path_as_generic_arg.rs: likewise
* rust/compile/privacy4.rs: likewise
* rust/compile/privacy6.rs: likewise
* rust/compile/sizeof-stray-infer-var-bug.rs: likewise
* rust/compile/stmt_with_block_dot.rs: likewise
* rust/compile/torture/associated_types1.rs: likewise
* rust/compile/torture/forward_decl_5.rs: likewise
* rust/compile/torture/generics1.rs: likewise
* rust/compile/torture/generics10.rs: likewise
* rust/compile/torture/generics11.rs: likewise
* rust/compile/torture/generics12.rs: likewise
* rust/compile/torture/generics13.rs: likewise
* rust/compile/torture/generics14.rs: likewise
* rust/compile/torture/generics15.rs: likewise
* rust/compile/torture/generics16.rs: likewise
* rust/compile/torture/generics17.rs: likewise
* rust/compile/torture/generics18.rs: likewise
* rust/compile/torture/generics19.rs: likewise
* rust/compile/torture/generics2.rs: likewise
* rust/compile/torture/generics20.rs: likewise
* rust/compile/torture/generics21.rs: likewise
* rust/compile/torture/generics22.rs: likewise
* rust/compile/torture/generics23.rs: likewise
* rust/compile/torture/generics24.rs: likewise
* rust/compile/torture/generics25.rs: likewise
* rust/compile/torture/generics26.rs: likewise
* rust/compile/torture/generics27.rs: likewise
* rust/compile/torture/generics28.rs: likewise
* rust/compile/torture/generics29.rs: likewise
* rust/compile/torture/generics3.rs: likewise
* rust/compile/torture/generics30.rs: likewise
* rust/compile/torture/generics31.rs: likewise
* rust/compile/torture/generics32.rs: likewise
* rust/compile/torture/generics4.rs: likewise
* rust/compile/torture/generics5.rs: likewise
* rust/compile/torture/generics6.rs: likewise
* rust/compile/torture/generics7.rs: likewise
* rust/compile/torture/generics8.rs: likewise
* rust/compile/torture/generics9.rs: likewise
* rust/compile/torture/intrinsics-2.rs: likewise
* rust/compile/torture/intrinsics-6.rs: likewise
* rust/compile/torture/intrinsics-7.rs: likewise
* rust/compile/torture/intrinsics-8.rs: likewise
* rust/compile/torture/issue-1024.rs: likewise
* rust/compile/torture/issue-1075.rs: likewise
* rust/compile/torture/issue-1432.rs: likewise
* rust/compile/torture/issue-1555.rs: likewise
* rust/compile/torture/issue-368.rs: likewise
* rust/compile/torture/issue-808.rs: likewise
* rust/compile/torture/issue-862.rs: likewise
* rust/compile/torture/issue-893-2.rs: likewise
* rust/compile/torture/issue-893.rs: likewise
* rust/compile/torture/must_use2.rs: likewise
* rust/compile/torture/nested_fn2.rs: likewise
* rust/compile/torture/phantom_data.rs: likewise
* rust/compile/torture/range-lang-item1.rs: likewise
* rust/compile/torture/traits1.rs: likewise
* rust/compile/torture/traits11.rs: likewise
* rust/compile/torture/traits12.rs: likewise
* rust/compile/torture/traits13.rs: likewise
* rust/compile/torture/traits14.rs: likewise
* rust/compile/torture/traits15.rs: likewise
* rust/compile/torture/traits16.rs: likewise
* rust/compile/torture/traits17.rs: likewise
* rust/compile/torture/traits18.rs: likewise
* rust/compile/torture/traits19.rs: likewise
* rust/compile/torture/traits2.rs: likewise
* rust/compile/torture/traits3.rs: likewise
* rust/compile/torture/traits4.rs: likewise
* rust/compile/torture/traits5.rs: likewise
* rust/compile/torture/traits6.rs: likewise
* rust/compile/torture/traits7.rs: likewise
* rust/compile/torture/traits8.rs: likewise
* rust/compile/torture/traits9.rs: likewise
* rust/compile/torture/transmute-size-check-1.rs: likewise
* rust/compile/torture/transmute1.rs: likewise
* rust/compile/torture/uninit-intrinsic-1.rs: likewise
* rust/compile/torture/utf8_identifiers.rs: likewise
* rust/compile/traits1.rs: likewise
* rust/compile/traits10.rs: likewise
* rust/compile/traits11.rs: likewise
* rust/compile/traits12.rs: likewise
* rust/compile/traits2.rs: likewise
* rust/compile/traits3.rs: likewise
* rust/compile/traits4.rs: likewise
* rust/compile/traits5.rs: likewise
* rust/compile/traits6.rs: likewise
* rust/compile/traits7.rs: likewise
* rust/compile/traits8.rs: likewise
* rust/compile/traits9.rs: likewise
* rust/compile/type-bindings1.rs: likewise
* rust/compile/unconstrained_type_param.rs: likewise
* rust/compile/unsafe10.rs: likewise
* rust/execute/torture/closure1.rs: likewise
* rust/execute/torture/closure2.rs: likewise
* rust/execute/torture/closure3.rs: likewise
* rust/execute/torture/closure4.rs: likewise
* rust/execute/torture/coercion1.rs: likewise
* rust/execute/torture/coercion2.rs: likewise
* rust/execute/torture/coercion3.rs: likewise
* rust/execute/torture/copy_nonoverlapping1.rs: likewise
* rust/execute/torture/derive_macro1.rs: likewise
* rust/execute/torture/derive_macro3.rs: likewise
* rust/execute/torture/derive_macro4.rs: likewise
* rust/execute/torture/index1.rs: likewise
* rust/execute/torture/issue-1120.rs: likewise
* rust/execute/torture/issue-1133.rs: likewise
* rust/execute/torture/issue-1198.rs: likewise
* rust/execute/torture/issue-1232.rs: likewise
* rust/execute/torture/issue-1249.rs: likewise
* rust/execute/torture/issue-1436.rs: likewise
* rust/execute/torture/issue-1496.rs: likewise
* rust/execute/torture/issue-1720-2.rs: likewise
* rust/execute/torture/issue-1720.rs: likewise
* rust/execute/torture/issue-2052.rs: likewise
* rust/execute/torture/issue-2179.rs: likewise
* rust/execute/torture/issue-2180.rs: likewise
* rust/execute/torture/issue-2236.rs: likewise
* rust/execute/torture/issue-647.rs: likewise
* rust/execute/torture/issue-845.rs: likewise
* rust/execute/torture/issue-851.rs: likewise
* rust/execute/torture/issue-858.rs: likewise
* rust/execute/torture/macros23.rs: likewise
* rust/execute/torture/macros28.rs: likewise
* rust/execute/torture/method2.rs: likewise
* rust/execute/torture/method3.rs: likewise
* rust/execute/torture/method4.rs: likewise
* rust/execute/torture/operator_overload_1.rs: likewise
* rust/execute/torture/operator_overload_10.rs: likewise
* rust/execute/torture/operator_overload_11.rs: likewise
* rust/execute/torture/operator_overload_12.rs: likewise
* rust/execute/torture/operator_overload_2.rs: likewise
* rust/execute/torture/operator_overload_3.rs: likewise
* rust/execute/torture/operator_overload_4.rs: likewise
* rust/execute/torture/operator_overload_5.rs: likewise
* rust/execute/torture/operator_overload_6.rs: likewise
* rust/execute/torture/operator_overload_7.rs: likewise
* rust/execute/torture/operator_overload_8.rs: likewise
* rust/execute/torture/operator_overload_9.rs: likewise
* rust/execute/torture/prefetch_data.rs: likewise
* rust/execute/torture/ref-pattern2.rs: likewise
* rust/execute/torture/slice-magic.rs: likewise
* rust/execute/torture/slice-magic2.rs: likewise
* rust/execute/torture/slice1.rs: likewise
* rust/execute/torture/str-layout1.rs: likewise
* rust/execute/torture/trait1.rs: likewise
* rust/execute/torture/trait10.rs: likewise
* rust/execute/torture/trait11.rs: likewise
* rust/execute/torture/trait12.rs: likewise
* rust/execute/torture/trait13.rs: likewise
* rust/execute/torture/trait2.rs: likewise
* rust/execute/torture/trait3.rs: likewise
* rust/execute/torture/trait4.rs: likewise
* rust/execute/torture/trait5.rs: likewise
* rust/execute/torture/trait6.rs: likewise
* rust/execute/torture/trait7.rs: likewise
* rust/execute/torture/trait8.rs: likewise
* rust/execute/torture/trait9.rs: likewise
* rust/execute/torture/transmute1.rs: likewise
* rust/execute/torture/wrapping_op1.rs: likewise
* rust/execute/torture/wrapping_op2.rs: likewise
* rust/link/generic_function_0.rs: likewise
* rust/link/generic_function_1.rs: likewise
* rust/compile/issue-2375.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Track polarity in type bound predicate
Philip Herron [Tue, 18 Jul 2023 15:07:32 +0000 (16:07 +0100)] 
gccrs: Track polarity in type bound predicate

Addresses #2443

gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc: track regular polarity
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): likewise
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): likewise
* typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): likewise
(TypeBoundPredicate::TypeBoundPredicate): update ctor
(TypeBoundPredicate::operator=): update copy assignment ctor
(TypeBoundPredicate::error): update error node
* typecheck/rust-tyty.h: add polarity field to predicate

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Track trait bound polarity properly
Philip Herron [Tue, 18 Jul 2023 11:12:22 +0000 (12:12 +0100)] 
gccrs: Track trait bound polarity properly

Trait bounds can have three forms in Rust the regular trait bound, '!' the
negative trait bound to enforice that this trait must not be implmented and
'?' the anti trait bound to remove this bound. This patch extends our
Polarity enum to include the Anti trait bound and updates the HIR lowering
code to track this properly.

Addresses #2443

gcc/rust/ChangeLog:

* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): use new BoundPolarity enum
* hir/rust-ast-lower-type.cc (ASTLoweringTypeBounds::visit): likewise
* hir/rust-hir-dump.cc (BoundPolarityString): new helper
(Dump::visit): update hir dump
* hir/tree/rust-hir-item.h (class ImplBlock): likewise
* hir/tree/rust-hir-type.h (class TraitBound): likewise
* hir/tree/rust-hir.cc (TraitBound::as_string): fix as string
* util/rust-common.h (enum Polarity): add new anti bound
(enum BoundPolarity): likewise
* util/rust-hir-map.cc (Mappings::Mappings): update naming

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Move Gcc_backend declaration to header file
Owen Avery [Fri, 14 Jul 2023 19:39:14 +0000 (15:39 -0400)] 
gccrs: Move Gcc_backend declaration to header file

gcc/rust/ChangeLog:

* rust-backend.h: Include "rust-gcc.h".
(class Gcc_backend): Move to ...
* rust-gcc.cc (class Gcc_backend): ... here.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: fix ICE when we have unimplemented/invalid trait items
Philip Herron [Sat, 29 Jul 2023 16:33:47 +0000 (17:33 +0100)] 
gccrs: fix ICE when we have unimplemented/invalid trait items

When the resulting trait item is in an error state this means the
underlying fields will be null.

Fixes #2478

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-item.cc: add is_error check

gcc/testsuite/ChangeLog:

* rust/compile/non_member_const.rs: add missing error message
* rust/compile/issue-2478.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Add function for Unicode NFC normalization
Raiki Tamura [Fri, 14 Jul 2023 05:45:34 +0000 (14:45 +0900)] 
gccrs: Add function for Unicode NFC normalization

gcc/rust/ChangeLog:

* Make-lang.in: Add rust-unicode.o
* rust-lang.cc (run_rust_tests): Add test.
* rust-system.h: Include <array>
* util/make-rust-unicode.py: Generater of rust-unicode-data.h.
* util/rust-unicode-data.h: Auto-generated file.
* util/rust-unicode.cc: New file.
* util/rust-unicode.h: New file.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
18 months agogccrs: error codes: Add rust_error_codes.def, refactor ErrorCode enum
Arthur Cohen [Fri, 28 Jul 2023 12:33:34 +0000 (14:33 +0200)] 
gccrs: error codes: Add rust_error_codes.def, refactor ErrorCode enum

gcc/rust/ChangeLog:

* rust-diagnostics.cc: Rework `make_description` and `make_url` functions.
* rust-diagnostics.h: Specify ErrorCode's underlying type,
remove error_codes_strings table.
* rust_error_codes.def: New file.

18 months agogccrs: Remove Location typedef
Owen Avery [Tue, 11 Jul 2023 00:15:19 +0000 (20:15 -0400)] 
gccrs: Remove Location typedef

gcc/rust/ChangeLog:

* rust-location.h (typedef Location): Remove.

* expand/rust-proc-macro.cc
(register_callback): Replace Location constructor with UNDEF_LOCATION.

* ast/rust-ast-collector.h: Replace Location with location_t.
* checks/errors/privacy/rust-privacy-reporter.cc: Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
* checks/errors/privacy/rust-pub-restricted-visitor.cc: Likewise.
* checks/errors/privacy/rust-pub-restricted-visitor.h: Likewise.
* checks/errors/rust-feature-gate.cc: Likewise.
* checks/errors/rust-feature-gate.h: Likewise.
* metadata/rust-imports.h: Likewise.
* resolve/rust-ast-resolve-path.h: Likewise.
* resolve/rust-name-resolver.h: Likewise.
* rust-backend.h: Likewise.
* rust-diagnostics.h: Likewise.
* rust-gcc.cc: Likewise.
* rust-linemap.h: Likewise.
* util/rust-attributes.cc: Likewise.
* util/rust-hir-map.cc: Likewise.
* util/rust-hir-map.h: Likewise.
* util/rust-token-converter.cc: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Replace usages of Location with location_t in typechecking
Owen Avery [Tue, 11 Jul 2023 02:19:51 +0000 (22:19 -0400)] 
gccrs: Replace usages of Location with location_t in typechecking

gcc/rust/ChangeLog:

* typecheck/rust-autoderef.cc: Replace Location with location_t.
* typecheck/rust-coercion.cc: Likewise.
* typecheck/rust-coercion.h: Likewise.
* typecheck/rust-hir-path-probe.h: Likewise.
* typecheck/rust-hir-trait-reference.cc: Likewise.
* typecheck/rust-hir-trait-resolve.cc: Likewise.
* typecheck/rust-hir-type-check-base.cc: Likewise.
* typecheck/rust-hir-type-check-expr.cc: Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.
* typecheck/rust-hir-type-check-implitem.cc: Likewise.
* typecheck/rust-hir-type-check-item.cc: Likewise.
* typecheck/rust-hir-type-check-path.cc: Likewise.
* typecheck/rust-hir-type-check-pattern.cc: Likewise.
* typecheck/rust-hir-type-check-stmt.cc: Likewise.
* typecheck/rust-hir-type-check-struct.cc: Likewise.
* typecheck/rust-hir-type-check-type.cc: Likewise.
* typecheck/rust-hir-type-check-type.h: Likewise.
* typecheck/rust-type-util.cc: Likewise.
* typecheck/rust-type-util.h: Likewise.
* typecheck/rust-tyty-bounds.cc: Likewise.
* typecheck/rust-tyty-call.cc: Likewise.
* typecheck/rust-tyty-call.h: Likewise.
* typecheck/rust-tyty-cmp.h: Likewise.
* typecheck/rust-tyty-subst.cc: Likewise.
* typecheck/rust-tyty-subst.h: Likewise.
* typecheck/rust-tyty.cc: Likewise.

18 months agogccrs: [E0571] break with argument in non-loop loop
Muhammad Mahad [Thu, 27 Jul 2023 11:36:09 +0000 (16:36 +0500)] 
gccrs: [E0571] break with argument in non-loop loop

Refactored error message similiar to rustc
& called error function.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
refactored error message & called error function.

gcc/testsuite/ChangeLog:

* rust/compile/break2.rs: Modified file to pass test case.
* rust/compile/break_with_value_inside_loop.rs: New test.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: proc_macro: Add literal_from_string callback
Pierre-Emmanuel Patry [Thu, 27 Jul 2023 14:21:25 +0000 (16:21 +0200)] 
gccrs: proc_macro: Add literal_from_string callback

The function to get a literal from a string missed an implementation.
It did require a conversion function to achieve it, now that callback
system has been merged this function can be easily implemented.

gcc/rust/ChangeLog:

* expand/rust-proc-macro.cc (literal_from_string): Add callback
function.
(load_macros_array): Likewise.

libgrust/ChangeLog:

* libproc_macro/literal.cc (Literal__from_string): Add
implementation with call to constructor.
(Literal::make_literal): Add new constructor which calls the
callback.
* libproc_macro/literal.h: Add new constructor's
prototype.
* libproc_macro/proc_macro.cc (bridge_is_available):
Change symbol name to match convention.
* libproc_macro/registration.h: Add lit_from_str
symbol.
* libproc_macro/tokenstream.cc (TokenStream::make_tokenstream):
Change symbol name to disambiguate with literal from string.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: converter: Move literal conversion out
Pierre-Emmanuel Patry [Thu, 27 Jul 2023 13:57:07 +0000 (15:57 +0200)] 
gccrs: converter: Move literal conversion out

The literal conversion code could be used for the literal_from_string
callback, this means we should move it out of the function in it's own
function. This involves a new switch, which is quite sad but we're not
yet at a performance profiling phase, there may be lower hanging fruits.

gcc/rust/ChangeLog:

* util/rust-token-converter.cc (handle_suffix): Rework function
to make it work with the new literal conversion function.
(convert_literal): Add a new function to convert to a proc macro
literal from a literal tokenptr. The function will abort if the
pointer does not point to a literal.
(convert): Add call to convert literal for every literal case.
* util/rust-token-converter.h (convert_literal): Add public
prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Move callbacked function in a new namespace
Pierre-Emmanuel Patry [Thu, 27 Jul 2023 13:22:48 +0000 (15:22 +0200)] 
gccrs: Move callbacked function in a new namespace

Move the function registered as a callback in a new anonymous namespace
in order to group every callback in the future under the same namespace.

gcc/rust/ChangeLog:

* expand/rust-proc-macro.cc: Remove static modifier and move to
an anonymous namespace.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: New Error Code Framework
Muhammad Mahad [Thu, 27 Jul 2023 16:36:55 +0000 (21:36 +0500)] 
gccrs: New Error Code Framework

Updated ErrorCode struct to enum class to enforce proper
error codes, similiar to rustc. For converting the enum
to the respective error code, I used a map and updated
make_description & make_url function accordingly and
also removes the memory leak from the previous frame-
work. Also, added macro to safely convert the enum
number to string.

gcc/rust/ChangeLog:

* backend/rust-compile-intrinsic.cc (Intrinsics::compile):
Formatted according to enum class.
* checks/errors/rust-feature-gate.cc (FeatureGate::gate): likewise.
* checks/errors/rust-unsafe-checker.cc (check_unsafe_call): likewise.
* hir/rust-ast-lower-base.cc (struct_field_name_exists): likewise.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): likewise.
* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path):
likewise.
* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::go): likewise.
(PatternDeclaration::add_new_binding): likewise.
* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): likewise.
* resolve/rust-ast-verify-assignee.h: likewise.
* rust-diagnostics.cc: updated make_desc & url function for enum class.
* rust-diagnostics.h (struct ErrorCode): removed struct to switch to enum.
(enum class): Switched from errorcode struct to enum class.
(XSTR): Macro for converting enum to string.
(STR): macro Used by XSTR for converting to string.
(ERROR_CODE): macro used by map for check.
(TABLE_TO_MAP): macro used by map for check
* typecheck/rust-casts.cc (TypeCastRules::emit_cast_error):
Formatted according to enum class.
* typecheck/rust-hir-path-probe.h: likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit):
likewise.
(TypeCheckImplItemWithTrait::visit): likewise.
* typecheck/rust-hir-type-check-item.cc: likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): likewise.
(emit_invalid_field_error): likewise.
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve): likewise.
* typecheck/rust-tyty-call.cc (emit_unexpected_argument_error): likewise.
(TypeCheckCallExpr::visit): likewise.
* typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args):
likewise.
* typecheck/rust-tyty.cc (BaseType::bounds_compatible): likewise.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
18 months agogccrs: Add multiple tests for non root proc macro
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 10:47:57 +0000 (12:47 +0200)] 
gccrs: Add multiple tests for non root proc macro

Add multiple tests to prevent regressions on procedural macros errors
when one is declared outside of the crate's top level.

gcc/testsuite/ChangeLog:

* rust/compile/proc_macro_attribute_non_root_function.rs: New test.
* rust/compile/proc_macro_attribute_non_root_method.rs: New test.
* rust/compile/proc_macro_attribute_non_root_module.rs: New test.
* rust/compile/proc_macro_derive_non_root_function.rs: New test.
* rust/compile/proc_macro_derive_non_root_method.rs: New test.
* rust/compile/proc_macro_derive_non_root_module.rs: New test.
* rust/compile/proc_macro_non_root_function.rs: New test.
* rust/compile/proc_macro_non_root_method.rs: New test.
* rust/compile/proc_macro_non_root_module.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Check proc_macro attributes on non root functions
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 10:16:12 +0000 (12:16 +0200)] 
gccrs: Check proc_macro attributes on non root functions

Check proc_macro, proc_macro_attribute and proc_macro_derive attributes
on non root functions, emit an error when one is found.

gcc/rust/ChangeLog:

* util/rust-attributes.cc (check_proc_macro_non_root): Add
function to emit this specific error.
(AttributeChecker::visit): Modify visitor to propagate to some
containers that were not handled correctly.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Replace Location with location_t in unnamed function parameters
Owen Avery [Mon, 10 Jul 2023 23:39:02 +0000 (19:39 -0400)] 
gccrs: Replace Location with location_t in unnamed function parameters

gcc/rust/ChangeLog:

* backend/rust-compile-base.h: Replace Location with location_t.
* metadata/rust-imports.h: Likewise.
* resolve/rust-name-resolver.cc: Likewise.
* resolve/rust-name-resolver.h: Likewise.
* rust-backend.h: Likewise.
* rust-gcc.cc: Likewise.
* rust-gcc.h: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: proc_macro: Remove useless typedef
Pierre-Emmanuel Patry [Thu, 27 Jul 2023 09:58:56 +0000 (11:58 +0200)] 
gccrs: proc_macro: Remove useless typedef

Initially a typedef was used to easily get the callback function pointer
type. Since this type has changed to a simpler well defined type, this
using declaration has no more purpose.

libgrust/ChangeLog:

* libproc_macro/proc_macro.cc: Remove type alias.
* libproc_macro/registration.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: proc_macro: Delete unused prototype
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 16:05:42 +0000 (18:05 +0200)] 
gccrs: proc_macro: Delete unused prototype

This function prototype was forgotten when the function was deleted.

libgrust/ChangeLog:

* libproc_macro/proc_macro.h (proc_macro_register_from_str):
Remove rogue function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: proc_macro: Remode function indirection
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 15:44:50 +0000 (17:44 +0200)] 
gccrs: proc_macro: Remode function indirection

There was no need to register a function when the value could be
registered directly.

gcc/rust/ChangeLog:

* expand/rust-proc-macro.cc (available): Remove function.
(load_macros_array): There was no need for an indirection here.

libgrust/ChangeLog:

* libproc_macro/proc_macro.cc (not_available): Remove
function.
* libproc_macro/proc_macro.h (not_available): Remove
function prototype.
* libproc_macro/registration.h: Change symbol type.
* libproc_macro/bridge.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: proc_macro: Add is_available function
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 15:00:57 +0000 (17:00 +0200)] 
gccrs: proc_macro: Add is_available function

Add is_available function to the C++ library.

libgrust/ChangeLog:

* libproc_macro/proc_macro.cc (bridge_is_available):
Add bridge function.
* libproc_macro/proc_macro.h (bridge_is_available):
Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: proc_macro: Add is_available callback
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 14:48:37 +0000 (16:48 +0200)] 
gccrs: proc_macro: Add is_available callback

Add a callback from gcc to determine wether the bridge is available or
not.

gcc/rust/ChangeLog:

* expand/rust-proc-macro.cc (available): Add symbol
registration.
(load_macros_array): Likewise.

libgrust/ChangeLog:

* libproc_macro/proc_macro.cc (not_available): Add a
function to express bridge unavailability.
* libproc_macro/proc_macro.h (not_available): Likewise.
* libproc_macro/registration.h: Add symbol type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: proc_macro: Rename from_string callback symbol
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 14:44:59 +0000 (16:44 +0200)] 
gccrs: proc_macro: Rename from_string callback symbol

The symbol had a different convention from rust standard naming
convention (?) hence the change before adding new callback.

gcc/rust/ChangeLog:

* expand/rust-proc-macro.cc (load_macros_array): Symbol rename.

libgrust/ChangeLog:

* libproc_macro/proc_macro.cc (Procmacro::make_bang):
Change symbol name.
* libproc_macro/registration.h: Likewise.
* libproc_macro/tokenstream.cc (TokenStream::make_tokenstream): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: proc_macro: Refactor attribute search
Pierre-Emmanuel Patry [Thu, 27 Jul 2023 11:11:08 +0000 (13:11 +0200)] 
gccrs: proc_macro: Refactor attribute search

Refactor attribute search with early return. Also fix the optional
building an object with it's default empty constructor by explicitely
using tl::null_opt.

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc (find_proc_macro_attribute):
Refactor the function to be safer and more efficient.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: privacy: Refactor proc macro privacy check
Pierre-Emmanuel Patry [Thu, 20 Jul 2023 11:40:35 +0000 (13:40 +0200)] 
gccrs: privacy: Refactor proc macro privacy check

Refactor proc macro specific privacy check in multiple shorter
functions.

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc (find_proc_macro_attribute):
Add a new function to find a potential proc macro type
attribute on a given item.
(proc_macro_privacy_check): Move all proc macro privacy check in
their own function to avoid cluttering the usual privacy check.
(PrivacyReporter::go): Add call to newly created proc macro
privacy check function.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: testsuite: Add tests for pub items in proc_macros
Pierre-Emmanuel Patry [Thu, 20 Jul 2023 11:06:32 +0000 (13:06 +0200)] 
gccrs: testsuite: Add tests for pub items in proc_macros

Crates of type 'proc-macro' should not have any other pub member than
procedural macros. These new test will avoid regression on error
messages in such sitation.

gcc/testsuite/ChangeLog:

* rust/compile/proc_macro_pub_function.rs: New test.
* rust/compile/proc_macro_pub_module.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: testsuite: Replace dg-excess-errors with dg-error
Pierre-Emmanuel Patry [Thu, 20 Jul 2023 10:52:50 +0000 (12:52 +0200)] 
gccrs: testsuite: Replace dg-excess-errors with dg-error

Some test were using dg-excess-errors instead of dg-error, this is now
fixed.

gcc/testsuite/ChangeLog:

* rust/compile/proc_macro_attribute_crate_type.rs: Replace
dg-excess-errors with dg-error and fix the line so the test
can pass.
* rust/compile/proc_macro_crate_type.rs: Likewise.
* rust/compile/proc_macro_derive_crate_type.rs: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: privacy: Add tests for private proc macro error
Pierre-Emmanuel Patry [Thu, 20 Jul 2023 10:37:47 +0000 (12:37 +0200)] 
gccrs: privacy: Add tests for private proc macro error

Add some tests to prevent regression on private procedural macros error
messages.

gcc/testsuite/ChangeLog:

* rust/compile/proc_macro_attribute_private.rs: New test.
* rust/compile/proc_macro_derive_private.rs: New test.
* rust/compile/proc_macro_private.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: proc macro: Add privacy check
Pierre-Emmanuel Patry [Tue, 18 Jul 2023 15:36:11 +0000 (17:36 +0200)] 
gccrs: proc macro: Add privacy check

Proc macro crates cannot have any public function but proc macros. Proc
macros should be public.

gcc/rust/ChangeLog:

* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::go):
Add visibility verification.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add tests for non function proc_macro_derive
Pierre-Emmanuel Patry [Fri, 21 Jul 2023 12:18:12 +0000 (14:18 +0200)] 
gccrs: Add tests for non function proc_macro_derive

Add a bunch of test cases to avoid regressions on proc_macro_derive
attribute errors when placed on any non function item.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Add tests for non function proc_macro_attribute
Pierre-Emmanuel Patry [Fri, 21 Jul 2023 12:03:10 +0000 (14:03 +0200)] 
gccrs: Add tests for non function proc_macro_attribute

Add a bunch of test case to avoid regressions on proc_macro_attribute
attribute error messages.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>