Skip to content

Commit 8ff9d67

Browse files
authored
fix(lints): handle lints separately at ws pkg level (#16367)
### What does this PR try to resolve? `unknown_lints` is special that it analyzes only at package level, and warn if your lint is inherited from workspace. According to the discussion in <#16321 (comment)>, we should lint against workspace always plus selected packages. This additionally handles unstable lint gating. ### How to test and review this PR? Two new tests are added to reflect that workspace lints were not analyzed if not inheriting.
2 parents 14116aa + e5db075 commit 8ff9d67

File tree

5 files changed

+234
-180
lines changed

5 files changed

+234
-180
lines changed

src/cargo/core/workspace.rs

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,6 @@ impl<'gctx> Workspace<'gctx> {
12691269
}
12701270

12711271
pub fn emit_pkg_lints(&self, pkg: &Package, path: &Path) -> CargoResult<()> {
1272-
let mut error_count = 0;
12731272
let toml_lints = pkg
12741273
.manifest()
12751274
.normalized_toml()
@@ -1282,40 +1281,44 @@ impl<'gctx> Workspace<'gctx> {
12821281
.cloned()
12831282
.unwrap_or(manifest::TomlToolLints::default());
12841283

1285-
let ws_contents = self.root_maybe().contents();
1286-
1287-
let ws_document = self.root_maybe().document();
1288-
12891284
if self.gctx.cli_unstable().cargo_lints {
1285+
let mut verify_error_count = 0;
1286+
12901287
analyze_cargo_lints_table(
1291-
pkg,
1288+
pkg.into(),
12921289
&path,
12931290
&cargo_lints,
1294-
ws_contents,
1295-
ws_document,
1296-
self.root_manifest(),
1291+
&mut verify_error_count,
12971292
self.gctx,
12981293
)?;
1299-
check_im_a_teapot(pkg, &path, &cargo_lints, &mut error_count, self.gctx)?;
1294+
1295+
if verify_error_count > 0 {
1296+
let plural = if verify_error_count == 1 { "" } else { "s" };
1297+
bail!("encountered {verify_error_count} error{plural} while verifying lints")
1298+
}
1299+
1300+
let mut run_error_count = 0;
1301+
1302+
check_im_a_teapot(pkg, &path, &cargo_lints, &mut run_error_count, self.gctx)?;
13001303
implicit_minimum_version_req(
13011304
pkg.into(),
13021305
&path,
13031306
&cargo_lints,
1304-
&mut error_count,
1307+
&mut run_error_count,
13051308
self.gctx,
13061309
)?;
1307-
}
13081310

1309-
if error_count > 0 {
1310-
let plural = if error_count == 1 { "" } else { "s" };
1311-
bail!("encountered {error_count} error{plural} while running lints")
1312-
} else {
1313-
Ok(())
1311+
if run_error_count > 0 {
1312+
let plural = if run_error_count == 1 { "" } else { "s" };
1313+
bail!("encountered {run_error_count} error{plural} while running lints")
1314+
}
13141315
}
1316+
1317+
Ok(())
13151318
}
13161319

13171320
pub fn emit_ws_lints(&self) -> CargoResult<()> {
1318-
let mut error_count = 0;
1321+
let mut run_error_count = 0;
13191322

13201323
let cargo_lints = match self.root_maybe() {
13211324
MaybePackage::Package(pkg) => {
@@ -1339,12 +1342,26 @@ impl<'gctx> Workspace<'gctx> {
13391342
.unwrap_or(manifest::TomlToolLints::default());
13401343

13411344
if self.gctx.cli_unstable().cargo_lints {
1342-
// Calls to lint functions go in here
1345+
let mut verify_error_count = 0;
1346+
1347+
analyze_cargo_lints_table(
1348+
self.root_maybe().into(),
1349+
self.root_manifest(),
1350+
&cargo_lints,
1351+
&mut verify_error_count,
1352+
self.gctx,
1353+
)?;
1354+
1355+
if verify_error_count > 0 {
1356+
let plural = if verify_error_count == 1 { "" } else { "s" };
1357+
bail!("encountered {verify_error_count} error{plural} while verifying lints")
1358+
}
1359+
13431360
implicit_minimum_version_req(
13441361
self.root_maybe().into(),
13451362
self.root_manifest(),
13461363
&cargo_lints,
1347-
&mut error_count,
1364+
&mut run_error_count,
13481365
self.gctx,
13491366
)?;
13501367
}
@@ -1357,14 +1374,14 @@ impl<'gctx> Workspace<'gctx> {
13571374
self.root_maybe(),
13581375
self.root_manifest(),
13591376
&cargo_lints,
1360-
&mut error_count,
1377+
&mut run_error_count,
13611378
self.gctx,
13621379
)?;
13631380
}
13641381

1365-
if error_count > 0 {
1366-
let plural = if error_count == 1 { "" } else { "s" };
1367-
bail!("encountered {error_count} error{plural} while running lints")
1382+
if run_error_count > 0 {
1383+
let plural = if run_error_count == 1 { "" } else { "s" };
1384+
bail!("encountered {run_error_count} error{plural} while running lints")
13681385
} else {
13691386
Ok(())
13701387
}

0 commit comments

Comments
 (0)