mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
feat(add): Fallback to rustc when rust-version is unset
This commit is contained in:
parent
a30652f2d4
commit
d756ff8882
@ -11,6 +11,7 @@ use std::str::FromStr;
|
||||
|
||||
use anyhow::Context as _;
|
||||
use cargo_util::paths;
|
||||
use cargo_util_schemas::core::PartialVersion;
|
||||
use cargo_util_schemas::manifest::RustVersion;
|
||||
use indexmap::IndexSet;
|
||||
use itertools::Itertools;
|
||||
@ -615,17 +616,36 @@ fn get_latest_dependency(
|
||||
})?;
|
||||
|
||||
if gctx.cli_unstable().msrv_policy && honor_rust_version {
|
||||
if let Some(req_msrv) = spec.rust_version() {
|
||||
let msrvs = possibilities
|
||||
.iter()
|
||||
.map(|s| (s, s.rust_version()))
|
||||
.collect::<Vec<_>>();
|
||||
let req_msrv = spec
|
||||
.rust_version()
|
||||
.cloned()
|
||||
.map(CargoResult::Ok)
|
||||
.unwrap_or_else(|| {
|
||||
let rustc = gctx.load_global_rustc(None)?;
|
||||
|
||||
// Find the latest version of the dep which has a compatible rust-version. To
|
||||
// determine whether or not one rust-version is compatible with another, we
|
||||
// compare the lowest possible versions they could represent, and treat
|
||||
// candidates without a rust-version as compatible by default.
|
||||
let latest_msrv = latest_compatible(&msrvs, req_msrv).ok_or_else(|| {
|
||||
// Remove any pre-release identifiers for easier comparison
|
||||
let current_version = &rustc.version;
|
||||
let untagged_version = RustVersion::try_from(PartialVersion {
|
||||
major: current_version.major,
|
||||
minor: Some(current_version.minor),
|
||||
patch: Some(current_version.patch),
|
||||
pre: None,
|
||||
build: None,
|
||||
})
|
||||
.unwrap();
|
||||
Ok(untagged_version)
|
||||
})?;
|
||||
|
||||
let msrvs = possibilities
|
||||
.iter()
|
||||
.map(|s| (s, s.rust_version()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Find the latest version of the dep which has a compatible rust-version. To
|
||||
// determine whether or not one rust-version is compatible with another, we
|
||||
// compare the lowest possible versions they could represent, and treat
|
||||
// candidates without a rust-version as compatible by default.
|
||||
let latest_msrv = latest_compatible(&msrvs, &req_msrv).ok_or_else(|| {
|
||||
let name = spec.name();
|
||||
let dep_name = &dependency.name;
|
||||
let latest_version = latest.version();
|
||||
@ -639,17 +659,16 @@ help: pass `--ignore-rust-version` to select {dep_name}@{latest_version} which r
|
||||
)
|
||||
})?;
|
||||
|
||||
if latest_msrv.version() < latest.version() {
|
||||
let latest_version = latest.version();
|
||||
let latest_rust_version = latest.rust_version().unwrap();
|
||||
let name = spec.name();
|
||||
gctx.shell().warn(format_args!(
|
||||
if latest_msrv.version() < latest.version() {
|
||||
let latest_version = latest.version();
|
||||
let latest_rust_version = latest.rust_version().unwrap();
|
||||
let name = spec.name();
|
||||
gctx.shell().warn(format_args!(
|
||||
"\
|
||||
ignoring {dependency}@{latest_version} (which requires rustc {latest_rust_version}) to maintain {name}'s rust-version of {req_msrv}",
|
||||
))?;
|
||||
|
||||
latest = latest_msrv;
|
||||
}
|
||||
latest = latest_msrv;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ fn case() {
|
||||
.current_dir(cwd)
|
||||
.masquerade_as_nightly_cargo(&["msrv-policy"])
|
||||
.assert()
|
||||
.success()
|
||||
.failure()
|
||||
.stdout_matches(str![""])
|
||||
.stderr_matches(file!["stderr.term.svg"]);
|
||||
|
||||
|
@ -4,6 +4,3 @@
|
||||
name = "cargo-list-test-fixture"
|
||||
version = "0.0.0"
|
||||
edition = "2015"
|
||||
|
||||
[dependencies]
|
||||
rust-version-user = "0.2.1"
|
||||
|
@ -1,8 +1,9 @@
|
||||
<svg width="740px" height="74px" xmlns="http://www.w3.org/2000/svg">
|
||||
<svg width="928px" height="92px" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.fg { fill: #AAAAAA }
|
||||
.bg { background: #000000 }
|
||||
.fg-green { fill: #00AA00 }
|
||||
.fg-red { fill: #AA0000 }
|
||||
.container {
|
||||
padding: 0 10px;
|
||||
line-height: 18px;
|
||||
@ -20,9 +21,11 @@
|
||||
<text xml:space="preserve" class="container fg">
|
||||
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Updating</tspan><tspan> `dummy-registry` index</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="46px"><tspan class="fg-green bold"> Adding</tspan><tspan> rust-version-user v0.2.1 to dependencies</tspan>
|
||||
<tspan x="10px" y="46px"><tspan class="fg-red bold">error</tspan><tspan class="bold">:</tspan><tspan> no version of crate `rust-version-user` can maintain cargo-list-test-fixture's rust-version of [..]</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="64px">
|
||||
<tspan x="10px" y="64px"><tspan>help: pass `--ignore-rust-version` to select rust-version-user@0.2.1 which requires rustc 1.2345</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="82px">
|
||||
</tspan>
|
||||
</text>
|
||||
|
||||
|
Before Width: | Height: | Size: 873 B After Width: | Height: | Size: 1.1 KiB |
@ -6,4 +6,4 @@ version = "0.0.0"
|
||||
edition = "2015"
|
||||
|
||||
[dependencies]
|
||||
rust-version-user = "0.2.1"
|
||||
rust-version-user = "0.1.1"
|
||||
|
@ -1,8 +1,9 @@
|
||||
<svg width="740px" height="74px" xmlns="http://www.w3.org/2000/svg">
|
||||
<svg width="1129px" height="92px" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.fg { fill: #AAAAAA }
|
||||
.bg { background: #000000 }
|
||||
.fg-green { fill: #00AA00 }
|
||||
.fg-yellow { fill: #AA5500 }
|
||||
.container {
|
||||
padding: 0 10px;
|
||||
line-height: 18px;
|
||||
@ -20,9 +21,11 @@
|
||||
<text xml:space="preserve" class="container fg">
|
||||
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Updating</tspan><tspan> `dummy-registry` index</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="46px"><tspan class="fg-green bold"> Adding</tspan><tspan> rust-version-user v0.2.1 to dependencies</tspan>
|
||||
<tspan x="10px" y="46px"><tspan class="fg-yellow bold">warning</tspan><tspan class="bold">:</tspan><tspan> ignoring rust-version-user@0.2.1 (which requires rustc 1.2345) to maintain cargo-list-test-fixture's rust-version of [..]</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="64px">
|
||||
<tspan x="10px" y="64px"><tspan class="fg-green bold"> Adding</tspan><tspan> rust-version-user v0.1.1 to dependencies</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="82px">
|
||||
</tspan>
|
||||
</text>
|
||||
|
||||
|
Before Width: | Height: | Size: 873 B After Width: | Height: | Size: 1.1 KiB |
@ -6,4 +6,4 @@ version = "0.0.0"
|
||||
edition = "2015"
|
||||
|
||||
[dependencies]
|
||||
rust-version-user = "0.2.1"
|
||||
rust-version-user = "0.1.1"
|
||||
|
@ -1,8 +1,9 @@
|
||||
<svg width="740px" height="74px" xmlns="http://www.w3.org/2000/svg">
|
||||
<svg width="1129px" height="92px" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.fg { fill: #AAAAAA }
|
||||
.bg { background: #000000 }
|
||||
.fg-green { fill: #00AA00 }
|
||||
.fg-yellow { fill: #AA5500 }
|
||||
.container {
|
||||
padding: 0 10px;
|
||||
line-height: 18px;
|
||||
@ -20,9 +21,11 @@
|
||||
<text xml:space="preserve" class="container fg">
|
||||
<tspan x="10px" y="28px"><tspan class="fg-green bold"> Updating</tspan><tspan> `dummy-registry` index</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="46px"><tspan class="fg-green bold"> Adding</tspan><tspan> rust-version-user v0.2.1 to dependencies</tspan>
|
||||
<tspan x="10px" y="46px"><tspan class="fg-yellow bold">warning</tspan><tspan class="bold">:</tspan><tspan> ignoring rust-version-user@0.2.1 (which requires rustc 1.2345) to maintain cargo-list-test-fixture's rust-version of [..]</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="64px">
|
||||
<tspan x="10px" y="64px"><tspan class="fg-green bold"> Adding</tspan><tspan> rust-version-user v0.1.1 to dependencies</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="82px">
|
||||
</tspan>
|
||||
</text>
|
||||
|
||||
|
Before Width: | Height: | Size: 873 B After Width: | Height: | Size: 1.1 KiB |
Loading…
x
Reference in New Issue
Block a user