Emit dropped unemitted errors to aid in ICE debugging

This commit is contained in:
Esteban Küber 2019-07-11 16:59:19 -07:00
parent 4bb6b4a5ed
commit c9f7a3d206
3 changed files with 16 additions and 12 deletions

View File

@ -380,10 +380,13 @@ impl<'a> Debug for DiagnosticBuilder<'a> {
impl<'a> Drop for DiagnosticBuilder<'a> { impl<'a> Drop for DiagnosticBuilder<'a> {
fn drop(&mut self) { fn drop(&mut self) {
if !panicking() && !self.cancelled() { if !panicking() && !self.cancelled() {
let mut db = DiagnosticBuilder::new(self.handler, let mut db = DiagnosticBuilder::new(
Level::Bug, self.handler,
"Error constructed but not emitted"); Level::Bug,
"the following error was constructed but not emitted",
);
db.emit(); db.emit();
self.emit();
panic!(); panic!();
} }
} }

View File

@ -6666,12 +6666,13 @@ impl<'a> Parser<'a> {
} }
/// Reads a module from a source file. /// Reads a module from a source file.
fn eval_src_mod(&mut self, fn eval_src_mod(
path: PathBuf, &mut self,
directory_ownership: DirectoryOwnership, path: PathBuf,
name: String, directory_ownership: DirectoryOwnership,
id_sp: Span) name: String,
-> PResult<'a, (ast::Mod, Vec<Attribute> )> { id_sp: Span,
) -> PResult<'a, (ast::Mod, Vec<Attribute>)> {
let mut included_mod_stack = self.sess.included_mod_stack.borrow_mut(); let mut included_mod_stack = self.sess.included_mod_stack.borrow_mut();
if let Some(i) = included_mod_stack.iter().position(|p| *p == path) { if let Some(i) = included_mod_stack.iter().position(|p| *p == path) {
let mut err = String::from("circular modules: "); let mut err = String::from("circular modules: ");

View File

@ -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. /// 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()); let ps = ParseSess::new(FilePathMapping::empty());
with_error_checking_parse(source_str, &ps, |p| { with_error_checking_parse(source_str, &ps, |p| {
p.parse_crate_mod() p.parse_crate_mod()
@ -42,7 +42,7 @@ pub fn string_to_crate (source_str : String) -> ast::Crate {
} }
/// Parse a string, return an expr /// Parse a string, return an expr
pub fn string_to_expr (source_str : String) -> P<ast::Expr> { pub fn string_to_expr(source_str : String) -> P<ast::Expr> {
let ps = ParseSess::new(FilePathMapping::empty()); let ps = ParseSess::new(FilePathMapping::empty());
with_error_checking_parse(source_str, &ps, |p| { with_error_checking_parse(source_str, &ps, |p| {
p.parse_expr() p.parse_expr()
@ -50,7 +50,7 @@ pub fn string_to_expr (source_str : String) -> P<ast::Expr> {
} }
/// Parse a string, return an item /// Parse a string, return an item
pub fn string_to_item (source_str : String) -> Option<P<ast::Item>> { pub fn string_to_item(source_str : String) -> Option<P<ast::Item>> {
let ps = ParseSess::new(FilePathMapping::empty()); let ps = ParseSess::new(FilePathMapping::empty());
with_error_checking_parse(source_str, &ps, |p| { with_error_checking_parse(source_str, &ps, |p| {
p.parse_item() p.parse_item()