@@ -140,6 +140,7 @@ use crate::core::compiler::future_incompat::{
140140} ;
141141use crate :: core:: resolver:: ResolveBehavior ;
142142use crate :: core:: { PackageId , Shell , TargetKind } ;
143+ use crate :: util:: context:: WarningHandling ;
143144use crate :: util:: diagnostic_server:: { self , DiagnosticPrinter } ;
144145use crate :: util:: errors:: AlreadyPrintedError ;
145146use crate :: util:: machine_message:: { self , Message as _} ;
@@ -601,6 +602,7 @@ impl<'gctx> DrainState<'gctx> {
601602 plan : & mut BuildPlan ,
602603 event : Message ,
603604 ) -> Result < ( ) , ErrorToHandle > {
605+ let warning_handling = build_runner. bcx . gctx . warning_handling ( ) ?;
604606 match event {
605607 Message :: Run ( id, cmd) => {
606608 build_runner
@@ -638,7 +640,9 @@ impl<'gctx> DrainState<'gctx> {
638640 }
639641 }
640642 Message :: Warning { id, warning } => {
641- build_runner. bcx . gctx . shell ( ) . warn ( warning) ?;
643+ if warning_handling != WarningHandling :: Allow {
644+ build_runner. bcx . gctx . shell ( ) . warn ( warning) ?;
645+ }
642646 self . bump_warning_count ( id, true , false ) ;
643647 }
644648 Message :: WarningCount {
@@ -652,13 +656,14 @@ impl<'gctx> DrainState<'gctx> {
652656 self . print . print ( & msg) ?;
653657 }
654658 Message :: Finish ( id, artifact, result) => {
659+ let mut warning_count = 0 ;
655660 let unit = match artifact {
656661 // If `id` has completely finished we remove it
657662 // from the `active` map ...
658663 Artifact :: All => {
659664 trace ! ( "end: {:?}" , id) ;
660665 self . finished += 1 ;
661- self . report_warning_count (
666+ warning_count = self . report_warning_count (
662667 build_runner. bcx . gctx ,
663668 id,
664669 & build_runner. bcx . rustc ( ) . workspace_wrapper ,
@@ -693,6 +698,12 @@ impl<'gctx> DrainState<'gctx> {
693698 } ) ;
694699 }
695700 }
701+ if let Err ( error) = warning_handling. error_for_warnings ( warning_count) {
702+ return Err ( ErrorToHandle {
703+ error,
704+ print_always : true ,
705+ } ) ;
706+ }
696707 }
697708 Message :: FutureIncompatReport ( id, items) => {
698709 let package_id = self . active [ & id] . pkg . package_id ( ) ;
@@ -963,32 +974,32 @@ impl<'gctx> DrainState<'gctx> {
963974 }
964975
965976 fn emit_warnings (
966- & mut self ,
977+ & self ,
967978 msg : Option < & str > ,
968979 unit : & Unit ,
969- build_runner : & mut BuildRunner < ' _ , ' _ > ,
980+ build_runner : & BuildRunner < ' _ , ' _ > ,
970981 ) -> CargoResult < ( ) > {
971982 let outputs = build_runner. build_script_outputs . lock ( ) . unwrap ( ) ;
972983 let Some ( metadata) = build_runner. find_build_script_metadata ( unit) else {
973984 return Ok ( ( ) ) ;
974985 } ;
975- let bcx = & mut build_runner. bcx ;
986+ let gctx = build_runner. bcx . gctx ;
976987 if let Some ( output) = outputs. get ( metadata) {
977988 if !output. warnings . is_empty ( ) {
978989 if let Some ( msg) = msg {
979- writeln ! ( bcx . gctx. shell( ) . err( ) , "{}\n " , msg) ?;
990+ writeln ! ( gctx. shell( ) . err( ) , "{}\n " , msg) ?;
980991 }
981992
982993 for warning in output. warnings . iter ( ) {
983994 let warning_with_package =
984995 format ! ( "{}@{}: {}" , unit. pkg. name( ) , unit. pkg. version( ) , warning) ;
985996
986- bcx . gctx . shell ( ) . warn ( warning_with_package) ?;
997+ gctx. shell ( ) . warn ( warning_with_package) ?;
987998 }
988999
9891000 if msg. is_some ( ) {
9901001 // Output an empty line.
991- writeln ! ( bcx . gctx. shell( ) . err( ) ) ?;
1002+ writeln ! ( gctx. shell( ) . err( ) ) ?;
9921003 }
9931004 }
9941005 }
@@ -1022,13 +1033,13 @@ impl<'gctx> DrainState<'gctx> {
10221033 gctx : & GlobalContext ,
10231034 id : JobId ,
10241035 rustc_workspace_wrapper : & Option < PathBuf > ,
1025- ) {
1036+ ) -> usize {
10261037 let count = match self . warning_count . remove ( & id) {
10271038 // An error could add an entry for a `Unit`
10281039 // with 0 warnings but having fixable
10291040 // warnings be disallowed
10301041 Some ( count) if count. total > 0 => count,
1031- None | Some ( _) => return ,
1042+ None | Some ( _) => return 0 ,
10321043 } ;
10331044 let unit = & self . active [ & id] ;
10341045 let mut message = descriptive_pkg_name ( & unit. pkg . name ( ) , & unit. target , & unit. mode ) ;
@@ -1089,6 +1100,7 @@ impl<'gctx> DrainState<'gctx> {
10891100 // Errors are ignored here because it is tricky to handle them
10901101 // correctly, and they aren't important.
10911102 let _ = gctx. shell ( ) . warn ( message) ;
1103+ count. total
10921104 }
10931105
10941106 fn finish (
0 commit comments