Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b437240

Browse files
committedSep 5, 2019
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

Lines changed: 1 addition & 5 deletions
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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 4 deletions
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

Lines changed: 2 additions & 13 deletions
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

Lines changed: 9 additions & 9 deletions
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

Lines changed: 2 additions & 3 deletions
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

Lines changed: 2 additions & 7 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 3 additions & 7 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 3 additions & 8 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 1 addition & 4 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 2 additions & 7 deletions
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

Lines changed: 12 additions & 12 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 5 deletions
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 }

‎src/librustc_typeck/error_codes.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ignore-tidy-filelength
22

3-
register_long_diagnostics! {
3+
syntax::register_diagnostics! {
44

55
E0023: r##"
66
A pattern used to match against an enum variant must provide a sub-pattern for
@@ -4870,10 +4870,7 @@ fn foo_recursive(n: usize) -> Pin<Box<dyn Future<Output = ()>>> {
48704870
The `Box<...>` ensures that the result is of known size,
48714871
and the pin is required to keep it in the same place in memory.
48724872
"##,
4873-
4874-
} // (end of detailed error messages)
4875-
4876-
register_diagnostics! {
4873+
;
48774874
// E0035, merged into E0087/E0089
48784875
// E0036, merged into E0087/E0089
48794876
// E0068,

‎src/librustc_typeck/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ This API is completely unstable and subject to change.
7878

7979
#[macro_use] extern crate rustc;
8080

81-
// N.B., this module needs to be declared first so diagnostics are
82-
// registered before they are used.
83-
mod error_codes;
81+
pub mod error_codes;
8482

8583
mod astconv;
8684
mod check;
@@ -389,5 +387,3 @@ pub fn hir_trait_to_predicates<'tcx>(
389387

390388
bounds
391389
}
392-
393-
__build_diagnostic_array! { librustc_typeck, DIAGNOSTICS }

‎src/librustc_typeck/structured_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for VariadicError<'tcx> {
4848
fn session(&self) -> &Session { self.sess }
4949

5050
fn code(&self) -> DiagnosticId {
51-
__diagnostic_used!(E0617);
51+
syntax::diagnostic_used!(E0617);
5252
DiagnosticId::Error("E0617".to_owned())
5353
}
5454

@@ -104,7 +104,7 @@ impl<'tcx> StructuredDiagnostic<'tcx> for SizedUnsizedCastError<'tcx> {
104104
fn session(&self) -> &Session { self.sess }
105105

106106
fn code(&self) -> DiagnosticId {
107-
__diagnostic_used!(E0607);
107+
syntax::diagnostic_used!(E0607);
108108
DiagnosticId::Error("E0607".to_owned())
109109
}
110110

‎src/libsyntax/diagnostics/macros.rs

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#[macro_export]
2-
macro_rules! register_diagnostic {
3-
($code:tt, $description:tt) => (__register_diagnostic! { $code, $description });
4-
($code:tt) => (__register_diagnostic! { $code })
2+
macro_rules! diagnostic_used {
3+
($code:ident) => (
4+
let _ = crate::error_codes::$code;
5+
)
56
}
67

78
#[macro_export]
89
macro_rules! span_fatal {
910
($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
10-
__diagnostic_used!($code);
11+
$crate::diagnostic_used!($code);
1112
$session.span_fatal_with_code(
1213
$span,
1314
&format!($($message)*),
@@ -19,7 +20,7 @@ macro_rules! span_fatal {
1920
#[macro_export]
2021
macro_rules! span_err {
2122
($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
22-
__diagnostic_used!($code);
23+
$crate::diagnostic_used!($code);
2324
$session.span_err_with_code(
2425
$span,
2526
&format!($($message)*),
@@ -31,7 +32,7 @@ macro_rules! span_err {
3132
#[macro_export]
3233
macro_rules! span_warn {
3334
($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
34-
__diagnostic_used!($code);
35+
$crate::diagnostic_used!($code);
3536
$session.span_warn_with_code(
3637
$span,
3738
&format!($($message)*),
@@ -43,7 +44,7 @@ macro_rules! span_warn {
4344
#[macro_export]
4445
macro_rules! struct_err {
4546
($session:expr, $code:ident, $($message:tt)*) => ({
46-
__diagnostic_used!($code);
47+
$crate::diagnostic_used!($code);
4748
$session.struct_err_with_code(
4849
&format!($($message)*),
4950
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned()),
@@ -54,7 +55,7 @@ macro_rules! struct_err {
5455
#[macro_export]
5556
macro_rules! span_err_or_warn {
5657
($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
57-
__diagnostic_used!($code);
58+
$crate::diagnostic_used!($code);
5859
if $is_warning {
5960
$session.span_warn_with_code(
6061
$span,
@@ -74,7 +75,7 @@ macro_rules! span_err_or_warn {
7475
#[macro_export]
7576
macro_rules! struct_span_fatal {
7677
($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
77-
__diagnostic_used!($code);
78+
$crate::diagnostic_used!($code);
7879
$session.struct_span_fatal_with_code(
7980
$span,
8081
&format!($($message)*),
@@ -86,7 +87,7 @@ macro_rules! struct_span_fatal {
8687
#[macro_export]
8788
macro_rules! struct_span_err {
8889
($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
89-
__diagnostic_used!($code);
90+
$crate::diagnostic_used!($code);
9091
$session.struct_span_err_with_code(
9192
$span,
9293
&format!($($message)*),
@@ -98,7 +99,7 @@ macro_rules! struct_span_err {
9899
#[macro_export]
99100
macro_rules! stringify_error_code {
100101
($code:ident) => ({
101-
__diagnostic_used!($code);
102+
$crate::diagnostic_used!($code);
102103
$crate::errors::DiagnosticId::Error(stringify!($code).to_owned())
103104
})
104105
}
@@ -117,7 +118,7 @@ macro_rules! type_error_struct {
117118
#[macro_export]
118119
macro_rules! struct_span_warn {
119120
($session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
120-
__diagnostic_used!($code);
121+
$crate::diagnostic_used!($code);
121122
$session.struct_span_warn_with_code(
122123
$span,
123124
&format!($($message)*),
@@ -129,7 +130,7 @@ macro_rules! struct_span_warn {
129130
#[macro_export]
130131
macro_rules! struct_span_err_or_warn {
131132
($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({
132-
__diagnostic_used!($code);
133+
$crate::diagnostic_used!($code);
133134
if $is_warning {
134135
$session.struct_span_warn_with_code(
135136
$span,
@@ -169,20 +170,22 @@ macro_rules! help {
169170

170171
#[macro_export]
171172
macro_rules! register_diagnostics {
172-
($($code:tt),*) => (
173-
$($crate::register_diagnostic! { $code })*
173+
($($ecode:ident: $message:expr,)*) => (
174+
$crate::register_diagnostics!{$($ecode:$message,)* ;}
174175
);
175-
($($code:tt),*,) => (
176-
$($crate::register_diagnostic! { $code })*
177-
)
178-
}
179176

180-
#[macro_export]
181-
macro_rules! register_long_diagnostics {
182-
($($code:tt: $description:tt),*) => (
183-
$($crate::register_diagnostic! { $code, $description })*
184-
);
185-
($($code:tt: $description:tt),*,) => (
186-
$($crate::register_diagnostic! { $code, $description })*
177+
($($ecode:ident: $message:expr,)* ; $($code:ident,)*) => (
178+
pub static DIAGNOSTICS: &[(&str, &str)] = &[
179+
$( (stringify!($ecode), $message), )*
180+
];
181+
182+
$(
183+
#[deny(unused)]
184+
pub(crate) const $ecode: &str = $message;
185+
)*
186+
$(
187+
#[deny(unused)]
188+
pub(crate) const $code: () = ();
189+
)*
187190
)
188191
}

‎src/libsyntax/diagnostics/plugin.rs

Lines changed: 0 additions & 185 deletions
This file was deleted.

‎src/libsyntax/error_codes.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,8 @@ Delete the offending feature attribute, or add it to the list of allowed
421421
features in the `-Z allow_features` flag.
422422
"##,
423423

424-
}
424+
;
425425

426-
register_diagnostics! {
427426
E0539, // incorrect meta item
428427
E0540, // multiple rustc_deprecated attributes
429428
E0542, // missing 'since'
@@ -447,7 +446,7 @@ register_diagnostics! {
447446
// attribute
448447
E0630,
449448
E0693, // incorrect `repr(align)` attribute format
450-
E0694, // an unknown tool name found in scoped attributes
449+
// E0694, // an unknown tool name found in scoped attributes
451450
E0703, // invalid ABI
452451
E0717, // rustc_promotable without stability attribute
453452
}

‎src/libsyntax/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,8 @@ scoped_tls::scoped_thread_local!(pub static GLOBALS: Globals);
123123
pub mod diagnostics {
124124
#[macro_use]
125125
pub mod macros;
126-
pub mod plugin;
127126
}
128127

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

133130
pub mod util {
@@ -182,5 +179,3 @@ pub mod ext {
182179
}
183180

184181
pub mod early_buffered_lints;
185-
186-
__build_diagnostic_array! { libsyntax, DIAGNOSTICS }

‎src/libsyntax/parse/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::parse::parser::Parser;
88
use crate::parse::parser::emit_unclosed_delims;
99
use crate::parse::token::TokenKind;
1010
use crate::tokenstream::{TokenStream, TokenTree};
11-
use crate::diagnostics::plugin::ErrorMap;
1211
use crate::print::pprust;
1312
use crate::symbol::Symbol;
1413

@@ -64,8 +63,6 @@ pub struct ParseSess {
6463
pub missing_fragment_specifiers: Lock<FxHashSet<Span>>,
6564
/// Places where raw identifiers were used. This is used for feature-gating raw identifiers.
6665
pub raw_identifier_spans: Lock<Vec<Span>>,
67-
/// The registered diagnostics codes.
68-
crate registered_diagnostics: Lock<ErrorMap>,
6966
/// Used to determine and report recursive module inclusions.
7067
included_mod_stack: Lock<Vec<PathBuf>>,
7168
source_map: Lrc<SourceMap>,
@@ -95,7 +92,6 @@ impl ParseSess {
9592
config: FxHashSet::default(),
9693
missing_fragment_specifiers: Lock::new(FxHashSet::default()),
9794
raw_identifier_spans: Lock::new(Vec::new()),
98-
registered_diagnostics: Lock::new(ErrorMap::new()),
9995
included_mod_stack: Lock::new(vec![]),
10096
source_map,
10197
buffered_lints: Lock::new(vec![]),

‎src/libsyntax_ext/error_codes.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use syntax::register_long_diagnostics;
2-
31
// Error messages for EXXXX errors.
42
// Each message should start and end with a new line, and be wrapped to 80
53
// characters. In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use

0 commit comments

Comments
 (0)
Please sign in to comment.