Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate internal diagnostic registration to macro_rules #64139

Merged
merged 6 commits into from
Sep 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3129,11 +3129,7 @@ dependencies = [
name = "rustc_codegen_llvm"
version = "0.0.0"
dependencies = [
"cc",
"memmap",
"num_cpus",
"rustc_llvm",
"tempfile",
]

[[package]]
Expand Down
5 changes: 4 additions & 1 deletion src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,10 @@ impl Step for Compiletest {
cmd.env("RUSTC_PROFILER_SUPPORT", "1");
}

cmd.env("RUST_TEST_TMPDIR", builder.out.join("tmp"));
let tmp = builder.out.join("tmp");
std::fs::create_dir_all(&tmp).unwrap();
cmd.env("RUST_TEST_TMPDIR", tmp);


cmd.arg("--adb-path").arg("adb");
cmd.arg("--adb-test-dir").arg(ADB_TEST_DIR);
Expand Down
24 changes: 12 additions & 12 deletions src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// 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! {
// 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.
syntax::register_diagnostics! {
E0038: r##"
Trait objects like `Box<Trait>` can only be constructed when certain
requirements are satisfied by the trait in question.
Expand Down Expand Up @@ -2183,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 All @@ -2206,7 +2203,8 @@ register_diagnostics! {
// E0305, // expected constant
E0311, // thing may not live long enough
E0312, // lifetime of reference outlives lifetime of borrowed content
E0313, // lifetime of borrowed pointer outlives lifetime of captured variable
E0313, // lifetime of borrowed pointer outlives lifetime of captured
// variable
E0314, // closure outlives stack frame
E0315, // cannot invoke closure outside of its lifetime
E0316, // nested quantification of lifetimes
Expand All @@ -2223,12 +2221,13 @@ register_diagnostics! {
E0483, // lifetime of operand does not outlive the operation
E0484, // reference is not valid at the time of borrow
E0485, // automatically reference is not valid at the time of borrow
E0486, // type of expression contains references that are not valid during...
E0486, // type of expression contains references that are not valid during..
E0487, // unsafe use of destructor: destructor might be called while...
E0488, // lifetime of variable does not enclose its declaration
E0489, // type/lifetime parameter not in scope here
E0490, // a value of type `..` is borrowed for too long
E0495, // cannot infer an appropriate lifetime due to conflicting requirements
E0495, // cannot infer an appropriate lifetime due to conflicting
// requirements
E0566, // conflicting representation hints
E0623, // lifetime mismatch where both parameters are anonymous regions
E0628, // generators cannot have explicit parameters
Expand All @@ -2239,7 +2238,8 @@ register_diagnostics! {
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
E0697, // closures cannot be static
E0707, // multiple elided lifetimes used in arguments of `async fn`
E0708, // `async` non-`move` closures with parameters are not currently supported
E0708, // `async` non-`move` closures with parameters are not currently
// supported
E0709, // multiple different lifetimes used in arguments of `async fn`
E0710, // an unknown tool name found in scoped lint
E0711, // a feature has been declared with conflicting stability attributes
Expand Down
6 changes: 0 additions & 6 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#![feature(non_exhaustive)]
#![feature(optin_builtin_traits)]
#![feature(range_is_empty)]
#![feature(rustc_diagnostic_macros)]
#![feature(slice_patterns)]
#![feature(specialization)]
#![feature(unboxed_closures)]
Expand Down Expand Up @@ -88,8 +87,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 +140,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 }
4 changes: 0 additions & 4 deletions src/librustc_codegen_llvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ crate-type = ["dylib"]
test = false

[dependencies]
cc = "1.0.1" # Used to locate MSVC
num_cpus = "1.0"
tempfile = "3.0"
rustc_llvm = { path = "../librustc_llvm" }
memmap = "0.6"

[features]
# This is used to convince Cargo to separately cache builds of `rustc_codegen_llvm`
Expand Down
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
5 changes: 1 addition & 4 deletions src/librustc_codegen_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#![feature(in_band_lifetimes)]
#![feature(libc)]
#![feature(nll)]
#![feature(rustc_diagnostic_macros)]
#![feature(optin_builtin_traits)]
#![feature(concat_idents)]
#![feature(link_args)]
Expand Down Expand Up @@ -256,7 +255,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 +424,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
5 changes: 0 additions & 5 deletions src/librustc_codegen_ssa/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![feature(box_syntax)]
#![feature(core_intrinsics)]
#![feature(libc)]
#![feature(rustc_diagnostic_macros)]
#![feature(stmt_expr_attributes)]
#![feature(try_blocks)]
#![feature(in_band_lifetimes)]
Expand Down Expand Up @@ -35,8 +34,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 +155,3 @@ pub struct CodegenResults {
pub linker_info: back::linker::LinkerInfo,
pub crate_info: CrateInfo,
}

__build_diagnostic_array! { librustc_codegen_ssa, DIAGNOSTICS }
1 change: 0 additions & 1 deletion src/librustc_codegen_utils/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#![feature(core_intrinsics)]
#![feature(never_type)]
#![feature(nll)]
#![feature(rustc_diagnostic_macros)]
#![feature(in_band_lifetimes)]

#![recursion_limit="256"]
Expand Down
1 change: 0 additions & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#![feature(box_syntax)]
#![cfg_attr(unix, feature(libc))]
#![feature(nll)]
#![feature(rustc_diagnostic_macros)]
#![feature(set_stdio)]
#![feature(no_debug)]
#![feature(integer_atomics)]
Expand Down
17 changes: 1 addition & 16 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 @@ -291,21 +291,6 @@ pub fn register_plugins<'a>(
let mut registry = Registry::new(sess, krate.span);

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,
);
}

for registrar in registrars {
registry.args_hidden = Some(registrar.args);
(registrar.fun)(&mut registry);
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
}
1 change: 0 additions & 1 deletion src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#![feature(box_patterns)]
#![feature(box_syntax)]
#![feature(nll)]
#![feature(rustc_diagnostic_macros)]

#![recursion_limit="256"]

Expand Down
12 changes: 4 additions & 8 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 All @@ -97,5 +92,6 @@ register_diagnostics! {
E0464, // multiple matching crates for `..`
E0465, // multiple .. candidates for `..` found
E0519, // local crate and dependency have same (crate-name, disambiguator)
E0523, // two dependencies have same (crate-name, disambiguator) but different SVH
// two dependencies have same (crate-name, disambiguator) but different SVH
E0523,
}
5 changes: 1 addition & 4 deletions src/librustc_metadata/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#![feature(nll)]
#![feature(proc_macro_internals)]
#![feature(proc_macro_quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
#![feature(slice_patterns)]
#![feature(specialization)]
Expand All @@ -23,7 +22,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 +67,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
5 changes: 1 addition & 4 deletions src/librustc_mir/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
#![feature(const_fn)]
#![feature(decl_macro)]
#![feature(exhaustive_patterns)]
#![feature(rustc_diagnostic_macros)]
#![feature(never_type)]
#![feature(specialization)]
#![feature(try_trait)]
Expand All @@ -32,7 +31,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 +61,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
Loading