Skip to content

Add documentation for allow and cfg attributes.#158070

Closed
kantnero wants to merge 2 commits into
rust-lang:mainfrom
kantnero:attribute-docs-allow-cfg
Closed

Add documentation for allow and cfg attributes.#158070
kantnero wants to merge 2 commits into
rust-lang:mainfrom
kantnero:attribute-docs-allow-cfg

Conversation

@kantnero

@kantnero kantnero commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Added documentation for built-in allow and cfg attributes using the #[doc(attribute = "...")] mechanism.

Part of #157604.

@rustbot r? @GuillaumeGomez

Signed-off-by: Emmanuel Ugwu <emmanuelugwu121@gmail.com>
@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 Jun 18, 2026
@rustbot

rustbot commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @Darksonn (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 12 candidates
  • Random selection from Darksonn, Mark-Simulacrum, clarfonthey, jhpratt

@rustbot rustbot assigned GuillaumeGomez and unassigned Darksonn Jun 18, 2026
Comment thread library/std/src/attribute_docs.rs Outdated
Comment on lines +91 to +94
/// Suppress compiler warnings for unused code.
///
/// The `allow` attribute suppresses compiler warnings for unused functions,
/// variables or imports.

@fmease fmease Jun 18, 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.

It's not for suppressing "warnings for unused code", it's for suppressing any lint (or lint group) (assuming the link in question has not been forbid'den already in the current scope).

dead_code, unused_function, unused_variables and unused_mut you mention below are only 4 out of currently 243 rustc lints and 13 rustc lint groups (ignoring the 819 clippy lints and 10 clippy lint groups, etc.).

It's not just warnings it can be errors, too, since lints can be deny-by-default or set to deny.

View changes since the review

///
/// The `allow` attribute suppresses compiler warnings for unused functions,
/// variables or imports.
///

@fmease fmease Jun 18, 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.

I think it would be worth mentioning that lints at forbid level can't be allow'ed1.

View changes since the review

Footnotes

  1. unless --cap-lints is passed with a value of deny, warn or allow but that needn't be mentioned in these docs I think.

@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 Jun 18, 2026
@rustbot

rustbot commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

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

/// You can also use `cfg` more than once on the same item. The item is only
/// kept if all the conditions are true, same as combining them with `all(...)`.
///
/// For a check you can use inside a function, see the [`cfg!`] macro. To

@fmease fmease Jun 18, 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 the cfg macro is defined in core and re-exported from std, we could (and probably should) link to the API docs instead of the Reference, using an intra-doc link. IINM you can just remove [`cfg!`]: ../reference/conditional-compilation.html#the-cfg-macro below and the [`cfg!`] should already resolve to https://doc.rust-lang.org/nightly/std/macro.cfg.html 🤔.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have addressed it. Please take another look

@kantnero kantnero closed this Jun 22, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

5 participants