Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto trait AST validation #2749

Merged
merged 5 commits into from
Nov 21, 2023
Merged

Conversation

P-E-P
Copy link
Member

@P-E-P P-E-P commented Nov 20, 2023

Some constructs are forbidden in rust with auto traits such as generic arguments and super traits. Rust code containing such construct should be rejected and the compiler should emit an error.

Generic parameters are not allowed on auto traits, the compiler should
emit an error.

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
	check for generics on auto traits.
	* checks/errors/rust-ast-validation.h: Add visit function prototype.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Generics are forbidden on auto traits and an error should be emitted.
This commit highlight this behavior.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
@P-E-P P-E-P added this to the GCC 14.1 release milestone Nov 20, 2023
@P-E-P P-E-P self-assigned this Nov 20, 2023
Reject auto traits containing a super trait bound during AST validation
pass.

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Reject
	auto traits with super traits.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Add a new regression test to highlight the error behavior with a super
trait on an auto trait.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Reject rust code with associated items on auto traits.

gcc/rust/ChangeLog:

	* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add auto
	trait associated item check in AST validation pass.
	* parse/rust-parse-impl.h: Remove old error emission done during
	parsing pass.

gcc/testsuite/ChangeLog:

	* rust/compile/auto_trait_invalid.rs: Update old test with updated
	error message.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
@P-E-P P-E-P force-pushed the auto-trait-validation branch from 2a995c2 to cf6dcc8 Compare November 20, 2023 14:27
@P-E-P P-E-P marked this pull request as ready for review November 20, 2023 14:39
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great. note that auto traits might get removed from Rust entirely since they're only available in very specific cases, and I believe there is ongoing discussion to only allow them for compiler builtins such as Send, Sync and Sized

@P-E-P P-E-P added this pull request to the merge queue Nov 21, 2023
Merged via the queue into Rust-GCC:master with commit b1b0de6 Nov 21, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants