@@ -391,7 +391,6 @@ use std::backtrace::{Backtrace, BacktraceStatus};
391391/// Certain errors (fatal, bug, unimpl) may cause immediate exit,
392392/// others log errors for later reporting.
393393pub struct Handler {
394- flags : HandlerFlags ,
395394 inner : Lock < HandlerInner > ,
396395}
397396
@@ -549,69 +548,47 @@ impl Drop for HandlerInner {
549548
550549impl Handler {
551550 pub fn with_tty_emitter (
552- color_config : ColorConfig ,
553- can_emit_warnings : bool ,
554- treat_err_as_bug : Option < NonZeroUsize > ,
555551 sm : Option < Lrc < SourceMap > > ,
556- fluent_bundle : Option < Lrc < FluentBundle > > ,
557552 fallback_bundle : LazyFallbackBundle ,
558- ice_file : Option < PathBuf > ,
559- ) -> Self {
560- Self :: with_tty_emitter_and_flags (
561- color_config,
562- sm,
563- fluent_bundle,
564- fallback_bundle,
565- HandlerFlags { can_emit_warnings, treat_err_as_bug, ..Default :: default ( ) } ,
566- ice_file,
567- )
568- }
569-
570- pub fn with_tty_emitter_and_flags (
571- color_config : ColorConfig ,
572- sm : Option < Lrc < SourceMap > > ,
573- fluent_bundle : Option < Lrc < FluentBundle > > ,
574- fallback_bundle : LazyFallbackBundle ,
575- flags : HandlerFlags ,
576- ice_file : Option < PathBuf > ,
577553 ) -> Self {
578554 let emitter = Box :: new ( EmitterWriter :: stderr (
579- color_config ,
555+ ColorConfig :: Auto ,
580556 sm,
581- fluent_bundle ,
557+ None ,
582558 fallback_bundle,
583559 false ,
584560 false ,
585561 None ,
586- flags . macro_backtrace ,
587- flags . track_diagnostics ,
562+ false ,
563+ false ,
588564 TerminalUrl :: No ,
589565 ) ) ;
590- Self :: with_emitter_and_flags ( emitter, flags, ice_file)
566+ Self :: with_emitter ( emitter)
567+ }
568+ pub fn disable_warnings ( mut self ) -> Self {
569+ self . inner . get_mut ( ) . flags . can_emit_warnings = false ;
570+ self
591571 }
592572
593- pub fn with_emitter (
594- can_emit_warnings : bool ,
595- treat_err_as_bug : Option < NonZeroUsize > ,
596- emitter : Box < dyn Emitter + sync:: Send > ,
597- ice_file : Option < PathBuf > ,
598- ) -> Self {
599- Handler :: with_emitter_and_flags (
600- emitter,
601- HandlerFlags { can_emit_warnings, treat_err_as_bug, ..Default :: default ( ) } ,
602- ice_file,
603- )
573+ pub fn treat_err_as_bug ( mut self , treat_err_as_bug : NonZeroUsize ) -> Self {
574+ self . inner . get_mut ( ) . flags . treat_err_as_bug = Some ( treat_err_as_bug) ;
575+ self
604576 }
605577
606- pub fn with_emitter_and_flags (
607- emitter : Box < dyn Emitter + sync:: Send > ,
608- flags : HandlerFlags ,
609- ice_file : Option < PathBuf > ,
610- ) -> Self {
578+ pub fn with_flags ( mut self , flags : HandlerFlags ) -> Self {
579+ self . inner . get_mut ( ) . flags = flags;
580+ self
581+ }
582+
583+ pub fn with_ice_file ( mut self , ice_file : PathBuf ) -> Self {
584+ self . inner . get_mut ( ) . ice_file = Some ( ice_file) ;
585+ self
586+ }
587+
588+ pub fn with_emitter ( emitter : Box < dyn Emitter + sync:: Send > ) -> Self {
611589 Self {
612- flags,
613590 inner : Lock :: new ( HandlerInner {
614- flags,
591+ flags : HandlerFlags { can_emit_warnings : true , .. Default :: default ( ) } ,
615592 lint_err_count : 0 ,
616593 err_count : 0 ,
617594 warn_count : 0 ,
@@ -629,7 +606,7 @@ impl Handler {
629606 check_unstable_expect_diagnostics : false ,
630607 unstable_expect_diagnostics : Vec :: new ( ) ,
631608 fulfilled_expectations : Default :: default ( ) ,
632- ice_file,
609+ ice_file : None ,
633610 } ) ,
634611 }
635612 }
@@ -657,7 +634,7 @@ impl Handler {
657634 // This is here to not allow mutation of flags;
658635 // as of this writing it's only used in tests in librustc_middle.
659636 pub fn can_emit_warnings ( & self ) -> bool {
660- self . flags . can_emit_warnings
637+ self . inner . lock ( ) . flags . can_emit_warnings
661638 }
662639
663640 /// Resets the diagnostic error count as well as the cached emitted diagnostics.
0 commit comments