mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
refactor(manifest): Clarify the specialized role of RustVersion
This commit is contained in:
parent
d5336f813d
commit
4135f562b8
@ -17,7 +17,7 @@ use cargo::core::Resolve;
|
||||
use cargo::core::{Dependency, PackageId, Registry, Summary};
|
||||
use cargo::core::{GitReference, SourceId};
|
||||
use cargo::sources::source::QueryKind;
|
||||
use cargo::util::{CargoResult, Config, Graph, IntoUrl, PartialVersion};
|
||||
use cargo::util::{CargoResult, Config, Graph, IntoUrl, RustVersion};
|
||||
|
||||
use proptest::collection::{btree_map, vec};
|
||||
use proptest::prelude::*;
|
||||
@ -185,7 +185,7 @@ pub fn resolve_with_config_raw(
|
||||
deps,
|
||||
&BTreeMap::new(),
|
||||
None::<&String>,
|
||||
None::<PartialVersion>,
|
||||
None::<RustVersion>,
|
||||
)
|
||||
.unwrap();
|
||||
let opts = ResolveOpts::everything();
|
||||
@ -588,7 +588,7 @@ pub fn pkg_dep<T: ToPkgId>(name: T, dep: Vec<Dependency>) -> Summary {
|
||||
dep,
|
||||
&BTreeMap::new(),
|
||||
link,
|
||||
None::<PartialVersion>,
|
||||
None::<RustVersion>,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
@ -616,7 +616,7 @@ pub fn pkg_loc(name: &str, loc: &str) -> Summary {
|
||||
Vec::new(),
|
||||
&BTreeMap::new(),
|
||||
link,
|
||||
None::<PartialVersion>,
|
||||
None::<RustVersion>,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
@ -630,7 +630,7 @@ pub fn remove_dep(sum: &Summary, ind: usize) -> Summary {
|
||||
deps,
|
||||
&BTreeMap::new(),
|
||||
sum.links().map(|a| a.as_str()),
|
||||
None::<PartialVersion>,
|
||||
None::<RustVersion>,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ use crate::core::{Edition, Feature, Features, WorkspaceConfig};
|
||||
use crate::util::errors::*;
|
||||
use crate::util::interning::InternedString;
|
||||
use crate::util::toml::{TomlManifest, TomlProfiles};
|
||||
use crate::util::{short_hash, Config, Filesystem, PartialVersion};
|
||||
use crate::util::{short_hash, Config, Filesystem, RustVersion};
|
||||
|
||||
pub enum EitherManifest {
|
||||
Real(Manifest),
|
||||
@ -58,7 +58,7 @@ pub struct Manifest {
|
||||
original: Rc<TomlManifest>,
|
||||
unstable_features: Features,
|
||||
edition: Edition,
|
||||
rust_version: Option<PartialVersion>,
|
||||
rust_version: Option<RustVersion>,
|
||||
im_a_teapot: Option<bool>,
|
||||
default_run: Option<String>,
|
||||
metabuild: Option<Vec<String>>,
|
||||
@ -112,7 +112,7 @@ pub struct ManifestMetadata {
|
||||
pub documentation: Option<String>, // URL
|
||||
pub badges: BTreeMap<String, BTreeMap<String, String>>,
|
||||
pub links: Option<String>,
|
||||
pub rust_version: Option<PartialVersion>,
|
||||
pub rust_version: Option<RustVersion>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||
@ -401,7 +401,7 @@ impl Manifest {
|
||||
workspace: WorkspaceConfig,
|
||||
unstable_features: Features,
|
||||
edition: Edition,
|
||||
rust_version: Option<PartialVersion>,
|
||||
rust_version: Option<RustVersion>,
|
||||
im_a_teapot: Option<bool>,
|
||||
default_run: Option<String>,
|
||||
original: Rc<TomlManifest>,
|
||||
@ -570,7 +570,7 @@ impl Manifest {
|
||||
self.edition
|
||||
}
|
||||
|
||||
pub fn rust_version(&self) -> Option<PartialVersion> {
|
||||
pub fn rust_version(&self) -> Option<RustVersion> {
|
||||
self.rust_version
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ use crate::util::network::http::http_handle_and_timeout;
|
||||
use crate::util::network::http::HttpTimeout;
|
||||
use crate::util::network::retry::{Retry, RetryResult};
|
||||
use crate::util::network::sleep::SleepTracker;
|
||||
use crate::util::PartialVersion;
|
||||
use crate::util::RustVersion;
|
||||
use crate::util::{self, internal, Config, Progress, ProgressStyle};
|
||||
|
||||
pub const MANIFEST_PREAMBLE: &str = "\
|
||||
@ -104,7 +104,7 @@ pub struct SerializedPackage {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
metabuild: Option<Vec<String>>,
|
||||
default_run: Option<String>,
|
||||
rust_version: Option<PartialVersion>,
|
||||
rust_version: Option<RustVersion>,
|
||||
}
|
||||
|
||||
impl Package {
|
||||
@ -178,7 +178,7 @@ impl Package {
|
||||
self.targets().iter().any(|target| target.proc_macro())
|
||||
}
|
||||
/// Gets the package's minimum Rust version.
|
||||
pub fn rust_version(&self) -> Option<PartialVersion> {
|
||||
pub fn rust_version(&self) -> Option<RustVersion> {
|
||||
self.manifest().rust_version()
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ use crate::core::{Dependency, FeatureValue, PackageId, PackageIdSpec, Registry,
|
||||
use crate::sources::source::QueryKind;
|
||||
use crate::util::errors::CargoResult;
|
||||
use crate::util::interning::InternedString;
|
||||
use crate::util::PartialVersion;
|
||||
use crate::util::RustVersion;
|
||||
|
||||
use anyhow::Context as _;
|
||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||
@ -36,7 +36,7 @@ pub struct RegistryQueryer<'a> {
|
||||
/// versions first. That allows `cargo update -Z minimal-versions` which will
|
||||
/// specify minimum dependency versions to be used.
|
||||
minimal_versions: bool,
|
||||
max_rust_version: Option<PartialVersion>,
|
||||
max_rust_version: Option<RustVersion>,
|
||||
/// a cache of `Candidate`s that fulfil a `Dependency` (and whether `first_minimal_version`)
|
||||
registry_cache: HashMap<(Dependency, bool), Poll<Rc<Vec<Summary>>>>,
|
||||
/// a cache of `Dependency`s that are required for a `Summary`
|
||||
@ -58,7 +58,7 @@ impl<'a> RegistryQueryer<'a> {
|
||||
replacements: &'a [(PackageIdSpec, Dependency)],
|
||||
version_prefs: &'a VersionPreferences,
|
||||
minimal_versions: bool,
|
||||
max_rust_version: Option<PartialVersion>,
|
||||
max_rust_version: Option<RustVersion>,
|
||||
) -> Self {
|
||||
RegistryQueryer {
|
||||
registry,
|
||||
|
@ -71,7 +71,7 @@ use crate::util::config::Config;
|
||||
use crate::util::errors::CargoResult;
|
||||
use crate::util::network::PollExt;
|
||||
use crate::util::profile;
|
||||
use crate::util::PartialVersion;
|
||||
use crate::util::RustVersion;
|
||||
|
||||
use self::context::Context;
|
||||
use self::dep_cache::RegistryQueryer;
|
||||
@ -139,7 +139,7 @@ pub fn resolve(
|
||||
version_prefs: &VersionPreferences,
|
||||
config: Option<&Config>,
|
||||
check_public_visible_dependencies: bool,
|
||||
mut max_rust_version: Option<PartialVersion>,
|
||||
mut max_rust_version: Option<RustVersion>,
|
||||
) -> CargoResult<Resolve> {
|
||||
let _p = profile::start("resolving");
|
||||
let minimal_versions = match config {
|
||||
|
@ -81,7 +81,7 @@ impl VersionPreferences {
|
||||
mod test {
|
||||
use super::*;
|
||||
use crate::core::SourceId;
|
||||
use crate::util::PartialVersion;
|
||||
use crate::util::RustVersion;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
fn pkgid(name: &str, version: &str) -> PackageId {
|
||||
@ -104,7 +104,7 @@ mod test {
|
||||
Vec::new(),
|
||||
&features,
|
||||
None::<&String>,
|
||||
None::<PartialVersion>,
|
||||
None::<RustVersion>,
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::core::{Dependency, PackageId, SourceId};
|
||||
use crate::util::interning::InternedString;
|
||||
use crate::util::CargoResult;
|
||||
use crate::util::PartialVersion;
|
||||
use crate::util::RustVersion;
|
||||
use anyhow::bail;
|
||||
use semver::Version;
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
@ -26,7 +26,7 @@ struct Inner {
|
||||
features: Rc<FeatureMap>,
|
||||
checksum: Option<String>,
|
||||
links: Option<InternedString>,
|
||||
rust_version: Option<PartialVersion>,
|
||||
rust_version: Option<RustVersion>,
|
||||
}
|
||||
|
||||
impl Summary {
|
||||
@ -35,7 +35,7 @@ impl Summary {
|
||||
dependencies: Vec<Dependency>,
|
||||
features: &BTreeMap<InternedString, Vec<InternedString>>,
|
||||
links: Option<impl Into<InternedString>>,
|
||||
rust_version: Option<PartialVersion>,
|
||||
rust_version: Option<RustVersion>,
|
||||
) -> CargoResult<Summary> {
|
||||
// ****CAUTION**** If you change anything here that may raise a new
|
||||
// error, be sure to coordinate that change with either the index
|
||||
@ -88,7 +88,7 @@ impl Summary {
|
||||
self.inner.links
|
||||
}
|
||||
|
||||
pub fn rust_version(&self) -> Option<PartialVersion> {
|
||||
pub fn rust_version(&self) -> Option<RustVersion> {
|
||||
self.inner.rust_version
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ use crate::util::edit_distance;
|
||||
use crate::util::errors::{CargoResult, ManifestError};
|
||||
use crate::util::interning::InternedString;
|
||||
use crate::util::toml::{read_manifest, InheritableFields, TomlDependency, TomlProfiles};
|
||||
use crate::util::PartialVersion;
|
||||
use crate::util::RustVersion;
|
||||
use crate::util::{config::ConfigRelativePath, Config, Filesystem, IntoUrl};
|
||||
use cargo_util::paths;
|
||||
use cargo_util::paths::normalize_path;
|
||||
@ -598,7 +598,7 @@ impl<'cfg> Workspace<'cfg> {
|
||||
|
||||
/// Get the lowest-common denominator `package.rust-version` within the workspace, if specified
|
||||
/// anywhere
|
||||
pub fn rust_version(&self) -> Option<PartialVersion> {
|
||||
pub fn rust_version(&self) -> Option<RustVersion> {
|
||||
self.members().filter_map(|pkg| pkg.rust_version()).min()
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ use crate::util::toml_mut::dependency::Source;
|
||||
use crate::util::toml_mut::dependency::WorkspaceSource;
|
||||
use crate::util::toml_mut::manifest::DepTable;
|
||||
use crate::util::toml_mut::manifest::LocalManifest;
|
||||
use crate::util::PartialVersion;
|
||||
use crate::util::RustVersion;
|
||||
use crate::CargoResult;
|
||||
use crate::Config;
|
||||
use crate_spec::CrateSpec;
|
||||
@ -564,7 +564,7 @@ fn get_latest_dependency(
|
||||
})?;
|
||||
|
||||
if config.cli_unstable().msrv_policy && honor_rust_version {
|
||||
fn parse_msrv(comp: PartialVersion) -> (u64, u64, u64) {
|
||||
fn parse_msrv(comp: RustVersion) -> (u64, u64, u64) {
|
||||
(comp.major, comp.minor.unwrap_or(0), comp.patch.unwrap_or(0))
|
||||
}
|
||||
|
||||
@ -624,7 +624,7 @@ fn get_latest_dependency(
|
||||
|
||||
fn rust_version_incompat_error(
|
||||
dep: &str,
|
||||
rust_version: PartialVersion,
|
||||
rust_version: RustVersion,
|
||||
lowest_rust_version: Option<&Summary>,
|
||||
) -> anyhow::Error {
|
||||
let mut error_msg = format!(
|
||||
|
@ -69,7 +69,7 @@ use crate::core::{GitReference, PackageId, PackageIdSpec, PackageSet, SourceId,
|
||||
use crate::ops;
|
||||
use crate::sources::PathSource;
|
||||
use crate::util::errors::CargoResult;
|
||||
use crate::util::PartialVersion;
|
||||
use crate::util::RustVersion;
|
||||
use crate::util::{profile, CanonicalUrl};
|
||||
use anyhow::Context as _;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@ -133,7 +133,7 @@ pub fn resolve_ws_with_opts<'cfg>(
|
||||
specs: &[PackageIdSpec],
|
||||
has_dev_units: HasDevUnits,
|
||||
force_all_targets: ForceAllTargets,
|
||||
max_rust_version: Option<PartialVersion>,
|
||||
max_rust_version: Option<RustVersion>,
|
||||
) -> CargoResult<WorkspaceResolve<'cfg>> {
|
||||
let mut registry = PackageRegistry::new(ws.config())?;
|
||||
let mut add_patches = true;
|
||||
@ -240,7 +240,7 @@ pub fn resolve_ws_with_opts<'cfg>(
|
||||
fn resolve_with_registry<'cfg>(
|
||||
ws: &Workspace<'cfg>,
|
||||
registry: &mut PackageRegistry<'cfg>,
|
||||
max_rust_version: Option<PartialVersion>,
|
||||
max_rust_version: Option<RustVersion>,
|
||||
) -> CargoResult<Resolve> {
|
||||
let prev = ops::load_pkg_lockfile(ws)?;
|
||||
let mut resolve = resolve_with_previous(
|
||||
@ -285,7 +285,7 @@ pub fn resolve_with_previous<'cfg>(
|
||||
to_avoid: Option<&HashSet<PackageId>>,
|
||||
specs: &[PackageIdSpec],
|
||||
register_patches: bool,
|
||||
max_rust_version: Option<PartialVersion>,
|
||||
max_rust_version: Option<RustVersion>,
|
||||
) -> CargoResult<Resolve> {
|
||||
// We only want one Cargo at a time resolving a crate graph since this can
|
||||
// involve a lot of frobbing of the global caches.
|
||||
|
@ -91,7 +91,7 @@ use crate::core::{PackageId, SourceId, Summary};
|
||||
use crate::sources::registry::{LoadResponse, RegistryData};
|
||||
use crate::util::interning::InternedString;
|
||||
use crate::util::IntoUrl;
|
||||
use crate::util::{internal, CargoResult, Config, Filesystem, OptVersionReq, PartialVersion};
|
||||
use crate::util::{internal, CargoResult, Config, Filesystem, OptVersionReq, RustVersion};
|
||||
use anyhow::bail;
|
||||
use cargo_util::{paths, registry::make_dep_path};
|
||||
use semver::Version;
|
||||
@ -358,7 +358,7 @@ pub struct IndexPackage<'a> {
|
||||
///
|
||||
/// Added in 2023 (see <https://github.com/rust-lang/crates.io/pull/6267>),
|
||||
/// can be `None` if published before then or if not set in the manifest.
|
||||
rust_version: Option<PartialVersion>,
|
||||
rust_version: Option<RustVersion>,
|
||||
/// The schema version for this entry.
|
||||
///
|
||||
/// If this is None, it defaults to version `1`. Entries with unknown
|
||||
|
@ -22,7 +22,7 @@ pub use self::progress::{Progress, ProgressStyle};
|
||||
pub use self::queue::Queue;
|
||||
pub use self::restricted_names::validate_package_name;
|
||||
pub use self::rustc::Rustc;
|
||||
pub use self::semver_ext::{OptVersionReq, PartialVersion, VersionExt, VersionReqExt};
|
||||
pub use self::semver_ext::{OptVersionReq, RustVersion, VersionExt, VersionReqExt};
|
||||
pub use self::to_semver::ToSemver;
|
||||
pub use self::vcs::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
|
||||
pub use self::workspace::{
|
||||
|
@ -110,13 +110,13 @@ impl From<VersionReq> for OptVersionReq {
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Clone, Debug)]
|
||||
pub struct PartialVersion {
|
||||
pub struct RustVersion {
|
||||
pub major: u64,
|
||||
pub minor: Option<u64>,
|
||||
pub patch: Option<u64>,
|
||||
}
|
||||
|
||||
impl PartialVersion {
|
||||
impl RustVersion {
|
||||
pub fn caret_req(&self) -> VersionReq {
|
||||
VersionReq {
|
||||
comparators: vec![Comparator {
|
||||
@ -130,11 +130,11 @@ impl PartialVersion {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for PartialVersion {
|
||||
impl std::str::FromStr for RustVersion {
|
||||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(value: &str) -> Result<Self, Self::Err> {
|
||||
// HACK: `PartialVersion` is a subset of the `VersionReq` syntax that only ever
|
||||
// HACK: `RustVersion` is a subset of the `VersionReq` syntax that only ever
|
||||
// has one comparator with a required minor and optional patch, and uses no
|
||||
// other features.
|
||||
if is_req(value) {
|
||||
@ -163,7 +163,7 @@ impl std::str::FromStr for PartialVersion {
|
||||
semver::Prerelease::EMPTY,
|
||||
"guarenteed by character check"
|
||||
);
|
||||
Ok(PartialVersion {
|
||||
Ok(RustVersion {
|
||||
major: comp.major,
|
||||
minor: comp.minor,
|
||||
patch: comp.patch,
|
||||
@ -171,7 +171,7 @@ impl std::str::FromStr for PartialVersion {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for PartialVersion {
|
||||
impl Display for RustVersion {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let major = self.major;
|
||||
write!(f, "{major}")?;
|
||||
@ -185,7 +185,7 @@ impl Display for PartialVersion {
|
||||
}
|
||||
}
|
||||
|
||||
impl serde::Serialize for PartialVersion {
|
||||
impl serde::Serialize for RustVersion {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
@ -194,7 +194,7 @@ impl serde::Serialize for PartialVersion {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> serde::Deserialize<'de> for PartialVersion {
|
||||
impl<'de> serde::Deserialize<'de> for RustVersion {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
|
@ -30,7 +30,7 @@ use crate::util::errors::{CargoResult, ManifestError};
|
||||
use crate::util::interning::InternedString;
|
||||
use crate::util::{
|
||||
self, config::ConfigRelativePath, validate_package_name, Config, IntoUrl, OptVersionReq,
|
||||
PartialVersion,
|
||||
RustVersion,
|
||||
};
|
||||
|
||||
pub mod embedded;
|
||||
@ -1182,8 +1182,8 @@ impl<'de> de::Deserialize<'de> for MaybeWorkspaceString {
|
||||
}
|
||||
}
|
||||
|
||||
type MaybeWorkspacePartialVersion = MaybeWorkspace<PartialVersion, TomlWorkspaceField>;
|
||||
impl<'de> de::Deserialize<'de> for MaybeWorkspacePartialVersion {
|
||||
type MaybeWorkspaceRustVersion = MaybeWorkspace<RustVersion, TomlWorkspaceField>;
|
||||
impl<'de> de::Deserialize<'de> for MaybeWorkspaceRustVersion {
|
||||
fn deserialize<D>(d: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: de::Deserializer<'de>,
|
||||
@ -1191,7 +1191,7 @@ impl<'de> de::Deserialize<'de> for MaybeWorkspacePartialVersion {
|
||||
struct Visitor;
|
||||
|
||||
impl<'de> de::Visitor<'de> for Visitor {
|
||||
type Value = MaybeWorkspacePartialVersion;
|
||||
type Value = MaybeWorkspaceRustVersion;
|
||||
|
||||
fn expecting(&self, f: &mut fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
|
||||
f.write_str("a semver or workspace")
|
||||
@ -1201,8 +1201,8 @@ impl<'de> de::Deserialize<'de> for MaybeWorkspacePartialVersion {
|
||||
where
|
||||
E: de::Error,
|
||||
{
|
||||
let value = value.parse::<PartialVersion>().map_err(|e| E::custom(e))?;
|
||||
Ok(MaybeWorkspacePartialVersion::Defined(value))
|
||||
let value = value.parse::<RustVersion>().map_err(|e| E::custom(e))?;
|
||||
Ok(MaybeWorkspaceRustVersion::Defined(value))
|
||||
}
|
||||
|
||||
fn visit_map<V>(self, map: V) -> Result<Self::Value, V::Error>
|
||||
@ -1400,7 +1400,7 @@ impl WorkspaceInherit for TomlWorkspaceField {
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct TomlPackage {
|
||||
edition: Option<MaybeWorkspaceString>,
|
||||
rust_version: Option<MaybeWorkspacePartialVersion>,
|
||||
rust_version: Option<MaybeWorkspaceRustVersion>,
|
||||
name: InternedString,
|
||||
#[serde(deserialize_with = "version_trim_whitespace")]
|
||||
version: MaybeWorkspaceSemverVersion,
|
||||
@ -1490,7 +1490,7 @@ pub struct InheritableFields {
|
||||
exclude: Option<Vec<String>>,
|
||||
include: Option<Vec<String>>,
|
||||
#[serde(rename = "rust-version")]
|
||||
rust_version: Option<PartialVersion>,
|
||||
rust_version: Option<RustVersion>,
|
||||
// We use skip here since it will never be present when deserializing
|
||||
// and we don't want it present when serializing
|
||||
#[serde(skip)]
|
||||
@ -1530,7 +1530,7 @@ impl InheritableFields {
|
||||
("package.license", license -> String),
|
||||
("package.publish", publish -> VecStringOrBool),
|
||||
("package.repository", repository -> String),
|
||||
("package.rust-version", rust_version -> PartialVersion),
|
||||
("package.rust-version", rust_version -> RustVersion),
|
||||
("package.version", version -> semver::Version),
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user