diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-31 21:25:16 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-01-08 04:25:33 +0100 |
| commit | 2c3e5d3de023c0bfbf4a4c4d3b0d7a9844e96ffe (patch) | |
| tree | d8a6e6281016eab3b52f1e0bbd0b89b7ea09035e /src/libsyntax | |
| parent | 7e393b5b3b543d355ae16c1940cf98b6c7fcb8aa (diff) | |
| download | rust-2c3e5d3de023c0bfbf4a4c4d3b0d7a9844e96ffe.tar.gz rust-2c3e5d3de023c0bfbf4a4c4d3b0d7a9844e96ffe.zip | |
- remove syntax::{span_warn!, span_err!, span_fatal!. struct_err!}
- remove syntax::{help!, span_help!, span_note!}
- remove unused syntax::{struct_span_fatal, struct_span_err_or_warn!, span_err_or_warn!}
- lintify check_for_bindings_named_same_as_variants + conflicting_repr_hints
- inline syntax::{struct_span_warn!, diagnostic_used!}
- stringify_error_code! -> error_code! & use it more.
- find_plugin_registrar: de-fatalize an error
- de-fatalize metadata errors
- move type_error_struct! to rustc_typeck
- struct_span_err! -> rustc_errors
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/attr/builtin.rs | 73 | ||||
| -rw-r--r-- | src/libsyntax/diagnostics/macros.rs | 169 | ||||
| -rw-r--r-- | src/libsyntax/feature_gate/check.rs | 28 | ||||
| -rw-r--r-- | src/libsyntax/lib.rs | 6 |
4 files changed, 60 insertions, 216 deletions
diff --git a/src/libsyntax/attr/builtin.rs b/src/libsyntax/attr/builtin.rs index 04c28dd5c5b..b308d479545 100644 --- a/src/libsyntax/attr/builtin.rs +++ b/src/libsyntax/attr/builtin.rs @@ -6,7 +6,7 @@ use crate::feature_gate::feature_err; use crate::print::pprust; use crate::sess::ParseSess; -use errors::{Applicability, Handler}; +use errors::{struct_span_err, Applicability, Handler}; use rustc_feature::{find_gated_cfg, is_builtin_attr_name, Features, GatedCfg}; use rustc_macros::HashStable_Generic; use rustc_span::hygiene::Transparency; @@ -31,17 +31,21 @@ enum AttrError { fn handle_errors(sess: &ParseSess, span: Span, error: AttrError) { let diag = &sess.span_diagnostic; match error { - AttrError::MultipleItem(item) => span_err!(diag, span, E0538, "multiple '{}' items", item), + AttrError::MultipleItem(item) => { + struct_span_err!(diag, span, E0538, "multiple '{}' items", item).emit(); + } AttrError::UnknownMetaItem(item, expected) => { let expected = expected.iter().map(|name| format!("`{}`", name)).collect::<Vec<_>>(); struct_span_err!(diag, span, E0541, "unknown meta item '{}'", item) .span_label(span, format!("expected one of {}", expected.join(", "))) .emit(); } - AttrError::MissingSince => span_err!(diag, span, E0542, "missing 'since'"), - AttrError::MissingFeature => span_err!(diag, span, E0546, "missing 'feature'"), + AttrError::MissingSince => struct_span_err!(diag, span, E0542, "missing 'since'").emit(), + AttrError::MissingFeature => { + struct_span_err!(diag, span, E0546, "missing 'feature'").emit(); + } AttrError::MultipleStabilityLevels => { - span_err!(diag, span, E0544, "multiple stability levels") + struct_span_err!(diag, span, E0544, "multiple stability levels").emit(); } AttrError::UnsupportedLiteral(msg, is_bytestr) => { let mut err = struct_span_err!(diag, span, E0565, "{}", msg); @@ -283,7 +287,7 @@ where *item = Some(v); true } else { - span_err!(diagnostic, meta.span, E0539, "incorrect meta item"); + struct_span_err!(diagnostic, meta.span, E0539, "incorrect meta item").emit(); false } }; @@ -331,12 +335,13 @@ where match meta_name { sym::rustc_deprecated => { if rustc_depr.is_some() { - span_err!( + struct_span_err!( diagnostic, item_sp, E0540, "multiple rustc_deprecated attributes" - ); + ) + .emit(); continue 'outer; } @@ -351,7 +356,8 @@ where continue; } _ => { - span_err!(diagnostic, attr.span, E0543, "missing 'reason'"); + struct_span_err!(diagnostic, attr.span, E0543, "missing 'reason'") + .emit(); continue; } } @@ -426,12 +432,13 @@ where // Disallowing this requires updates to some submodules NonZeroU32::new(num) } else { - span_err!( + struct_span_err!( diagnostic, attr.span, E0545, "incorrect 'issue'" - ); + ) + .emit(); continue; } } @@ -453,7 +460,8 @@ where continue; } _ => { - span_err!(diagnostic, attr.span, E0547, "missing 'issue'"); + struct_span_err!(diagnostic, attr.span, E0547, "missing 'issue'") + .emit(); continue; } } @@ -539,13 +547,14 @@ where if let Some(ref mut stab) = stab { stab.rustc_depr = Some(rustc_depr); } else { - span_err!( + struct_span_err!( diagnostic, item_sp, E0549, "rustc_deprecated attribute must be paired with \ either stable or unstable attribute" - ); + ) + .emit(); } } @@ -555,14 +564,15 @@ where stab.promotable = promotable; stab.allow_const_fn_ptr = allow_const_fn_ptr; } else { - span_err!( + struct_span_err!( diagnostic, item_sp, E0717, "rustc_promotable and rustc_allow_const_fn_ptr attributes \ must be paired with either a rustc_const_unstable or a rustc_const_stable \ attribute" - ); + ) + .emit(); } } @@ -649,20 +659,27 @@ pub fn eval_condition( } sym::not => { if mis.len() != 1 { - span_err!(sess.span_diagnostic, cfg.span, E0536, "expected 1 cfg-pattern"); + struct_span_err!( + sess.span_diagnostic, + cfg.span, + E0536, + "expected 1 cfg-pattern" + ) + .emit(); return false; } !eval_condition(mis[0].meta_item().unwrap(), sess, eval) } _ => { - span_err!( + struct_span_err!( sess.span_diagnostic, cfg.span, E0537, "invalid predicate `{}`", pprust::path_to_string(&cfg.path) - ); + ) + .emit(); false } } @@ -703,7 +720,7 @@ where } if depr.is_some() { - span_err!(diagnostic, item_sp, E0550, "multiple deprecated attributes"); + struct_span_err!(diagnostic, item_sp, E0550, "multiple deprecated attributes").emit(); break; } @@ -741,7 +758,8 @@ where ), ); } else { - span_err!(diagnostic, meta.span, E0551, "incorrect meta item"); + struct_span_err!(diagnostic, meta.span, E0551, "incorrect meta item") + .emit(); } false @@ -900,13 +918,14 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> { }; } if let Some(literal_error) = literal_error { - span_err!( + struct_span_err!( diagnostic, item.span(), E0589, "invalid `repr(align)` attribute: {}", literal_error - ); + ) + .emit(); } } else { if let Some(meta_item) = item.meta_item() { @@ -945,7 +964,13 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> { } if !recognised { // Not a word we recognize - span_err!(diagnostic, item.span(), E0552, "unrecognized representation hint"); + struct_span_err!( + diagnostic, + item.span(), + E0552, + "unrecognized representation hint" + ) + .emit(); } } } diff --git a/src/libsyntax/diagnostics/macros.rs b/src/libsyntax/diagnostics/macros.rs deleted file mode 100644 index 4ed17418c30..00000000000 --- a/src/libsyntax/diagnostics/macros.rs +++ /dev/null @@ -1,169 +0,0 @@ -#[macro_export] -macro_rules! diagnostic_used { - ($code:ident) => { - let _ = $code; - }; -} - -#[macro_export] -macro_rules! span_fatal { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.span_fatal_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! span_err { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.span_err_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! span_warn { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.span_warn_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! struct_err { - ($session:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.struct_err_with_code( - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! span_err_or_warn { - ($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - if $is_warning { - $session.span_warn_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - } else { - $session.span_err_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - } - }) -} - -#[macro_export] -macro_rules! struct_span_fatal { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.struct_span_fatal_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! struct_span_err { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.struct_span_err_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! stringify_error_code { - ($code:ident) => {{ - $crate::diagnostic_used!($code); - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()) - }}; -} - -#[macro_export] -macro_rules! type_error_struct { - ($session:expr, $span:expr, $typ:expr, $code:ident, $($message:tt)*) => ({ - if $typ.references_error() { - $session.diagnostic().struct_dummy() - } else { - struct_span_err!($session, $span, $code, $($message)*) - } - }) -} - -#[macro_export] -macro_rules! struct_span_warn { - ($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - $session.struct_span_warn_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - }) -} - -#[macro_export] -macro_rules! struct_span_err_or_warn { - ($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ - $crate::diagnostic_used!($code); - if $is_warning { - $session.struct_span_warn_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - } else { - $session.struct_span_err_with_code( - $span, - &format!($($message)*), - $crate::errors::DiagnosticId::Error(stringify!($code).to_owned()), - ) - } - }) -} - -#[macro_export] -macro_rules! span_note { - ($err:expr, $span:expr, $($message:tt)*) => ({ - ($err).span_note($span, &format!($($message)*)); - }) -} - -#[macro_export] -macro_rules! span_help { - ($err:expr, $span:expr, $($message:tt)*) => ({ - ($err).span_help($span, &format!($($message)*)); - }) -} - -#[macro_export] -macro_rules! help { - ($err:expr, $($message:tt)*) => ({ - ($err).help(&format!($($message)*)); - }) -} 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(); } } } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 72beddf7bb5..b197eab7394 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -62,12 +62,6 @@ pub fn with_default_globals<R>(f: impl FnOnce() -> R) -> R { scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals); -#[macro_use] -pub mod diagnostics { - #[macro_use] - pub mod macros; -} - pub mod util { pub mod classify; pub mod comments; |
