From c9f7a3d2060a7b2c6f691f4f4b32328edffcf5bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 11 Jul 2019 16:59:19 -0700 Subject: [PATCH] Emit dropped unemitted errors to aid in ICE debugging --- src/librustc_errors/diagnostic_builder.rs | 9 ++++++--- src/libsyntax/parse/parser.rs | 13 +++++++------ src/libsyntax/util/parser_testing.rs | 6 +++--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs index fc74e43ff5739..41d0638f7c6bd 100644 --- a/src/librustc_errors/diagnostic_builder.rs +++ b/src/librustc_errors/diagnostic_builder.rs @@ -380,10 +380,13 @@ impl<'a> Debug for DiagnosticBuilder<'a> { impl<'a> Drop for DiagnosticBuilder<'a> { fn drop(&mut self) { if !panicking() && !self.cancelled() { - let mut db = DiagnosticBuilder::new(self.handler, - Level::Bug, - "Error constructed but not emitted"); + let mut db = DiagnosticBuilder::new( + self.handler, + Level::Bug, + "the following error was constructed but not emitted", + ); db.emit(); + self.emit(); panic!(); } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 83dbff6b2d574..871fc0e7062d6 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6666,12 +6666,13 @@ impl<'a> Parser<'a> { } /// Reads a module from a source file. - fn eval_src_mod(&mut self, - path: PathBuf, - directory_ownership: DirectoryOwnership, - name: String, - id_sp: Span) - -> PResult<'a, (ast::Mod, Vec )> { + fn eval_src_mod( + &mut self, + path: PathBuf, + directory_ownership: DirectoryOwnership, + name: String, + id_sp: Span, + ) -> PResult<'a, (ast::Mod, Vec)> { let mut included_mod_stack = self.sess.included_mod_stack.borrow_mut(); if let Some(i) = included_mod_stack.iter().position(|p| *p == path) { let mut err = String::from("circular modules: "); diff --git a/src/libsyntax/util/parser_testing.rs b/src/libsyntax/util/parser_testing.rs index f850960624ce7..2ef32d37d44cd 100644 --- a/src/libsyntax/util/parser_testing.rs +++ b/src/libsyntax/util/parser_testing.rs @@ -34,7 +34,7 @@ fn with_error_checking_parse<'a, T, F>(s: String, ps: &'a ParseSess, f: F) -> T } /// Parse a string, return a crate. -pub fn string_to_crate (source_str : String) -> ast::Crate { +pub fn string_to_crate(source_str : String) -> ast::Crate { let ps = ParseSess::new(FilePathMapping::empty()); with_error_checking_parse(source_str, &ps, |p| { p.parse_crate_mod() @@ -42,7 +42,7 @@ pub fn string_to_crate (source_str : String) -> ast::Crate { } /// Parse a string, return an expr -pub fn string_to_expr (source_str : String) -> P { +pub fn string_to_expr(source_str : String) -> P { let ps = ParseSess::new(FilePathMapping::empty()); with_error_checking_parse(source_str, &ps, |p| { p.parse_expr() @@ -50,7 +50,7 @@ pub fn string_to_expr (source_str : String) -> P { } /// Parse a string, return an item -pub fn string_to_item (source_str : String) -> Option> { +pub fn string_to_item(source_str : String) -> Option> { let ps = ParseSess::new(FilePathMapping::empty()); with_error_checking_parse(source_str, &ps, |p| { p.parse_item()