Skip to content

Conversation

@Bryntet
Copy link
Contributor

@Bryntet Bryntet commented Jan 9, 2026

Couple things to note:

This change includes making all so-far parsed attrs emit an error if they are targeting Param (by adding Error(Target::Param))

^ The above is not a breaking change, because there was previously a step that emitted an error pre-attr parsing, for all attrs that were not in the list [allow, cfg_trace, cfg_attr_trace, deny, expect, forbid, warn]

The check mentioned above has been disabled for all parsed attrs, meaning we in practice have replaced the error lint above, with the nicer lint from the attribute parser

I also removed Allow(Target::Param) from the ALL_TARGETS const, since all attrs with the exception of allow, cfg_trace, cfg_attr_trace, deny, expect, forbid, warn had this emitting error previously anyways

The latter two commits I would want someone to verify closely that I have not made some mistake/broken something with! I think they're good, but I still feel like I don't know exactly enough about the compiler to say that they are 100% OK

This also fixes this part of #147417

r? @JonathanBrouwer

@rustbot
Copy link
Collaborator

rustbot commented Jan 9, 2026

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

@rustbot rustbot added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Jan 9, 2026
@rustbot rustbot added 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 Jan 9, 2026
@Bryntet Bryntet force-pushed the edv/prettier_error_for_attr_on_fn_param branch from 8597baf to 4d39647 Compare January 9, 2026 23:13
@Bryntet
Copy link
Contributor Author

Bryntet commented Jan 9, 2026

@jdonszelmann think it would be good if you did a quick look at this as well when you have time, just so you are up to date with the updates to const ALL_TARGETS as well as AllowedTargets::AllowListWarnRest

@jdonszelmann jdonszelmann self-requested a review January 9, 2026 23:18
Comment on lines 740 to 746
attrs = self.lower_attrs_with_extra(
hir_id,
param.attrs(),
param.span,
Target::Param,
attrs,
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unsure if this should actually be appending the param attrs here or not

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should just be a lower_attrs call, the extra attributes from attrs are the attributes of the foreign fn, and the params should not inherit those.

Copy link
Contributor

Choose a reason for hiding this comment

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

indeed

@Bryntet Bryntet force-pushed the edv/prettier_error_for_attr_on_fn_param branch from 4d39647 to 34a3158 Compare January 9, 2026 23:28
Comment on lines 740 to 746
attrs = self.lower_attrs_with_extra(
hir_id,
param.attrs(),
param.span,
Target::Param,
attrs,
);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should just be a lower_attrs call, the extra attributes from attrs are the attributes of the foreign fn, and the params should not inherit those.

@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 Jan 10, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 10, 2026

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

// All attributes were previously erroring on Target::Param except a few that are allow-listed.
// Therefore, to avoid accidentally regressing from emitting error to emitting warn when parsing new attrs
// we have this check that always emits an error if Target::Param unless it's explicitly been allowed
if target == Target::Param || list.contains(&Policy::Error(target)) {
Copy link
Contributor

@JonathanBrouwer JonathanBrouwer Jan 10, 2026

Choose a reason for hiding this comment

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

I don't like how special Target::Param is here.

There are other targets, such as Target::WherePredicate, that similarly were previously checked separately, and now have to be added to all attributes with AllowListWarnRest. We should have some way to ensure that these weird targets are not forgotten, but this doesn't feel right.

If we do this, we should at least rename AllowListWarnRest so the name is something like AllowListWarnMost, but even then this feels iffy to me.

@jdonszelmann what is your opinion?

Copy link
Contributor

Choose a reason for hiding this comment

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

hm, we could:

  • force people to list exhaustively (infeasible)
  • write a rustc lint (could be neat)
  • have some special sets that allow most (like you suggest, seems reasonable)

I've never written a rustc lint before, but I've seen them around. Could be worth considering.

Copy link
Contributor

@JonathanBrouwer JonathanBrouwer Jan 13, 2026

Choose a reason for hiding this comment

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

@Bryntet
What Jana meant is defining a full-on lint pass in rustc_lint/src/internal.rs, that checks for misuse of these allowed target lists. This is a possible solution but I feel like it's too overkill for this relatively simple problem.

I don't like this approach to "linting" because it has runtime overhead.
I'd personally prefer to go for the "special sets" approach

@Bryntet Bryntet force-pushed the edv/prettier_error_for_attr_on_fn_param branch from 34a3158 to 7cbb620 Compare January 12, 2026 21:40
@rustbot
Copy link
Collaborator

rustbot commented Jan 12, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Bryntet Bryntet force-pushed the edv/prettier_error_for_attr_on_fn_param branch from 7cbb620 to 7d4a0f5 Compare January 12, 2026 21:41
@Bryntet
Copy link
Contributor Author

Bryntet commented Jan 12, 2026

i tried the approach of linting inside of rustc instead

unsure if this is the proper way of making a rustc lint though?

@rust-log-analyzer

This comment has been minimized.

just did this to pass tests, commit will look different before merge
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 13, 2026

☔ The latest upstream changes (presumably #151051) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) 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.

Duplicate warning on some attributes with wrong targets

5 participants