Skip to content

Commit 2ffeb9b

Browse files
authored
Rollup merge of rust-lang#153610 - mu001999-contrib:fix/unused-stable-features, r=JonathanBrouwer
Only lint unused features if they are unstable Fixes rust-lang#153523
2 parents a4a57a2 + dfd5e90 commit 2ffeb9b

4 files changed

Lines changed: 26 additions & 10 deletions

File tree

compiler/rustc_passes/src/stability.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,9 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
964964
let mut lang_features = UnordSet::default();
965965
for EnabledLangFeature { gate_name, attr_sp, stable_since } in enabled_lang_features {
966966
if let Some(version) = stable_since {
967+
// Mark the feature as enabled, to ensure that it is not marked as unused.
968+
let _ = tcx.features().enabled(*gate_name);
969+
967970
// Warn if the user has enabled an already-stable lang feature.
968971
unnecessary_stable_feature_lint(tcx, *attr_sp, *gate_name, *version);
969972
}
@@ -1021,6 +1024,9 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
10211024
if let FeatureStability::AcceptedSince(since) = stability
10221025
&& let Some(span) = remaining_lib_features.get(&feature)
10231026
{
1027+
// Mark the feature as enabled, to ensure that it is not marked as unused.
1028+
let _ = tcx.features().enabled(feature);
1029+
10241030
// Warn if the user has enabled an already-stable lib feature.
10251031
if let Some(implies) = all_implications.get(&feature) {
10261032
unnecessary_partially_stable_feature_lint(tcx, *span, feature, *implies, since);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ check-pass
2+
3+
#![deny(warnings)]
4+
#![allow(stable_features)]
5+
6+
// Lang feature
7+
#![feature(lint_reasons)]
8+
9+
// Lib feature
10+
#![feature(euclidean_division)]
11+
12+
#[allow(unused_variables, reason = "my reason")]
13+
fn main() {
14+
let x = ();
15+
16+
let _ = 42.0_f32.div_euclid(3.0);
17+
}

tests/ui/lint/unused-features/unused-library-features.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#![feature(step_trait)]
66
//~^ ERROR feature `step_trait` is declared but not used
77
#![feature(is_sorted)]
8-
//~^ ERROR feature `is_sorted` is declared but not used
9-
//~^^ WARN the feature `is_sorted` has been stable since 1.82.0 and no longer requires an attribute to enable
8+
//~^ WARN the feature `is_sorted` has been stable since 1.82.0 and no longer requires an attribute to enable
109

1110
// Enabled via cfg_attr, unused
1211
#![cfg_attr(all(), feature(slice_ptr_get))]

tests/ui/lint/unused-features/unused-library-features.stderr

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,11 @@ note: the lint level is defined here
1818
LL | #![deny(unused_features)]
1919
| ^^^^^^^^^^^^^^^
2020

21-
error: feature `is_sorted` is declared but not used
22-
--> $DIR/unused-library-features.rs:7:12
23-
|
24-
LL | #![feature(is_sorted)]
25-
| ^^^^^^^^^
26-
2721
error: feature `slice_ptr_get` is declared but not used
28-
--> $DIR/unused-library-features.rs:12:28
22+
--> $DIR/unused-library-features.rs:11:28
2923
|
3024
LL | #![cfg_attr(all(), feature(slice_ptr_get))]
3125
| ^^^^^^^^^^^^^
3226

33-
error: aborting due to 3 previous errors; 1 warning emitted
27+
error: aborting due to 2 previous errors; 1 warning emitted
3428

0 commit comments

Comments
 (0)