Skip to content

Conversation

@JonathanBrouwer
Copy link
Contributor

@JonathanBrouwer JonathanBrouwer commented Nov 9, 2025

This PR turns applying the following attributes on required trait methods (that is, trait methods without a default implementation) into a FCW:

  • #[cold]
  • #[link_section]
  • #[linkage] (unstable)
  • #[rustc_allow_const_fn_unstable] (internal attribute)

These attributes already had no effect when applied to a required trait method, this PR only adds a warning.

Furthermore, it adds a comment in the code that the following codegen attributes are inherited when applied to a required trait method:

  • #[track_caller]
  • #[align] (unstable)

@rustbot labels +I-lang-nominated
@rust-lang/lang

Two questions for the lang team:

  • Is adding this warning ok?
  • Does the current behaviour of these attributes align with that you would expect them to be?

Fixes #147432

@rustbot
Copy link
Collaborator

rustbot commented Nov 9, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

@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 Nov 9, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 9, 2025

r? @jackh726

rustbot has assigned @jackh726.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the I-lang-nominated Nominated for discussion during a lang team meeting. label Nov 9, 2025
@JonathanBrouwer JonathanBrouwer changed the title Warn on codegen attributes on trait methods Warn on codegen attributes on required trait methods Nov 9, 2025
@traviscross traviscross added the P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang label Nov 10, 2025
@jdonszelmann
Copy link
Contributor

r? jdonszelmann

@rustbot rustbot assigned jdonszelmann and unassigned jackh726 Nov 10, 2025
@traviscross traviscross added the T-lang Relevant to the language team label Nov 12, 2025
@traviscross
Copy link
Contributor

@rfcbot fcp merge lang

@rust-rfcbot
Copy link
Collaborator

rust-rfcbot commented Nov 12, 2025

Team member @traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:

Concerns:

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Nov 12, 2025
@tmandry
Copy link
Member

tmandry commented Nov 19, 2025

@rfcbot reviewed

@rust-rfcbot rust-rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Nov 19, 2025
@rust-rfcbot
Copy link
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@jackh726
Copy link
Member

So, I'd like to file a concern here that we should do a crater run on this before landing. Here's my reasoning:

This is landing as a FCW, which means that the team wants to remove this behavior, In my mind, this means that the team should know what the barriers are for that. If, for example, crater says that nobody is relying on it, it may mean that we want to move rather fast on that. If crater shows that a bunch of crates are relying on this, we should know that to be able to plan (I think Niko mentioned e.g. making the change over an edition in that case would be a possibility).

Essentially, the concern from me is that a FCW here indicates it's important enough for people to think about, and I think that the lang team should have the data about who it effects. And, not blocking landing this on that data runs the (high) risk of it falling through the cracks.

@nikomatsakis
Copy link
Contributor

@rfcbot concern jackh726-concern

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Nov 19, 2025
@traviscross traviscross added the I-lang-radar Items that are on lang's radar and will need eventual work or consideration. label Nov 19, 2025
@jdonszelmann
Copy link
Contributor

@JonathanBrouwer could you make a parallel PR that makes this a full error, then we crater that. Or at least I believe we wouldn't see this warning in a crate run right?

rust-bors bot added a commit that referenced this pull request Nov 20, 2025
@JonathanBrouwer
Copy link
Contributor Author

Crater run will happen here: #149137

@fmease fmease mentioned this pull request Nov 20, 2025
@traviscross traviscross added S-waiting-on-crater Status: Waiting on a crater run to be completed. S-waiting-on-concerns Status: Awaiting concerns to be addressed by the author labels Nov 20, 2025
@jdonszelmann
Copy link
Contributor

@rustbot blocked

@rustbot rustbot added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 24, 2025
@JonathanBrouwer
Copy link
Contributor Author

JonathanBrouwer commented Nov 26, 2025

The crater results are here https://crater-reports.s3.amazonaws.com/pr-149137/index.html

  • 259 crates fail to build because they depend on rhai, which has a #[cold] attribute on a required trait method
  • 7 crates (including rhai itself) fail to build because they themselves have a #[cold] attribute on a required trait method
  • 1 spurious

That's more results than I expected, mostly due to one popular crate making this mistake. I'm still convinced we need to add the warning here, since putting a cold attribute on a required trait method currently has no effect and users might expect it to. But this means we might need to be more careful in transitioning this into an error.

@nikomatsakis @jackh726 does this address your concern?

@scottmcm
Copy link
Member

I still think we should do this, as it's consistent with other things that we've done previously (like breaking struct Foo { #[inline] x: u32 }).

Given that this has never worked and the fix is removing something that doesn't do anything -- and thus has no semver concerns -- I don't have concerns. It would be nice to send PRs to rhai (and any of the others that are "real", at least), of course.

@rfcbot reviewed

@jackh726
Copy link
Member

jackh726 commented Nov 26, 2025

Great - thank you @JonathanBrouwer for doing that.

The results certainly make it clear that we couldn't make this a hard error immediately, but also that it definitely makes sense as a FCW. I do think it'd be pretty quick and easy to make PRs to the affected crates and then switch this to be an error or deny-by-default FCW, but I don't think we typically do that for FCWs. For rhai, it's pretty reasonable given it makes up to large majority of affected cases, I'm happy to send a PR though myself if you aren't able to @JonathanBrouwer.

@nikomatsakis will have to resolve the concern for me, but happy from my side here

@JonathanBrouwer
Copy link
Contributor Author

JonathanBrouwer commented Nov 26, 2025

I'll make a PR for rhai later tonight :)
Edit: rhaiscript/rhai#1057

@bors
Copy link
Collaborator

bors commented Nov 27, 2025

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

Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
@rustbot
Copy link
Collaborator

rustbot commented Nov 28, 2025

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.

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

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. S-blocked Status: Blocked on something else such as an RFC or other implementation work. S-waiting-on-concerns Status: Awaiting concerns to be addressed by the author S-waiting-on-crater Status: Waiting on a crater run to be completed. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Narrow down the list of targets #[link_section] and other link attributes can be applied to

10 participants