rust-lang / rust-lang/rust

Nightly-only cfg gating like `#[cfg(target_has_atomic)]` is confusing

Open
#133,295 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-cfg A-stability C-enhancement requires-nightly T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

EDIT: this is intended that cfg(target_has_atomic) is nightly-only (not feature-gated), but I find it still very confusing.


Note that #[cfg(target_has_atomic)] is not to be confused with #[cfg(target_has_atomic = "8")].

Given a snippet (just rustc --crate-type="lib", no additional --cfg flags)

#[cfg(target_has_atomic)]
fn foo() {}
  • On stable 1.82.0 this produces no warnings.
  • On nightly 2024-11-20 this produces a dead_code warning indicating target_has_atomic cfg is enabled.
warning: function `foo` is never used
 --> src/lib.rs:2:4
  |
2 | fn foo() {}
  |    ^^^
  |
  = note: `#[warn(dead_code)]` on by default

AFAICT there is no test coverage for the intended behavior of just #[cfg(target_has_atomic)] alone, other test coverage is mostly for check-cfg.

cc @Urgau since you worked on builtin-cfg rejection do you know anything about if this is intended, and if so, what is the intended behavior here?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two reported cases with rustc --crate-type="lib" and the bare #[cfg(target_has_atomic)] snippet on stable and nightly. Review the existing builtin-cfg and check-cfg tests, then establish what behavior is intended and add coverage for the bare form; done means the behavior is explicitly settled and tested.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.