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>
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>
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.
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.
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>
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>
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>
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.
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.
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.
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>