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.

You May Also Like

Polymarket, Kalshi bet big on web3—and global expansion

Polymarket, Kalshi bet big on web3—and global expansion

The post Polymarket, Kalshi bet big on web3—and global expansion appeared on BitcoinEthereumNews.com. Polymarket and Kalshi are doubling down on their future — literally — as both prediction-market platforms push into web3 and global markets in search of new revenue streams. Both startups are also on the hunt for regulatory approvals, and partnerships with sports organizations. Summary Polymarket and Kalshi reportedly kicked off expansion efforts. The plans were unveiled at a private New York dinner attended by ICE CEO Jeffrey Sprecher. Both platforms are exploring decentralized technologies and international venue partnerships as trading volumes rise. Bloomberg reports the expansion was kicked off in classic Wall Street fashion: with a private dinner high above New York’s financial district, where even Intercontinental Exchange CEO Jeffrey Sprecher showed up. Why it matters Both companies have been ramping up their growth strategies, each aiming to break out of their current lanes. Polymarket, which is about to relaunch in the U.S., and Kalshi, which just partnered with Coinbase, are now circling opportunities in web3 technologies — essentially taking prediction markets from the basement of the internet to the broader blockchain universe. As trading volumes rise, regulators and institutional players have been paying much closer attention to the sector — and so is big tech. Alphabet, for example, will soon display live probabilities from Kalshi and Polymarket on Google Finance and Google Search. This will allow users to type natural-language questions such as “Will the Fed cut rates in December?” and instantly see odds and how they’ve shifted over time. Kalshi supplies regulated U.S. event markets tied to economic data and policy decisions, while Polymarket covers a wider global range of topics, including politics, sports, and crypto. Both platforms have seen rising activity as more traders rely on prediction markets to assess future outcomes rather than traditional polls or analyst forecasts. Still, details on specific deals or regulatory filings…
Share
BitcoinEthereumNews2025/11/21 10:27
Why are XRP, BTC, ETH, and DOGE Prices Crashing?

Why are XRP, BTC, ETH, and DOGE Prices Crashing?

The post Why are XRP, BTC, ETH, and DOGE Prices Crashing? appeared on BitcoinEthereumNews.com. XRP, BTC, ETH, and DOGE prices are experiencing significant declines, with the overall crypto market down 2.71% in the past 24 hours. Bitcoin has fallen below $90K, and Ethereum dropped under $3K, contributing to a broader market downturn. XRP Price Struggles as Price Dips Below $2 In the last 24 hours, the XRP price crashed by 2% and it has reduced by 15% in the current week, at a lower price of less than $2 in a bearish market. The price of the cryptocurrency is presented in the form of a descending triangle, which is indicative of the risk of a further decrease. A breakdown of major support lines added to the decline in the recent past, leading to stop-losses and a minor spurt of leveraged sell-side liquidations. Moreover, the whale action increased with 190 million XRP being sold within the past 48 hours. In the meantime, there is a Bitwise XRP ETF that has been launched, but the situation is unstable in the market. 190 million $XRP sold by whales in the last 48 hours! pic.twitter.com/nB0P7jADCx — Ali (@ali_charts) November 20, 2025 Bitcoin Price Plunges, Falling Below $90K Amid Market Sell-Off Bitcoin price dropped 2.24% to $86,858 over the past 24 hours, continuing a 12% weekly decline. The BTC was selling at a low of less than $90k as investor confidence shifted to the negative. Redemptions of Bitcoin ETFs amounted to a sharp decline of $3.3 billion this month, which further contributed to the negative pressure. Also, the Federal Reserve rate cut in December was in doubt, with the probability being now 33% and this burdened risk assets.  BTC also sent down vital support levels, causing automated selling. The recent better-than-anticipated jobs report in United States sparked a question as to what Fed would do in future. Ethereum Price…
Share
BitcoinEthereumNews2025/11/21 10:29
Music body ICMP laments “wilful” theft of artists’ work

Music body ICMP laments “wilful” theft of artists’ work

The post Music body ICMP laments “wilful” theft of artists’ work appeared on BitcoinEthereumNews.com. A major music industry group, ICMP, has lamented the use of artists’ work by AI companies, calling them guilty of “wilful” copyright infringement, as the battle between the tech firms and the arts industry continues. The Brussels-based group known as the International Confederation of Music Publishers (ICMP) comprises major record labels and other music industry professionals. Their voice adds to many others within the arts industry that have expressed displeasure at AI firms for using their creative work to train their systems without permission. ICMP accuses AI firms of deliberate copyright infringement ICMP director general John Phelan told AFP that big tech firms and AI-specific companies were involved in what he termed “the largest copyright infringement exercise that has been seen.” He cited the likes of OpenAI, Suno, Udio, and Mistral as some of the culprits. The ICMP carried out an investigation for nearly two years to ascertain how generative AI firms were using material by creatives to enrich themselves. The Brussels-based group is one of a number of industry bodies that span across news media and publishing to target the fast-growing AI sector over its use of content without paying any royalties. Suno and Udio, who are AI music generators, can produce tracks with voices, melodies, and musical styles that echo those of the original artists such as the Beatles, Depeche Mode, Mariah Carey, and the Beach boys. “What is legal or illegal is how the technologies are used. That means the corporate decisions made by the chief executives of companies matter immensely and should comply with the law,” Phelan told AFP. “What we see is they are engaged in wilful, commercial-scale copyright infringement.” Phelan. In June last year, a US trade group, the Recording Industry Association of America, filed a lawsuit against Suno and Udio. However, an exception…
Share
BitcoinEthereumNews2025/09/18 04:41