Skip to content

Add suggestions for using #[export_name] instead of #[link_name] on static#159253

Open
asuto15 wants to merge 2 commits into
rust-lang:mainfrom
asuto15:suggest-export-name
Open

Add suggestions for using #[export_name] instead of #[link_name] on static#159253
asuto15 wants to merge 2 commits into
rust-lang:mainfrom
asuto15:suggest-export-name

Conversation

@asuto15

@asuto15 asuto15 commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #159247.

This adds a suggestion for using #[unsafe(export_name = "...")] when #[link_name = "..."] is applied to a static.

It also handles the existing #[unsafe(link_name = "...")] form by replacing only the attribute name.

Tested with:

  • ./x test tests/ui/attributes/link-name-on-static.rs
  • ./x test tests/ui/attributes/unsafe-link-name-on-static.rs

@rustbot

rustbot commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@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 Jul 13, 2026
@rustbot

rustbot commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 18 candidates

Comment thread compiler/rustc_attr_parsing/src/target_checking.rs Outdated
Comment thread tests/ui/attributes/unsafe-link-name-on-static.rs Outdated
@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 Jul 25, 2026
@rustbot

rustbot commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

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

@asuto15

asuto15 commented Jul 26, 2026

Copy link
Copy Markdown
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 Jul 26, 2026
@asuto15
asuto15 requested a review from JonathanBrouwer July 26, 2026 11:38

@JonathanBrouwer JonathanBrouwer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rust-bors

rust-bors Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b4fec82 has been approved by JonathanBrouwer

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

Reason for tree closure: spurious failures

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 26, 2026
@rust-log-analyzer

This comment has been minimized.

@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors r-
Ci

@rust-bors rust-bors Bot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 26, 2026
@rust-bors

rust-bors Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

View changes since this unapproval

@rust-bors rust-bors Bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jul 26, 2026
@asuto15
asuto15 force-pushed the suggest-export-name branch from b4fec82 to 5e5367b Compare July 26, 2026 13:04
@rustbot

rustbot commented Jul 26, 2026

Copy link
Copy Markdown
Collaborator

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.

@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 5e5367b has been approved by JonathanBrouwer

It is now in the queue for this repository.

🌲 The tree is currently closed for pull requests below priority 100. This pull request will be tested once the tree is reopened.

Reason for tree closure: spurious failures

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 26, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 27, 2026
…athanBrouwer

Add suggestions for using `#[export_name]` instead of `#[link_name]` on static

Fixes rust-lang#159247.

This adds a suggestion for using `#[unsafe(export_name = "...")]` when `#[link_name = "..."]` is applied to a static.

It also handles the existing `#[unsafe(link_name = "...")]` form by replacing only the attribute name.

Tested with:

- `./x test tests/ui/attributes/link-name-on-static.rs`
- `./x test tests/ui/attributes/unsafe-link-name-on-static.rs`
rust-bors Bot pushed a commit that referenced this pull request Jul 27, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #159085 (Fix decoding attributes of `SyntheticCoroutineBody`)
 - #159554 (feat: Update method signature of int_from_ascii)
 - #159637 (Some place analysis tweaks)
 - #159961 (sanitize_standard_fds: Miri supports poll now)
 - #159967 (rustc_target: callconv: mips64: Return structs with single f128 in FPRs)
 - #159253 (Add suggestions for using `#[export_name]` instead of `#[link_name]` on static)
 - #159840 (Fix opaque type ICE in late lints under the next-generation trait solver)
 - #159956 (Fix observable intermediate state in `thread::add_spawn_hook`)
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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

"warning: #[link_name] attribute cannot be used on statics" warning/error should mention #[export_name]

5 participants