Note: This bug report was written by Claude Code based on a debugging session where Claude isolated this issue with my help; it was then edited by me. I have verified the report independently: to the best of my knowledge and ability it is correct, and clearer and more complete than what I would have written.
Summary
When using sccache with Rust 2024 edition projects, check-cfg warnings about unknown feature values are cached and persist even after:
- The
Cargo.toml is properly configured with the features
- Running
cargo clean
- Restarting the
sccache server
The cached warnings only clear when either:
- The
sccache cache directory is manually deleted (rm -rf ~/.cache/sccache)
sccache is bypassed entirely (RUSTC_WRAPPER="" cargo check)
- The package name is changed (forcing a new cache key)
This causes confusing behavior where cargo is passing the correct --check-cfg flags to rustc, but the compilation output still shows warnings about missing features.
Environment
- Rust version: 1.93.1 (01f6ddf75 2026-02-11)
- Cargo version: 1.93.1 (083ac5135 2025-12-15)
- sccache version: 0.13.0
- OS: Linux 6.18.9+deb14-amd64
- Edition: 2024
Reproduction Steps
1. Create a new library with Rust 2024 edition (WITHOUT features initially):
cargo new --lib test_sccache_bug
cd test_sccache_bug
2. Edit Cargo.toml to use edition 2024 but DON'T add features yet:
[package]
name = "test_sccache_bug"
version = "0.1.0"
edition = "2024"
3. Edit src/lib.rs to reference a feature that doesn't exist:
#![cfg_attr(not(feature = "std"), no_std)]
4. Build with sccache enabled to cache the warning:
cargo check --no-default-features
Expected: Warning about unknown std feature (this is correct behavior at this point)
Actual: You'll see the expected warning:
warning: unexpected `cfg` condition value: `std`
--> src/lib.rs:1:17
|
1 | #![cfg_attr(not(feature = "std"), no_std)]
| ^^^^^^^^^^^^^^^ help: remove the condition
|
= note: no expected values for `feature`
= help: consider adding `std` as a feature in `Cargo.toml`
This warning is now cached by sccache.
5. Fix the configuration by adding the feature to Cargo.toml:
[package]
name = "test_sccache_bug"
version = "0.1.0"
edition = "2024"
[features]
std = []
default = ["std"]
6. Build again - the warning should disappear but doesn't:
cargo check --no-default-features
Expected: No warnings (the std feature is now properly defined)
Actual: The same warning still appears! This is the bug.
7. Verify cargo is passing correct flags:
cargo clean
cargo check --no-default-features -vv 2>&1 | grep "check-cfg"
You'll see that cargo IS correctly passing:
--check-cfg 'cfg(feature, values("default", "std"))'
This proves cargo knows about the feature and is telling rustc, but sccache is returning the cached warning.
8. Confirm it's an sccache caching issue:
# Bypass sccache - warning disappears
cargo clean
RUSTC_WRAPPER="" cargo check --no-default-features
# No warning!
# Or clear sccache cache - warning disappears
rm -rf ~/.cache/sccache
cargo clean
cargo check --no-default-features
# No warning!
Root Cause Analysis
When cargo passes updated --check-cfg flags to rustc via sccache, sccache appears to return cached compilation results (including cached warnings) from a previous compilation where the flags were different or missing.
The cache key doesn't seem to properly account for changes in the --check-cfg flags, causing stale warnings to persist even when the underlying issue has been fixed in the project configuration.
Expected Behavior
sccache should either:
- Include
--check-cfg flags in its cache key calculation, or
- Not cache warning/diagnostic output separately from the compilation itself, or
- Invalidate cached results when
--check-cfg flags change
Impact
This issue is particularly problematic because:
- It causes confusion during development (warnings that shouldn't exist)
- It makes it unclear whether project configuration is correct
- Standard debugging steps (
cargo clean) don't resolve it
- It specifically affects Rust 2024 edition projects using the new
check-cfg features
- New users may think there's a problem with their
Cargo.toml when it's actually correct
Note: This bug report was written by Claude Code based on a debugging session where Claude isolated this issue with my help; it was then edited by me. I have verified the report independently: to the best of my knowledge and ability it is correct, and clearer and more complete than what I would have written.
Summary
When using
sccachewith Rust 2024 edition projects,check-cfgwarnings about unknown feature values are cached and persist even after:Cargo.tomlis properly configured with the featurescargo cleansccacheserverThe cached warnings only clear when either:
sccachecache directory is manually deleted (rm -rf ~/.cache/sccache)sccacheis bypassed entirely (RUSTC_WRAPPER="" cargo check)This causes confusing behavior where
cargois passing the correct--check-cfgflags torustc, but the compilation output still shows warnings about missing features.Environment
Reproduction Steps
1. Create a new library with Rust 2024 edition (WITHOUT features initially):
cargo new --lib test_sccache_bug cd test_sccache_bug2. Edit
Cargo.tomlto use edition 2024 but DON'T add features yet:3. Edit
src/lib.rsto reference a feature that doesn't exist:#![cfg_attr(not(feature = "std"), no_std)]4. Build with
sccacheenabled to cache the warning:Expected: Warning about unknown
stdfeature (this is correct behavior at this point)Actual: You'll see the expected warning:
This warning is now cached by
sccache.5. Fix the configuration by adding the feature to
Cargo.toml:6. Build again - the warning should disappear but doesn't:
Expected: No warnings (the
stdfeature is now properly defined)Actual: The same warning still appears! This is the bug.
7. Verify
cargois passing correct flags:You'll see that
cargoIS correctly passing:This proves
cargoknows about the feature and is tellingrustc, butsccacheis returning the cached warning.8. Confirm it's an
sccachecaching issue:Root Cause Analysis
When
cargopasses updated--check-cfgflags torustcviasccache,sccacheappears to return cached compilation results (including cached warnings) from a previous compilation where the flags were different or missing.The cache key doesn't seem to properly account for changes in the
--check-cfgflags, causing stale warnings to persist even when the underlying issue has been fixed in the project configuration.Expected Behavior
sccacheshould either:--check-cfgflags in its cache key calculation, or--check-cfgflags changeImpact
This issue is particularly problematic because:
cargo clean) don't resolve itcheck-cfgfeaturesCargo.tomlwhen it's actually correct