This can help with verifying that the crate is correctly handling conditional compilation for different target platforms or features. It ensures that the cfg settings are consistent between what is intended and what is used, helping to catch potential bugs or errors early in the development process.This can help with verifying that the crate is correctly handling conditional compilation for different target platforms or features. It ensures that the cfg settings are consistent between what is intended and what is used, helping to catch potential bugs or errors early in the development process.

The Automatic Checking of cfgs: How It Works

2025/11/03 01:15

The Cargo and Compiler team are delighted to announce that starting with Rust 1.80 (or nightly-2024-05-05) every reachable #[cfg] will be automatically checked that they match the expected config names and values.

\ This can help with verifying that the crate is correctly handling conditional compilation for different target platforms or features. It ensures that the cfg settings are consistent between what is intended and what is used, helping to catch potential bugs or errors early in the development process.

\ This addresses a common pitfall for new and advanced users.

\ This is another step to our commitment to provide user-focused tooling and we are eager and excited to finally see it fixed, after more than two years since the original RFC 30131.

A look at the feature

Every time a Cargo feature is declared that feature is transformed into a config that is passed to rustc (the Rust compiler) so it can verify with it along with well known cfgs if any of the #[cfg], #![cfg_attr] and cfg! have unexpected configs and report a warning with the unexpected_cfgs lint.

Cargo.toml:

[package] name = "foo" [features] lasers = [] zapping = []

\ src/lib.rs:

#[cfg(feature = "lasers")] // This condition is expected // as "lasers" is an expected value // of the `feature` cfg fn shoot_lasers() {} #[cfg(feature = "monkeys")] // This condition is UNEXPECTED // as "monkeys" is NOT an expected // value of the `feature` cfg fn write_shakespeare() {} #[cfg(windosw)] // This condition is UNEXPECTED // it's supposed to be `windows` fn win() {}

\ cargo check:

Expecting custom cfgs

UPDATE: This section was added with the release of nightly-2024-05-19.

\ Some crates might use custom cfgs, like loom, fuzzing or tokio_unstable that they expected from the environment (RUSTFLAGS or other means) and which are always statically known at compile time. For those cases, Cargo provides via the [lints] table a way to statically declare those cfgs as expected.

\ Defining those custom cfgs as expected is done through the special check-cfg config under [lints.rust.unexpected_cfgs]:

Cargo.toml

[lints.rust] unexpected_cfgs = { level = "warn", check-cfg = ['cfg(loom)', 'cfg(fuzzing)'] }

Custom cfgs in build scripts

On the other hand some crates use custom cfgs that are enabled by some logic in the crate build.rs. For those crates Cargo provides a new instruction: cargo::rustc-check-cfg2 (or cargo:rustc-check-cfg for older Cargo version).

\ The syntax to use is described in the rustc book section checking configuration, but in a nutshell the basic syntax of --check-cfg is:

cfg(name, values("value1", "value2", ..., "valueN"))

\ Note that every custom cfgs must always be expected, regardless if the cfg is active or not!

build.rs example

build.rs:

fn main() { println!("cargo::rustc-check-cfg=cfg(has_foo)"); // ^^^^^^^^^^^^^^^^^^^^^^ new with Cargo 1.80 if has_foo() { println!("cargo::rustc-cfg=has_foo"); } }

Equivalence table

\ More details can be found in the rustc book.

Frequently asked questions

Can it be disabled?

For Cargo users, the feature is always on and cannot be disabled, but like any other lints it can be controlled: #![warn(unexpected_cfgs)].

Does the lint affect dependencies?

No, like most lints, unexpected_cfgs will only be reported for local packages thanks to cap-lints.

How does it interact with the RUSTFLAGS env?

You should be able to use the RUSTFLAGS environment variable like it was before. Currently --cfg arguments are not checked, only usage in code are.

\ This means that doing RUSTFLAGS="--cfg tokio_unstable" cargo check will not report any warnings, unless tokio_unstable is used within your local crates, in which case crate author will need to make sure that that custom cfg is expected with cargo::rustc-check-cfg in the build.rs of that crate.

How to expect custom cfgs without a build.rs?

UPDATE: Cargo with nightly-2024-05-19 now provides the [lints.rust.unexpected_cfgs.check-cfg] config to address the statically known custom cfgs.

\ There is currently no way to expect a custom cfg other than with cargo::rustc-check-cfg in a build.rs.

\ Crate authors that don't want to use a build.rs and cannot use [lints.rust.unexpected_cfgs.check-cfg], are encouraged to use Cargo features instead.

How does it interact with other build systems?

Non-Cargo based build systems are not affected by the lint by default. Build system authors that wish to have the same functionality should look at the rustc documentation for the --check-cfg flag for a detailed explanation of how to achieve the same functionality.

\

  1. The stabilized implementation and RFC 3013 diverge significantly, in particular there is only one form for --check-cfg: cfg() (instead of values() and names() being incomplete and subtlety incompatible with each other). ↩
  2. cargo::rustc-check-cfg will start working in Rust 1.80 (or nightly-2024-05-05). From Rust 1.77 to Rust 1.79 (inclusive) it is silently ignored. In Rust 1.76 and below a warning is emitted when used without the unstable Cargo flag -Zcheck-cfg. ↩

Urgau on behalf of The Cargo Team

\ Also published here

Disclaimer: The articles reposted on this site are sourced from public platforms and are provided for informational purposes only. They do not necessarily reflect the views of MEXC. All rights remain with the original authors. If you believe any content infringes on third-party rights, please contact service@support.mexc.com for removal. MEXC makes no guarantees regarding the accuracy, completeness, or timeliness of the content and is not responsible for any actions taken based on the information provided. The content does not constitute financial, legal, or other professional advice, nor should it be considered a recommendation or endorsement by MEXC.
Share Insights

You May Also Like

Is Doge Losing Steam As Traders Choose Pepeto For The Best Crypto Investment?

Is Doge Losing Steam As Traders Choose Pepeto For The Best Crypto Investment?

The post Is Doge Losing Steam As Traders Choose Pepeto For The Best Crypto Investment? appeared on BitcoinEthereumNews.com. Crypto News 17 September 2025 | 17:39 Is dogecoin really fading? As traders hunt the best crypto to buy now and weigh 2025 picks, Dogecoin (DOGE) still owns the meme coin spotlight, yet upside looks capped, today’s Dogecoin price prediction says as much. Attention is shifting to projects that blend culture with real on-chain tools. Buyers searching “best crypto to buy now” want shipped products, audits, and transparent tokenomics. That frames the true matchup: dogecoin vs. Pepeto. Enter Pepeto (PEPETO), an Ethereum-based memecoin with working rails: PepetoSwap, a zero-fee DEX, plus Pepeto Bridge for smooth cross-chain moves. By fusing story with tools people can use now, and speaking directly to crypto presale 2025 demand, Pepeto puts utility, clarity, and distribution in front. In a market where legacy meme coin leaders risk drifting on sentiment, Pepeto’s execution gives it a real seat in the “best crypto to buy now” debate. First, a quick look at why dogecoin may be losing altitude. Dogecoin Price Prediction: Is Doge Really Fading? Remember when dogecoin made crypto feel simple? In 2013, DOGE turned a meme into money and a loose forum into a movement. A decade on, the nonstop momentum has cooled; the backdrop is different, and the market is far more selective. With DOGE circling ~$0.268, the tape reads bearish-to-neutral for the next few weeks: hold the $0.26 shelf on daily closes and expect choppy range-trading toward $0.29–$0.30 where rallies keep stalling; lose $0.26 decisively and momentum often bleeds into $0.245 with risk of a deeper probe toward $0.22–$0.21; reclaim $0.30 on a clean daily close and the downside bias is likely neutralized, opening room for a squeeze into the low-$0.30s. Source: CoinMarketcap / TradingView Beyond the dogecoin price prediction, DOGE still centers on payments and lacks native smart contracts; ZK-proof verification is proposed,…
Share
BitcoinEthereumNews2025/09/18 00:14
LivLive ($LIVE) Dominates 2025 Top Crypto Presales as BlockDAG and Ozak AI Catch Fire

LivLive ($LIVE) Dominates 2025 Top Crypto Presales as BlockDAG and Ozak AI Catch Fire

The post LivLive ($LIVE) Dominates 2025 Top Crypto Presales as BlockDAG and Ozak AI Catch Fire appeared on BitcoinEthereumNews.com. Crypto Presales LivLive leads 2025’s top crypto presales with massive growth potential, while BlockDAG and Ozak AI gain investor momentum. Use code EARLY30 for 30% bonus tokens. Ever feel like your time, attention, and daily movement create value for others, but never for you? LivLive ($LIVE) fixes that by paying users for simply living life. It transforms everyday motion, event check-ins, and social participation into crypto rewards. In a year flooded with speculative presales, LivLive brings substance to blockchain utility, setting itself apart from tech-heavy rivals like BlockDAG ($BDAG) and Ozak AI ($OZAK). Instead of relying on online hype, LivLive channels energy from the real world. Each action, walking, exploring, or attending an event, converts into verifiable on-chain rewards. This unique design has already helped the project raise over $2 million in its early stage, drawing lifestyle enthusiasts and investors alike. With 30% bonus tokens available via the code EARLY30, LivLive is turning human activity into a true digital asset. LivLive ($LIVE) Real-World Utility: Turning Human Action Into Crypto Rewards The LivLive presale opened at $0.020 per $LIVE, offering access to NFT Packs, staking perks, and a share of the $2.5 million Treasure Vault Giveaway. Over 10 stages, the price will climb to $0.20 before the official $0.25 launch listing, giving early participants enormous upside. Buyers who enter early and apply EARLY30 receive an instant 30 % extra token bonus, multiplying returns as each stage sells out. LivLive’s AR wristband verifies real-world actions through geolocation. Completing quests or attending partnered events unlocks $LIVE rewards, redeemable for luxury experiences, tech gadgets, and travel prizes. This “move-to-earn” model connects physical life with blockchain profit. Each new user adds transaction volume and liquidity, reinforcing token demand. LivLive makes lifestyle participation financially meaningful, a feature missing from nearly every other presale today. The $2.5…
Share
BitcoinEthereumNews2025/11/05 03:35