Skip to content

Commit 396bdd3

Browse files
committed
Remove parsing of broken version syntax from 5 years ago
1 parent 3b62e46 commit 396bdd3

File tree

8 files changed

+17
-212
lines changed

8 files changed

+17
-212
lines changed

crates/resolver-tests/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ pub trait ToDep {
506506

507507
impl ToDep for &'static str {
508508
fn to_dep(self) -> Dependency {
509-
Dependency::parse_no_deprecated(self, Some("1.0.0"), registry_loc()).unwrap()
509+
Dependency::parse(self, Some("1.0.0"), registry_loc()).unwrap()
510510
}
511511
}
512512

@@ -626,7 +626,7 @@ pub fn dep(name: &str) -> Dependency {
626626
dep_req(name, "*")
627627
}
628628
pub fn dep_req(name: &str, req: &str) -> Dependency {
629-
Dependency::parse_no_deprecated(name, Some(req), registry_loc()).unwrap()
629+
Dependency::parse(name, Some(req), registry_loc()).unwrap()
630630
}
631631
pub fn dep_req_kind(name: &str, req: &str, kind: DepKind, public: bool) -> Dependency {
632632
let mut dep = dep_req(name, req);
@@ -639,7 +639,7 @@ pub fn dep_loc(name: &str, location: &str) -> Dependency {
639639
let url = location.into_url().unwrap();
640640
let master = GitReference::Branch("master".to_string());
641641
let source_id = SourceId::for_git(&url, master).unwrap();
642-
Dependency::parse_no_deprecated(name, Some("1.0.0"), source_id).unwrap()
642+
Dependency::parse(name, Some("1.0.0"), source_id).unwrap()
643643
}
644644
pub fn dep_kind(name: &str, kind: DepKind) -> Dependency {
645645
dep(name).set_kind(kind).clone()

src/cargo/core/compiler/standard_lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn resolve_std<'cfg>(
4747
.iter()
4848
.map(|&name| {
4949
let source_path = SourceId::for_path(&src_path.join("library").join(name))?;
50-
let dep = Dependency::parse_no_deprecated(name, None, source_path)?;
50+
let dep = Dependency::parse(name, None, source_path)?;
5151
Ok(dep)
5252
})
5353
.collect::<CargoResult<Vec<_>>>()?;

src/cargo/core/dependency.rs

Lines changed: 10 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::rc::Rc;
99
use crate::core::{PackageId, SourceId, Summary};
1010
use crate::util::errors::CargoResult;
1111
use crate::util::interning::InternedString;
12-
use crate::util::{Config, OptVersionReq};
12+
use crate::util::OptVersionReq;
1313

1414
/// Information about a dependency requested by a Cargo manifest.
1515
/// Cheap to copy.
@@ -97,58 +97,6 @@ pub enum DepKind {
9797
Build,
9898
}
9999

100-
fn parse_req_with_deprecated(
101-
name: InternedString,
102-
req: &str,
103-
extra: Option<(PackageId, &Config)>,
104-
) -> CargoResult<VersionReq> {
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-
"\
131-
parsed version requirement `{}` is no longer valid
132-
133-
Previous versions of Cargo accepted this malformed requirement,
134-
but it is being deprecated. This was found when parsing the manifest
135-
of {} {}, and the correct version requirement is `{}`.
136-
137-
This will soon become a hard error, so it's either recommended to
138-
update to a fixed version or contact the upstream maintainer about
139-
this warning.
140-
",
141-
req,
142-
inside.name(),
143-
inside.version(),
144-
corrected,
145-
);
146-
147-
config.shell().warn(&msg)?;
148-
149-
Ok(VersionReq::parse(corrected).unwrap())
150-
}
151-
152100
impl ser::Serialize for DepKind {
153101
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
154102
where
@@ -169,35 +117,18 @@ impl Dependency {
169117
name: impl Into<InternedString>,
170118
version: Option<&str>,
171119
source_id: SourceId,
172-
inside: PackageId,
173-
config: &Config,
174-
) -> CargoResult<Dependency> {
175-
let name = name.into();
176-
let arg = Some((inside, config));
177-
let (specified_req, version_req) = match version {
178-
Some(v) => (true, parse_req_with_deprecated(name, v, arg)?.into()),
179-
None => (false, OptVersionReq::Any),
180-
};
181-
182-
let mut ret = Dependency::new_override(name, source_id);
183-
{
184-
let ptr = Rc::make_mut(&mut ret.inner);
185-
ptr.only_match_name = false;
186-
ptr.req = version_req;
187-
ptr.specified_req = specified_req;
188-
}
189-
Ok(ret)
190-
}
191-
192-
/// Attempt to create a `Dependency` from an entry in the manifest.
193-
pub fn parse_no_deprecated(
194-
name: impl Into<InternedString>,
195-
version: Option<&str>,
196-
source_id: SourceId,
197120
) -> CargoResult<Dependency> {
198121
let name = name.into();
199122
let (specified_req, version_req) = match version {
200-
Some(v) => (true, parse_req_with_deprecated(name, v, None)?.into()),
123+
Some(v) => match VersionReq::parse(v) {
124+
Ok(req) => (true, OptVersionReq::Req(req)),
125+
Err(err) => {
126+
return Err(anyhow::Error::new(err).context(format!(
127+
"failed to parse the version requirement `{}` for dependency `{}`",
128+
v, name,
129+
)))
130+
}
131+
},
201132
None => (false, OptVersionReq::Any),
202133
};
203134

src/cargo/core/workspace.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ impl<'cfg> Workspace<'cfg> {
396396
.map(|(name, dep)| {
397397
dep.to_dependency_split(
398398
name,
399-
/* pkg_id */ None,
400399
source,
401400
&mut nested_paths,
402401
self.config,

src/cargo/ops/cargo_install.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,7 @@ fn install_one(
180180
} else {
181181
None
182182
};
183-
Some(Dependency::parse_no_deprecated(
184-
krate,
185-
vers.as_deref(),
186-
source_id,
187-
)?)
183+
Some(Dependency::parse(krate, vers.as_deref(), source_id)?)
188184
} else {
189185
None
190186
}

src/cargo/sources/registry/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ impl<'a> RegistryDependency<'a> {
373373
default
374374
};
375375

376-
let mut dep = Dependency::parse_no_deprecated(package.unwrap_or(name), Some(&req), id)?;
376+
let mut dep = Dependency::parse(package.unwrap_or(name), Some(&req), id)?;
377377
if package.is_some() {
378378
dep.set_explicit_name_in_toml(name);
379379
}

src/cargo/util/toml/mod.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,6 @@ impl TomlProject {
874874
}
875875

876876
struct Context<'a, 'b> {
877-
pkgid: Option<PackageId>,
878877
deps: &'a mut Vec<Dependency>,
879878
source_id: SourceId,
880879
nested_paths: &'a mut Vec<PathBuf>,
@@ -1189,7 +1188,6 @@ impl TomlManifest {
11891188

11901189
{
11911190
let mut cx = Context {
1192-
pkgid: Some(pkgid),
11931191
deps: &mut deps,
11941192
source_id,
11951193
nested_paths: &mut nested_paths,
@@ -1457,7 +1455,6 @@ impl TomlManifest {
14571455

14581456
let (replace, patch) = {
14591457
let mut cx = Context {
1460-
pkgid: None,
14611458
deps: &mut deps,
14621459
source_id,
14631460
nested_paths: &mut nested_paths,
@@ -1653,7 +1650,6 @@ impl<P: ResolveToPath> TomlDependency<P> {
16531650
pub(crate) fn to_dependency_split(
16541651
&self,
16551652
name: &str,
1656-
pkgid: Option<PackageId>,
16571653
source_id: SourceId,
16581654
nested_paths: &mut Vec<PathBuf>,
16591655
config: &Config,
@@ -1666,7 +1662,6 @@ impl<P: ResolveToPath> TomlDependency<P> {
16661662
self.to_dependency(
16671663
name,
16681664
&mut Context {
1669-
pkgid,
16701665
deps: &mut Vec::new(),
16711666
source_id,
16721667
nested_paths,
@@ -1875,10 +1870,7 @@ impl<P: ResolveToPath> DetailedTomlDependency<P> {
18751870
};
18761871

18771872
let version = self.version.as_deref();
1878-
let mut dep = match cx.pkgid {
1879-
Some(id) => Dependency::parse(pkg_name, version, new_source_id, id, cx.config)?,
1880-
None => Dependency::parse_no_deprecated(pkg_name, version, new_source_id)?,
1881-
};
1873+
let mut dep = Dependency::parse(pkg_name, version, new_source_id)?;
18821874
dep.set_features(self.features.iter().flatten())
18831875
.set_default_features(
18841876
self.default_features

tests/testsuite/registry.rs

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,119 +1695,6 @@ fn bump_version_dont_update_registry() {
16951695
.run();
16961696
}
16971697

1698-
#[cargo_test]
1699-
fn old_version_req() {
1700-
let p = project()
1701-
.file(
1702-
"Cargo.toml",
1703-
r#"
1704-
[project]
1705-
name = "bar"
1706-
version = "0.5.0"
1707-
authors = []
1708-
1709-
[dependencies]
1710-
remote = "0.2*"
1711-
"#,
1712-
)
1713-
.file("src/main.rs", "fn main() {}")
1714-
.build();
1715-
1716-
Package::new("remote", "0.2.0").publish();
1717-
1718-
p.cargo("build")
1719-
.with_stderr(
1720-
"\
1721-
warning: parsed version requirement `0.2*` is no longer valid
1722-
1723-
Previous versions of Cargo accepted this malformed requirement,
1724-
but it is being deprecated. This was found when parsing the manifest
1725-
of bar 0.5.0, and the correct version requirement is `0.2.*`.
1726-
1727-
This will soon become a hard error, so it's either recommended to
1728-
update to a fixed version or contact the upstream maintainer about
1729-
this warning.
1730-
1731-
warning: parsed version requirement `0.2*` is no longer valid
1732-
1733-
Previous versions of Cargo accepted this malformed requirement,
1734-
but it is being deprecated. This was found when parsing the manifest
1735-
of bar 0.5.0, and the correct version requirement is `0.2.*`.
1736-
1737-
This will soon become a hard error, so it's either recommended to
1738-
update to a fixed version or contact the upstream maintainer about
1739-
this warning.
1740-
1741-
[UPDATING] [..]
1742-
[DOWNLOADING] crates ...
1743-
[DOWNLOADED] [..]
1744-
[COMPILING] [..]
1745-
[COMPILING] [..]
1746-
[FINISHED] [..]
1747-
",
1748-
)
1749-
.run();
1750-
}
1751-
1752-
#[cargo_test]
1753-
fn old_version_req_upstream() {
1754-
let p = project()
1755-
.file(
1756-
"Cargo.toml",
1757-
r#"
1758-
[project]
1759-
name = "bar"
1760-
version = "0.5.0"
1761-
authors = []
1762-
1763-
[dependencies]
1764-
remote = "0.3"
1765-
"#,
1766-
)
1767-
.file("src/main.rs", "fn main() {}")
1768-
.build();
1769-
1770-
Package::new("remote", "0.3.0")
1771-
.file(
1772-
"Cargo.toml",
1773-
r#"
1774-
[project]
1775-
name = "remote"
1776-
version = "0.3.0"
1777-
authors = []
1778-
1779-
[dependencies]
1780-
bar = "0.2*"
1781-
"#,
1782-
)
1783-
.file("src/lib.rs", "")
1784-
.publish();
1785-
Package::new("bar", "0.2.0").publish();
1786-
1787-
p.cargo("build")
1788-
.with_stderr(
1789-
"\
1790-
[UPDATING] [..]
1791-
[DOWNLOADING] crates ...
1792-
[DOWNLOADED] [..]
1793-
warning: parsed version requirement `0.2*` is no longer valid
1794-
1795-
Previous versions of Cargo accepted this malformed requirement,
1796-
but it is being deprecated. This was found when parsing the manifest
1797-
of remote 0.3.0, and the correct version requirement is `0.2.*`.
1798-
1799-
This will soon become a hard error, so it's either recommended to
1800-
update to a fixed version or contact the upstream maintainer about
1801-
this warning.
1802-
1803-
[COMPILING] [..]
1804-
[COMPILING] [..]
1805-
[FINISHED] [..]
1806-
",
1807-
)
1808-
.run();
1809-
}
1810-
18111698
#[cargo_test]
18121699
fn toml_lies_but_index_is_truth() {
18131700
Package::new("foo", "0.2.0").publish();

0 commit comments

Comments
 (0)