Rollup merge of #68018 - petrochenkov:nosoft, r=Centril

feature_gate: Remove `GateStrength`

The "soft feature gating" from `feature_gate/check.rs` is unused, and even if it were used, hardcoded warning is not a good solution and [deny-by-default lint](https://github.com/rust-lang/rust/issues/64266) would be a better way to do this.

cc https://github.com/rust-lang/rust/pull/67806#discussion_r363091701
r? @Centril
This commit is contained in:
Mazdak Farrokhzad 2020-01-11 12:36:09 +01:00 committed by GitHub
commit 31d7ffa1e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 74 deletions

View File

@ -8,37 +8,25 @@ use rustc_span::Span;
use syntax::ast::{self, AssocTyConstraint, AssocTyConstraintKind, NodeId};
use syntax::ast::{GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData};
use syntax::attr;
use syntax::sess::{feature_err, leveled_feature_err, GateStrength, ParseSess};
use syntax::sess::{feature_err, feature_err_issue, ParseSess};
use syntax::visit::{self, FnKind, Visitor};
use log::debug;
macro_rules! gate_feature_fn {
($cx: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr, $level: expr) => {{
let (cx, has_feature, span, name, explain, level) =
(&*$cx, $has_feature, $span, $name, $explain, $level);
($cx: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr) => {{
let (cx, has_feature, span, name, explain) = (&*$cx, $has_feature, $span, $name, $explain);
let has_feature: bool = has_feature(&$cx.features);
debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", name, span, has_feature);
if !has_feature && !span.allows_unstable($name) {
leveled_feature_err(cx.parse_sess, name, span, GateIssue::Language, explain, level)
.emit();
feature_err_issue(cx.parse_sess, name, span, GateIssue::Language, explain).emit();
}
}};
}
macro_rules! gate_feature {
macro_rules! gate_feature_post {
($cx: expr, $feature: ident, $span: expr, $explain: expr) => {
gate_feature_fn!(
$cx,
|x: &Features| x.$feature,
$span,
sym::$feature,
$explain,
GateStrength::Hard
)
};
($cx: expr, $feature: ident, $span: expr, $explain: expr, $level: expr) => {
gate_feature_fn!($cx, |x: &Features| x.$feature, $span, sym::$feature, $explain, $level)
gate_feature_fn!($cx, |x: &Features| x.$feature, $span, sym::$feature, $explain)
};
}
@ -51,21 +39,6 @@ struct PostExpansionVisitor<'a> {
features: &'a Features,
}
macro_rules! gate_feature_post {
($cx: expr, $feature: ident, $span: expr, $explain: expr) => {{
let (cx, span) = ($cx, $span);
if !span.allows_unstable(sym::$feature) {
gate_feature!(cx, $feature, span, $explain)
}
}};
($cx: expr, $feature: ident, $span: expr, $explain: expr, $level: expr) => {{
let (cx, span) = ($cx, $span);
if !span.allows_unstable(sym::$feature) {
gate_feature!(cx, $feature, span, $explain, $level)
}
}};
}
impl<'a> PostExpansionVisitor<'a> {
fn check_abi(&self, abi: ast::StrLit) {
let ast::StrLit { symbol_unescaped, span, .. } = abi;
@ -257,7 +230,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)).map(|a| **a);
// Check feature gates for built-in attributes.
if let Some((.., AttributeGate::Gated(_, name, descr, has_feature))) = attr_info {
gate_feature_fn!(self, has_feature, attr.span, name, descr, GateStrength::Hard);
gate_feature_fn!(self, has_feature, attr.span, name, descr);
}
// Check unstable flavors of the `#[doc]` attribute.
if attr.check_name(sym::doc) {
@ -265,7 +238,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
macro_rules! gate_doc { ($($name:ident => $feature:ident)*) => {
$(if nested_meta.check_name(sym::$name) {
let msg = concat!("`#[doc(", stringify!($name), ")]` is experimental");
gate_feature!(self, $feature, attr.span, msg);
gate_feature_post!(self, $feature, attr.span, msg);
})*
}}
@ -666,7 +639,7 @@ pub fn check_crate(
macro_rules! gate_all {
($gate:ident, $msg:literal) => {
for span in spans.get(&sym::$gate).unwrap_or(&vec![]) {
gate_feature!(&visitor, $gate, *span, $msg);
gate_feature_post!(&visitor, $gate, *span, $msg);
}
};
}
@ -688,7 +661,7 @@ pub fn check_crate(
// disabling these uses of early feature-gatings.
if false {
for span in spans.get(&sym::$gate).unwrap_or(&vec![]) {
gate_feature!(&visitor, $gate, *span, $msg);
gate_feature_post!(&visitor, $gate, *span, $msg);
}
}
};

View File

@ -62,16 +62,6 @@ impl GatedSpans {
}
}
/// The strenght of a feature gate.
/// Either it is a `Hard` error, or only a `Soft` warning.
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum GateStrength {
/// A hard error. (Most feature gates should use this.)
Hard,
/// Only a warning. (Use this only as backwards-compatibility demands.)
Soft,
}
/// Construct a diagnostic for a language feature error due to the given `span`.
/// The `feature`'s `Symbol` is the one you used in `active.rs` and `rustc_span::symbols`.
pub fn feature_err<'a>(
@ -94,26 +84,7 @@ pub fn feature_err_issue<'a>(
issue: GateIssue,
explain: &str,
) -> DiagnosticBuilder<'a> {
leveled_feature_err(sess, feature, span, issue, explain, GateStrength::Hard)
}
/// Construct a diagnostic for a feature gate error / warning.
///
/// You should typically just use `feature_err` instead.
pub fn leveled_feature_err<'a>(
sess: &'a ParseSess,
feature: Symbol,
span: impl Into<MultiSpan>,
issue: GateIssue,
explain: &str,
level: GateStrength,
) -> DiagnosticBuilder<'a> {
let diag = &sess.span_diagnostic;
let mut err = match level {
GateStrength::Hard => diag.struct_span_err_with_code(span, explain, error_code!(E0658)),
GateStrength::Soft => diag.struct_span_warn(span, explain),
};
let mut err = sess.span_diagnostic.struct_span_err_with_code(span, explain, error_code!(E0658));
if let Some(n) = find_feature_issue(feature, issue) {
err.note(&format!(
@ -127,13 +98,6 @@ pub fn leveled_feature_err<'a>(
err.help(&format!("add `#![feature({})]` to the crate attributes to enable", feature));
}
// If we're on stable and only emitting a "soft" warning, add a note to
// clarify that the feature isn't "on" (rather than being on but
// warning-worthy).
if !sess.unstable_features.is_nightly_build() && level == GateStrength::Soft {
err.help("a nightly build of the compiler is required to enable this feature");
}
err
}