Skip to content

Port #[rustc_as_ptr] to the new attribute system #142498

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GrigorenkoPV
Copy link
Contributor

@GrigorenkoPV GrigorenkoPV commented Jun 14, 2025

It might make sense to introduce some new parser analogous to Single, but even more simple: for parsing attributes that take no arguments and may appear only once (such as #[rustc_as_ptr] or #[rustc_const_stable_indirect]). Not sure if this should be a single impl parsing all such attributes, or one impl per attribute. Or how it will play along with the upcoming rework of attribute validation. Or how these argumentless attributes should be called (I've loosely referred to them as markers in the name of the new module in this PR, but not sure how good it is).

This is a part of #131229, so
r? @jdonszelmann


For reference, the #[rustc_as_ptr] attribute was created back in #132732 as a followup to #128985.


@rustbot label +S-blocked
Blocked on #142552.

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 14, 2025

Some changes occurred in compiler/rustc_attr_data_structures

cc @jdonszelmann

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

Copy link
Contributor

@mejrs mejrs left a comment

Choose a reason for hiding this comment

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

Or how these argumentless attributes should be called (I've loosely referred to them as markers in the name of the new module in this PR, but not sure how good it is).

"markers" already means quite a lot, see https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_parsing/index.html for example.

Anyway, your questions seem to be about code organization - I think it would be better to organize attributes based on what they do rather than how they are parsed.

a single impl parsing all such attributes

The downside of this approach is that updating an attribute to take an argument would get annoying. Say if we had just #[blah] and then changed it to #[blah(alot|maybe| <nothing>)] then that would require moving all the code related to parsing blah, rather than just making changes in it.

@@ -147,6 +147,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| AttributeKind::ConstStabilityIndirect
| AttributeKind::MacroTransparency(_),
) => { /* do nothing */ }
Attribute::Parsed(AttributeKind::AsPtr) => {
self.check_applied_to_fn_or_method(hir_id, attr, span, target)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is an ICE, check_applied_to_fn_or_method runs attr.span() which aren't supported on parsed attributes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

no it isn't, look

attr_span: attr.span(),

It still calls attr.span()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

ah right

Copy link
Contributor

Choose a reason for hiding this comment

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

I kind of want to get rid of that function, the few that are in that list are there because it was too painful to migrate otherwise

Copy link
Contributor

Choose a reason for hiding this comment

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

could you solve it properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

could you solve it properly?

Fully getting rid of that function is going to be quite an effort, because it is in impl AttributeExt for Attribute, which is relied on by many parts of the compiler.

I've started the process (#142552) of migrating from Attribute to either AttrItem or AttributeKind in other parts of the compiler, which should help both with getting rid of that impl specifically and with other #131229-related changes in general.

While this PR can technically be fixed independently of #142552, it will cause merge conflicts, so I'm going to wait for that one first instead.

@jdonszelmann
Copy link
Contributor

a single impl parsing all such attributes

I agree with @mejrs here, all attributes should get their own parser. Only if a parsed hir attribute's diagnostics depends on more than one syntactic attribute is it sensible to combine accept functions (see stability, and for example I intend to do this with allow/deny)

@jdonszelmann
Copy link
Contributor

jdonszelmann commented Jun 14, 2025

I do intend to make a simpler parser for single word attribute parsers just like there's already SingleAttributeParser. That transformation is trivial later, let's keep it as is for now. This change is at least conceptually good @GrigorenkoPV , just needs some minor work

@jdonszelmann
Copy link
Contributor

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 14, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 14, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@GrigorenkoPV
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 14, 2025
@jdonszelmann
Copy link
Contributor

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 15, 2025
@GrigorenkoPV
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 15, 2025
@jdonszelmann
Copy link
Contributor

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 15, 2025
@rustbot rustbot added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) S-blocked Status: Blocked on something else such as an RFC or other implementation work. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants