diff --git a/Cargo.lock b/Cargo.lock index d06d4e89b..e5828e878 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -386,7 +386,6 @@ dependencies = [ "dylint_internal", "env_logger", "glob", - "home", "log", "once_cell", "predicates", @@ -908,7 +907,6 @@ dependencies = [ "glob", "heck", "hex", - "home", "if_chain", "is-terminal", "log", @@ -969,6 +967,7 @@ dependencies = [ "once_cell", "regex", "rust-embed", + "rustversion", "semver", "serde", "thiserror 2.0.9", diff --git a/Cargo.toml b/Cargo.toml index 5d8ca57da..837b74a1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ git2 = "0.18" glob = "0.3" heck = "0.5" hex = "0.4" -home = "0.5" +home = "=0.5.9" if_chain = "1.0" is-terminal = "0.4" log = "0.4" @@ -45,6 +45,7 @@ predicates = "3.1" regex = "1.11" rewriter = "0.1" rust-embed = "8.5" +rustversion = "1.0" semver = "1.0" serde = "1.0" serde-untagged = "0.1" diff --git a/cargo-dylint/Cargo.toml b/cargo-dylint/Cargo.toml index 5145812f9..7d1216b6b 100644 --- a/cargo-dylint/Cargo.toml +++ b/cargo-dylint/Cargo.toml @@ -26,7 +26,6 @@ assert_cmd = { workspace = true } cargo_metadata = { workspace = true } ctor = { workspace = true } glob = { workspace = true } -home = { workspace = true } log = { workspace = true } once_cell = { workspace = true } predicates = { workspace = true } diff --git a/cargo-dylint/tests/ci.rs b/cargo-dylint/tests/ci.rs index 2ccac6531..53d07d297 100644 --- a/cargo-dylint/tests/ci.rs +++ b/cargo-dylint/tests/ci.rs @@ -3,10 +3,10 @@ use anyhow::Result; use assert_cmd::Command; use cargo_metadata::{Dependency, Metadata, MetadataCommand}; -use dylint_internal::{cargo::current_metadata, env, examples}; +use dylint_internal::{cargo::current_metadata, env, examples, home}; use once_cell::sync::Lazy; use regex::Regex; -use semver::Version; +use semver::{Op, Version}; use similar_asserts::SimpleDiff; use std::{ env::{set_current_dir, set_var, var}, @@ -97,7 +97,7 @@ fn versions_are_exact_and_match() { } #[test] -fn requirements_do_not_include_patch_versions() { +fn patch_version_requirements_are_exact() { let metadata = ["driver", "utils/linting"].map(|path| { MetadataCommand::new() .current_dir(path) @@ -109,14 +109,11 @@ fn requirements_do_not_include_patch_versions() { for metadata in std::iter::once(&*METADATA).chain(metadata.iter()) { for package in &metadata.packages { for Dependency { name: dep, req, .. } in &package.dependencies { - if dep.starts_with("dylint") { - continue; - } assert!( req.comparators .iter() - .all(|comparator| comparator.patch.is_none()), - "`{}` requirement on `{dep}` includes patch version: {req}", + .all(|comparator| comparator.op == Op::Exact || comparator.patch.is_none()), + "`{}` requirement on `{dep}` includes patch version and is not exact: {req}", package.name ); } diff --git a/cargo-dylint/tests/supply_chain/aarch64-apple-darwin.json b/cargo-dylint/tests/supply_chain/aarch64-apple-darwin.json index dbd9f6f9e..f9bb5df8f 100644 --- a/cargo-dylint/tests/supply_chain/aarch64-apple-darwin.json +++ b/cargo-dylint/tests/supply_chain/aarch64-apple-darwin.json @@ -1756,6 +1756,14 @@ "name": "Dan Gohman" } ], + "rustversion": [ + { + "id": 3618, + "kind": "user", + "login": "dtolnay", + "name": "David Tolnay" + } + ], "ryu": [ { "id": 3618, diff --git a/cargo-dylint/tests/supply_chain/x86_64-apple-darwin.json b/cargo-dylint/tests/supply_chain/x86_64-apple-darwin.json index dbd9f6f9e..f9bb5df8f 100644 --- a/cargo-dylint/tests/supply_chain/x86_64-apple-darwin.json +++ b/cargo-dylint/tests/supply_chain/x86_64-apple-darwin.json @@ -1756,6 +1756,14 @@ "name": "Dan Gohman" } ], + "rustversion": [ + { + "id": 3618, + "kind": "user", + "login": "dtolnay", + "name": "David Tolnay" + } + ], "ryu": [ { "id": 3618, diff --git a/cargo-dylint/tests/supply_chain/x86_64-unknown-linux-gnu.json b/cargo-dylint/tests/supply_chain/x86_64-unknown-linux-gnu.json index b48dd0716..284663425 100644 --- a/cargo-dylint/tests/supply_chain/x86_64-unknown-linux-gnu.json +++ b/cargo-dylint/tests/supply_chain/x86_64-unknown-linux-gnu.json @@ -1726,6 +1726,14 @@ "name": "Dan Gohman" } ], + "rustversion": [ + { + "id": 3618, + "kind": "user", + "login": "dtolnay", + "name": "David Tolnay" + } + ], "ryu": [ { "id": 3618, diff --git a/dylint/Cargo.toml b/dylint/Cargo.toml index 2bb14f7b8..f884d07ee 100644 --- a/dylint/Cargo.toml +++ b/dylint/Cargo.toml @@ -23,7 +23,6 @@ fs_extra = { workspace = true, optional = true } glob = { workspace = true, optional = true } heck = { workspace = true, optional = true } hex = { workspace = true, optional = true } -home = { workspace = true, optional = true } if_chain = { workspace = true, optional = true } is-terminal = { workspace = true } log = { workspace = true } @@ -72,10 +71,10 @@ __cargo_cli = [ "cargo-util", "cargo-util-schemas", "dunce", + "dylint_internal/home", "fs_extra", "glob", "hex", - "home", "if_chain", "serde-untagged", "toml", diff --git a/dylint/src/library_packages/cargo_cli/mod.rs b/dylint/src/library_packages/cargo_cli/mod.rs index a62fa8575..3d97a3e9a 100644 --- a/dylint/src/library_packages/cargo_cli/mod.rs +++ b/dylint/src/library_packages/cargo_cli/mod.rs @@ -19,8 +19,7 @@ use crate::opts; use anyhow::{anyhow, bail, ensure, Context, Result}; use cargo_metadata::{Metadata, MetadataCommand}; use cargo_util_schemas::manifest::TomlDetailedDependency; -use dylint_internal::{packaging::isolate, CommandExt}; -use home::cargo_home; +use dylint_internal::{home::cargo_home, packaging::isolate, CommandExt}; use semver::Version; use serde::Serialize; use std::{ diff --git a/examples/experimental/derive_opportunity/Cargo.lock b/examples/experimental/derive_opportunity/Cargo.lock index d30f2e14c..2ceae1140 100644 --- a/examples/experimental/derive_opportunity/Cargo.lock +++ b/examples/experimental/derive_opportunity/Cargo.lock @@ -337,6 +337,7 @@ dependencies = [ "once_cell", "regex", "rust-embed", + "rustversion", "serde", "thiserror 2.0.7", "toml", diff --git a/examples/experimental/missing_doc_comment_openai/Cargo.lock b/examples/experimental/missing_doc_comment_openai/Cargo.lock index 5ad2ad0a4..e1eeb4527 100644 --- a/examples/experimental/missing_doc_comment_openai/Cargo.lock +++ b/examples/experimental/missing_doc_comment_openai/Cargo.lock @@ -353,6 +353,7 @@ dependencies = [ "once_cell", "regex", "rust-embed", + "rustversion", "serde", "thiserror 2.0.7", "toml", diff --git a/examples/general/Cargo.lock b/examples/general/Cargo.lock index 13ef11f3b..043062106 100644 --- a/examples/general/Cargo.lock +++ b/examples/general/Cargo.lock @@ -10,7 +10,6 @@ dependencies = [ "dylint_internal", "dylint_linting", "dylint_testing", - "home", "once_cell", ] @@ -427,6 +426,7 @@ dependencies = [ "once_cell", "regex", "rust-embed", + "rustversion", "serde", "thiserror 2.0.7", "toml", diff --git a/examples/general/Cargo.toml b/examples/general/Cargo.toml index 89f0b9cd7..3f77fdab4 100644 --- a/examples/general/Cargo.toml +++ b/examples/general/Cargo.toml @@ -49,7 +49,6 @@ members = [ bitflags = "2.6" clippy_utils = { git = "https://github.com/rust-lang/rust-clippy", rev = "ff4a26d442bead94a4c96fb1de967374bc4fbd8e" } derivative = "2.2.0" -home = "0.5" once_cell = "1.20" serde = "1.0" serde_json = "1.0" diff --git a/examples/general/abs_home_path/Cargo.toml b/examples/general/abs_home_path/Cargo.toml index ca8e977d4..c99afd058 100644 --- a/examples/general/abs_home_path/Cargo.toml +++ b/examples/general/abs_home_path/Cargo.toml @@ -11,10 +11,9 @@ crate-type = ["cdylib", "rlib"] [dependencies] clippy_utils = { workspace = true } -home = { workspace = true } once_cell = { workspace = true } -dylint_internal = { path = "../../../internal" } +dylint_internal = { path = "../../../internal", features = ["home"] } dylint_linting = { path = "../../../utils/linting" } [dev-dependencies] diff --git a/examples/general/abs_home_path/src/lib.rs b/examples/general/abs_home_path/src/lib.rs index 3928578ad..fceaf7066 100644 --- a/examples/general/abs_home_path/src/lib.rs +++ b/examples/general/abs_home_path/src/lib.rs @@ -7,7 +7,7 @@ extern crate rustc_hir; extern crate rustc_span; use clippy_utils::{diagnostics::span_lint, match_def_path, path_def_id}; -use dylint_internal::paths; +use dylint_internal::{home, paths}; use once_cell::unsync::OnceCell; use rustc_ast::ast::LitKind; use rustc_hir::{def_id::DefId, Closure, Expr, ExprKind, Item, ItemKind, Node}; diff --git a/examples/restriction/Cargo.lock b/examples/restriction/Cargo.lock index 7ff4741fb..c0bd51ee6 100644 --- a/examples/restriction/Cargo.lock +++ b/examples/restriction/Cargo.lock @@ -477,6 +477,7 @@ dependencies = [ "once_cell", "regex", "rust-embed", + "rustversion", "serde", "thiserror 2.0.7", "toml", diff --git a/examples/supplementary/Cargo.lock b/examples/supplementary/Cargo.lock index 6e0a6762d..7ebd8c12f 100644 --- a/examples/supplementary/Cargo.lock +++ b/examples/supplementary/Cargo.lock @@ -413,6 +413,7 @@ dependencies = [ "once_cell", "regex", "rust-embed", + "rustversion", "serde", "thiserror 2.0.7", "toml", diff --git a/examples/testing/clippy/Cargo.lock b/examples/testing/clippy/Cargo.lock index c463f1115..77702a76f 100644 --- a/examples/testing/clippy/Cargo.lock +++ b/examples/testing/clippy/Cargo.lock @@ -387,6 +387,7 @@ dependencies = [ "once_cell", "regex", "rust-embed", + "rustversion", "serde", "thiserror 2.0.7", "toml 0.8.19", diff --git a/examples/testing/marker/Cargo.lock b/examples/testing/marker/Cargo.lock index a8c1d5910..3de9e5aab 100644 --- a/examples/testing/marker/Cargo.lock +++ b/examples/testing/marker/Cargo.lock @@ -106,7 +106,7 @@ dependencies = [ "semver", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -120,7 +120,7 @@ dependencies = [ "semver", "serde", "serde_json", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -153,7 +153,7 @@ dependencies = [ [[package]] name = "dylint_internal" -version = "3.2.1" +version = "3.3.0" dependencies = [ "ansi_term", "anyhow", @@ -166,21 +166,22 @@ dependencies = [ "log", "once_cell", "regex", + "rustversion", "serde", - "thiserror", + "thiserror 2.0.9", "toml", ] [[package]] name = "dylint_linting" -version = "3.2.1" +version = "3.3.0" dependencies = [ "cargo_metadata 0.19.0", "dylint_internal", "paste", "rustversion", "serde", - "thiserror", + "thiserror 2.0.9", "toml", ] @@ -541,7 +542,7 @@ checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "marker" -version = "3.2.1" +version = "3.3.0" dependencies = [ "anyhow", "bumpalo", @@ -571,7 +572,7 @@ dependencies = [ "marker_error", "marker_utils", "miette", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -591,7 +592,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95f419aa64c113932944e82ac6c7d885e1fcf75deda3b871877dbf2a9752d38a" dependencies = [ "miette", - "thiserror", + "thiserror 1.0.69", "tracing-error", "yansi", ] @@ -642,7 +643,7 @@ dependencies = [ "supports-unicode", "terminal_size", "textwrap", - "thiserror", + "thiserror 1.0.69", "unicode-width", ] @@ -986,7 +987,16 @@ version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc" +dependencies = [ + "thiserror-impl 2.0.9", ] [[package]] @@ -1000,6 +1010,17 @@ dependencies = [ "syn", ] +[[package]] +name = "thiserror-impl" +version = "2.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thread_local" version = "1.1.8" diff --git a/examples/testing/straggler/Cargo.lock b/examples/testing/straggler/Cargo.lock index 7a743f442..7b2a63a56 100644 --- a/examples/testing/straggler/Cargo.lock +++ b/examples/testing/straggler/Cargo.lock @@ -333,6 +333,7 @@ dependencies = [ "once_cell", "regex", "rust-embed", + "rustversion", "serde", "thiserror 2.0.7", "toml 0.8.19", diff --git a/internal/Cargo.toml b/internal/Cargo.toml index c56e1d0b2..251771c41 100644 --- a/internal/Cargo.toml +++ b/internal/Cargo.toml @@ -23,7 +23,10 @@ home = { workspace = true, optional = true } if_chain = { workspace = true, optional = true } is-terminal = { workspace = true, optional = true } log = { workspace = true, optional = true } -rust-embed = { workspace = true, features = ["include-exclude"], optional = true } +rust-embed = { workspace = true, features = [ + "include-exclude", +], optional = true } +rustversion = { workspace = true, optional = true } semver = { workspace = true, optional = true } serde = { workspace = true, optional = true } thiserror = { workspace = true, optional = true } @@ -48,6 +51,7 @@ command = ["log"] config = ["cargo_metadata", "serde", "thiserror", "toml"] examples = ["cargo", "cargo-util", "rustup", "walkdir"] git = ["command", "git2", "if_chain"] +home = ["dep:home", "rustversion"] packaging = ["cargo", "rust-embed"] rustup = ["command"] sed = [] diff --git a/internal/src/cargo.rs b/internal/src/cargo.rs index 09e08f003..bc69cf726 100644 --- a/internal/src/cargo.rs +++ b/internal/src/cargo.rs @@ -1,4 +1,4 @@ -use crate::CommandExt; +use crate::{home, CommandExt}; use ansi_term::Style; use anyhow::{anyhow, ensure, Result}; use bitflags::bitflags; diff --git a/internal/src/home.rs b/internal/src/home.rs new file mode 100644 index 000000000..83b032fd7 --- /dev/null +++ b/internal/src/home.rs @@ -0,0 +1,18 @@ +use crate::env; +use std::path::PathBuf; + +#[must_use] +pub fn cargo_home() -> Option { + if let Ok(cargo_home) = env::var(env::CARGO_HOME) { + Some(PathBuf::from(cargo_home)) + } else { + home_dir().map(|path| path.join(".cargo")) + } +} + +// smoelius: https://github.com/rust-lang/cargo/commit/014378f8c07bec557b6c6608e5baf0761a12d504 +#[rustversion::before(1.86)] +pub use home::home_dir; + +#[rustversion::since(1.86)] +pub use std::env::home_dir; diff --git a/internal/src/lib.rs b/internal/src/lib.rs index e43a4558b..af3575ebf 100644 --- a/internal/src/lib.rs +++ b/internal/src/lib.rs @@ -28,6 +28,9 @@ pub use git::*; #[cfg(feature = "git")] pub use git2; +#[cfg(feature = "home")] +pub mod home; + #[cfg(feature = "packaging")] pub mod packaging;