Skip to main content

cargo/diagnostics/rules/
deferred_parse_diagnostics.rs

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