Move rustc_interface diagnostics to struct SessionDiagnostic derives
This commit is contained in:
parent
e4403ae9ff
commit
b411adec2a
4 changed files with 137 additions and 40 deletions
|
@ -4,3 +4,40 @@ interface_ferris_identifier =
|
||||||
|
|
||||||
interface_emoji_identifier =
|
interface_emoji_identifier =
|
||||||
identifiers cannot contain emoji: `{$ident}`
|
identifiers cannot contain emoji: `{$ident}`
|
||||||
|
|
||||||
|
mixed_bin_crate =
|
||||||
|
cannot mix `bin` crate type with others
|
||||||
|
|
||||||
|
mixed_proc_macro_crate =
|
||||||
|
cannot mix `proc-macro` crate type with others
|
||||||
|
|
||||||
|
proc_macro_doc_without_arg =
|
||||||
|
Trying to document proc macro crate without passing '--crate-type proc-macro to rustdoc
|
||||||
|
.warn = The generated documentation may be incorrect
|
||||||
|
|
||||||
|
error_writing_dependencies =
|
||||||
|
error writing dependencies to `{$path}`: {$error}
|
||||||
|
|
||||||
|
input_file_would_be_overwritten =
|
||||||
|
the input file "{$path}" would be overwritten by the generated executable
|
||||||
|
|
||||||
|
generated_file_conflicts_with_directory =
|
||||||
|
the generated executable for the input file "{$input_path}" conflicts with the existing directory "{$dir_path}"
|
||||||
|
|
||||||
|
temps_dir_error =
|
||||||
|
failed to find or create the directory specified by `--temps-dir`
|
||||||
|
|
||||||
|
out_dir_error =
|
||||||
|
failed to find or create the directory specified by `--out-dir`
|
||||||
|
|
||||||
|
cant_emit_mir =
|
||||||
|
could not emit MIR: {$error}
|
||||||
|
|
||||||
|
rustc_error_fatal =
|
||||||
|
fatal error triggered by #[rustc_error]
|
||||||
|
|
||||||
|
rustc_error_unexpected_annotation =
|
||||||
|
unexpected annotation used with `#[rustc_error(...)]!
|
||||||
|
|
||||||
|
failed_writing_file =
|
||||||
|
failed to write file {$path}: {$error}"
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use rustc_errors::DiagnosticArgFromDisplay;
|
||||||
use rustc_macros::SessionDiagnostic;
|
use rustc_macros::SessionDiagnostic;
|
||||||
use rustc_span::{Span, Symbol};
|
use rustc_span::{Span, Symbol};
|
||||||
|
|
||||||
|
@ -17,3 +18,70 @@ pub struct EmojiIdentifier {
|
||||||
pub spans: Vec<Span>,
|
pub spans: Vec<Span>,
|
||||||
pub ident: Symbol,
|
pub ident: Symbol,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(interface::mixed_bin_crate)]
|
||||||
|
pub struct MixedBinCrate;
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(interface::mixed_proc_macro_crate)]
|
||||||
|
pub struct MixedProcMacroCrate;
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(interface::proc_macro_doc_without_arg)]
|
||||||
|
pub struct ProcMacroDocWithoutArg;
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(interface::error_writing_dependencies)]
|
||||||
|
pub struct ErrorWritingDependencies<'a> {
|
||||||
|
pub path: DiagnosticArgFromDisplay<'a>,
|
||||||
|
pub error: DiagnosticArgFromDisplay<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(interface::input_file_would_be_overwritten)]
|
||||||
|
pub struct InputFileWouldBeOverWritten<'a> {
|
||||||
|
pub path: DiagnosticArgFromDisplay<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(interface::generated_file_conflicts_with_directory)]
|
||||||
|
pub struct GeneratedFileConflictsWithDirectory<'a> {
|
||||||
|
pub input_path: DiagnosticArgFromDisplay<'a>,
|
||||||
|
pub dir_path: DiagnosticArgFromDisplay<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(interface::temps_dir_error)]
|
||||||
|
pub struct TempsDirError;
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(interface::out_dir_error)]
|
||||||
|
pub struct OutDirError;
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(interface::cant_emit_mir)]
|
||||||
|
pub struct CantEmitMIR<'a> {
|
||||||
|
pub error: DiagnosticArgFromDisplay<'a>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(interface::rustc_error_fatal)]
|
||||||
|
pub struct RustcErrorFatal {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(interface::rustc_error_unexpected_annotation)]
|
||||||
|
pub struct RustcErrorUnexpectedAnnotation {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(interface::failed_writing_file)]
|
||||||
|
pub struct FailedWritingFile<'a> {
|
||||||
|
pub path: DiagnosticArgFromDisplay<'a>,
|
||||||
|
pub error: DiagnosticArgFromDisplay<'a>,
|
||||||
|
}
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
use crate::errors::{EmojiIdentifier, FerrisIdentifier};
|
use crate::errors::{
|
||||||
|
CantEmitMIR, EmojiIdentifier, ErrorWritingDependencies, FerrisIdentifier,
|
||||||
|
GeneratedFileConflictsWithDirectory, InputFileWouldBeOverWritten, MixedBinCrate,
|
||||||
|
MixedProcMacroCrate, OutDirError, ProcMacroDocWithoutArg, TempsDirError,
|
||||||
|
};
|
||||||
use crate::interface::{Compiler, Result};
|
use crate::interface::{Compiler, Result};
|
||||||
use crate::proc_macro_decls;
|
use crate::proc_macro_decls;
|
||||||
use crate::util;
|
use crate::util;
|
||||||
|
@ -375,10 +379,10 @@ pub fn configure_and_expand(
|
||||||
|
|
||||||
if crate_types.len() > 1 {
|
if crate_types.len() > 1 {
|
||||||
if is_executable_crate {
|
if is_executable_crate {
|
||||||
sess.err("cannot mix `bin` crate type with others");
|
sess.emit_err(MixedBinCrate);
|
||||||
}
|
}
|
||||||
if is_proc_macro_crate {
|
if is_proc_macro_crate {
|
||||||
sess.err("cannot mix `proc-macro` crate type with others");
|
sess.emit_err(MixedProcMacroCrate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,13 +393,7 @@ pub fn configure_and_expand(
|
||||||
// However, we do emit a warning, to let such users know that they should
|
// However, we do emit a warning, to let such users know that they should
|
||||||
// start passing '--crate-type proc-macro'
|
// start passing '--crate-type proc-macro'
|
||||||
if has_proc_macro_decls && sess.opts.actually_rustdoc && !is_proc_macro_crate {
|
if has_proc_macro_decls && sess.opts.actually_rustdoc && !is_proc_macro_crate {
|
||||||
let mut msg = sess.diagnostic().struct_warn(
|
sess.emit_warning(ProcMacroDocWithoutArg);
|
||||||
"Trying to document proc macro crate \
|
|
||||||
without passing '--crate-type proc-macro to rustdoc",
|
|
||||||
);
|
|
||||||
|
|
||||||
msg.warn("The generated documentation may be incorrect");
|
|
||||||
msg.emit();
|
|
||||||
} else {
|
} else {
|
||||||
krate = sess.time("maybe_create_a_macro_crate", || {
|
krate = sess.time("maybe_create_a_macro_crate", || {
|
||||||
let is_test_crate = sess.opts.test;
|
let is_test_crate = sess.opts.test;
|
||||||
|
@ -649,11 +647,12 @@ fn write_out_deps(
|
||||||
.emit_artifact_notification(&deps_filename, "dep-info");
|
.emit_artifact_notification(&deps_filename, "dep-info");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => sess.fatal(&format!(
|
Err(e) => {
|
||||||
"error writing dependencies to `{}`: {}",
|
sess.emit_fatal(ErrorWritingDependencies {
|
||||||
deps_filename.display(),
|
path: (&deps_filename.display()).into(),
|
||||||
e
|
error: (&e).into(),
|
||||||
)),
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -683,20 +682,15 @@ pub fn prepare_outputs(
|
||||||
if let Some(ref input_path) = compiler.input_path {
|
if let Some(ref input_path) = compiler.input_path {
|
||||||
if sess.opts.will_create_output_file() {
|
if sess.opts.will_create_output_file() {
|
||||||
if output_contains_path(&output_paths, input_path) {
|
if output_contains_path(&output_paths, input_path) {
|
||||||
let reported = sess.err(&format!(
|
let reported = sess
|
||||||
"the input file \"{}\" would be overwritten by the generated \
|
.emit_err(InputFileWouldBeOverWritten { path: (&input_path.display()).into() });
|
||||||
executable",
|
|
||||||
input_path.display()
|
|
||||||
));
|
|
||||||
return Err(reported);
|
return Err(reported);
|
||||||
}
|
}
|
||||||
if let Some(dir_path) = output_conflicts_with_dir(&output_paths) {
|
if let Some(dir_path) = output_conflicts_with_dir(&output_paths) {
|
||||||
let reported = sess.err(&format!(
|
let reported = sess.emit_err(GeneratedFileConflictsWithDirectory {
|
||||||
"the generated executable for the input file \"{}\" conflicts with the \
|
input_path: (&input_path.display()).into(),
|
||||||
existing directory \"{}\"",
|
dir_path: (&dir_path.display()).into(),
|
||||||
input_path.display(),
|
});
|
||||||
dir_path.display()
|
|
||||||
));
|
|
||||||
return Err(reported);
|
return Err(reported);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -704,8 +698,7 @@ pub fn prepare_outputs(
|
||||||
|
|
||||||
if let Some(ref dir) = compiler.temps_dir {
|
if let Some(ref dir) = compiler.temps_dir {
|
||||||
if fs::create_dir_all(dir).is_err() {
|
if fs::create_dir_all(dir).is_err() {
|
||||||
let reported =
|
let reported = sess.emit_err(TempsDirError);
|
||||||
sess.err("failed to find or create the directory specified by `--temps-dir`");
|
|
||||||
return Err(reported);
|
return Err(reported);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -718,8 +711,7 @@ pub fn prepare_outputs(
|
||||||
if !only_dep_info {
|
if !only_dep_info {
|
||||||
if let Some(ref dir) = compiler.output_dir {
|
if let Some(ref dir) = compiler.output_dir {
|
||||||
if fs::create_dir_all(dir).is_err() {
|
if fs::create_dir_all(dir).is_err() {
|
||||||
let reported =
|
let reported = sess.emit_err(OutDirError);
|
||||||
sess.err("failed to find or create the directory specified by `--out-dir`");
|
|
||||||
return Err(reported);
|
return Err(reported);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1003,7 +995,7 @@ pub fn start_codegen<'tcx>(
|
||||||
|
|
||||||
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
|
if tcx.sess.opts.output_types.contains_key(&OutputType::Mir) {
|
||||||
if let Err(e) = rustc_mir_transform::dump_mir::emit_mir(tcx, outputs) {
|
if let Err(e) = rustc_mir_transform::dump_mir::emit_mir(tcx, outputs) {
|
||||||
tcx.sess.err(&format!("could not emit MIR: {}", e));
|
tcx.sess.emit_err(CantEmitMIR { error: (&e).into() });
|
||||||
tcx.sess.abort_if_errors();
|
tcx.sess.abort_if_errors();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::errors::{FailedWritingFile, RustcErrorFatal, RustcErrorUnexpectedAnnotation};
|
||||||
use crate::interface::{Compiler, Result};
|
use crate::interface::{Compiler, Result};
|
||||||
use crate::passes::{self, BoxedResolver, QueryContext};
|
use crate::passes::{self, BoxedResolver, QueryContext};
|
||||||
|
|
||||||
|
@ -274,18 +275,14 @@ impl<'tcx> Queries<'tcx> {
|
||||||
|
|
||||||
// Bare `#[rustc_error]`.
|
// Bare `#[rustc_error]`.
|
||||||
None => {
|
None => {
|
||||||
tcx.sess.span_fatal(
|
tcx.sess.emit_fatal(RustcErrorFatal { span: tcx.def_span(def_id) });
|
||||||
tcx.def_span(def_id),
|
|
||||||
"fatal error triggered by #[rustc_error]",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some other attribute.
|
// Some other attribute.
|
||||||
Some(_) => {
|
Some(_) => {
|
||||||
tcx.sess.span_warn(
|
tcx.sess.emit_warning(RustcErrorUnexpectedAnnotation {
|
||||||
tcx.def_span(def_id),
|
span: tcx.def_span(def_id),
|
||||||
"unexpected annotation used with `#[rustc_error(...)]!",
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -361,7 +358,10 @@ impl Linker {
|
||||||
let encoded = CodegenResults::serialize_rlink(&codegen_results);
|
let encoded = CodegenResults::serialize_rlink(&codegen_results);
|
||||||
let rlink_file = self.prepare_outputs.with_extension(config::RLINK_EXT);
|
let rlink_file = self.prepare_outputs.with_extension(config::RLINK_EXT);
|
||||||
std::fs::write(&rlink_file, encoded).map_err(|err| {
|
std::fs::write(&rlink_file, encoded).map_err(|err| {
|
||||||
sess.fatal(&format!("failed to write file {}: {}", rlink_file.display(), err));
|
sess.emit_fatal(FailedWritingFile {
|
||||||
|
path: (&rlink_file.display()).into(),
|
||||||
|
error: (&err).into(),
|
||||||
|
})
|
||||||
})?;
|
})?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue