Skip to content

Error when no_mangle is applied to some wrong targets - #166358

Draft
JonathanBrouwer wants to merge 1 commit into
rust-lang:mainfrom
JonathanBrouwer:no-mangle-target
Draft

JonathanBrouwer wants to merge 1 commit into
rust-lang:mainfrom
JonathanBrouwer:no-mangle-target

Conversation

@JonathanBrouwer

Copy link
Copy Markdown
Member

Before this PR, #[no_mangle] has the following behaviour regarding targets it is allowed on:

  • It is allowed on free functions, statics, and methods in inherent and trait impl blocks
  • It is an error on consts, closures and params
  • It is a FCW on all other targets

This PR makes the following changes:

  • It is now an error on all targets expect foreign functions, foreign statics, foreign mods, struct, enums, use statements and type aliases.

A crater run was performed here: #164789 (comment)

@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 Nov 22, 2026
@mejrs

mejrs commented Nov 22, 2026

Copy link
Copy Markdown
Member

It is an error on consts, closures and params

It's a deny by default on constants, not an error.

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 (`#[…]`, `#![…]`) 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.

export_name on provided trait associated functions has funny behavior

3 participants