Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 5 additions & 204 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,6 @@ use crate::core::{
PatchLocation,
};
use crate::core::{EitherManifest, Package, SourceId, VirtualManifest};
use crate::diagnostics::DiagnosticStats;
use crate::diagnostics::rules::blanket_hint_mostly_unused;
use crate::diagnostics::rules::check_im_a_teapot;
use crate::diagnostics::rules::deferred_parse_diagnostics;
use crate::diagnostics::rules::implicit_minimum_version_req_pkg;
use crate::diagnostics::rules::implicit_minimum_version_req_ws;
use crate::diagnostics::rules::missing_lints_features;
use crate::diagnostics::rules::missing_lints_inheritance;
use crate::diagnostics::rules::non_kebab_case_bins;
use crate::diagnostics::rules::non_kebab_case_features;
use crate::diagnostics::rules::non_kebab_case_packages;
use crate::diagnostics::rules::non_snake_case_features;
use crate::diagnostics::rules::non_snake_case_packages;
use crate::diagnostics::rules::redundant_homepage;
use crate::diagnostics::rules::redundant_readme;
use crate::diagnostics::rules::text_direction_codepoint_in_comment;
use crate::diagnostics::rules::text_direction_codepoint_in_literal;
use crate::diagnostics::rules::unknown_lints;
use crate::diagnostics::rules::unused_build_dependencies_no_build_rs;
use crate::diagnostics::rules::unused_workspace_dependencies;
use crate::diagnostics::rules::unused_workspace_package_fields;
use crate::ops;
use crate::ops::lockfile::LOCKFILE_NAME;
use crate::sources::{CRATES_IO_INDEX, CRATES_IO_REGISTRY, PathSource, SourceConfigMap};
Expand All @@ -58,7 +37,6 @@ use crate::util::{

use cargo_util::paths;
use cargo_util::paths::normalize_path;
use cargo_util_schemas::manifest;
use cargo_util_schemas::manifest::RustVersion;
use cargo_util_schemas::manifest::{TomlDependency, TomlManifest, TomlProfiles};
use pathdiff::diff_paths;
Expand Down Expand Up @@ -632,6 +610,11 @@ impl<'gctx> Workspace<'gctx> {
Ok(combined)
}

/// Returns an iterator over all loaded manifests
pub fn loaded_maybe(&self) -> impl Iterator<Item = &MaybePackage> {
self.packages.packages.values()
}

/// Returns an iterator over all packages in this workspace
pub fn members(&self) -> impl Iterator<Item = &Package> {
let packages = &self.packages;
Expand Down Expand Up @@ -1291,188 +1274,6 @@ impl<'gctx> Workspace<'gctx> {
}
}

pub fn emit_parse_diagnostics(&self) -> CargoResult<()> {
let mut first_emitted_error = None;

if let Err(e) = self.emit_parse_ws_diagnostics() {
first_emitted_error = Some(e);
}

for (path, maybe_pkg) in &self.packages.packages {
if let MaybePackage::Package(pkg) = maybe_pkg {
if let Err(e) = self.emit_parse_pkg_diagnostics(pkg, &path)
&& first_emitted_error.is_none()
{
first_emitted_error = Some(e);
}
}
}

if let Some(error) = first_emitted_error {
Err(error)
} else {
Ok(())
}
}

pub fn emit_parse_pkg_diagnostics(&self, pkg: &Package, path: &Path) -> CargoResult<()> {
let mut stats = DiagnosticStats::new();

deferred_parse_diagnostics(pkg.into(), path, &mut stats, self.gctx)?;

let toml_lints = pkg
.manifest()
.normalized_toml()
.lints
.clone()
.map(|lints| lints.lints)
.unwrap_or(manifest::TomlLints::default());
let cargo_lints = toml_lints
.get("cargo")
.cloned()
.unwrap_or(manifest::TomlToolLints::default());

if self.gctx.cli_unstable().cargo_lints {
missing_lints_features(pkg.into(), &path, &cargo_lints, &mut stats, self.gctx)?;
unknown_lints(pkg.into(), &path, &cargo_lints, &mut stats, self.gctx)?;

check_im_a_teapot(pkg, &path, &cargo_lints, &mut stats, self.gctx)?;
implicit_minimum_version_req_pkg(pkg, &path, &cargo_lints, &mut stats, self.gctx)?;
non_kebab_case_packages(pkg, &path, &cargo_lints, &mut stats, self.gctx)?;
non_snake_case_packages(pkg, &path, &cargo_lints, &mut stats, self.gctx)?;
non_kebab_case_bins(self, pkg, &path, &cargo_lints, &mut stats, self.gctx)?;
non_kebab_case_features(pkg, &path, &cargo_lints, &mut stats, self.gctx)?;
non_snake_case_features(pkg, &path, &cargo_lints, &mut stats, self.gctx)?;
unused_build_dependencies_no_build_rs(pkg, &path, &cargo_lints, &mut stats, self.gctx)?;
redundant_readme(pkg, &path, &cargo_lints, &mut stats, self.gctx)?;
redundant_homepage(pkg, &path, &cargo_lints, &mut stats, self.gctx)?;
missing_lints_inheritance(self, pkg, &path, &cargo_lints, &mut stats, self.gctx)?;
text_direction_codepoint_in_comment(
pkg.into(),
&path,
&cargo_lints,
&mut stats,
self.gctx,
)?;
text_direction_codepoint_in_literal(
pkg.into(),
&path,
&cargo_lints,
&mut stats,
self.gctx,
)?;
}

stats.report_summary("parse", Some(&*pkg.name()), self.gctx)?;

Ok(())
}

pub fn emit_parse_ws_diagnostics(&self) -> CargoResult<()> {
let mut stats = DiagnosticStats::new();

deferred_parse_diagnostics(
(self, self.root_maybe()).into(),
self.root_manifest(),
&mut stats,
self.gctx,
)?;

let cargo_lints = match self.root_maybe() {
MaybePackage::Package(pkg) => {
let toml = pkg.manifest().normalized_toml();
if let Some(ws) = &toml.workspace {
ws.lints.as_ref()
} else {
toml.lints.as_ref().map(|l| &l.lints)
}
}
MaybePackage::Virtual(vm) => vm
.normalized_toml()
.workspace
.as_ref()
.unwrap()
.lints
.as_ref(),
}
.and_then(|t| t.get("cargo"))
.cloned()
.unwrap_or(manifest::TomlToolLints::default());

if self.gctx.cli_unstable().cargo_lints {
missing_lints_features(
(self, self.root_maybe()).into(),
self.root_manifest(),
&cargo_lints,
&mut stats,
self.gctx,
)?;
unknown_lints(
(self, self.root_maybe()).into(),
self.root_manifest(),
&cargo_lints,
&mut stats,
self.gctx,
)?;

unused_workspace_package_fields(
self,
self.root_maybe(),
self.root_manifest(),
&cargo_lints,
&mut stats,
self.gctx,
)?;
unused_workspace_dependencies(
self,
self.root_maybe(),
self.root_manifest(),
&cargo_lints,
&mut stats,
self.gctx,
)?;
implicit_minimum_version_req_ws(
self,
self.root_maybe(),
self.root_manifest(),
&cargo_lints,
&mut stats,
self.gctx,
)?;
text_direction_codepoint_in_comment(
(self, self.root_maybe()).into(),
self.root_manifest(),
&cargo_lints,
&mut stats,
self.gctx,
)?;
text_direction_codepoint_in_literal(
(self, self.root_maybe()).into(),
self.root_manifest(),
&cargo_lints,
&mut stats,
self.gctx,
)?;
}

// This is a short term hack to allow `blanket_hint_mostly_unused`
// to run without requiring `-Zcargo-lints`, which should hopefully
// improve the testing experience while we are collecting feedback
if self.gctx.cli_unstable().profile_hint_mostly_unused {
blanket_hint_mostly_unused(
self,
self.root_maybe(),
self.root_manifest(),
&cargo_lints,
&mut stats,
self.gctx,
)?;
}

stats.report_summary("parse", None, self.gctx)?;
Ok(())
}

pub fn set_target_dir(&mut self, target_dir: Filesystem) {
self.target_dir = Some(target_dir);
}
Expand Down
1 change: 1 addition & 0 deletions src/cargo/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::util::GlobalContext;
mod lint;
mod report;

pub mod passes;
pub mod rules;

pub use lint::{Lint, LintGroup, LintLevel, LintLevelSource};
Expand Down
Loading
Loading