Skip to content

Commit 89a69fd

Browse files
authored
Rollup merge of rust-lang#64139 - Mark-Simulacrum:strip-legacy-proc-macro, r=petrochenkov
Migrate internal diagnostic registration to macro_rules Review is best done commit-by-commit. Fixes rust-lang#64132.
2 parents 3c4a586 + 5153db1 commit 89a69fd

File tree

49 files changed

+176
-489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+176
-489
lines changed

Cargo.lock

-4
Original file line numberDiff line numberDiff line change
@@ -3129,11 +3129,7 @@ dependencies = [
31293129
name = "rustc_codegen_llvm"
31303130
version = "0.0.0"
31313131
dependencies = [
3132-
"cc",
3133-
"memmap",
3134-
"num_cpus",
31353132
"rustc_llvm",
3136-
"tempfile",
31373133
]
31383134

31393135
[[package]]

src/bootstrap/test.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,10 @@ impl Step for Compiletest {
13271327
cmd.env("RUSTC_PROFILER_SUPPORT", "1");
13281328
}
13291329

1330-
cmd.env("RUST_TEST_TMPDIR", builder.out.join("tmp"));
1330+
let tmp = builder.out.join("tmp");
1331+
std::fs::create_dir_all(&tmp).unwrap();
1332+
cmd.env("RUST_TEST_TMPDIR", tmp);
1333+
13311334

13321335
cmd.arg("--adb-path").arg("adb");
13331336
cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);

src/librustc/error_codes.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Error messages for EXXXX errors.
2-
// Each message should start and end with a new line, and be wrapped to 80 characters.
3-
// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
4-
register_long_diagnostics! {
2+
// Each message should start and end with a new line, and be wrapped to 80
3+
// characters. In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use
4+
// `:set tw=0` to disable.
5+
syntax::register_diagnostics! {
56
E0038: r##"
67
Trait objects like `Box<Trait>` can only be constructed when certain
78
requirements are satisfied by the trait in question.
@@ -2183,11 +2184,7 @@ Examples of erroneous code:
21832184
static X: u32 = 42;
21842185
```
21852186
"##,
2186-
2187-
}
2188-
2189-
2190-
register_diagnostics! {
2187+
;
21912188
// E0006, // merged with E0005
21922189
// E0101, // replaced with E0282
21932190
// E0102, // replaced with E0282
@@ -2206,7 +2203,8 @@ register_diagnostics! {
22062203
// E0305, // expected constant
22072204
E0311, // thing may not live long enough
22082205
E0312, // lifetime of reference outlives lifetime of borrowed content
2209-
E0313, // lifetime of borrowed pointer outlives lifetime of captured variable
2206+
E0313, // lifetime of borrowed pointer outlives lifetime of captured
2207+
// variable
22102208
E0314, // closure outlives stack frame
22112209
E0315, // cannot invoke closure outside of its lifetime
22122210
E0316, // nested quantification of lifetimes
@@ -2223,12 +2221,13 @@ register_diagnostics! {
22232221
E0483, // lifetime of operand does not outlive the operation
22242222
E0484, // reference is not valid at the time of borrow
22252223
E0485, // automatically reference is not valid at the time of borrow
2226-
E0486, // type of expression contains references that are not valid during...
2224+
E0486, // type of expression contains references that are not valid during..
22272225
E0487, // unsafe use of destructor: destructor might be called while...
22282226
E0488, // lifetime of variable does not enclose its declaration
22292227
E0489, // type/lifetime parameter not in scope here
22302228
E0490, // a value of type `..` is borrowed for too long
2231-
E0495, // cannot infer an appropriate lifetime due to conflicting requirements
2229+
E0495, // cannot infer an appropriate lifetime due to conflicting
2230+
// requirements
22322231
E0566, // conflicting representation hints
22332232
E0623, // lifetime mismatch where both parameters are anonymous regions
22342233
E0628, // generators cannot have explicit parameters
@@ -2239,7 +2238,8 @@ register_diagnostics! {
22392238
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
22402239
E0697, // closures cannot be static
22412240
E0707, // multiple elided lifetimes used in arguments of `async fn`
2242-
E0708, // `async` non-`move` closures with parameters are not currently supported
2241+
E0708, // `async` non-`move` closures with parameters are not currently
2242+
// supported
22432243
E0709, // multiple different lifetimes used in arguments of `async fn`
22442244
E0710, // an unknown tool name found in scoped lint
22452245
E0711, // a feature has been declared with conflicting stability attributes

src/librustc/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
#![feature(non_exhaustive)]
4646
#![feature(optin_builtin_traits)]
4747
#![feature(range_is_empty)]
48-
#![feature(rustc_diagnostic_macros)]
4948
#![feature(slice_patterns)]
5049
#![feature(specialization)]
5150
#![feature(unboxed_closures)]
@@ -88,8 +87,6 @@ mod tests;
8887
#[macro_use]
8988
mod macros;
9089

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

9592
#[macro_use]
@@ -142,6 +139,3 @@ pub mod util {
142139

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

src/librustc_codegen_llvm/Cargo.toml

-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ crate-type = ["dylib"]
1111
test = false
1212

1313
[dependencies]
14-
cc = "1.0.1" # Used to locate MSVC
15-
num_cpus = "1.0"
16-
tempfile = "3.0"
1714
rustc_llvm = { path = "../librustc_llvm" }
18-
memmap = "0.6"
1915

2016
[features]
2117
# This is used to convince Cargo to separately cache builds of `rustc_codegen_llvm`

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-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#![feature(in_band_lifetimes)]
1515
#![feature(libc)]
1616
#![feature(nll)]
17-
#![feature(rustc_diagnostic_macros)]
1817
#![feature(optin_builtin_traits)]
1918
#![feature(concat_idents)]
2019
#![feature(link_args)]
@@ -256,7 +255,7 @@ impl CodegenBackend for LlvmCodegenBackend {
256255
}
257256

258257
fn diagnostics(&self) -> &[(&'static str, &'static str)] {
259-
&DIAGNOSTICS
258+
&error_codes::DIAGNOSTICS
260259
}
261260

262261
fn target_features(&self, sess: &Session) -> Vec<Symbol> {
@@ -425,5 +424,3 @@ impl Drop for ModuleLlvm {
425424
}
426425
}
427426
}
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

-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#![feature(box_syntax)]
55
#![feature(core_intrinsics)]
66
#![feature(libc)]
7-
#![feature(rustc_diagnostic_macros)]
87
#![feature(stmt_expr_attributes)]
98
#![feature(try_blocks)]
109
#![feature(in_band_lifetimes)]
@@ -35,8 +34,6 @@ use rustc_data_structures::svh::Svh;
3534
use rustc::middle::cstore::{LibSource, CrateSource, NativeLibrary};
3635
use syntax_pos::symbol::Symbol;
3736

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

4239
pub mod common;
@@ -158,5 +155,3 @@ pub struct CodegenResults {
158155
pub linker_info: back::linker::LinkerInfo,
159156
pub crate_info: CrateInfo,
160157
}
161-
162-
__build_diagnostic_array! { librustc_codegen_ssa, DIAGNOSTICS }

src/librustc_codegen_utils/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#![feature(core_intrinsics)]
1111
#![feature(never_type)]
1212
#![feature(nll)]
13-
#![feature(rustc_diagnostic_macros)]
1413
#![feature(in_band_lifetimes)]
1514

1615
#![recursion_limit="256"]

src/librustc_driver/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#![feature(box_syntax)]
1010
#![cfg_attr(unix, feature(libc))]
1111
#![feature(nll)]
12-
#![feature(rustc_diagnostic_macros)]
1312
#![feature(set_stdio)]
1413
#![feature(no_debug)]
1514
#![feature(integer_atomics)]

src/librustc_interface/passes.rs

+1-16
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;
@@ -283,21 +283,6 @@ pub fn register_plugins<'a>(
283283
let mut registry = Registry::new(sess, krate.span);
284284

285285
time(sess, "plugin registration", || {
286-
if sess.features_untracked().rustc_diagnostic_macros {
287-
registry.register_macro(
288-
"__diagnostic_used",
289-
diagnostics::plugin::expand_diagnostic_used,
290-
);
291-
registry.register_macro(
292-
"__register_diagnostic",
293-
diagnostics::plugin::expand_register_diagnostic,
294-
);
295-
registry.register_macro(
296-
"__build_diagnostic_array",
297-
diagnostics::plugin::expand_build_diagnostic_array,
298-
);
299-
}
300-
301286
for registrar in registrars {
302287
registry.args_hidden = Some(registrar.args);
303288
(registrar.fun)(&mut registry);

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_lint/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#![feature(box_patterns)]
1616
#![feature(box_syntax)]
1717
#![feature(nll)]
18-
#![feature(rustc_diagnostic_macros)]
1918

2019
#![recursion_limit="256"]
2120

src/librustc_metadata/error_codes.rs

+4-8
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
@@ -97,5 +92,6 @@ register_diagnostics! {
9792
E0464, // multiple matching crates for `..`
9893
E0465, // multiple .. candidates for `..` found
9994
E0519, // local crate and dependency have same (crate-name, disambiguator)
100-
E0523, // two dependencies have same (crate-name, disambiguator) but different SVH
95+
// two dependencies have same (crate-name, disambiguator) but different SVH
96+
E0523,
10197
}

src/librustc_metadata/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#![feature(nll)]
99
#![feature(proc_macro_internals)]
1010
#![feature(proc_macro_quote)]
11-
#![feature(rustc_diagnostic_macros)]
1211
#![feature(rustc_private)]
1312
#![feature(slice_patterns)]
1413
#![feature(specialization)]
@@ -23,7 +22,7 @@ extern crate rustc;
2322
#[macro_use]
2423
extern crate rustc_data_structures;
2524

26-
mod error_codes;
25+
pub mod error_codes;
2726

2827
mod index;
2928
mod encoder;
@@ -68,5 +67,3 @@ pub fn validate_crate_name(
6867
sess.unwrap().abort_if_errors();
6968
}
7069
}
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-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
1414
#![feature(const_fn)]
1515
#![feature(decl_macro)]
1616
#![feature(exhaustive_patterns)]
17-
#![feature(rustc_diagnostic_macros)]
1817
#![feature(never_type)]
1918
#![feature(specialization)]
2019
#![feature(try_trait)]
@@ -32,7 +31,7 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
3231
#[macro_use] extern crate rustc_data_structures;
3332
#[macro_use] extern crate syntax;
3433

35-
mod error_codes;
34+
pub mod error_codes;
3635

3736
mod borrow_check;
3837
mod build;
@@ -62,5 +61,3 @@ pub fn provide(providers: &mut Providers<'_>) {
6261
};
6362
providers.type_name = interpret::type_name;
6463
}
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

0 commit comments

Comments
 (0)