about summary refs log tree commit diff
path: root/src/libsyntax/feature_gate
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-01-08 12:12:08 +0000
committerbors <bors@rust-lang.org>2020-01-08 12:12:08 +0000
commited6468da160bd67a2ce0573427f09a98daff8c07 (patch)
treef60a0277a129a9835cafbe0eb526b28a4888f0e8 /src/libsyntax/feature_gate
parent87540bd3bca8dcd86223261f8c76c5bbf6811ee6 (diff)
parent20ebb807d523947f5fac710c4ae95ac9730ad995 (diff)
Auto merge of #67770 - Centril:reduce-diversity-2, r=petrochenkov
More reductions in error handling diversity

In this follow up to https://github.com/rust-lang/rust/pull/67744, we:

- Remove all fatal / error / warning macros in `syntax` except for `struct_span_err`, which is moved to `rustc_errors`.

- Lintify some hard-coded warnings which used warning macros.

- Defatalize some errors.

In general, the goal here is to make it painful to use fatal or unstructured errors and so we hopefully won't see many of these creep in.

Fixes https://github.com/rust-lang/rust/issues/67933.
Diffstat (limited to 'src/libsyntax/feature_gate')
-rw-r--r--src/libsyntax/feature_gate/check.rs28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs
index 0e94a722777..26545bfa61b 100644
--- a/src/libsyntax/feature_gate/check.rs
+++ b/src/libsyntax/feature_gate/check.rs
@@ -4,7 +4,7 @@ use crate::attr;
 use crate::sess::ParseSess;
 use crate::visit::{self, FnKind, Visitor};
 
-use errors::{Applicability, DiagnosticBuilder, Handler};
+use errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder, Handler};
 use rustc_data_structures::fx::FxHashMap;
 use rustc_error_codes::*;
 use rustc_feature::{find_feature_issue, GateIssue};
@@ -91,9 +91,7 @@ fn leveled_feature_err<'a>(
     let diag = &sess.span_diagnostic;
 
     let mut err = match level {
-        GateStrength::Hard => {
-            diag.struct_span_err_with_code(span, explain, stringify_error_code!(E0658))
-        }
+        GateStrength::Hard => diag.struct_span_err_with_code(span, explain, error_code!(E0658)),
         GateStrength::Soft => diag.struct_span_warn(span, explain),
     };
 
@@ -827,15 +825,9 @@ pub fn get_features(
             };
 
             if let Some(edition) = edition_enabled_features.get(&name) {
-                struct_span_warn!(
-                    span_handler,
-                    mi.span(),
-                    E0705,
-                    "the feature `{}` is included in the Rust {} edition",
-                    name,
-                    edition,
-                )
-                .emit();
+                let msg =
+                    &format!("the feature `{}` is included in the Rust {} edition", name, edition);
+                span_handler.struct_span_warn_with_code(mi.span(), msg, error_code!(E0705)).emit();
                 continue;
             }
 
@@ -863,13 +855,14 @@ pub fn get_features(
 
             if let Some(allowed) = allow_features.as_ref() {
                 if allowed.iter().find(|&f| name.as_str() == *f).is_none() {
-                    span_err!(
+                    struct_span_err!(
                         span_handler,
                         mi.span(),
                         E0725,
                         "the feature `{}` is not in the list of allowed features",
                         name
-                    );
+                    )
+                    .emit();
                     continue;
                 }
             }
@@ -953,13 +946,14 @@ pub fn check_crate(
 fn maybe_stage_features(span_handler: &Handler, krate: &ast::Crate, unstable: UnstableFeatures) {
     if !unstable.is_nightly_build() {
         for attr in krate.attrs.iter().filter(|attr| attr.check_name(sym::feature)) {
-            span_err!(
+            struct_span_err!(
                 span_handler,
                 attr.span,
                 E0554,
                 "`#![feature]` may not be used on the {} release channel",
                 option_env!("CFG_RELEASE_CHANNEL").unwrap_or("(unknown)")
-            );
+            )
+            .emit();
         }
     }
 }