Skip to content

Commit 3b62e46

Browse files
committed
Update to semver 1.0.0-rc
1 parent e931e47 commit 3b62e46

File tree

14 files changed

+170
-82
lines changed

14 files changed

+170
-82
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ num_cpus = "1.0"
5050
opener = "0.4"
5151
percent-encoding = "2.0"
5252
rustfix = "0.5.0"
53-
semver = { version = "0.10", features = ["serde"] }
53+
semver = { version = "1.0.0-rc.2", features = ["serde"] }
5454
serde = { version = "1.0.123", features = ["derive"] }
5555
serde_ignored = "0.1.0"
5656
serde_json = { version = "1.0.30", features = ["raw_value"] }

src/cargo/core/compiler/compilation.rs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use std::path::PathBuf;
55

66
use cargo_platform::CfgExpr;
77
use cargo_util::{paths, ProcessBuilder};
8-
use semver::Version;
98

109
use super::BuildContext;
1110
use crate::core::compiler::{CompileKind, Metadata, Unit};
@@ -316,10 +315,7 @@ impl<'cfg> Compilation<'cfg> {
316315
.env("CARGO_PKG_VERSION_MAJOR", &pkg.version().major.to_string())
317316
.env("CARGO_PKG_VERSION_MINOR", &pkg.version().minor.to_string())
318317
.env("CARGO_PKG_VERSION_PATCH", &pkg.version().patch.to_string())
319-
.env(
320-
"CARGO_PKG_VERSION_PRE",
321-
&pre_version_component(pkg.version()),
322-
)
318+
.env("CARGO_PKG_VERSION_PRE", pkg.version().pre.as_str())
323319
.env("CARGO_PKG_VERSION", &pkg.version().to_string())
324320
.env("CARGO_PKG_NAME", &*pkg.name())
325321
.env(
@@ -368,23 +364,6 @@ fn fill_rustc_tool_env(mut cmd: ProcessBuilder, unit: &Unit) -> ProcessBuilder {
368364
cmd
369365
}
370366

371-
fn pre_version_component(v: &Version) -> String {
372-
if v.pre.is_empty() {
373-
return String::new();
374-
}
375-
376-
let mut ret = String::new();
377-
378-
for (i, x) in v.pre.iter().enumerate() {
379-
if i != 0 {
380-
ret.push('.')
381-
};
382-
ret.push_str(&x.to_string());
383-
}
384-
385-
ret
386-
}
387-
388367
fn target_runner(
389368
bcx: &BuildContext<'_, '_>,
390369
kind: CompileKind,

src/cargo/core/compiler/context/compilation_files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ fn hash_rustc_version(bcx: &BuildContext<'_, '_>, hasher: &mut StableHasher) {
595595
//
596596
// This assumes that the first segment is the important bit ("nightly",
597597
// "beta", "dev", etc.). Skip other parts like the `.3` in `-beta.3`.
598-
vers.pre[0].hash(hasher);
598+
vers.pre.split('.').next().hash(hasher);
599599
// Keep "host" since some people switch hosts to implicitly change
600600
// targets, (like gnu vs musl or gnu vs msvc). In the future, we may want
601601
// to consider hashing `unit.kind.short_name()` instead.

src/cargo/core/dependency.rs

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use anyhow::Context as _;
21
use cargo_platform::Platform;
32
use log::trace;
4-
use semver::ReqParseError;
53
use semver::VersionReq;
64
use serde::ser;
75
use serde::Serialize;
@@ -11,17 +9,17 @@ use std::rc::Rc;
119
use crate::core::{PackageId, SourceId, Summary};
1210
use crate::util::errors::CargoResult;
1311
use crate::util::interning::InternedString;
14-
use crate::util::Config;
12+
use crate::util::{Config, OptVersionReq};
1513

1614
/// Information about a dependency requested by a Cargo manifest.
1715
/// Cheap to copy.
18-
#[derive(PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Debug)]
16+
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
1917
pub struct Dependency {
2018
inner: Rc<Inner>,
2119
}
2220

2321
/// The data underlying a `Dependency`.
24-
#[derive(PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Debug)]
22+
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
2523
struct Inner {
2624
name: InternedString,
2725
source_id: SourceId,
@@ -32,7 +30,7 @@ struct Inner {
3230
/// `registry` is specified. Or in the case of a crates.io dependency,
3331
/// `source_id` will be crates.io and this will be None.
3432
registry_id: Option<SourceId>,
35-
req: VersionReq,
33+
req: OptVersionReq,
3634
specified_req: bool,
3735
kind: DepKind,
3836
only_match_name: bool,
@@ -104,14 +102,32 @@ fn parse_req_with_deprecated(
104102
req: &str,
105103
extra: Option<(PackageId, &Config)>,
106104
) -> CargoResult<VersionReq> {
107-
match VersionReq::parse(req) {
108-
Err(ReqParseError::DeprecatedVersionRequirement(requirement)) => {
109-
let (inside, config) = match extra {
110-
Some(pair) => pair,
111-
None => return Err(ReqParseError::DeprecatedVersionRequirement(requirement).into()),
112-
};
113-
let msg = format!(
114-
"\
105+
let err = match VersionReq::parse(req) {
106+
Ok(req) => return Ok(req),
107+
Err(err) => err,
108+
};
109+
110+
let (inside, config) = match extra {
111+
Some(pair) => pair,
112+
None => return Err(err.into()),
113+
};
114+
115+
let corrected = match req {
116+
".*" => "*",
117+
"0.1.0." => "0.1.0",
118+
"0.3.1.3" => "0.3.13",
119+
"0.2*" => "0.2.*",
120+
"*.0" => "*",
121+
_ => {
122+
return Err(anyhow::Error::new(err).context(format!(
123+
"failed to parse the version requirement `{}` for dependency `{}`",
124+
req, name,
125+
)));
126+
}
127+
};
128+
129+
let msg = format!(
130+
"\
115131
parsed version requirement `{}` is no longer valid
116132
117133
Previous versions of Cargo accepted this malformed requirement,
@@ -122,27 +138,15 @@ This will soon become a hard error, so it's either recommended to
122138
update to a fixed version or contact the upstream maintainer about
123139
this warning.
124140
",
125-
req,
126-
inside.name(),
127-
inside.version(),
128-
requirement
129-
);
130-
config.shell().warn(&msg)?;
131-
132-
Ok(requirement)
133-
}
134-
Err(e) => {
135-
let err: CargoResult<VersionReq> = Err(e.into());
136-
let v: VersionReq = err.with_context(|| {
137-
format!(
138-
"failed to parse the version requirement `{}` for dependency `{}`",
139-
req, name
140-
)
141-
})?;
142-
Ok(v)
143-
}
144-
Ok(v) => Ok(v),
145-
}
141+
req,
142+
inside.name(),
143+
inside.version(),
144+
corrected,
145+
);
146+
147+
config.shell().warn(&msg)?;
148+
149+
Ok(VersionReq::parse(corrected).unwrap())
146150
}
147151

148152
impl ser::Serialize for DepKind {
@@ -171,8 +175,8 @@ impl Dependency {
171175
let name = name.into();
172176
let arg = Some((inside, config));
173177
let (specified_req, version_req) = match version {
174-
Some(v) => (true, parse_req_with_deprecated(name, v, arg)?),
175-
None => (false, VersionReq::any()),
178+
Some(v) => (true, parse_req_with_deprecated(name, v, arg)?.into()),
179+
None => (false, OptVersionReq::Any),
176180
};
177181

178182
let mut ret = Dependency::new_override(name, source_id);
@@ -193,8 +197,8 @@ impl Dependency {
193197
) -> CargoResult<Dependency> {
194198
let name = name.into();
195199
let (specified_req, version_req) = match version {
196-
Some(v) => (true, parse_req_with_deprecated(name, v, None)?),
197-
None => (false, VersionReq::any()),
200+
Some(v) => (true, parse_req_with_deprecated(name, v, None)?.into()),
201+
None => (false, OptVersionReq::Any),
198202
};
199203

200204
let mut ret = Dependency::new_override(name, source_id);
@@ -214,7 +218,7 @@ impl Dependency {
214218
name,
215219
source_id,
216220
registry_id: None,
217-
req: VersionReq::any(),
221+
req: OptVersionReq::Any,
218222
kind: DepKind::Normal,
219223
only_match_name: true,
220224
optional: false,
@@ -228,7 +232,7 @@ impl Dependency {
228232
}
229233
}
230234

231-
pub fn version_req(&self) -> &VersionReq {
235+
pub fn version_req(&self) -> &OptVersionReq {
232236
&self.inner.req
233237
}
234238

@@ -365,7 +369,7 @@ impl Dependency {
365369

366370
/// Sets the version requirement for this dependency.
367371
pub fn set_version_req(&mut self, req: VersionReq) -> &mut Dependency {
368-
Rc::make_mut(&mut self.inner).req = req;
372+
Rc::make_mut(&mut self.inner).req = OptVersionReq::Req(req);
369373
self
370374
}
371375

@@ -394,7 +398,7 @@ impl Dependency {
394398
id
395399
);
396400
let me = Rc::make_mut(&mut self.inner);
397-
me.req = VersionReq::exact(id.version());
401+
me.req = OptVersionReq::exact(id.version());
398402

399403
// Only update the `precise` of this source to preserve other
400404
// information about dependency's source which may not otherwise be

src/cargo/core/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::core::{Dependency, PackageId, Source, SourceId, SourceMap, Summary};
55
use crate::sources::config::SourceConfigMap;
66
use crate::util::errors::CargoResult;
77
use crate::util::interning::InternedString;
8-
use crate::util::{profile, CanonicalUrl, Config};
8+
use crate::util::{profile, CanonicalUrl, Config, VersionReqExt};
99
use anyhow::{bail, Context as _};
1010
use log::{debug, trace};
1111
use semver::VersionReq;

src/cargo/core/resolver/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22

33
use crate::core::{Dependency, PackageId, Registry, Summary};
44
use crate::util::lev_distance::lev_distance;
5-
use crate::util::Config;
5+
use crate::util::{Config, VersionExt};
66
use anyhow::Error;
77

88
use super::context::Context;

src/cargo/ops/cargo_install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::core::{Dependency, Edition, Package, PackageId, Source, SourceId, Wor
88
use crate::ops::common_for_install_and_uninstall::*;
99
use crate::sources::{GitSource, PathSource, SourceConfigMap};
1010
use crate::util::errors::CargoResult;
11-
use crate::util::{Config, Filesystem, Rustc, ToSemver};
11+
use crate::util::{Config, Filesystem, Rustc, ToSemver, VersionReqExt};
1212
use crate::{drop_println, ops};
1313

1414
use anyhow::{bail, format_err, Context as _};

src/cargo/sources/registry/index.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ use crate::core::dependency::Dependency;
7070
use crate::core::{PackageId, SourceId, Summary};
7171
use crate::sources::registry::{RegistryData, RegistryPackage, INDEX_V_MAX};
7272
use crate::util::interning::InternedString;
73-
use crate::util::{internal, CargoResult, Config, Filesystem, ToSemver};
73+
use crate::util::{internal, CargoResult, Config, Filesystem, OptVersionReq, ToSemver};
7474
use anyhow::bail;
7575
use cargo_util::paths;
7676
use log::{debug, info};
77-
use semver::{Version, VersionReq};
77+
use semver::Version;
7878
use std::collections::{HashMap, HashSet};
7979
use std::convert::TryInto;
8080
use std::fs;
@@ -264,7 +264,7 @@ impl<'cfg> RegistryIndex<'cfg> {
264264

265265
/// Returns the hash listed for a specified `PackageId`.
266266
pub fn hash(&mut self, pkg: PackageId, load: &mut dyn RegistryData) -> CargoResult<&str> {
267-
let req = VersionReq::exact(pkg.version());
267+
let req = OptVersionReq::exact(pkg.version());
268268
let summary = self
269269
.summaries(pkg.name(), &req, load)?
270270
.next()
@@ -285,7 +285,7 @@ impl<'cfg> RegistryIndex<'cfg> {
285285
pub fn summaries<'a, 'b>(
286286
&'a mut self,
287287
name: InternedString,
288-
req: &'b VersionReq,
288+
req: &'b OptVersionReq,
289289
load: &mut dyn RegistryData,
290290
) -> CargoResult<impl Iterator<Item = &'a IndexSummary> + 'b>
291291
where
@@ -489,7 +489,7 @@ impl<'cfg> RegistryIndex<'cfg> {
489489
}
490490

491491
pub fn is_yanked(&mut self, pkg: PackageId, load: &mut dyn RegistryData) -> CargoResult<bool> {
492-
let req = VersionReq::exact(pkg.version());
492+
let req = OptVersionReq::exact(pkg.version());
493493
let found = self
494494
.summaries(pkg.name(), &req, load)?
495495
.any(|summary| summary.yanked);

src/cargo/sources/registry/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ use std::path::{Path, PathBuf};
168168
use anyhow::Context as _;
169169
use flate2::read::GzDecoder;
170170
use log::debug;
171-
use semver::{Version, VersionReq};
171+
use semver::Version;
172172
use serde::Deserialize;
173173
use tar::Archive;
174174

@@ -179,7 +179,7 @@ use crate::sources::PathSource;
179179
use crate::util::hex;
180180
use crate::util::interning::InternedString;
181181
use crate::util::into_url::IntoUrl;
182-
use crate::util::{restricted_names, CargoResult, Config, Filesystem};
182+
use crate::util::{restricted_names, CargoResult, Config, Filesystem, OptVersionReq};
183183

184184
const PACKAGE_SOURCE_LOCK: &str = ".cargo-ok";
185185
pub const CRATES_IO_INDEX: &str = "https://github.com/rust-lang/crates.io-index";
@@ -671,7 +671,7 @@ impl<'cfg> RegistrySource<'cfg> {
671671

672672
// After we've loaded the package configure its summary's `checksum`
673673
// field with the checksum we know for this `PackageId`.
674-
let req = VersionReq::exact(package.version());
674+
let req = OptVersionReq::exact(package.version());
675675
let summary_with_cksum = self
676676
.index
677677
.summaries(package.name(), &req, &mut *self.ops)?

src/cargo/util/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub use self::progress::{Progress, ProgressStyle};
2020
pub use self::queue::Queue;
2121
pub use self::restricted_names::validate_package_name;
2222
pub use self::rustc::Rustc;
23+
pub use self::semver_ext::{OptVersionReq, VersionExt, VersionReqExt};
2324
pub use self::to_semver::ToSemver;
2425
pub use self::vcs::{existing_vcs_repo, FossilRepo, GitRepo, HgRepo, PijulRepo};
2526
pub use self::workspace::{
@@ -53,6 +54,7 @@ mod progress;
5354
mod queue;
5455
pub mod restricted_names;
5556
pub mod rustc;
57+
mod semver_ext;
5658
pub mod to_semver;
5759
pub mod toml;
5860
mod vcs;

0 commit comments

Comments
 (0)