Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix -Z treat-err-as-bug
  • Loading branch information
arielb1 committed Jul 31, 2017
1 parent 91aff57 commit 1057a72
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/librustc_errors/diagnostic_builder.rs
Expand Up @@ -82,26 +82,27 @@ impl<'a> DiagnosticBuilder<'a> {
return;
}

match self.level {
let is_error = match self.level {
Level::Bug |
Level::Fatal |
Level::PhaseFatal |
Level::Error => {
self.handler.bump_err_count();
true
}

Level::Warning |
Level::Note |
Level::Help |
Level::Cancelled => {
false
}
}
};

self.handler.emitter.borrow_mut().emit(&self);
self.cancel();

if self.level == Level::Error {
self.handler.panic_if_treat_err_as_bug();
if is_error {
self.handler.bump_err_count();
}

// if self.is_fatal() {
Expand Down Expand Up @@ -210,4 +211,3 @@ impl<'a> Drop for DiagnosticBuilder<'a> {
}
}
}

5 changes: 1 addition & 4 deletions src/librustc_errors/lib.rs
Expand Up @@ -399,7 +399,6 @@ impl Handler {

pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> FatalError {
self.emit(&sp.into(), msg, Fatal);
self.panic_if_treat_err_as_bug();
FatalError
}
pub fn span_fatal_with_code<S: Into<MultiSpan>>(&self,
Expand All @@ -408,12 +407,10 @@ impl Handler {
code: &str)
-> FatalError {
self.emit_with_code(&sp.into(), msg, code, Fatal);
self.panic_if_treat_err_as_bug();
FatalError
}
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
self.emit(&sp.into(), msg, Error);
self.panic_if_treat_err_as_bug();
}
pub fn mut_span_err<'a, S: Into<MultiSpan>>(&'a self,
sp: S,
Expand All @@ -425,7 +422,6 @@ impl Handler {
}
pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: &str) {
self.emit_with_code(&sp.into(), msg, code, Error);
self.panic_if_treat_err_as_bug();
}
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
self.emit(&sp.into(), msg, Warning);
Expand Down Expand Up @@ -494,6 +490,7 @@ impl Handler {
}

pub fn bump_err_count(&self) {
self.panic_if_treat_err_as_bug();
self.err_count.set(self.err_count.get() + 1);
}

Expand Down
5 changes: 5 additions & 0 deletions src/test/run-make/treat-err-as-bug/Makefile
@@ -0,0 +1,5 @@
-include ../tools.mk

all:
$(RUSTC) err.rs -Z treat-err-as-bug 2>&1 \
| grep -q "panicked at 'encountered error with .-Z treat_err_as_bug'"
13 changes: 13 additions & 0 deletions src/test/run-make/treat-err-as-bug/err.rs
@@ -0,0 +1,13 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![crate_type="rlib"]

pub static C: u32 = 0-1;

0 comments on commit 1057a72

Please sign in to comment.