cargo/diagnostics/rules/
deferred_parse_diagnostics.rs1use std::path::Path;
2
3use tracing::instrument;
4
5use crate::CargoResult;
6use crate::GlobalContext;
7use crate::core::MaybePackage;
8use crate::diagnostics::DiagnosticStats;
9use crate::diagnostics::ManifestFor;
10use crate::diagnostics::rel_cwd_manifest_path;
11
12#[instrument(skip_all)]
13pub(crate) fn diagnose_manifest(
14 manifest: ManifestFor<'_>,
15 manifest_path: &Path,
16 stats: &mut DiagnosticStats,
17 gctx: &GlobalContext,
18) -> CargoResult<()> {
19 let warnings = match &manifest {
20 ManifestFor::Package(pkg) => pkg.manifest().warnings().warnings(),
21 ManifestFor::Workspace {
22 maybe_pkg: MaybePackage::Virtual(vm),
23 ..
24 } => vm.warnings().warnings(),
25 ManifestFor::Workspace {
26 maybe_pkg: MaybePackage::Package(_),
27 ..
28 } => {
29 return Ok(());
31 }
32 };
33
34 let manifest_path = rel_cwd_manifest_path(manifest_path, gctx);
35 for warning in warnings {
36 let msg = format!("{manifest_path}: {}", warning.message);
37 if warning.is_critical {
38 stats.record_error();
39 gctx.shell().error(msg)?
40 } else {
41 stats.record_warning();
42 gctx.shell().warn(msg)?
43 }
44 }
45
46 Ok(())
47}