Skip to content

Document symbol name attributes - #159758

Open
amirHdev wants to merge 2 commits into
rust-lang:mainfrom
amirHdev:docs-symbol-name-attributes
Open

Document symbol name attributes#159758
amirHdev wants to merge 2 commits into
rust-lang:mainfrom
amirHdev:docs-symbol-name-attributes

Conversation

@amirHdev

@amirHdev amirHdev commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Documents the no_mangle, export_name, link_name attributes

Part of #157604

r? @GuillaumeGomez

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 23, 2026
@rust-bors

This comment has been minimized.

@amirHdev
amirHdev force-pushed the docs-symbol-name-attributes branch from fd9a817 to 652be0c Compare August 1, 2026 12:19
@rustbot

This comment has been minimized.

Comment thread library/core/src/attribute_docs.rs Outdated
/// well-known symbol, which may cause undefined behavior.
///
/// Starting with the 2024 edition, the attribute must be written using the `unsafe(...)` syntax.
/// Earlier editions also permit `#[export_name = "..."]`.

@GuillaumeGomez GuillaumeGomez Aug 3, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rust-bors

This comment has been minimized.

Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
@amirHdev
amirHdev force-pushed the docs-symbol-name-attributes branch from 652be0c to c9d3bb5 Compare September 1, 2026 10:21
@rustbot

rustbot commented Sep 1, 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.

Comment thread library/core/src/attribute_docs.rs Outdated
/// pub extern "C" fn initialize() {}
/// ```
///
/// The attribute controls the symbol name and export behavior, but does not change the function's

@GuillaumeGomez GuillaumeGomez Sep 1, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and export behavior

How so?

View changes since the review

Comment thread library/core/src/attribute_docs.rs Outdated
///
/// ```rust
/// #[unsafe(no_mangle)]
/// pub extern "C" fn initialize() {}

@GuillaumeGomez GuillaumeGomez Sep 1, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since below you mention that no_mangle is usually used on extern "C" function, maybe only write:

Suggested change
/// pub extern "C" fn initialize() {}
pub fn initialize() {}

here?

View changes since the review

Comment thread library/core/src/attribute_docs.rs Outdated
/// Rust normally changes an item's symbol name to encode information such as its module path.
/// Applying `no_mangle` instead uses the item's identifier as the exported symbol name.
///
/// ```rust

@GuillaumeGomez GuillaumeGomez Sep 1, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
/// ```rust
/// ```

And same on all rust code blocks.

View changes since the review

Comment thread library/core/src/attribute_docs.rs Outdated
/// ```
///
/// In this example, Rust code uses `name_in_rust`, while the linker resolves
/// `actual_symbol_name`. The attribute can only be applied to function and static declarations

@GuillaumeGomez GuillaumeGomez Sep 1, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
/// `actual_symbol_name`. The attribute can only be applied to function and static declarations
/// `actual_symbol_name`. The attribute can only be applied to declarations of static variables and of functions.

View changes since the review

@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 Sep 1, 2026
@rustbot

rustbot commented Sep 1, 2026

Copy link
Copy Markdown
Collaborator

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

Signed-off-by: Amirhossein Akhlaghpour <m9.akhlaghpoor@gmail.com>
@amirHdev

amirHdev commented Sep 1, 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 Sep 1, 2026
@amirHdev

amirHdev commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

@GuillaumeGomez Thanks , updated

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants