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

Fix outer attribute parsing on generic parameters #3014

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

P-E-P
Copy link
Member

@P-E-P P-E-P commented May 20, 2024

Outer attributes were not correctly parsed on generic parameter, this prevented the #[may_dangle] outer attribute from being used.

This feature also provides a new feature gate dropck_eyepatch to prevent #[may_dangle] attributes from being used in safe context.

Requires #3012

Content:
https://github.com/Rust-GCC/gccrs/compare/552c36c..3c311a9c33340382fd0ea043f365ddfef9068a8f

@P-E-P P-E-P added the parser label May 20, 2024
@P-E-P P-E-P requested a review from CohenArthur May 20, 2024 11:34
@P-E-P P-E-P self-assigned this May 20, 2024
Add support for old box expression syntax.

gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): Add visit member
	function for BoxExpr nodes.
	* ast/rust-ast-collector.h: Add visit function prototype.
	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Add visit member
	function to default ast visitor.
	* ast/rust-ast-visitor.h: Add visit function's prototype.
	* ast/rust-ast.cc (BoxExpr::as_string): Add as_string function
	implementation for BoxExpr.
	(BoxExpr::accept_vis): Add accept_vis implementation to BoxExpr.
	* ast/rust-expr.h (class BoxExpr): Add BoxExpr class to represent boxed
	expressions.
	* expand/rust-derive.h: Add BoxExpr visit function prototype.
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Add BoxExpr
	visitor implementation.
	* hir/rust-ast-lower-base.h: Add visit function's prototype.
	* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Add BoxExpr
	visitor implementation.
	* hir/rust-ast-lower-expr.h: Add visit function's prototype.
	* parse/rust-parse-impl.h (Parser::parse_box_expr): Add parse_box_expr
	function's implementation.
	* parse/rust-parse.h: Add parse_box_expr function's prototype.
	* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add resolver
	visit implementation.
	* resolve/rust-ast-resolve-base.h: Add resolver's visit function
	prototype.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
P-E-P added 4 commits May 28, 2024 13:35
The box syntax is experimental even though it is used in the standard
library. It should be feature gated to prevent anyone from using it in
stable rust.

gcc/rust/ChangeLog:

	* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Allow
	visitor recursion in functions. Also add the gate for the box syntax.
	* checks/errors/rust-feature-gate.h: Remove several recursion fences
	in the feature gate visitor.
	* checks/errors/rust-feature.cc (Feature::create): Add a new feature.
	(Feature::as_name): Likewise.
	* checks/errors/rust-feature.h: Add box_syntax gate.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Add a new test to prevent regressions on the box syntax as well as its
feature gate.

gcc/testsuite/ChangeLog:

	* rust/compile/box_syntax.rs: New test.
	* rust/compile/box_syntax_feature_gate.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Generic parameter parsing failed when an outer attribute was used on it.

gcc/rust/ChangeLog:

	* parse/rust-parse-impl.h (Parser::parse_generic_param): Change token
	reference to be the last token after all outer attributes have been
	parsed.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Previously generic params only allowed one outer attribute in front of
them.

gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit): Visit outer
	attributes.
	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Change outer
	attribute visit, we need to visit all of them.
	* ast/rust-ast.cc (LifetimeParam::as_string): Change as_string
	implementation to allow multiple outer attributes.
	(TypeParam::as_string): Likewise.
	* ast/rust-ast.h (class LifetimeParam): Allow multiple outer
	attributes.
	* ast/rust-item.h (class TypeParam): Likewise.
	* ast/rust-path.h: Likewise.
	* parse/rust-parse-impl.h (Parser::parse_generic_param): Change call
	to outer attribute parsing to collect several attributes.
	(Parser::parse_lifetime_param): Likewise.
	(Parser::parse_type_param): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
P-E-P added 2 commits May 28, 2024 13:51
Add a new feature gate for may_dangle generic param outer attributes.

gcc/rust/ChangeLog:

	* checks/errors/rust-feature-gate.cc: Visit and gate may_dangle
	attributes.
	* checks/errors/rust-feature-gate.h: Update visit function prototype
	and add a new member function to check on a set of attributes whether
	one is may_dangle.
	* checks/errors/rust-feature.cc (Feature::create): Add new
	dropck_eyepatch feature.
	* checks/errors/rust-feature.h: Likewise.
	* util/rust-attribute-values.h: Add new may_dangle attribute value.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
First test checks the may_dangle outer atttribute on generic params can
be parsed. The second one tests whether may_dangle attributes are
correctly feature gated.

gcc/testsuite/ChangeLog:

	* rust/compile/dropck_eyepatch_feature_gate.rs: New test.
	* rust/compile/may_dangle.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

None yet

1 participant