mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Turn INCOMPLETE_FEATURES into a lint.
This commit is contained in:
parent
4eeaaa722d
commit
dcc4b994b9
@ -33,13 +33,12 @@ use lint::{LintPass, LateLintPass, EarlyLintPass, EarlyContext};
|
||||
use rustc::util::nodemap::FxHashSet;
|
||||
|
||||
use syntax::tokenstream::{TokenTree, TokenStream};
|
||||
use syntax::ast;
|
||||
use syntax::ast::{self, Expr};
|
||||
use syntax::ptr::P;
|
||||
use syntax::ast::Expr;
|
||||
use syntax::attr::{self, HasAttrs, AttributeTemplate};
|
||||
use syntax::source_map::Spanned;
|
||||
use syntax::edition::Edition;
|
||||
use syntax::feature_gate::{AttributeGate, AttributeType};
|
||||
use syntax::feature_gate::{self, AttributeGate, AttributeType};
|
||||
use syntax::feature_gate::{Stability, deprecated_attributes};
|
||||
use syntax_pos::{BytePos, Span, SyntaxContext};
|
||||
use syntax::symbol::{Symbol, kw, sym};
|
||||
@ -1831,3 +1830,35 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare_lint! {
|
||||
pub INCOMPLETE_FEATURES,
|
||||
Warn,
|
||||
"incomplete features that may function improperly in some or all cases"
|
||||
}
|
||||
|
||||
declare_lint_pass!(
|
||||
/// Check for used feature gates in `INCOMPLETE_FEATURES` in `feature_gate.rs`.
|
||||
IncompleteFeatures => [INCOMPLETE_FEATURES]
|
||||
);
|
||||
|
||||
impl EarlyLintPass for IncompleteFeatures {
|
||||
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
|
||||
let features = cx.sess.features_untracked();
|
||||
features.declared_lang_features
|
||||
.iter().map(|(name, span, _)| (name, span))
|
||||
.chain(features.declared_lib_features.iter().map(|(name, span)| (name, span)))
|
||||
.filter(|(name, _)| feature_gate::INCOMPLETE_FEATURES.iter().any(|f| name == &f))
|
||||
.for_each(|(name, &span)| {
|
||||
cx.struct_span_lint(
|
||||
INCOMPLETE_FEATURES,
|
||||
span,
|
||||
&format!(
|
||||
"the feature `{}` is incomplete and may cause the compiler to crash",
|
||||
name,
|
||||
)
|
||||
)
|
||||
.emit();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -97,6 +97,7 @@ macro_rules! early_lint_passes {
|
||||
DeprecatedAttr: DeprecatedAttr::new(),
|
||||
WhileTrue: WhileTrue,
|
||||
NonAsciiIdents: NonAsciiIdents,
|
||||
IncompleteFeatures: IncompleteFeatures,
|
||||
]);
|
||||
)
|
||||
}
|
||||
|
@ -569,10 +569,10 @@ declare_features! (
|
||||
// -------------------------------------------------------------------------
|
||||
);
|
||||
|
||||
// Some features are known to be incomplete and using them is likely to have
|
||||
// unanticipated results, such as compiler crashes. We warn the user about these
|
||||
// to alert them.
|
||||
const INCOMPLETE_FEATURES: &[Symbol] = &[
|
||||
/// Some features are known to be incomplete and using them is likely to have
|
||||
/// unanticipated results, such as compiler crashes. We warn the user about these
|
||||
/// to alert them.
|
||||
pub const INCOMPLETE_FEATURES: &[Symbol] = &[
|
||||
sym::impl_trait_in_bindings,
|
||||
sym::generic_associated_types,
|
||||
sym::const_generics,
|
||||
@ -2338,15 +2338,6 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
|
||||
}
|
||||
|
||||
let name = mi.name_or_empty();
|
||||
if INCOMPLETE_FEATURES.iter().any(|f| name == *f) {
|
||||
span_handler.struct_span_warn(
|
||||
mi.span(),
|
||||
&format!(
|
||||
"the feature `{}` is incomplete and may cause the compiler to crash",
|
||||
name
|
||||
)
|
||||
).emit();
|
||||
}
|
||||
|
||||
if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) {
|
||||
if *edition <= crate_edition {
|
||||
|
Loading…
Reference in New Issue
Block a user