@@ -1200,10 +1200,19 @@ impl<'gctx> Workspace<'gctx> {
12001200
12011201 pub fn emit_warnings ( & self ) -> CargoResult < ( ) > {
12021202 let mut first_emitted_error = None ;
1203+
1204+ if self . gctx . cli_unstable ( ) . cargo_lints {
1205+ if let Err ( e) = self . emit_ws_lints ( )
1206+ && first_emitted_error. is_none ( )
1207+ {
1208+ first_emitted_error = Some ( e) ;
1209+ }
1210+ }
1211+
12031212 for ( path, maybe_pkg) in & self . packages . packages {
12041213 if let MaybePackage :: Package ( pkg) = maybe_pkg {
12051214 if self . gctx . cli_unstable ( ) . cargo_lints {
1206- if let Err ( e) = self . emit_lints ( pkg, & path)
1215+ if let Err ( e) = self . emit_pkg_lints ( pkg, & path)
12071216 && first_emitted_error. is_none ( )
12081217 {
12091218 first_emitted_error = Some ( e) ;
@@ -1242,7 +1251,7 @@ impl<'gctx> Workspace<'gctx> {
12421251 }
12431252 }
12441253
1245- pub fn emit_lints ( & self , pkg : & Package , path : & Path ) -> CargoResult < ( ) > {
1254+ pub fn emit_pkg_lints ( & self , pkg : & Package , path : & Path ) -> CargoResult < ( ) > {
12461255 let mut error_count = 0 ;
12471256 let toml_lints = pkg
12481257 . manifest ( )
@@ -1270,6 +1279,41 @@ impl<'gctx> Workspace<'gctx> {
12701279 self . gctx ,
12711280 ) ?;
12721281 check_im_a_teapot ( pkg, & path, & cargo_lints, & mut error_count, self . gctx ) ?;
1282+
1283+ if error_count > 0 {
1284+ Err ( crate :: util:: errors:: AlreadyPrintedError :: new ( anyhow ! (
1285+ "encountered {error_count} errors(s) while running lints"
1286+ ) )
1287+ . into ( ) )
1288+ } else {
1289+ Ok ( ( ) )
1290+ }
1291+ }
1292+
1293+ pub fn emit_ws_lints ( & self ) -> CargoResult < ( ) > {
1294+ let error_count = 0 ;
1295+
1296+ let _cargo_lints = match self . root_maybe ( ) {
1297+ MaybePackage :: Package ( pkg) => {
1298+ let toml = pkg. manifest ( ) . normalized_toml ( ) ;
1299+ if let Some ( ws) = & toml. workspace {
1300+ ws. lints . as_ref ( )
1301+ } else {
1302+ toml. lints . as_ref ( ) . map ( |l| & l. lints )
1303+ }
1304+ }
1305+ MaybePackage :: Virtual ( vm) => vm
1306+ . normalized_toml ( )
1307+ . workspace
1308+ . as_ref ( )
1309+ . unwrap ( )
1310+ . lints
1311+ . as_ref ( ) ,
1312+ }
1313+ . and_then ( |t| t. get ( "cargo" ) )
1314+ . cloned ( )
1315+ . unwrap_or ( manifest:: TomlToolLints :: default ( ) ) ;
1316+
12731317 if error_count > 0 {
12741318 Err ( crate :: util:: errors:: AlreadyPrintedError :: new ( anyhow ! (
12751319 "encountered {error_count} errors(s) while running lints"
0 commit comments