Verified Solution[rust-lang/rust] `unused_features` triggers on stable `lint_reasons` despite usage
Sponsored Content
**ROOT CAUSE**
The `unused_features` lint is incorrectly triggered for the `lint_reasons` feature, which is a stable feature. This occurs because the compiler's `unused_features` lint does not properly exclude stabilized features from its checks. The issue arises from a misinteraction between the `#[feature(...)]` attribute and the `unused_features` lint, which should not apply to stable features.
---
**CODE FIX**
```rust
#![allow(unused_features)] // Explicitly allow unused features to bypass the lint
#![allow(stable_features)]
#![feature(lint_reasons)]
#[allow(unused_variables, reason = "my reason")]
fn main() {
let x = ();
}
```
**Explanation**:
- The `#[allow(unused_features)]` attribute suppresses the `unused_features` lint globally, preventing the error.
- The `lint_reasons` feature is still used via `#[allow(...)]` with a reason, ensuring the feature is marked as utilized.
- This approach avoids relying on the compiler's unstable feature tracking for stabilized features.
Deploy on DigitalOcean ($200 Credit)
Related Fixes
[golang/go] cmd/cgo/internal/test: build error on macOS 26 in Go 1.25 [1.25 backport]
[StackOverflow/reactjs] Invalidate queries with subquery
[StackOverflow/go] Is it possible to make a flexible/dynamic query with sqlc?