Skip to content

Commit 9b95eef

Browse files
committed
save_analysis: Migrate diagnostics
1 parent a1bea15 commit 9b95eef

File tree

6 files changed

+21
-1
lines changed

6 files changed

+21
-1
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -4421,9 +4421,11 @@ dependencies = [
44214421
"rustc_ast",
44224422
"rustc_ast_pretty",
44234423
"rustc_data_structures",
4424+
"rustc_errors",
44244425
"rustc_hir",
44254426
"rustc_hir_pretty",
44264427
"rustc_lexer",
4428+
"rustc_macros",
44274429
"rustc_middle",
44284430
"rustc_session",
44294431
"rustc_span",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save_analysis_could_not_open = Could not open `{$file_name}`: `{$err}`

compiler/rustc_error_messages/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ fluent_messages! {
4343
passes => "../locales/en-US/passes.ftl",
4444
plugin_impl => "../locales/en-US/plugin_impl.ftl",
4545
privacy => "../locales/en-US/privacy.ftl",
46+
save_analysis => "../locales/en-US/save_analysis.ftl",
4647
typeck => "../locales/en-US/typeck.ftl",
4748
}
4849

compiler/rustc_save_analysis/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ rustc_middle = { path = "../rustc_middle" }
99
rustc_ast = { path = "../rustc_ast" }
1010
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1111
rustc_data_structures = { path = "../rustc_data_structures" }
12+
rustc_errors = { path = "../rustc_errors" }
1213
rustc_hir = { path = "../rustc_hir" }
1314
rustc_hir_pretty = { path = "../rustc_hir_pretty" }
1415
rustc_lexer = { path = "../rustc_lexer" }
16+
rustc_macros = { path = "../rustc_macros" }
1517
serde_json = "1"
1618
rustc_session = { path = "../rustc_session" }
1719
rustc_span = { path = "../rustc_span" }
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use rustc_macros::SessionDiagnostic;
2+
3+
use std::path::Path;
4+
5+
#[derive(SessionDiagnostic)]
6+
#[diag(save_analysis::could_not_open)]
7+
pub(crate) struct CouldNotOpen<'a> {
8+
pub file_name: &'a Path,
9+
pub err: std::io::Error,
10+
}

compiler/rustc_save_analysis/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
#![feature(let_else)]
44
#![recursion_limit = "256"]
55
#![allow(rustc::potential_query_instability)]
6+
#![feature(never_type)]
7+
#![deny(rustc::untranslatable_diagnostic)]
8+
#![deny(rustc::diagnostic_outside_of_impl)]
69

710
mod dump_visitor;
811
mod dumper;
912
#[macro_use]
1013
mod span_utils;
14+
mod errors;
1115
mod sig;
1216

1317
use rustc_ast as ast;
@@ -928,7 +932,7 @@ impl<'a> DumpHandler<'a> {
928932
info!("Writing output to {}", file_name.display());
929933

930934
let output_file = BufWriter::new(File::create(&file_name).unwrap_or_else(|e| {
931-
sess.fatal(&format!("Could not open {}: {}", file_name.display(), e))
935+
sess.emit_fatal(errors::CouldNotOpen { file_name: file_name.as_path(), err: e })
932936
}));
933937

934938
(output_file, file_name)

0 commit comments

Comments
 (0)