Skip to content

Error on wrong targets for no_mangle and export_name - #164789

Draft
JonathanBrouwer wants to merge 2 commits into
rust-lang:mainfrom
JonathanBrouwer:export-name-target
Draft

JonathanBrouwer wants to merge 2 commits into
rust-lang:mainfrom
JonathanBrouwer:export-name-target

Conversation

@JonathanBrouwer

@JonathanBrouwer JonathanBrouwer commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

This PR makes applying the #[no_mangle] and #[export_name] attributes an error, rather than a warning.

It also makes applying the attributes to a provided trait function consistently an error.
This is necessary because the current behavior is very buggy, and it is not clear to me what the correct behavior should be.

History:

  • Historically, export_name used to error on all targets except fields, arms, macro defs, and macro calls.
  • Historically, no_mangle has always warned on invalid targets. It has always had buggy behaviour on provided trait functions.
  • A year ago, Rework target checking for built-in attributes #145085 introduced a bug which allows export_name on provided trait functions. The behaviour is buggy.

The specific changes this PR makes are:

  • export_name goes from warning to error on fields, arms, macro defs, and macro calls
  • export_name goes from allowed to error on provided trait functions
  • no_mangle goes from warning to error on all targets except the allowed targets: free functions, statics, inherent methods and trait impl methods.

Fixes #164571

cc @mejrs

@rustbot rustbot added 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. labels Oct 23, 2026
@JonathanBrouwer JonathanBrouwer added S-waiting-on-crater Status: Waiting on a crater run to be completed. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. needs-crater This change needs a crater run to check for possible breakage in the ecosystem. labels Oct 23, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member Author

This needs a crater run
@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Oct 23, 2026
Error on wrong targets for `no_mangle` and `export_name`,
@JonathanBrouwer JonathanBrouwer changed the title Error on wrong targets for no_mangle and export_name, Error on wrong targets for no_mangle and export_name Oct 23, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 4d7c0cd (4d7c0cd298ace72490220301fa543d63a154f8ce)
Base parent: 0cefa27 (0cefa27fe3deee26fc98ee44249406358d9f0d26)

@JonathanBrouwer

Copy link
Copy Markdown
Member Author

@craterbot check

@craterbot

Copy link
Copy Markdown
Collaborator

👌 Experiment pr-164789 created and queued.
🤖 Automatically detected try build 4d7c0cd
⚠️ Try build based on commit 5c4119b, but latest commit is 6717514. Did you forget to make a new try build?
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 23, 2026
@rust-log-analyzer

This comment has been minimized.

@mejrs

mejrs commented Oct 23, 2026

Copy link
Copy Markdown
Member

rustc_codegen_ssa has a bunch of code defending against invalid codegen attrs, being able to clean that up would be nice. (for example, #159374 adds some)

@rust-bors

rust-bors Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

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

@craterbot

Copy link
Copy Markdown
Collaborator

🚧 Experiment pr-164789 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

This branch has not been deployed

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

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) needs-crater This change needs a crater run to check for possible breakage in the ecosystem. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

export_name on provided trait associated functions has funny behavior

5 participants