Skip to content

Commit 97ca8d7

Browse files
committed
fix -Z treat-err-as-bug
1 parent df5c62b commit 97ca8d7

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

src/libsyntax/errors/mod.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl error::Error for ExplicitBug {
180180
#[must_use]
181181
#[derive(Clone)]
182182
pub struct DiagnosticBuilder<'a> {
183-
emitter: &'a RefCell<Box<Emitter>>,
183+
handler: &'a Handler,
184184
level: Level,
185185
message: String,
186186
code: Option<String>,
@@ -204,8 +204,9 @@ impl<'a> DiagnosticBuilder<'a> {
204204
return;
205205
}
206206

207-
self.emitter.borrow_mut().emit_struct(&self);
207+
self.handler.emit.borrow_mut().emit_struct(&self);
208208
self.cancel();
209+
self.handler.panic_if_treat_err_as_bug();
209210

210211
// if self.is_fatal() {
211212
// panic!(FatalError);
@@ -321,11 +322,11 @@ impl<'a> DiagnosticBuilder<'a> {
321322

322323
/// Convenience function for internal use, clients should use one of the
323324
/// struct_* methods on Handler.
324-
fn new(emitter: &'a RefCell<Box<Emitter>>,
325+
fn new(handler: &'a Handler,
325326
level: Level,
326327
message: &str) -> DiagnosticBuilder<'a> {
327328
DiagnosticBuilder {
328-
emitter: emitter,
329+
handler: handler,
329330
level: level,
330331
message: message.to_owned(),
331332
code: None,
@@ -362,10 +363,10 @@ impl<'a> fmt::Debug for DiagnosticBuilder<'a> {
362363
impl<'a> Drop for DiagnosticBuilder<'a> {
363364
fn drop(&mut self) {
364365
if !panicking() && !self.cancelled() {
365-
self.emitter.borrow_mut().emit(&MultiSpan::new(),
366-
"Error constructed but not emitted",
367-
None,
368-
Bug);
366+
self.handler.emit.borrow_mut().emit(&MultiSpan::new(),
367+
"Error constructed but not emitted",
368+
None,
369+
Bug);
369370
panic!();
370371
}
371372
}
@@ -412,14 +413,14 @@ impl Handler {
412413
}
413414

414415
pub fn struct_dummy<'a>(&'a self) -> DiagnosticBuilder<'a> {
415-
DiagnosticBuilder::new(&self.emit, Level::Cancelled, "")
416+
DiagnosticBuilder::new(self, Level::Cancelled, "")
416417
}
417418

418419
pub fn struct_span_warn<'a, S: Into<MultiSpan>>(&'a self,
419420
sp: S,
420421
msg: &str)
421422
-> DiagnosticBuilder<'a> {
422-
let mut result = DiagnosticBuilder::new(&self.emit, Level::Warning, msg);
423+
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
423424
result.set_span(sp);
424425
if !self.can_emit_warnings {
425426
result.cancel();
@@ -431,7 +432,7 @@ impl Handler {
431432
msg: &str,
432433
code: &str)
433434
-> DiagnosticBuilder<'a> {
434-
let mut result = DiagnosticBuilder::new(&self.emit, Level::Warning, msg);
435+
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
435436
result.set_span(sp);
436437
result.code(code.to_owned());
437438
if !self.can_emit_warnings {
@@ -440,7 +441,7 @@ impl Handler {
440441
result
441442
}
442443
pub fn struct_warn<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
443-
let mut result = DiagnosticBuilder::new(&self.emit, Level::Warning, msg);
444+
let mut result = DiagnosticBuilder::new(self, Level::Warning, msg);
444445
if !self.can_emit_warnings {
445446
result.cancel();
446447
}
@@ -451,7 +452,7 @@ impl Handler {
451452
msg: &str)
452453
-> DiagnosticBuilder<'a> {
453454
self.bump_err_count();
454-
let mut result = DiagnosticBuilder::new(&self.emit, Level::Error, msg);
455+
let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
455456
result.set_span(sp);
456457
result
457458
}
@@ -461,21 +462,21 @@ impl Handler {
461462
code: &str)
462463
-> DiagnosticBuilder<'a> {
463464
self.bump_err_count();
464-
let mut result = DiagnosticBuilder::new(&self.emit, Level::Error, msg);
465+
let mut result = DiagnosticBuilder::new(self, Level::Error, msg);
465466
result.set_span(sp);
466467
result.code(code.to_owned());
467468
result
468469
}
469470
pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
470471
self.bump_err_count();
471-
DiagnosticBuilder::new(&self.emit, Level::Error, msg)
472+
DiagnosticBuilder::new(self, Level::Error, msg)
472473
}
473474
pub fn struct_span_fatal<'a, S: Into<MultiSpan>>(&'a self,
474475
sp: S,
475476
msg: &str)
476477
-> DiagnosticBuilder<'a> {
477478
self.bump_err_count();
478-
let mut result = DiagnosticBuilder::new(&self.emit, Level::Fatal, msg);
479+
let mut result = DiagnosticBuilder::new(self, Level::Fatal, msg);
479480
result.set_span(sp);
480481
result
481482
}
@@ -485,14 +486,14 @@ impl Handler {
485486
code: &str)
486487
-> DiagnosticBuilder<'a> {
487488
self.bump_err_count();
488-
let mut result = DiagnosticBuilder::new(&self.emit, Level::Fatal, msg);
489+
let mut result = DiagnosticBuilder::new(self, Level::Fatal, msg);
489490
result.set_span(sp);
490491
result.code(code.to_owned());
491492
result
492493
}
493494
pub fn struct_fatal<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> {
494495
self.bump_err_count();
495-
DiagnosticBuilder::new(&self.emit, Level::Fatal, msg)
496+
DiagnosticBuilder::new(self, Level::Fatal, msg)
496497
}
497498

498499
pub fn cancel(&mut self, err: &mut DiagnosticBuilder) {
@@ -503,36 +504,35 @@ impl Handler {
503504
err.cancel();
504505
}
505506

506-
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str) -> FatalError {
507+
fn panic_if_treat_err_as_bug(&self) {
507508
if self.treat_err_as_bug {
508-
self.span_bug(sp, msg);
509+
panic!("encountered error with `-Z treat_err_as_bug");
509510
}
511+
}
512+
513+
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: &str)
514+
-> FatalError {
510515
self.emit(&sp.into(), msg, Fatal);
511516
self.bump_err_count();
517+
self.panic_if_treat_err_as_bug();
512518
return FatalError;
513519
}
514520
pub fn span_fatal_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: &str)
515-
-> FatalError {
516-
if self.treat_err_as_bug {
517-
self.span_bug(sp, msg);
518-
}
521+
-> FatalError {
519522
self.emit_with_code(&sp.into(), msg, code, Fatal);
520523
self.bump_err_count();
524+
self.panic_if_treat_err_as_bug();
521525
return FatalError;
522526
}
523527
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
524-
if self.treat_err_as_bug {
525-
self.span_bug(sp, msg);
526-
}
527528
self.emit(&sp.into(), msg, Error);
528529
self.bump_err_count();
530+
self.panic_if_treat_err_as_bug();
529531
}
530532
pub fn span_err_with_code<S: Into<MultiSpan>>(&self, sp: S, msg: &str, code: &str) {
531-
if self.treat_err_as_bug {
532-
self.span_bug(sp, msg);
533-
}
534533
self.emit_with_code(&sp.into(), msg, code, Error);
535534
self.bump_err_count();
535+
self.panic_if_treat_err_as_bug();
536536
}
537537
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
538538
self.emit(&sp.into(), msg, Warning);

0 commit comments

Comments
 (0)