|
9 | 9 | #![feature(once_cell)] |
10 | 10 | #![recursion_limit = "256"] |
11 | 11 | #![allow(rustc::potential_query_instability)] |
| 12 | +#![deny(rustc::untranslatable_diagnostic)] |
| 13 | +#![deny(rustc::diagnostic_outside_of_impl)] |
12 | 14 |
|
13 | 15 | #[macro_use] |
14 | 16 | extern crate tracing; |
@@ -56,6 +58,9 @@ use std::time::Instant; |
56 | 58 |
|
57 | 59 | pub mod args; |
58 | 60 | pub mod pretty; |
| 61 | +mod session_diagnostics; |
| 62 | + |
| 63 | +use crate::session_diagnostics::{RlinkNotAFile, RlinkUnableToDeserialize, RlinkUnableToRead}; |
59 | 64 |
|
60 | 65 | /// Exit status code used for successful compilation and help output. |
61 | 66 | pub const EXIT_SUCCESS: i32 = 0; |
@@ -545,7 +550,11 @@ fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) { |
545 | 550 |
|
546 | 551 | fn show_content_with_pager(content: &str) { |
547 | 552 | let pager_name = env::var_os("PAGER").unwrap_or_else(|| { |
548 | | - if cfg!(windows) { OsString::from("more.com") } else { OsString::from("less") } |
| 553 | + if cfg!(windows) { |
| 554 | + OsString::from("more.com") |
| 555 | + } else { |
| 556 | + OsString::from("less") |
| 557 | + } |
549 | 558 | }); |
550 | 559 |
|
551 | 560 | let mut fallback_to_println = false; |
@@ -581,18 +590,24 @@ pub fn try_process_rlink(sess: &Session, compiler: &interface::Compiler) -> Comp |
581 | 590 | sess.init_crate_types(collect_crate_types(sess, &[])); |
582 | 591 | let outputs = compiler.build_output_filenames(sess, &[]); |
583 | 592 | let rlink_data = fs::read(file).unwrap_or_else(|err| { |
584 | | - sess.fatal(&format!("failed to read rlink file: {}", err)); |
| 593 | + sess.fatal(RlinkUnableToRead { |
| 594 | + span: Default::default(), |
| 595 | + error_message: err.to_string(), |
| 596 | + }); |
585 | 597 | }); |
586 | 598 | let codegen_results = match CodegenResults::deserialize_rlink(rlink_data) { |
587 | 599 | Ok(codegen) => codegen, |
588 | 600 | Err(error) => { |
589 | | - sess.fatal(&format!("Could not deserialize .rlink file: {error}")); |
| 601 | + sess.fatal(RlinkUnableToDeserialize { |
| 602 | + span: Default::default(), |
| 603 | + error_message: error.to_string(), |
| 604 | + }); |
590 | 605 | } |
591 | 606 | }; |
592 | 607 | let result = compiler.codegen_backend().link(sess, codegen_results, &outputs); |
593 | 608 | abort_on_err(result, sess); |
594 | 609 | } else { |
595 | | - sess.fatal("rlink must be a file") |
| 610 | + sess.fatal(RlinkNotAFile { span: Default::default() }) |
596 | 611 | } |
597 | 612 | Compilation::Stop |
598 | 613 | } else { |
@@ -1116,7 +1131,11 @@ fn extra_compiler_flags() -> Option<(Vec<String>, bool)> { |
1116 | 1131 | } |
1117 | 1132 | } |
1118 | 1133 |
|
1119 | | - if !result.is_empty() { Some((result, excluded_cargo_defaults)) } else { None } |
| 1134 | + if !result.is_empty() { |
| 1135 | + Some((result, excluded_cargo_defaults)) |
| 1136 | + } else { |
| 1137 | + None |
| 1138 | + } |
1120 | 1139 | } |
1121 | 1140 |
|
1122 | 1141 | /// Runs a closure and catches unwinds triggered by fatal errors. |
|
0 commit comments