Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,9 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
let mut lang_features = UnordSet::default();
for EnabledLangFeature { gate_name, attr_sp, stable_since } in enabled_lang_features {
if let Some(version) = stable_since {
// Mark the feature as enabled, to ensure that it is not marked as unused.
let _ = tcx.features().enabled(*gate_name);

// Warn if the user has enabled an already-stable lang feature.
unnecessary_stable_feature_lint(tcx, *attr_sp, *gate_name, *version);
}
Expand Down Expand Up @@ -1021,6 +1024,9 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
if let FeatureStability::AcceptedSince(since) = stability
&& let Some(span) = remaining_lib_features.get(&feature)
{
// Mark the feature as enabled, to ensure that it is not marked as unused.
let _ = tcx.features().enabled(feature);

// Warn if the user has enabled an already-stable lib feature.
if let Some(implies) = all_implications.get(&feature) {
unnecessary_partially_stable_feature_lint(tcx, *span, feature, *implies, since);
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/lint/unused-features/stable-features.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ check-pass

#![deny(warnings)]
#![allow(stable_features)]

// Lang feature
#![feature(lint_reasons)]

// Lib feature
#![feature(euclidean_division)]

#[allow(unused_variables, reason = "my reason")]
fn main() {
let x = ();

let _ = 42.0_f32.div_euclid(3.0);
}
3 changes: 1 addition & 2 deletions tests/ui/lint/unused-features/unused-library-features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
#![feature(step_trait)]
//~^ ERROR feature `step_trait` is declared but not used
#![feature(is_sorted)]
//~^ ERROR feature `is_sorted` is declared but not used
//~^^ WARN the feature `is_sorted` has been stable since 1.82.0 and no longer requires an attribute to enable
//~^ WARN the feature `is_sorted` has been stable since 1.82.0 and no longer requires an attribute to enable

// Enabled via cfg_attr, unused
#![cfg_attr(all(), feature(slice_ptr_get))]
Expand Down
10 changes: 2 additions & 8 deletions tests/ui/lint/unused-features/unused-library-features.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@ note: the lint level is defined here
LL | #![deny(unused_features)]
| ^^^^^^^^^^^^^^^

error: feature `is_sorted` is declared but not used
--> $DIR/unused-library-features.rs:7:12
|
LL | #![feature(is_sorted)]
| ^^^^^^^^^

error: feature `slice_ptr_get` is declared but not used
--> $DIR/unused-library-features.rs:12:28
--> $DIR/unused-library-features.rs:11:28
|
LL | #![cfg_attr(all(), feature(slice_ptr_get))]
| ^^^^^^^^^^^^^

error: aborting due to 3 previous errors; 1 warning emitted
error: aborting due to 2 previous errors; 1 warning emitted

Loading