Skip to content

Commit 45aad17

Browse files
committed
Reinstate emit_stashed_diagnostics in DiagCtxtInner::drop.
I removed it in rust-lang#121206 because I thought thought it wasn't necessary. But then I had to add an `emit_stashed_diagnostics` call elsewhere in rustfmt to avoid the assertion failure (which took two attempts to get right, rust-lang#121487 and rust-lang#121615), and now there's an assertion failure in clippy as well (rust-lang/rust-clippy#12364). So this commit just reinstates the call in `DiagCtxtInner::drop`. It also reverts the rustfmt changes from rust-lang#121487 and rust-lang#121615, though it keeps the tests added for those PRs.
1 parent 4026fd7 commit 45aad17

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

src/formatting.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn format_project<T: FormatHandler>(
109109
let main_file = input.file_name();
110110
let input_is_stdin = main_file == FileName::Stdin;
111111

112-
let mut parse_session = ParseSess::new(config)?;
112+
let parse_session = ParseSess::new(config)?;
113113
if config.skip_children() && parse_session.ignore_file(&main_file) {
114114
return Ok(FormatReport::new());
115115
}
@@ -118,20 +118,11 @@ fn format_project<T: FormatHandler>(
118118
let mut report = FormatReport::new();
119119
let directory_ownership = input.to_directory_ownership();
120120

121-
// rustfmt doesn't use `run_compiler` like other tools, so it must emit any
122-
// stashed diagnostics itself, otherwise the `DiagCtxt` will assert when
123-
// dropped. The final result here combines the parsing result and the
124-
// `emit_stashed_diagnostics` result.
125-
let parse_res = Parser::parse_crate(input, &parse_session);
126-
let stashed_res = parse_session.emit_stashed_diagnostics();
127-
let krate = match (parse_res, stashed_res) {
128-
(Ok(krate), None) => krate,
129-
(parse_res, _) => {
130-
// Surface parse error via Session (errors are merged there from report).
131-
let forbid_verbose = match parse_res {
132-
Err(e) if e != ParserError::ParsePanicError => true,
133-
_ => input_is_stdin,
134-
};
121+
let krate = match Parser::parse_crate(input, &parse_session) {
122+
Ok(krate) => krate,
123+
// Surface parse error via Session (errors are merged there from report)
124+
Err(e) => {
125+
let forbid_verbose = input_is_stdin || e != ParserError::ParsePanicError;
135126
should_emit_verbose(forbid_verbose, config, || {
136127
eprintln!("The Rust parser panicked");
137128
});

src/parse/session.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use std::sync::atomic::{AtomicBool, Ordering};
55
use rustc_data_structures::sync::{IntoDynSyncSend, Lrc};
66
use rustc_errors::emitter::{DynEmitter, Emitter, HumanEmitter};
77
use rustc_errors::translation::Translate;
8-
use rustc_errors::{
9-
ColorConfig, Diag, DiagCtxt, DiagInner, ErrorGuaranteed, Level as DiagnosticLevel,
10-
};
8+
use rustc_errors::{ColorConfig, Diag, DiagCtxt, DiagInner, Level as DiagnosticLevel};
119
use rustc_session::parse::ParseSess as RawParseSess;
1210
use rustc_span::{
1311
source_map::{FilePathMapping, SourceMap},
@@ -230,10 +228,6 @@ impl ParseSess {
230228
self.ignore_path_set.as_ref().is_match(path)
231229
}
232230

233-
pub(crate) fn emit_stashed_diagnostics(&mut self) -> Option<ErrorGuaranteed> {
234-
self.parse_sess.dcx.emit_stashed_diagnostics()
235-
}
236-
237231
pub(crate) fn set_silent_emitter(&mut self) {
238232
self.parse_sess.dcx = DiagCtxt::with_emitter(silent_emitter());
239233
}

0 commit comments

Comments
 (0)