mirror of
https://github.com/rust-lang/cargo
synced 2024-10-13 19:22:33 +00:00
fix(add): Limit 'Features as of vX.Y.Z' to when relevant
This will only show the messaeg if we didn't already show a version req with full precision specified ... mostly. We'll also skip it if its a local or git dependency but we never show the version in those cases because it doesn't matter. The `precise_version` logic came from cargo-upgrade.
This commit is contained in:
parent
73906aeaf8
commit
7ce2b7d42a
|
@ -769,7 +769,16 @@ fn print_msg(shell: &mut Shell, dep: &DependencyEx, section: &[String]) -> Cargo
|
|||
if !activated.is_empty() || !deactivated.is_empty() {
|
||||
let prefix = format!("{:>13}", " ");
|
||||
let suffix = if let Some(version) = &dep.available_version {
|
||||
format!(" as of v{}", version)
|
||||
let version = version.to_string();
|
||||
let version_req = dep
|
||||
.version()
|
||||
.and_then(|v| semver::VersionReq::parse(v).ok())
|
||||
.and_then(|v| precise_version(&v));
|
||||
if version_req.as_deref() != Some(version.as_str()) {
|
||||
format!(" as of v{}", version)
|
||||
} else {
|
||||
"".to_owned()
|
||||
}
|
||||
} else {
|
||||
"".to_owned()
|
||||
};
|
||||
|
@ -832,3 +841,35 @@ fn find_workspace_dep(toml_key: &str, root_manifest: &Path) -> CargoResult<Depen
|
|||
))?;
|
||||
Dependency::from_toml(root_manifest.parent().unwrap(), toml_key, dep_item)
|
||||
}
|
||||
|
||||
fn precise_version(version_req: &semver::VersionReq) -> Option<String> {
|
||||
version_req
|
||||
.comparators
|
||||
.iter()
|
||||
.filter(|c| {
|
||||
matches!(
|
||||
c.op,
|
||||
// Only ops we can determine a precise version from
|
||||
semver::Op::Exact
|
||||
| semver::Op::GreaterEq
|
||||
| semver::Op::LessEq
|
||||
| semver::Op::Tilde
|
||||
| semver::Op::Caret
|
||||
| semver::Op::Wildcard
|
||||
)
|
||||
})
|
||||
.filter_map(|c| {
|
||||
// Only do it when full precision is specified
|
||||
c.minor.and_then(|minor| {
|
||||
c.patch.map(|patch| semver::Version {
|
||||
major: c.major,
|
||||
minor,
|
||||
patch,
|
||||
pre: c.pre.clone(),
|
||||
build: Default::default(),
|
||||
})
|
||||
})
|
||||
})
|
||||
.max()
|
||||
.map(|v| v.to_string())
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
warning: translating `linked_hash_map` to `linked-hash-map`
|
||||
warning: translating `Inflector` to `inflector`
|
||||
Adding linked-hash-map v0.5.4 to dependencies.
|
||||
Features as of v0.5.4:
|
||||
Features:
|
||||
- clippy
|
||||
- heapsize
|
||||
- heapsize_impl
|
||||
|
@ -11,7 +11,7 @@ warning: translating `Inflector` to `inflector`
|
|||
- serde_impl
|
||||
- serde_test
|
||||
Adding inflector v0.11.4 to dependencies.
|
||||
Features as of v0.11.4:
|
||||
Features:
|
||||
+ heavyweight
|
||||
+ lazy_static
|
||||
+ regex
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Adding cargo-list-test-fixture-dependency (local) to build-dependencies.
|
||||
Features as of v0.0.0:
|
||||
Features:
|
||||
- one
|
||||
- two
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Adding your-face (local) to dependencies.
|
||||
Features as of v0.1.3:
|
||||
Features:
|
||||
+ mouth
|
||||
+ nose
|
||||
- eyes
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Adding your-face (local) to dependencies.
|
||||
Features as of v0.1.3:
|
||||
Features:
|
||||
- eyes
|
||||
- mouth
|
||||
- nose
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Adding your-face (local) to dev-dependencies.
|
||||
Features as of v0.0.0:
|
||||
Features:
|
||||
+ mouth
|
||||
+ nose
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Adding your-face (local) to optional dependencies.
|
||||
Features as of v0.0.0:
|
||||
Features:
|
||||
+ mouth
|
||||
+ nose
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Adding your-face (local) to optional dependencies.
|
||||
Features as of v0.0.0:
|
||||
Features:
|
||||
+ mouth
|
||||
+ nose
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Adding foo (local) to dependencies.
|
||||
Features as of v0.0.0:
|
||||
Features:
|
||||
+ default-base
|
||||
+ default-merge-base
|
||||
+ default-test-base
|
||||
|
|
Loading…
Reference in a new issue