Skip to content

Commit b437240

Browse files
Replace diagnostic plugins with macro_rules
1 parent 74563b4 commit b437240

File tree

32 files changed

+87
-351
lines changed

32 files changed

+87
-351
lines changed

src/librustc/error_codes.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -2184,11 +2184,7 @@ Examples of erroneous code:
21842184
static X: u32 = 42;
21852185
```
21862186
"##,
2187-
2188-
}
2189-
2190-
2191-
register_diagnostics! {
2187+
;
21922188
// E0006, // merged with E0005
21932189
// E0101, // replaced with E0282
21942190
// E0102, // replaced with E0282

src/librustc/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ mod tests;
8888
#[macro_use]
8989
mod macros;
9090

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

9593
#[macro_use]
@@ -143,6 +141,3 @@ pub mod util {
143141

144142
// Allows macros to refer to this crate as `::rustc`
145143
extern crate self as rustc;
146-
147-
// Build the diagnostics array at the end so that the metadata includes error use sites.
148-
__build_diagnostic_array! { librustc, DIAGNOSTICS }

src/librustc_codegen_llvm/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
register_long_diagnostics! {
1+
register_diagnostics! {
22

33
E0511: r##"
44
Invalid monomorphization of an intrinsic function was used. Erroneous code

src/librustc_codegen_llvm/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl CodegenBackend for LlvmCodegenBackend {
256256
}
257257

258258
fn diagnostics(&self) -> &[(&'static str, &'static str)] {
259-
&DIAGNOSTICS
259+
&error_codes::DIAGNOSTICS
260260
}
261261

262262
fn target_features(&self, sess: &Session) -> Vec<Symbol> {
@@ -425,5 +425,3 @@ impl Drop for ModuleLlvm {
425425
}
426426
}
427427
}
428-
429-
__build_diagnostic_array! { librustc_codegen_llvm, DIAGNOSTICS }

src/librustc_codegen_ssa/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
register_long_diagnostics! {
1+
syntax::register_diagnostics! {
22

33
E0668: r##"
44
Malformed inline assembly rejected by LLVM.

src/librustc_codegen_ssa/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ use rustc_data_structures::svh::Svh;
3535
use rustc::middle::cstore::{LibSource, CrateSource, NativeLibrary};
3636
use syntax_pos::symbol::Symbol;
3737

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

4240
pub mod common;
@@ -158,5 +156,3 @@ pub struct CodegenResults {
158156
pub linker_info: back::linker::LinkerInfo,
159157
pub crate_info: CrateInfo,
160158
}
161-
162-
__build_diagnostic_array! { librustc_codegen_ssa, DIAGNOSTICS }

src/librustc_interface/passes.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use rustc_privacy;
3434
use rustc_resolve::{Resolver, ResolverArenas};
3535
use rustc_traits;
3636
use rustc_typeck as typeck;
37-
use syntax::{self, ast, diagnostics, visit};
37+
use syntax::{self, ast, visit};
3838
use syntax::early_buffered_lints::BufferedEarlyLint;
3939
use syntax::ext::base::{NamedSyntaxExtension, ExtCtxt};
4040
use syntax::mut_visit::MutVisitor;
@@ -292,18 +292,7 @@ pub fn register_plugins<'a>(
292292

293293
time(sess, "plugin registration", || {
294294
if sess.features_untracked().rustc_diagnostic_macros {
295-
registry.register_macro(
296-
"__diagnostic_used",
297-
diagnostics::plugin::expand_diagnostic_used,
298-
);
299-
registry.register_macro(
300-
"__register_diagnostic",
301-
diagnostics::plugin::expand_register_diagnostic,
302-
);
303-
registry.register_macro(
304-
"__build_diagnostic_array",
305-
diagnostics::plugin::expand_build_diagnostic_array,
306-
);
295+
// FIXME: remove feature gate
307296
}
308297

309298
for registrar in registrars {

src/librustc_interface/util.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ use std::{thread, panic};
4343

4444
pub fn diagnostics_registry() -> Registry {
4545
let mut all_errors = Vec::new();
46-
all_errors.extend_from_slice(&rustc::DIAGNOSTICS);
47-
all_errors.extend_from_slice(&rustc_typeck::DIAGNOSTICS);
48-
all_errors.extend_from_slice(&rustc_resolve::DIAGNOSTICS);
49-
all_errors.extend_from_slice(&rustc_privacy::DIAGNOSTICS);
46+
all_errors.extend_from_slice(&rustc::error_codes::DIAGNOSTICS);
47+
all_errors.extend_from_slice(&rustc_typeck::error_codes::DIAGNOSTICS);
48+
all_errors.extend_from_slice(&rustc_resolve::error_codes::DIAGNOSTICS);
49+
all_errors.extend_from_slice(&rustc_privacy::error_codes::DIAGNOSTICS);
5050
// FIXME: need to figure out a way to get these back in here
5151
// all_errors.extend_from_slice(get_codegen_backend(sess).diagnostics());
52-
all_errors.extend_from_slice(&rustc_metadata::DIAGNOSTICS);
53-
all_errors.extend_from_slice(&rustc_passes::DIAGNOSTICS);
54-
all_errors.extend_from_slice(&rustc_plugin::DIAGNOSTICS);
55-
all_errors.extend_from_slice(&rustc_mir::DIAGNOSTICS);
56-
all_errors.extend_from_slice(&syntax::DIAGNOSTICS);
52+
all_errors.extend_from_slice(&rustc_metadata::error_codes::DIAGNOSTICS);
53+
all_errors.extend_from_slice(&rustc_passes::error_codes::DIAGNOSTICS);
54+
all_errors.extend_from_slice(&rustc_plugin::error_codes::DIAGNOSTICS);
55+
all_errors.extend_from_slice(&rustc_mir::error_codes::DIAGNOSTICS);
56+
all_errors.extend_from_slice(&syntax::error_codes::DIAGNOSTICS);
5757

5858
Registry::new(&all_errors)
5959
}

src/librustc_lint/error_codes.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use syntax::register_diagnostics;
2-
3-
register_diagnostics! {
1+
syntax::register_diagnostics! {
2+
;
43
E0721, // `await` keyword
54
}

src/librustc_metadata/error_codes.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use syntax::{register_diagnostics, register_long_diagnostics};
2-
3-
register_long_diagnostics! {
1+
syntax::register_diagnostics! {
42
E0454: r##"
53
A link name was given with an empty name. Erroneous code example:
64
@@ -84,10 +82,7 @@ You need to link your code to the relevant crate in order to be able to use it
8482
(through Cargo or the `-L` option of rustc example). Plugins are crates as
8583
well, and you link to them the same way.
8684
"##,
87-
88-
}
89-
90-
register_diagnostics! {
85+
;
9186
E0456, // plugin `..` is not available for triple `..`
9287
E0457, // plugin `..` only found in rlib format, but must be available...
9388
E0514, // metadata version mismatch

src/librustc_metadata/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern crate rustc;
2323
#[macro_use]
2424
extern crate rustc_data_structures;
2525

26-
mod error_codes;
26+
pub mod error_codes;
2727

2828
mod index;
2929
mod encoder;
@@ -68,5 +68,3 @@ pub fn validate_crate_name(
6868
sess.unwrap().abort_if_errors();
6969
}
7070
}
71-
72-
__build_diagnostic_array! { librustc_metadata, DIAGNOSTICS }

src/librustc_mir/error_codes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
register_long_diagnostics! {
1+
syntax::register_diagnostics! {
22

33

44
E0001: r##"
@@ -2448,9 +2448,9 @@ information.
24482448
24492449
There are some known bugs that trigger this message.
24502450
"##,
2451-
}
24522451

2453-
register_diagnostics! {
2452+
;
2453+
24542454
// E0298, // cannot compare constants
24552455
// E0299, // mismatched types between arms
24562456
// E0471, // constant evaluation error (in pattern)

src/librustc_mir/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
3232
#[macro_use] extern crate rustc_data_structures;
3333
#[macro_use] extern crate syntax;
3434

35-
mod error_codes;
35+
pub mod error_codes;
3636

3737
mod borrow_check;
3838
mod build;
@@ -62,5 +62,3 @@ pub fn provide(providers: &mut Providers<'_>) {
6262
};
6363
providers.type_name = interpret::type_name;
6464
}
65-
66-
__build_diagnostic_array! { librustc_mir, DIAGNOSTICS }

src/librustc_passes/error_codes.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use syntax::{register_diagnostics, register_long_diagnostics};
2-
3-
register_long_diagnostics! {
1+
syntax::register_diagnostics! {
42
/*
53
E0014: r##"
64
Constants can only be initialized by a constant value or, in a future
@@ -320,10 +318,8 @@ async fn foo() {}
320318
```
321319
322320
Switch to the Rust 2018 edition to use `async fn`.
323-
"##
324-
}
325-
326-
register_diagnostics! {
321+
"##,
322+
;
327323
E0226, // only a single explicit lifetime bound is permitted
328324
E0472, // asm! is unsupported on this target
329325
E0561, // patterns aren't allowed in function pointer types

src/librustc_passes/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,14 @@ extern crate rustc;
1818

1919
use rustc::ty::query::Providers;
2020

21-
mod error_codes;
21+
pub mod error_codes;
2222

2323
pub mod ast_validation;
2424
pub mod rvalue_promotion;
2525
pub mod hir_stats;
2626
pub mod layout_test;
2727
pub mod loops;
2828

29-
__build_diagnostic_array! { librustc_passes, DIAGNOSTICS }
30-
3129
pub fn provide(providers: &mut Providers<'_>) {
3230
rvalue_promotion::provide(providers);
3331
loops::provide(providers);

src/librustc_plugin/error_codes.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
use syntax::{register_diagnostics, register_long_diagnostics};
2-
3-
register_long_diagnostics! {
4-
5-
}
6-
7-
register_diagnostics! {
8-
E0498 // malformed plugin attribute
1+
syntax::register_diagnostics! {
2+
;
3+
E0498, // malformed plugin attribute
94
}

src/librustc_plugin/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@
6060

6161
pub use registry::Registry;
6262

63-
mod error_codes;
63+
pub mod error_codes;
6464
pub mod registry;
6565
pub mod load;
6666
pub mod build;
67-
68-
__build_diagnostic_array! { librustc_plugin, DIAGNOSTICS }

src/librustc_privacy/error_codes.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
register_long_diagnostics! {
1+
syntax::register_diagnostics! {
22

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

157-
}
158-
159-
register_diagnostics! {
160157
// E0450, moved into resolve
161158
}

src/librustc_privacy/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use syntax_pos::Span;
3131
use std::{cmp, fmt, mem};
3232
use std::marker::PhantomData;
3333

34-
mod error_codes;
34+
pub mod error_codes;
3535

3636
////////////////////////////////////////////////////////////////////////////////
3737
/// Generic infrastructure used to implement specific visitors below.
@@ -2035,5 +2035,3 @@ fn check_private_in_public(tcx: TyCtxt<'_>, krate: CrateNum) {
20352035
};
20362036
krate.visit_all_item_likes(&mut DeepVisitor::new(&mut visitor));
20372037
}
2038-
2039-
__build_diagnostic_array! { librustc_privacy, DIAGNOSTICS }

src/librustc_resolve/error_codes.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use syntax::{register_diagnostics, register_long_diagnostics};
2-
31
// Error messages for EXXXX errors. Each message should start and end with a
42
// new line, and be wrapped to 80 characters. In vim you can `:set tw=80` and
53
// use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
6-
register_long_diagnostics! {
4+
syntax::register_diagnostics! {
75

86
E0128: r##"
97
Type parameter defaults can only use parameters that occur before them.
@@ -1662,10 +1660,7 @@ fn const_id<T, const N: T>() -> T { // error: const parameter
16621660
}
16631661
```
16641662
"##,
1665-
1666-
}
1667-
1668-
register_diagnostics! {
1663+
;
16691664
// E0153, unused error code
16701665
// E0157, unused error code
16711666
// E0257,

src/librustc_resolve/late.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -286,18 +286,18 @@ impl<'a> PathSource<'a> {
286286
}
287287

288288
fn error_code(self, has_unexpected_resolution: bool) -> &'static str {
289-
__diagnostic_used!(E0404);
290-
__diagnostic_used!(E0405);
291-
__diagnostic_used!(E0412);
292-
__diagnostic_used!(E0422);
293-
__diagnostic_used!(E0423);
294-
__diagnostic_used!(E0425);
295-
__diagnostic_used!(E0531);
296-
__diagnostic_used!(E0532);
297-
__diagnostic_used!(E0573);
298-
__diagnostic_used!(E0574);
299-
__diagnostic_used!(E0575);
300-
__diagnostic_used!(E0576);
289+
syntax::diagnostic_used!(E0404);
290+
syntax::diagnostic_used!(E0405);
291+
syntax::diagnostic_used!(E0412);
292+
syntax::diagnostic_used!(E0422);
293+
syntax::diagnostic_used!(E0423);
294+
syntax::diagnostic_used!(E0425);
295+
syntax::diagnostic_used!(E0531);
296+
syntax::diagnostic_used!(E0532);
297+
syntax::diagnostic_used!(E0573);
298+
syntax::diagnostic_used!(E0574);
299+
syntax::diagnostic_used!(E0575);
300+
syntax::diagnostic_used!(E0576);
301301
match (self, has_unexpected_resolution) {
302302
(PathSource::Trait(_), true) => "E0404",
303303
(PathSource::Trait(_), false) => "E0405",

src/librustc_resolve/late/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<'a> LateResolutionVisitor<'a, '_> {
113113

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

125-
__diagnostic_used!(E0424);
125+
syntax::diagnostic_used!(E0424);
126126
err.code(DiagnosticId::Error("E0424".into()));
127127
err.span_label(span, match source {
128128
PathSource::Pat => {

src/librustc_resolve/lib.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ use macros::{LegacyBinding, LegacyScope};
6767

6868
type Res = def::Res<NodeId>;
6969

70-
// N.B., this module needs to be declared first so diagnostics are
71-
// registered before they are used.
72-
mod error_codes;
70+
pub mod error_codes;
7371
mod diagnostics;
7472
mod late;
7573
mod macros;
@@ -2817,5 +2815,3 @@ impl CrateLint {
28172815
}
28182816
}
28192817
}
2820-
2821-
__build_diagnostic_array! { librustc_resolve, DIAGNOSTICS }

0 commit comments

Comments
 (0)