mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
Report usage of lib features in ast validation
This commit is contained in:
parent
c092b28976
commit
153a381104
@ -607,8 +607,7 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate)
|
||||
// does not check the same for lib features unless there's at least one
|
||||
// declared lang feature
|
||||
if !sess.opts.unstable_features.is_nightly_build() {
|
||||
let lang_features = &features.declared_lang_features;
|
||||
if lang_features.len() == 0 {
|
||||
if features.declared_features.is_empty() {
|
||||
return;
|
||||
}
|
||||
for attr in krate.attrs.iter().filter(|attr| attr.has_name(sym::feature)) {
|
||||
@ -624,7 +623,8 @@ fn maybe_stage_features(sess: &Session, features: &Features, krate: &ast::Crate)
|
||||
attr.meta_item_list().into_iter().flatten().flat_map(|nested| nested.ident())
|
||||
{
|
||||
let name = ident.name;
|
||||
let stable_since = lang_features
|
||||
let stable_since = features
|
||||
.declared_lang_features
|
||||
.iter()
|
||||
.flat_map(|&(feature, _, since)| if feature == name { since } else { None })
|
||||
.next();
|
||||
|
@ -290,9 +290,6 @@ passes_export_name =
|
||||
passes_extern_main =
|
||||
the `main` function cannot be declared in an `extern` block
|
||||
|
||||
passes_feature_only_on_nightly =
|
||||
`#![feature]` may not be used on the {$release_channel} release channel
|
||||
|
||||
passes_feature_previously_declared =
|
||||
feature `{$feature}` is declared {$declared}, but was previously declared {$prev_declared}
|
||||
|
||||
|
@ -1492,14 +1492,6 @@ pub struct TraitImplConstStable {
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes_feature_only_on_nightly, code = E0554)]
|
||||
pub struct FeatureOnlyOnNightly {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub release_channel: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes_unknown_feature, code = E0635)]
|
||||
pub struct UnknownFeature {
|
||||
|
@ -936,12 +936,6 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
|
||||
let declared_lib_features = &tcx.features().declared_lib_features;
|
||||
let mut remaining_lib_features = FxIndexMap::default();
|
||||
for (feature, span) in declared_lib_features {
|
||||
if !tcx.sess.opts.unstable_features.is_nightly_build() {
|
||||
tcx.dcx().emit_err(errors::FeatureOnlyOnNightly {
|
||||
span: *span,
|
||||
release_channel: env!("CFG_RELEASE_CHANNEL"),
|
||||
});
|
||||
}
|
||||
if remaining_lib_features.contains_key(&feature) {
|
||||
// Warn if the user enables a lib feature multiple times.
|
||||
tcx.dcx().emit_err(errors::DuplicateFeatureErr { span: *span, feature: *feature });
|
||||
|
Loading…
Reference in New Issue
Block a user