From 8e35c4f74ccc8e5cd537f50dd02ffb25edfd5ba6 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 8 Jan 2020 20:27:06 +0300 Subject: [PATCH] feature_gate: Remove `GateStrength` --- src/librustc_ast_passes/feature_gate.rs | 47 ++++++------------------- src/librustc_session/parse.rs | 38 +------------------- 2 files changed, 11 insertions(+), 74 deletions(-) diff --git a/src/librustc_ast_passes/feature_gate.rs b/src/librustc_ast_passes/feature_gate.rs index 1e396d6fe8e47..e6f4535a38dba 100644 --- a/src/librustc_ast_passes/feature_gate.rs +++ b/src/librustc_ast_passes/feature_gate.rs @@ -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); } } }; diff --git a/src/librustc_session/parse.rs b/src/librustc_session/parse.rs index 946e77d35595e..a98cf929095ea 100644 --- a/src/librustc_session/parse.rs +++ b/src/librustc_session/parse.rs @@ -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, - 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 }