mirror of
https://github.com/rust-lang/cargo.git
synced 2026-04-11 20:44:19 +00:00
refactor(lint): bail outside lint logic
This commit is contained in:
@@ -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<()> {
|
||||
|
||||
@@ -59,9 +59,9 @@ pub fn analyze_cargo_lints_table(
|
||||
ws_contents: &str,
|
||||
ws_document: &toml::Spanned<toml::de::DeTable<'static>>,
|
||||
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>(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<svg width="818px" height="272px" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.fg { fill: #AAAAAA }
|
||||
.bg { background: #000000 }
|
||||
.bg { fill: #000000 }
|
||||
.fg-bright-blue { fill: #5555FF }
|
||||
.fg-bright-green { fill: #55FF55 }
|
||||
.fg-bright-red { fill: #FF5555 }
|
||||
@@ -44,7 +44,7 @@
|
||||
</tspan>
|
||||
<tspan x="10px" y="226px"><tspan> </tspan><tspan class="fg-bright-blue bold">|</tspan><tspan> </tspan><tspan class="fg-bright-blue bold">----------------</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="244px"><tspan class="fg-bright-red bold">error</tspan><tspan>: encountered 1 errors(s) while verifying lints</tspan>
|
||||
<tspan x="10px" y="244px"><tspan class="fg-bright-red bold">error</tspan><tspan>: encountered 1 error while verifying lints</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="262px">
|
||||
</tspan>
|
||||
|
||||
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
@@ -257,7 +257,7 @@ im_a_teapot = "warn"
|
||||
| ^^^^^^^^^^^ this is behind `test-dummy-unstable`, which is not enabled
|
||||
|
|
||||
= [HELP] consider adding `cargo-features = ["test-dummy-unstable"]` to the top of the manifest
|
||||
[ERROR] encountered 1 errors(s) while verifying lints
|
||||
[ERROR] encountered 1 error while verifying lints
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
@@ -321,7 +321,7 @@ workspace = true
|
||||
|
|
||||
9 | workspace = true
|
||||
| ----------------
|
||||
[ERROR] encountered 2 errors(s) while verifying lints
|
||||
[ERROR] encountered 2 errors while verifying lints
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
|
||||
Reference in New Issue
Block a user