summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-01-02 11:41:57 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-01-11 03:15:32 +0100
commit6007641d2101e6489aa6b9a3ba84b6a2b9b04fa5 (patch)
tree353a36be5e908f39eb2fe9d7f1b49e8934174acb /src/libsyntax
parent175631311716d7dfeceec40d2587cde7142ffa8c (diff)
downloadrust-6007641d2101e6489aa6b9a3ba84b6a2b9b04fa5.tar.gz
rust-6007641d2101e6489aa6b9a3ba84b6a2b9b04fa5.zip
gating diagnostics -> rustc_session::parse
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/attr/builtin.rs3
-rw-r--r--src/libsyntax/feature_gate/check.rs73
-rw-r--r--src/libsyntax/lib.rs3
3 files changed, 7 insertions, 72 deletions
diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs
index 958e4373cc0..70f4f47621a 100644
--- a/src/libsyntax/attr/builtin.rs
+++ b/src/libsyntax/attr/builtin.rs
@@ -2,9 +2,8 @@
 
 use super::{mark_used, MetaItemKind};
 use crate::ast::{self, Attribute, MetaItem, NestedMetaItem};
-use crate::feature_gate::feature_err;
 use crate::print::pprust;
-use crate::sess::ParseSess;
+use crate::sess::{feature_err, ParseSess};
 
 use rustc_errors::{struct_span_err, Applicability, Handler};
 use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg};
diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs
index 4eee4e943c2..2b49a296a08 100644
--- a/src/libsyntax/feature_gate/check.rs
+++ b/src/libsyntax/feature_gate/check.rs
@@ -1,22 +1,21 @@
 use crate::ast::{self, AssocTyConstraint, AssocTyConstraintKind, NodeId};
 use crate::ast::{GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData};
 use crate::attr;
-use crate::sess::ParseSess;
+use crate::sess::{feature_err, leveled_feature_err, GateStrength, ParseSess};
 use crate::visit::{self, FnKind, Visitor};
 
 use rustc_data_structures::fx::FxHashMap;
 use rustc_error_codes::*;
-use rustc_errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder, Handler};
-use rustc_feature::{find_feature_issue, GateIssue};
+use rustc_errors::{error_code, struct_span_err, Applicability, Handler};
 use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
-use rustc_feature::{Feature, Features, State as FeatureState, UnstableFeatures};
+use rustc_feature::{Feature, Features, GateIssue, State as FeatureState, UnstableFeatures};
 use rustc_feature::{
     ACCEPTED_FEATURES, ACTIVE_FEATURES, REMOVED_FEATURES, STABLE_REMOVED_FEATURES,
 };
 use rustc_span::edition::{Edition, ALL_EDITIONS};
 use rustc_span::source_map::Spanned;
 use rustc_span::symbol::{sym, Symbol};
-use rustc_span::{MultiSpan, Span, DUMMY_SP};
+use rustc_span::{Span, DUMMY_SP};
 
 use log::debug;
 
@@ -53,70 +52,6 @@ pub fn check_attribute(attr: &ast::Attribute, parse_sess: &ParseSess, features:
     PostExpansionVisitor { parse_sess, features }.visit_attribute(attr)
 }
 
-#[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,
-}
-
-pub fn feature_err<'a>(
-    sess: &'a ParseSess,
-    feature: Symbol,
-    span: impl Into<MultiSpan>,
-    explain: &str,
-) -> DiagnosticBuilder<'a> {
-    feature_err_issue(sess, feature, span, GateIssue::Language, explain)
-}
-
-pub fn feature_err_issue<'a>(
-    sess: &'a ParseSess,
-    feature: Symbol,
-    span: impl Into<MultiSpan>,
-    issue: GateIssue,
-    explain: &str,
-) -> DiagnosticBuilder<'a> {
-    leveled_feature_err(sess, feature, span, issue, explain, GateStrength::Hard)
-}
-
-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),
-    };
-
-    if let Some(n) = find_feature_issue(feature, issue) {
-        err.note(&format!(
-            "for more information, see https://github.com/rust-lang/rust/issues/{}",
-            n,
-        ));
-    }
-
-    // #23973: do not suggest `#![feature(...)]` if we are in beta/stable
-    if sess.unstable_features.is_nightly_build() {
-        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
-}
-
 struct PostExpansionVisitor<'a> {
     parse_sess: &'a ParseSess,
     features: &'a Features,
diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs
index 7ee4ca4603c..ffb0d7e7f97 100644
--- a/src/libsyntax/lib.rs
+++ b/src/libsyntax/lib.rs
@@ -77,7 +77,8 @@ pub mod entry;
 pub mod expand;
 pub mod feature_gate {
     mod check;
-    pub use check::{check_attribute, check_crate, feature_err, feature_err_issue, get_features};
+    pub use check::{check_attribute, check_crate, get_features};
+    pub use rustc_session::parse::{feature_err, feature_err_issue};
 }
 pub mod mut_visit;
 pub mod ptr;