Skip to content

Commit 1057a72

Browse files
committed
fix -Z treat-err-as-bug
1 parent 91aff57 commit 1057a72

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

src/librustc_errors/diagnostic_builder.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,27 @@ impl<'a> DiagnosticBuilder<'a> {
8282
return;
8383
}
8484

85-
match self.level {
85+
let is_error = match self.level {
8686
Level::Bug |
8787
Level::Fatal |
8888
Level::PhaseFatal |
8989
Level::Error => {
90-
self.handler.bump_err_count();
90+
true
9191
}
9292

9393
Level::Warning |
9494
Level::Note |
9595
Level::Help |
9696
Level::Cancelled => {
97+
false
9798
}
98-
}
99+
};
99100

100101
self.handler.emitter.borrow_mut().emit(&self);
101102
self.cancel();
102103

103-
if self.level == Level::Error {
104-
self.handler.panic_if_treat_err_as_bug();
104+
if is_error {
105+
self.handler.bump_err_count();
105106
}
106107

107108
// if self.is_fatal() {
@@ -210,4 +211,3 @@ impl<'a> Drop for DiagnosticBuilder<'a> {
210211
}
211212
}
212213
}
213-

src/librustc_errors/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,6 @@ impl Handler {
399399

400400
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> FatalError {
401401
self.emit(&sp.into(), msg, Fatal);
402-
self.panic_if_treat_err_as_bug();
403402
FatalError
404403
}
405404
pub fn span_fatal_with_code<S: Into<MultiSpan>>(&self,
@@ -408,12 +407,10 @@ impl Handler {
408407
code: &str)
409408
-> FatalError {
410409
self.emit_with_code(&sp.into(), msg, code, Fatal);
411-
self.panic_if_treat_err_as_bug();
412410
FatalError
413411
}
414412
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
415413
self.emit(&sp.into(), msg, Error);
416-
self.panic_if_treat_err_as_bug();
417414
}
418415
pub fn mut_span_err<'a, S: Into<MultiSpan>>(&'a self,
419416
sp: S,
@@ -425,7 +422,6 @@ impl Handler {
425422
}
426423
pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: &str) {
427424
self.emit_with_code(&sp.into(), msg, code, Error);
428-
self.panic_if_treat_err_as_bug();
429425
}
430426
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
431427
self.emit(&sp.into(), msg, Warning);
@@ -494,6 +490,7 @@ impl Handler {
494490
}
495491

496492
pub fn bump_err_count(&self) {
493+
self.panic_if_treat_err_as_bug();
497494
self.err_count.set(self.err_count.get() + 1);
498495
}
499496

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) err.rs -Z treat-err-as-bug 2>&1 \
5+
| grep -q "panicked at 'encountered error with .-Z treat_err_as_bug'"
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![crate_type="rlib"]
12+
13+
pub static C: u32 = 0-1;

0 commit comments

Comments
 (0)