Skip to content

Commit

Permalink
Replace diagnostic plugins with macro_rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Sep 5, 2019
1 parent 74563b4 commit b437240
Show file tree
Hide file tree
Showing 32 changed files with 87 additions and 351 deletions.
6 changes: 1 addition & 5 deletions src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2184,11 +2184,7 @@ Examples of erroneous code:
static X: u32 = 42;
```
"##,

}


register_diagnostics! {
;
// E0006, // merged with E0005
// E0101, // replaced with E0282
// E0102, // replaced with E0282
Expand Down
5 changes: 0 additions & 5 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ mod tests;
#[macro_use]
mod macros;

// N.B., this module needs to be declared first so diagnostics are
// registered before they are used.
pub mod error_codes;

#[macro_use]
Expand Down Expand Up @@ -143,6 +141,3 @@ pub mod util {

// Allows macros to refer to this crate as `::rustc`
extern crate self as rustc;

// Build the diagnostics array at the end so that the metadata includes error use sites.
__build_diagnostic_array! { librustc, DIAGNOSTICS }
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/error_codes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
register_long_diagnostics! {
register_diagnostics! {

E0511: r##"
Invalid monomorphization of an intrinsic function was used. Erroneous code
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_codegen_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl CodegenBackend for LlvmCodegenBackend {
}

fn diagnostics(&self) -> &[(&'static str, &'static str)] {
&DIAGNOSTICS
&error_codes::DIAGNOSTICS
}

fn target_features(&self, sess: &Session) -> Vec<Symbol> {
Expand Down Expand Up @@ -425,5 +425,3 @@ impl Drop for ModuleLlvm {
}
}
}

__build_diagnostic_array! { librustc_codegen_llvm, DIAGNOSTICS }
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/error_codes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
register_long_diagnostics! {
syntax::register_diagnostics! {

E0668: r##"
Malformed inline assembly rejected by LLVM.
Expand Down
4 changes: 0 additions & 4 deletions src/librustc_codegen_ssa/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ use rustc_data_structures::svh::Svh;
use rustc::middle::cstore::{LibSource, CrateSource, NativeLibrary};
use syntax_pos::symbol::Symbol;

// N.B., this module needs to be declared first so diagnostics are
// registered before they are used.
mod error_codes;

pub mod common;
Expand Down Expand Up @@ -158,5 +156,3 @@ pub struct CodegenResults {
pub linker_info: back::linker::LinkerInfo,
pub crate_info: CrateInfo,
}

__build_diagnostic_array! { librustc_codegen_ssa, DIAGNOSTICS }
15 changes: 2 additions & 13 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use rustc_privacy;
use rustc_resolve::{Resolver, ResolverArenas};
use rustc_traits;
use rustc_typeck as typeck;
use syntax::{self, ast, diagnostics, visit};
use syntax::{self, ast, visit};
use syntax::early_buffered_lints::BufferedEarlyLint;
use syntax::ext::base::{NamedSyntaxExtension, ExtCtxt};
use syntax::mut_visit::MutVisitor;
Expand Down Expand Up @@ -292,18 +292,7 @@ pub fn register_plugins<'a>(

time(sess, "plugin registration", || {
if sess.features_untracked().rustc_diagnostic_macros {
registry.register_macro(
"__diagnostic_used",
diagnostics::plugin::expand_diagnostic_used,
);
registry.register_macro(
"__register_diagnostic",
diagnostics::plugin::expand_register_diagnostic,
);
registry.register_macro(
"__build_diagnostic_array",
diagnostics::plugin::expand_build_diagnostic_array,
);
// FIXME: remove feature gate
}

for registrar in registrars {
Expand Down
18 changes: 9 additions & 9 deletions src/librustc_interface/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ use std::{thread, panic};

pub fn diagnostics_registry() -> Registry {
let mut all_errors = Vec::new();
all_errors.extend_from_slice(&rustc::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_typeck::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_resolve::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_privacy::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc::error_codes::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_typeck::error_codes::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_resolve::error_codes::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_privacy::error_codes::DIAGNOSTICS);
// FIXME: need to figure out a way to get these back in here
// all_errors.extend_from_slice(get_codegen_backend(sess).diagnostics());
all_errors.extend_from_slice(&rustc_metadata::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_passes::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_plugin::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_mir::DIAGNOSTICS);
all_errors.extend_from_slice(&syntax::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_metadata::error_codes::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_passes::error_codes::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_plugin::error_codes::DIAGNOSTICS);
all_errors.extend_from_slice(&rustc_mir::error_codes::DIAGNOSTICS);
all_errors.extend_from_slice(&syntax::error_codes::DIAGNOSTICS);

Registry::new(&all_errors)
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc_lint/error_codes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use syntax::register_diagnostics;

register_diagnostics! {
syntax::register_diagnostics! {
;
E0721, // `await` keyword
}
9 changes: 2 additions & 7 deletions src/librustc_metadata/error_codes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use syntax::{register_diagnostics, register_long_diagnostics};

register_long_diagnostics! {
syntax::register_diagnostics! {
E0454: r##"
A link name was given with an empty name. Erroneous code example:
Expand Down Expand Up @@ -84,10 +82,7 @@ You need to link your code to the relevant crate in order to be able to use it
(through Cargo or the `-L` option of rustc example). Plugins are crates as
well, and you link to them the same way.
"##,

}

register_diagnostics! {
;
E0456, // plugin `..` is not available for triple `..`
E0457, // plugin `..` only found in rlib format, but must be available...
E0514, // metadata version mismatch
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_metadata/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extern crate rustc;
#[macro_use]
extern crate rustc_data_structures;

mod error_codes;
pub mod error_codes;

mod index;
mod encoder;
Expand Down Expand Up @@ -68,5 +68,3 @@ pub fn validate_crate_name(
sess.unwrap().abort_if_errors();
}
}

__build_diagnostic_array! { librustc_metadata, DIAGNOSTICS }
6 changes: 3 additions & 3 deletions src/librustc_mir/error_codes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
register_long_diagnostics! {
syntax::register_diagnostics! {


E0001: r##"
Expand Down Expand Up @@ -2448,9 +2448,9 @@ information.
There are some known bugs that trigger this message.
"##,
}

register_diagnostics! {
;

// E0298, // cannot compare constants
// E0299, // mismatched types between arms
// E0471, // constant evaluation error (in pattern)
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_mir/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
#[macro_use] extern crate rustc_data_structures;
#[macro_use] extern crate syntax;

mod error_codes;
pub mod error_codes;

mod borrow_check;
mod build;
Expand Down Expand Up @@ -62,5 +62,3 @@ pub fn provide(providers: &mut Providers<'_>) {
};
providers.type_name = interpret::type_name;
}

__build_diagnostic_array! { librustc_mir, DIAGNOSTICS }
10 changes: 3 additions & 7 deletions src/librustc_passes/error_codes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use syntax::{register_diagnostics, register_long_diagnostics};

register_long_diagnostics! {
syntax::register_diagnostics! {
/*
E0014: r##"
Constants can only be initialized by a constant value or, in a future
Expand Down Expand Up @@ -320,10 +318,8 @@ async fn foo() {}
```
Switch to the Rust 2018 edition to use `async fn`.
"##
}

register_diagnostics! {
"##,
;
E0226, // only a single explicit lifetime bound is permitted
E0472, // asm! is unsupported on this target
E0561, // patterns aren't allowed in function pointer types
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_passes/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@ extern crate rustc;

use rustc::ty::query::Providers;

mod error_codes;
pub mod error_codes;

pub mod ast_validation;
pub mod rvalue_promotion;
pub mod hir_stats;
pub mod layout_test;
pub mod loops;

__build_diagnostic_array! { librustc_passes, DIAGNOSTICS }

pub fn provide(providers: &mut Providers<'_>) {
rvalue_promotion::provide(providers);
loops::provide(providers);
Expand Down
11 changes: 3 additions & 8 deletions src/librustc_plugin/error_codes.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use syntax::{register_diagnostics, register_long_diagnostics};

register_long_diagnostics! {

}

register_diagnostics! {
E0498 // malformed plugin attribute
syntax::register_diagnostics! {
;
E0498, // malformed plugin attribute
}
4 changes: 1 addition & 3 deletions src/librustc_plugin/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@

pub use registry::Registry;

mod error_codes;
pub mod error_codes;
pub mod registry;
pub mod load;
pub mod build;

__build_diagnostic_array! { librustc_plugin, DIAGNOSTICS }
5 changes: 1 addition & 4 deletions src/librustc_privacy/error_codes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
register_long_diagnostics! {
syntax::register_diagnostics! {

E0445: r##"
A private trait was used on a public type parameter bound. Erroneous code
Expand Down Expand Up @@ -154,8 +154,5 @@ let f = Bar::Foo::new(); // ok!
```
"##,

}

register_diagnostics! {
// E0450, moved into resolve
}
4 changes: 1 addition & 3 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use syntax_pos::Span;
use std::{cmp, fmt, mem};
use std::marker::PhantomData;

mod error_codes;
pub mod error_codes;

////////////////////////////////////////////////////////////////////////////////
/// Generic infrastructure used to implement specific visitors below.
Expand Down Expand Up @@ -2035,5 +2035,3 @@ fn check_private_in_public(tcx: TyCtxt<'_>, krate: CrateNum) {
};
krate.visit_all_item_likes(&mut DeepVisitor::new(&mut visitor));
}

__build_diagnostic_array! { librustc_privacy, DIAGNOSTICS }
9 changes: 2 additions & 7 deletions src/librustc_resolve/error_codes.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use syntax::{register_diagnostics, register_long_diagnostics};

// Error messages for EXXXX errors. Each message should start and end with a
// new line, and be wrapped to 80 characters. In vim you can `:set tw=80` and
// use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
register_long_diagnostics! {
syntax::register_diagnostics! {

E0128: r##"
Type parameter defaults can only use parameters that occur before them.
Expand Down Expand Up @@ -1662,10 +1660,7 @@ fn const_id<T, const N: T>() -> T { // error: const parameter
}
```
"##,

}

register_diagnostics! {
;
// E0153, unused error code
// E0157, unused error code
// E0257,
Expand Down
24 changes: 12 additions & 12 deletions src/librustc_resolve/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,18 @@ impl<'a> PathSource<'a> {
}

fn error_code(self, has_unexpected_resolution: bool) -> &'static str {
__diagnostic_used!(E0404);
__diagnostic_used!(E0405);
__diagnostic_used!(E0412);
__diagnostic_used!(E0422);
__diagnostic_used!(E0423);
__diagnostic_used!(E0425);
__diagnostic_used!(E0531);
__diagnostic_used!(E0532);
__diagnostic_used!(E0573);
__diagnostic_used!(E0574);
__diagnostic_used!(E0575);
__diagnostic_used!(E0576);
syntax::diagnostic_used!(E0404);
syntax::diagnostic_used!(E0405);
syntax::diagnostic_used!(E0412);
syntax::diagnostic_used!(E0422);
syntax::diagnostic_used!(E0423);
syntax::diagnostic_used!(E0425);
syntax::diagnostic_used!(E0531);
syntax::diagnostic_used!(E0532);
syntax::diagnostic_used!(E0573);
syntax::diagnostic_used!(E0574);
syntax::diagnostic_used!(E0575);
syntax::diagnostic_used!(E0576);
match (self, has_unexpected_resolution) {
(PathSource::Trait(_), true) => "E0404",
(PathSource::Trait(_), false) => "E0405",
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_resolve/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<'a> LateResolutionVisitor<'a, '_> {

// Emit special messages for unresolved `Self` and `self`.
if is_self_type(path, ns) {
__diagnostic_used!(E0411);
syntax::diagnostic_used!(E0411);
err.code(DiagnosticId::Error("E0411".into()));
err.span_label(span, format!("`Self` is only available in impls, traits, \
and type definitions"));
Expand All @@ -122,7 +122,7 @@ impl<'a> LateResolutionVisitor<'a, '_> {
if is_self_value(path, ns) {
debug!("smart_resolve_path_fragment: E0424, source={:?}", source);

__diagnostic_used!(E0424);
syntax::diagnostic_used!(E0424);
err.code(DiagnosticId::Error("E0424".into()));
err.span_label(span, match source {
PathSource::Pat => {
Expand Down
6 changes: 1 addition & 5 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ use macros::{LegacyBinding, LegacyScope};

type Res = def::Res<NodeId>;

// N.B., this module needs to be declared first so diagnostics are
// registered before they are used.
mod error_codes;
pub mod error_codes;
mod diagnostics;
mod late;
mod macros;
Expand Down Expand Up @@ -2817,5 +2815,3 @@ impl CrateLint {
}
}
}

__build_diagnostic_array! { librustc_resolve, DIAGNOSTICS }
Loading

0 comments on commit b437240

Please sign in to comment.