This new test highlight the fix of #2656.
gcc/testsuite/ChangeLog:
* rust/compile/closure_in_closure.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
The parser was unable to process as closure inside a closure because the
lexer could not differentiate an OR from two PIPE tokens.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_closure_expr_pratt): Fix
closure parsing function to handle consecutive parameter lists.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Add a new test to highlight the fix introduced for #2653.
gcc/testsuite/ChangeLog:
* rust/compile/macro-issue2653.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
The previous follow set rules did not allow PATH fragment, changing this
allow gccrs to accept more valid rust macros.
gcc/rust/ChangeLog:
* ast/rust-macro.h: Add PATH fragment to follow set restrictions.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Macro rules named macro_rules may cause some problems if not handled
correctly. This new test ensure we always compile those macros named
macro_rules correctly as well as other macro definitions.
gcc/testsuite/ChangeLog:
* rust/compile/macro57.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This new test highlight the fix for #2651.
gcc/testsuite/ChangeLog:
* rust/compile/macro_rules_macro_rules.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Change the constraints around macro rules declaration in order to allow
macro_rules named macro as well as tighter constraint around macro rules
definitions.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::is_macro_rules_def): Add a function
that checks tokens given by the lexer represents an accurate macro
definition. This will reduce code duplication.
(Parser::parse_item): Replace condition with call to new checking
function.
(Parser::parse_stmt): Likewise.
* parse/rust-parse.h: Add function prototype for is_macro_rules_def.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Add a new test to highlight fix of #2658.
gcc/testsuite/ChangeLog:
* rust/compile/while_break_expr.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Add a new test to highlight the fix made for #2660.
gcc/testsuite/ChangeLog:
* rust/compile/range_from_expr_for_loop.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Those ranges were looking for a curly brace after the brace, leading
to an error when using range from expr in for loops.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_expr): Fix range from expr.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This test highlight the fix required for #2655.
gcc/testsuite/ChangeLog:
* rust/compile/parse_item_default_macro.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
The parser was too agressive and did reject any line beginning with
default even if this was a macro call.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_item): Relax constraints
around default identifier at item scope to accept "default" macros.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
New regression test to highlight behavior of #2652.
gcc/testsuite/ChangeLog:
* rust/compile/parse_generic_path_expr.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
When a token was identified as bit left shift it slipped through the
parser and resulted in an error.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_path_expr_segment): Accept
left shift tokens in order to let generic parsing function split the
token.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This new test highlight the fix for issue #2657.
gcc/testsuite/ChangeLog:
* rust/compile/match_break.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Add a comma as an expr delimiter, this will allow correct parsing of
match arm expressions.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_expr): Add comma delimiter.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Add a new test to highlight fix for #2648.
gcc/testsuite/ChangeLog:
* rust/compile/parse_pub_unit_type.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Public unit types where not parsed correctly due to visibility specifiers
within parenthesis. Fixes#2648.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_visibility): Relax constraints
over public visibility return condition in order to accept pub unit
types.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Associate each subclass with its kind and create cast/match+cast
methods.
gcc/rust/ChangeLog:
* typecheck/rust-tyty.cc (InferType::InferType): Use static constant for kind information.
(ErrorType::ErrorType): Use static constant for kind information.
(TupleType::TupleType): Use static constant for kind information.
(BoolType::BoolType): Use static constant for kind information.
(IntType::IntType): Use static constant for kind information.
(UintType::UintType): Use static constant for kind information.
(FloatType::FloatType): Use static constant for kind information.
(USizeType::USizeType): Use static constant for kind information.
(ISizeType::ISizeType): Use static constant for kind information.
(CharType::CharType): Use static constant for kind information.
(ReferenceType::ReferenceType): Use static constant for kind information.
(PointerType::PointerType): Use static constant for kind information.
(ParamType::ParamType): Use static constant for kind information.
(StrType::StrType): Use static constant for kind information.
(NeverType::NeverType): Use static constant for kind information.
(PlaceholderType::PlaceholderType): Use static constant for kind information.
* typecheck/rust-tyty.h: Add static kind information to all TyTy classes.
Create safe cast and check methods.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
The function parsing type param bounds had a problem with scope
resolution opening token.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_type_param_bound): Add missing
case for lifetime switch.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This will ensure an accurate representation of the token. Also update the
as_string function to represent accurately scope resolution tokens.
gcc/rust/ChangeLog:
* lex/rust-token.cc (Token::as_string): Update function to output scope
resolution tokens correctly.
* parse/rust-parse-impl.h (Parser::parse_generic_param): Change call to
as_string.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ChangeLog:
* backend/rust-compile-context.h: Modify declaration.
* backend/rust-mangle.cc (struct V0Path): New struct.
(v0_path): New function.
(legacy_mangle_name): Take Context as argument.
(v0_numeric_prefix): Fix type strings.
(v0_complex_type_prefix): New function.
(v0_add_integer_62): Deleted
(v0_integer_62): New function.
(v0_add_opt_integer_62): Deleted.
(v0_opt_integer_62): New function.
(v0_add_disambiguator): Deleted.
(v0_disambiguator): New function.
(v0_type_prefix): Support more types.
(v0_generic_args): New function.
(v0_add_identifier): Deleted.
(v0_identifier): New function.
(v0_type_path): New function.
(v0_function_path): New function.
(v0_scope_path): New function.
(v0_crate_path): New function.
(v0_inherent_or_trait_impl_path): New function.
(v0_mangle_item): Use v0_path.
(Mangler::mangle_item): Take Context as argument.
* backend/rust-mangle.h (class Context): Add forward declaration.
* hir/tree/rust-hir-item.h: Fix include.
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Fix a typo and merge 2 if clauses using the same condition.
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): Merge 2 if clauses.
* backend/rust-compile-extern.h: Fix typo in comment.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
There was a mismatch between a manual discriminant test and the static cast.
gcc/rust/ChangeLog:
* backend/rust-compile.cc (HIRCompileBase::coercion_site1): Fix wrong cast
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
When an error was emitted during the cfg strip pass by the crate loader,
it was ignored and the error state propagated until another pass
(name resolver).
gcc/rust/ChangeLog:
* rust-session-manager.cc (Session::expansion): Add early break on
error.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ChangeLog:
* util/rust-canonical-path.h: Add new segment kind for inherent impl.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Use it.
* resolve/rust-ast-resolve-toplevel.h: Use it.
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Add simple debug wrapper to dump HIR nodes on stderr.
Similar to what we already have for AST.
gcc/rust/ChangeLog:
* hir/rust-hir-dump.cc (Dump::debug): New.
(debug): New.
* hir/rust-hir-dump.h (debug): New.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
There are some certain rust types must be cast before
passing them to a variadic function, because of arcane
ABI rules dictated by the C standard. To fix the error,
cast the value to the type specified by the error message.
gcc/rust/ChangeLog:
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit):
Added ErrorCode & more fixit hints.
gcc/testsuite/ChangeLog:
* rust/compile/variadic.rs: Added new checks.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
... also made `copy_nonoverlapping` handler more generic
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc: add `copy`
intrinsics and make `copy_nonoverlapping` handler more generic
Signed-off-by: Zixing Liu <liushuyu011@gmail.com>