From 7a03b4c75ad985812467742faa8d76a14a4bf601 Mon Sep 17 00:00:00 2001
From: Tommy Ip <hkmp7tommy@gmail.com>
Date: Fri, 12 May 2017 12:48:18 +0100
Subject: [PATCH] Fix unexpected panic with the -Z treat-err-as-bug option

This fix an issue where the compiler panics even if there is no
error when passed with the `-Z treat-err-as-bug` option.

Fixes #35886.
---
 src/librustc_errors/diagnostic_builder.rs | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/librustc_errors/diagnostic_builder.rs b/src/librustc_errors/diagnostic_builder.rs
index a9c2bbeba2aa4..84fb4b192750b 100644
--- a/src/librustc_errors/diagnostic_builder.rs
+++ b/src/librustc_errors/diagnostic_builder.rs
@@ -99,7 +99,10 @@ impl<'a> DiagnosticBuilder<'a> {
 
         self.handler.emitter.borrow_mut().emit(&self);
         self.cancel();
-        self.handler.panic_if_treat_err_as_bug();
+
+        if self.level == Level::Error {
+            self.handler.panic_if_treat_err_as_bug();
+        }
 
         // if self.is_fatal() {
         //     panic!(FatalError);