@@ -140,6 +140,7 @@ use crate::core::compiler::future_incompat::{
140
140
} ;
141
141
use crate :: core:: resolver:: ResolveBehavior ;
142
142
use crate :: core:: { PackageId , Shell , TargetKind } ;
143
+ use crate :: util:: context:: WarningHandling ;
143
144
use crate :: util:: diagnostic_server:: { self , DiagnosticPrinter } ;
144
145
use crate :: util:: errors:: AlreadyPrintedError ;
145
146
use crate :: util:: machine_message:: { self , Message as _} ;
@@ -601,6 +602,7 @@ impl<'gctx> DrainState<'gctx> {
601
602
plan : & mut BuildPlan ,
602
603
event : Message ,
603
604
) -> Result < ( ) , ErrorToHandle > {
605
+ let warning_handling = build_runner. bcx . gctx . warning_handling ( ) ?;
604
606
match event {
605
607
Message :: Run ( id, cmd) => {
606
608
build_runner
@@ -638,7 +640,9 @@ impl<'gctx> DrainState<'gctx> {
638
640
}
639
641
}
640
642
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
+ }
642
646
self . bump_warning_count ( id, true , false ) ;
643
647
}
644
648
Message :: WarningCount {
@@ -652,13 +656,14 @@ impl<'gctx> DrainState<'gctx> {
652
656
self . print . print ( & msg) ?;
653
657
}
654
658
Message :: Finish ( id, artifact, result) => {
659
+ let mut warning_count = 0 ;
655
660
let unit = match artifact {
656
661
// If `id` has completely finished we remove it
657
662
// from the `active` map ...
658
663
Artifact :: All => {
659
664
trace ! ( "end: {:?}" , id) ;
660
665
self . finished += 1 ;
661
- self . report_warning_count (
666
+ warning_count = self . report_warning_count (
662
667
build_runner. bcx . gctx ,
663
668
id,
664
669
& build_runner. bcx . rustc ( ) . workspace_wrapper ,
@@ -693,6 +698,12 @@ impl<'gctx> DrainState<'gctx> {
693
698
} ) ;
694
699
}
695
700
}
701
+ if let Err ( error) = warning_handling. error_for_warnings ( warning_count) {
702
+ return Err ( ErrorToHandle {
703
+ error,
704
+ print_always : true ,
705
+ } ) ;
706
+ }
696
707
}
697
708
Message :: FutureIncompatReport ( id, items) => {
698
709
let package_id = self . active [ & id] . pkg . package_id ( ) ;
@@ -963,32 +974,32 @@ impl<'gctx> DrainState<'gctx> {
963
974
}
964
975
965
976
fn emit_warnings (
966
- & mut self ,
977
+ & self ,
967
978
msg : Option < & str > ,
968
979
unit : & Unit ,
969
- build_runner : & mut BuildRunner < ' _ , ' _ > ,
980
+ build_runner : & BuildRunner < ' _ , ' _ > ,
970
981
) -> CargoResult < ( ) > {
971
982
let outputs = build_runner. build_script_outputs . lock ( ) . unwrap ( ) ;
972
983
let Some ( metadata) = build_runner. find_build_script_metadata ( unit) else {
973
984
return Ok ( ( ) ) ;
974
985
} ;
975
- let bcx = & mut build_runner. bcx ;
986
+ let gctx = build_runner. bcx . gctx ;
976
987
if let Some ( output) = outputs. get ( metadata) {
977
988
if !output. warnings . is_empty ( ) {
978
989
if let Some ( msg) = msg {
979
- writeln ! ( bcx . gctx. shell( ) . err( ) , "{}\n " , msg) ?;
990
+ writeln ! ( gctx. shell( ) . err( ) , "{}\n " , msg) ?;
980
991
}
981
992
982
993
for warning in output. warnings . iter ( ) {
983
994
let warning_with_package =
984
995
format ! ( "{}@{}: {}" , unit. pkg. name( ) , unit. pkg. version( ) , warning) ;
985
996
986
- bcx . gctx . shell ( ) . warn ( warning_with_package) ?;
997
+ gctx. shell ( ) . warn ( warning_with_package) ?;
987
998
}
988
999
989
1000
if msg. is_some ( ) {
990
1001
// Output an empty line.
991
- writeln ! ( bcx . gctx. shell( ) . err( ) ) ?;
1002
+ writeln ! ( gctx. shell( ) . err( ) ) ?;
992
1003
}
993
1004
}
994
1005
}
@@ -1022,13 +1033,13 @@ impl<'gctx> DrainState<'gctx> {
1022
1033
gctx : & GlobalContext ,
1023
1034
id : JobId ,
1024
1035
rustc_workspace_wrapper : & Option < PathBuf > ,
1025
- ) {
1036
+ ) -> usize {
1026
1037
let count = match self . warning_count . remove ( & id) {
1027
1038
// An error could add an entry for a `Unit`
1028
1039
// with 0 warnings but having fixable
1029
1040
// warnings be disallowed
1030
1041
Some ( count) if count. total > 0 => count,
1031
- None | Some ( _) => return ,
1042
+ None | Some ( _) => return 0 ,
1032
1043
} ;
1033
1044
let unit = & self . active [ & id] ;
1034
1045
let mut message = descriptive_pkg_name ( & unit. pkg . name ( ) , & unit. target , & unit. mode ) ;
@@ -1089,6 +1100,7 @@ impl<'gctx> DrainState<'gctx> {
1089
1100
// Errors are ignored here because it is tricky to handle them
1090
1101
// correctly, and they aren't important.
1091
1102
let _ = gctx. shell ( ) . warn ( message) ;
1103
+ count. total
1092
1104
}
1093
1105
1094
1106
fn finish (
0 commit comments