Skip to content

Commit a7aba58

Browse files
committed
Auto merge of #83722 - jyn514:stable-help, r=estebank
On stable, suggest removing `#![feature]` for features that have been stabilized I don't know how to test this (https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Run.20tests.20without.20enabling.20nightly.20features.3F). I confirmed locally that this gives the appropriate help with `channel = "beta"`: ``` error[E0554]: `#![feature]` may not be used on the beta release channel --> src/lib.rs:2:1 | 2 | #![feature(min_const_generics)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the attribute | = help: the feature `min_const_generics` has been stable since 1.51.0 and no longer requires an attribute to enable error[E0554]: `#![feature]` may not be used on the beta release channel --> src/lib.rs:3:1 | 3 | #![feature(min_const_generics, min_specialization)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: the feature `min_const_generics` has been stable since 1.51.0 and no longer requires an attribute to enable error[E0554]: `#![feature]` may not be used on the beta release channel --> src/lib.rs:4:1 | 4 | #![feature(box_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ ``` Closes #83715.
2 parents 8ad0821 + 53a1105 commit a7aba58

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+33-3
Original file line numberDiff line numberDiff line change
@@ -727,16 +727,46 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
727727
}
728728

729729
fn maybe_stage_features(sess: &Session, krate: &ast::Crate) {
730+
use rustc_errors::Applicability;
731+
730732
if !sess.opts.unstable_features.is_nightly_build() {
733+
let lang_features = &sess.features_untracked().declared_lang_features;
731734
for attr in krate.attrs.iter().filter(|attr| sess.check_name(attr, sym::feature)) {
732-
struct_span_err!(
735+
let mut err = struct_span_err!(
733736
sess.parse_sess.span_diagnostic,
734737
attr.span,
735738
E0554,
736739
"`#![feature]` may not be used on the {} release channel",
737740
option_env!("CFG_RELEASE_CHANNEL").unwrap_or("(unknown)")
738-
)
739-
.emit();
741+
);
742+
let mut all_stable = true;
743+
for ident in
744+
attr.meta_item_list().into_iter().flatten().map(|nested| nested.ident()).flatten()
745+
{
746+
let name = ident.name;
747+
let stable_since = lang_features
748+
.iter()
749+
.flat_map(|&(feature, _, since)| if feature == name { since } else { None })
750+
.next();
751+
if let Some(since) = stable_since {
752+
err.help(&format!(
753+
"the feature `{}` has been stable since {} and no longer requires \
754+
an attribute to enable",
755+
name, since
756+
));
757+
} else {
758+
all_stable = false;
759+
}
760+
}
761+
if all_stable {
762+
err.span_suggestion(
763+
attr.span,
764+
"remove the attribute",
765+
String::new(),
766+
Applicability::MachineApplicable,
767+
);
768+
}
769+
err.emit();
740770
}
741771
}
742772
}

0 commit comments

Comments
 (0)