@@ -520,12 +520,28 @@ impl Handler {
520520 }
521521
522522 /// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
523+ ///
524+ /// The builder will be canceled if warnings cannot be emitted.
523525 pub fn struct_span_warn ( & self , span : impl Into < MultiSpan > , msg : & str ) -> DiagnosticBuilder < ' _ > {
524526 let mut result = self . struct_warn ( msg) ;
525527 result. set_span ( span) ;
526528 result
527529 }
528530
531+ /// Construct a builder at the `Warning` level at the given `span` and with the `msg`.
532+ ///
533+ /// This will "force" the warning meaning it will not be canceled even
534+ /// if warnings cannot be emitted.
535+ pub fn struct_span_force_warn (
536+ & self ,
537+ span : impl Into < MultiSpan > ,
538+ msg : & str ,
539+ ) -> DiagnosticBuilder < ' _ > {
540+ let mut result = self . struct_force_warn ( msg) ;
541+ result. set_span ( span) ;
542+ result
543+ }
544+
529545 /// Construct a builder at the `Allow` level at the given `span` and with the `msg`.
530546 pub fn struct_span_allow (
531547 & self ,
@@ -551,6 +567,8 @@ impl Handler {
551567 }
552568
553569 /// Construct a builder at the `Warning` level with the `msg`.
570+ ///
571+ /// The builder will be canceled if warnings cannot be emitted.
554572 pub fn struct_warn ( & self , msg : & str ) -> DiagnosticBuilder < ' _ > {
555573 let mut result = DiagnosticBuilder :: new ( self , Level :: Warning , msg) ;
556574 if !self . flags . can_emit_warnings {
@@ -559,6 +577,14 @@ impl Handler {
559577 result
560578 }
561579
580+ /// Construct a builder at the `Warning` level with the `msg`.
581+ ///
582+ /// This will "force" a warning meaning it will not be canceled even
583+ /// if warnings cannot be emitted.
584+ pub fn struct_force_warn ( & self , msg : & str ) -> DiagnosticBuilder < ' _ > {
585+ DiagnosticBuilder :: new ( self , Level :: Warning , msg)
586+ }
587+
562588 /// Construct a builder at the `Allow` level with the `msg`.
563589 pub fn struct_allow ( & self , msg : & str ) -> DiagnosticBuilder < ' _ > {
564590 DiagnosticBuilder :: new ( self , Level :: Allow , msg)
@@ -801,7 +827,10 @@ impl HandlerInner {
801827 self . future_breakage_diagnostics . push ( diagnostic. clone ( ) ) ;
802828 }
803829
804- if diagnostic. level == Warning && !self . flags . can_emit_warnings {
830+ if diagnostic. level == Warning
831+ && !self . flags . can_emit_warnings
832+ && !diagnostic. is_force_warn ( )
833+ {
805834 if diagnostic. has_future_breakage ( ) {
806835 ( * TRACK_DIAGNOSTICS ) ( diagnostic) ;
807836 }
@@ -873,7 +902,7 @@ impl HandlerInner {
873902
874903 match ( errors. len ( ) , warnings. len ( ) ) {
875904 ( 0 , 0 ) => return ,
876- ( 0 , _) => self . emit_diagnostic ( & Diagnostic :: new ( Level :: Warning , & warnings) ) ,
905+ ( 0 , _) => self . emitter . emit_diagnostic ( & Diagnostic :: new ( Level :: Warning , & warnings) ) ,
877906 ( _, 0 ) => {
878907 let _ = self . fatal ( & errors) ;
879908 }
0 commit comments