@@ -1200,10 +1200,17 @@ impl<'gctx> Workspace<'gctx> {
1200
1200
1201
1201
pub fn emit_warnings ( & self ) -> CargoResult < ( ) > {
1202
1202
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 = Some ( e) ;
1207
+ }
1208
+ }
1209
+
1203
1210
for ( path, maybe_pkg) in & self . packages . packages {
1204
1211
if let MaybePackage :: Package ( pkg) = maybe_pkg {
1205
1212
if self . gctx . cli_unstable ( ) . cargo_lints {
1206
- if let Err ( e) = self . emit_lints ( pkg, & path)
1213
+ if let Err ( e) = self . emit_pkg_lints ( pkg, & path)
1207
1214
&& first_emitted_error. is_none ( )
1208
1215
{
1209
1216
first_emitted_error = Some ( e) ;
@@ -1242,7 +1249,7 @@ impl<'gctx> Workspace<'gctx> {
1242
1249
}
1243
1250
}
1244
1251
1245
- pub fn emit_lints ( & self , pkg : & Package , path : & Path ) -> CargoResult < ( ) > {
1252
+ pub fn emit_pkg_lints ( & self , pkg : & Package , path : & Path ) -> CargoResult < ( ) > {
1246
1253
let mut error_count = 0 ;
1247
1254
let toml_lints = pkg
1248
1255
. manifest ( )
@@ -1270,6 +1277,41 @@ impl<'gctx> Workspace<'gctx> {
1270
1277
self . gctx ,
1271
1278
) ?;
1272
1279
check_im_a_teapot ( pkg, & path, & cargo_lints, & mut error_count, self . gctx ) ?;
1280
+
1281
+ if error_count > 0 {
1282
+ Err ( crate :: util:: errors:: AlreadyPrintedError :: new ( anyhow ! (
1283
+ "encountered {error_count} errors(s) while running lints"
1284
+ ) )
1285
+ . into ( ) )
1286
+ } else {
1287
+ Ok ( ( ) )
1288
+ }
1289
+ }
1290
+
1291
+ pub fn emit_ws_lints ( & self ) -> CargoResult < ( ) > {
1292
+ let error_count = 0 ;
1293
+
1294
+ let _cargo_lints = match self . root_maybe ( ) {
1295
+ MaybePackage :: Package ( pkg) => {
1296
+ let toml = pkg. manifest ( ) . normalized_toml ( ) ;
1297
+ if let Some ( ws) = & toml. workspace {
1298
+ ws. lints . as_ref ( )
1299
+ } else {
1300
+ toml. lints . as_ref ( ) . map ( |l| & l. lints )
1301
+ }
1302
+ }
1303
+ MaybePackage :: Virtual ( vm) => vm
1304
+ . normalized_toml ( )
1305
+ . workspace
1306
+ . as_ref ( )
1307
+ . unwrap ( )
1308
+ . lints
1309
+ . as_ref ( ) ,
1310
+ }
1311
+ . and_then ( |t| t. get ( "cargo" ) )
1312
+ . cloned ( )
1313
+ . unwrap_or ( manifest:: TomlToolLints :: default ( ) ) ;
1314
+
1273
1315
if error_count > 0 {
1274
1316
Err ( crate :: util:: errors:: AlreadyPrintedError :: new ( anyhow ! (
1275
1317
"encountered {error_count} errors(s) while running lints"
0 commit comments