@@ -180,7 +180,7 @@ impl error::Error for ExplicitBug {
180
180
#[ must_use]
181
181
#[ derive( Clone ) ]
182
182
pub struct DiagnosticBuilder < ' a > {
183
- emitter : & ' a RefCell < Box < Emitter > > ,
183
+ handler : & ' a Handler ,
184
184
level : Level ,
185
185
message : String ,
186
186
code : Option < String > ,
@@ -204,8 +204,9 @@ impl<'a> DiagnosticBuilder<'a> {
204
204
return ;
205
205
}
206
206
207
- self . emitter . borrow_mut ( ) . emit_struct ( & self ) ;
207
+ self . handler . emit . borrow_mut ( ) . emit_struct ( & self ) ;
208
208
self . cancel ( ) ;
209
+ self . handler . panic_if_treat_err_as_bug ( ) ;
209
210
210
211
// if self.is_fatal() {
211
212
// panic!(FatalError);
@@ -321,11 +322,11 @@ impl<'a> DiagnosticBuilder<'a> {
321
322
322
323
/// Convenience function for internal use, clients should use one of the
323
324
/// struct_* methods on Handler.
324
- fn new ( emitter : & ' a RefCell < Box < Emitter > > ,
325
+ fn new ( handler : & ' a Handler ,
325
326
level : Level ,
326
327
message : & str ) -> DiagnosticBuilder < ' a > {
327
328
DiagnosticBuilder {
328
- emitter : emitter ,
329
+ handler : handler ,
329
330
level : level,
330
331
message : message. to_owned ( ) ,
331
332
code : None ,
@@ -362,10 +363,10 @@ impl<'a> fmt::Debug for DiagnosticBuilder<'a> {
362
363
impl < ' a > Drop for DiagnosticBuilder < ' a > {
363
364
fn drop ( & mut self ) {
364
365
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 ) ;
369
370
panic ! ( ) ;
370
371
}
371
372
}
@@ -412,14 +413,14 @@ impl Handler {
412
413
}
413
414
414
415
pub fn struct_dummy < ' a > ( & ' a self ) -> DiagnosticBuilder < ' a > {
415
- DiagnosticBuilder :: new ( & self . emit , Level :: Cancelled , "" )
416
+ DiagnosticBuilder :: new ( self , Level :: Cancelled , "" )
416
417
}
417
418
418
419
pub fn struct_span_warn < ' a , S : Into < MultiSpan > > ( & ' a self ,
419
420
sp : S ,
420
421
msg : & str )
421
422
-> DiagnosticBuilder < ' a > {
422
- let mut result = DiagnosticBuilder :: new ( & self . emit , Level :: Warning , msg) ;
423
+ let mut result = DiagnosticBuilder :: new ( self , Level :: Warning , msg) ;
423
424
result. set_span ( sp) ;
424
425
if !self . can_emit_warnings {
425
426
result. cancel ( ) ;
@@ -431,7 +432,7 @@ impl Handler {
431
432
msg : & str ,
432
433
code : & str )
433
434
-> DiagnosticBuilder < ' a > {
434
- let mut result = DiagnosticBuilder :: new ( & self . emit , Level :: Warning , msg) ;
435
+ let mut result = DiagnosticBuilder :: new ( self , Level :: Warning , msg) ;
435
436
result. set_span ( sp) ;
436
437
result. code ( code. to_owned ( ) ) ;
437
438
if !self . can_emit_warnings {
@@ -440,7 +441,7 @@ impl Handler {
440
441
result
441
442
}
442
443
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) ;
444
445
if !self . can_emit_warnings {
445
446
result. cancel ( ) ;
446
447
}
@@ -451,7 +452,7 @@ impl Handler {
451
452
msg : & str )
452
453
-> DiagnosticBuilder < ' a > {
453
454
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) ;
455
456
result. set_span ( sp) ;
456
457
result
457
458
}
@@ -461,21 +462,21 @@ impl Handler {
461
462
code : & str )
462
463
-> DiagnosticBuilder < ' a > {
463
464
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) ;
465
466
result. set_span ( sp) ;
466
467
result. code ( code. to_owned ( ) ) ;
467
468
result
468
469
}
469
470
pub fn struct_err < ' a > ( & ' a self , msg : & str ) -> DiagnosticBuilder < ' a > {
470
471
self . bump_err_count ( ) ;
471
- DiagnosticBuilder :: new ( & self . emit , Level :: Error , msg)
472
+ DiagnosticBuilder :: new ( self , Level :: Error , msg)
472
473
}
473
474
pub fn struct_span_fatal < ' a , S : Into < MultiSpan > > ( & ' a self ,
474
475
sp : S ,
475
476
msg : & str )
476
477
-> DiagnosticBuilder < ' a > {
477
478
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) ;
479
480
result. set_span ( sp) ;
480
481
result
481
482
}
@@ -485,14 +486,14 @@ impl Handler {
485
486
code : & str )
486
487
-> DiagnosticBuilder < ' a > {
487
488
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) ;
489
490
result. set_span ( sp) ;
490
491
result. code ( code. to_owned ( ) ) ;
491
492
result
492
493
}
493
494
pub fn struct_fatal < ' a > ( & ' a self , msg : & str ) -> DiagnosticBuilder < ' a > {
494
495
self . bump_err_count ( ) ;
495
- DiagnosticBuilder :: new ( & self . emit , Level :: Fatal , msg)
496
+ DiagnosticBuilder :: new ( self , Level :: Fatal , msg)
496
497
}
497
498
498
499
pub fn cancel ( & mut self , err : & mut DiagnosticBuilder ) {
@@ -503,36 +504,35 @@ impl Handler {
503
504
err. cancel ( ) ;
504
505
}
505
506
506
- pub fn span_fatal < S : Into < MultiSpan > > ( & self , sp : S , msg : & str ) -> FatalError {
507
+ fn panic_if_treat_err_as_bug ( & self ) {
507
508
if self . treat_err_as_bug {
508
- self . span_bug ( sp , msg ) ;
509
+ panic ! ( "encountered error with `-Z treat_err_as_bug" ) ;
509
510
}
511
+ }
512
+
513
+ pub fn span_fatal < S : Into < MultiSpan > > ( & self , sp : S , msg : & str )
514
+ -> FatalError {
510
515
self . emit ( & sp. into ( ) , msg, Fatal ) ;
511
516
self . bump_err_count ( ) ;
517
+ self . panic_if_treat_err_as_bug ( ) ;
512
518
return FatalError ;
513
519
}
514
520
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 {
519
522
self . emit_with_code ( & sp. into ( ) , msg, code, Fatal ) ;
520
523
self . bump_err_count ( ) ;
524
+ self . panic_if_treat_err_as_bug ( ) ;
521
525
return FatalError ;
522
526
}
523
527
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
- }
527
528
self . emit ( & sp. into ( ) , msg, Error ) ;
528
529
self . bump_err_count ( ) ;
530
+ self . panic_if_treat_err_as_bug ( ) ;
529
531
}
530
532
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
- }
534
533
self . emit_with_code ( & sp. into ( ) , msg, code, Error ) ;
535
534
self . bump_err_count ( ) ;
535
+ self . panic_if_treat_err_as_bug ( ) ;
536
536
}
537
537
pub fn span_warn < S : Into < MultiSpan > > ( & self , sp : S , msg : & str ) {
538
538
self . emit ( & sp. into ( ) , msg, Warning ) ;
0 commit comments