diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index a0bd9367d..f23ba5d2c 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -1269,7 +1269,6 @@ impl<'gctx> Workspace<'gctx> { } pub fn emit_pkg_lints(&self, pkg: &Package, path: &Path) -> CargoResult<()> { - let mut error_count = 0; let toml_lints = pkg .manifest() .normalized_toml() @@ -1287,6 +1286,8 @@ impl<'gctx> Workspace<'gctx> { let ws_document = self.root_maybe().document(); if self.gctx.cli_unstable().cargo_lints { + let mut verify_error_count = 0; + analyze_cargo_lints_table( pkg, &path, @@ -1294,24 +1295,33 @@ impl<'gctx> Workspace<'gctx> { ws_contents, ws_document, self.root_manifest(), + &mut verify_error_count, self.gctx, )?; - check_im_a_teapot(pkg, &path, &cargo_lints, &mut error_count, self.gctx)?; + + if verify_error_count > 0 { + let plural = if verify_error_count == 1 { "" } else { "s" }; + bail!("encountered {verify_error_count} error{plural} while verifying lints") + } + + let mut run_error_count = 0; + + check_im_a_teapot(pkg, &path, &cargo_lints, &mut run_error_count, self.gctx)?; implicit_minimum_version_req( pkg.into(), &path, &cargo_lints, - &mut error_count, + &mut run_error_count, self.gctx, )?; + + if run_error_count > 0 { + let plural = if run_error_count == 1 { "" } else { "s" }; + bail!("encountered {run_error_count} error{plural} while running lints") + } } - if error_count > 0 { - let plural = if error_count == 1 { "" } else { "s" }; - bail!("encountered {error_count} error{plural} while running lints") - } else { - Ok(()) - } + Ok(()) } pub fn emit_ws_lints(&self) -> CargoResult<()> { diff --git a/src/cargo/util/lints/mod.rs b/src/cargo/util/lints/mod.rs index 14a1746e4..8abc9f443 100644 --- a/src/cargo/util/lints/mod.rs +++ b/src/cargo/util/lints/mod.rs @@ -59,9 +59,9 @@ pub fn analyze_cargo_lints_table( ws_contents: &str, ws_document: &toml::Spanned>, ws_path: &Path, + error_count: &mut usize, gctx: &GlobalContext, ) -> CargoResult<()> { - let mut error_count = 0; let manifest = pkg.manifest(); let manifest_path = rel_cwd_manifest_path(manifest_path, gctx); let ws_path = rel_cwd_manifest_path(ws_path, gctx); @@ -97,7 +97,7 @@ pub fn analyze_cargo_lints_table( ws_contents, ws_document, &ws_path, - &mut error_count, + error_count, gctx, )?; } @@ -111,17 +111,11 @@ pub fn analyze_cargo_lints_table( ws_contents, ws_document, &ws_path, - &mut error_count, + error_count, gctx, )?; - if error_count > 0 { - Err(anyhow::anyhow!( - "encountered {error_count} errors(s) while verifying lints", - )) - } else { - Ok(()) - } + Ok(()) } fn find_lint_or_group<'a>( diff --git a/tests/testsuite/lints/inherited/stderr.term.svg b/tests/testsuite/lints/inherited/stderr.term.svg index 9fd203d10..17de625f8 100644 --- a/tests/testsuite/lints/inherited/stderr.term.svg +++ b/tests/testsuite/lints/inherited/stderr.term.svg @@ -1,7 +1,7 @@