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

Unsafe module #2752

Merged
merged 4 commits into from
Nov 30, 2023
Merged

Unsafe module #2752

merged 4 commits into from
Nov 30, 2023

Conversation

P-E-P
Copy link
Member

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

GCCRS does not allow unsafe module with it's parser even though the code shall be rejected at a later stage.

The rust syntax allows unsafe module even if those are rejected at a
later stage.

gcc/rust/ChangeLog:

	* ast/rust-item.h: Add safety status to Modules in the AST.
	* parse/rust-parse-impl.h (Parser::parse_module): Adapt constructors.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Unsafe module are rejected at a later stage but could not be parsed
properly. This commit changes the parser in order to allow unsafe module
in the AST.

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_vis_item): Dispatch to parse
	module when meeting an unsafe module.
	(Parser::parse_module): Set unsafe status when the parser encounter an
	unsafe keyword.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
@P-E-P P-E-P added this to the GCC 14.1 release milestone Nov 21, 2023
@P-E-P P-E-P self-assigned this Nov 21, 2023
An error should be emitted on unsafe modules during the AST validation
pass as the syntax allows those even though they're not alowed later down
the line.

gcc/rust/ChangeLog:

	* ast/rust-item.h: Add safety getter to modules.
	* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Check
	a module's safety and emit an error when meeting an unsafe module.
	* checks/errors/rust-ast-validation.h: Add function prototype.
	* parse/rust-parse-impl.h (Parser::parse_module): Move the module locus
	to the first token instead of the mod keyword.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Add a new test to check for unsafe modules during AST validation pass.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
@P-E-P P-E-P marked this pull request as ready for review November 21, 2023 18:36
@P-E-P P-E-P requested a review from CohenArthur November 21, 2023 18:36
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

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

LGTM i like the new errors pass

@P-E-P P-E-P added this pull request to the merge queue Nov 29, 2023
Merged via the queue into Rust-GCC:master with commit 16d0a2d Nov 30, 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