mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +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 anyhow::Context as _;
|
||||||
use cargo_util::paths;
|
use cargo_util::paths;
|
||||||
|
use cargo_util_schemas::core::PartialVersion;
|
||||||
use cargo_util_schemas::manifest::RustVersion;
|
use cargo_util_schemas::manifest::RustVersion;
|
||||||
use indexmap::IndexSet;
|
use indexmap::IndexSet;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
@ -615,7 +616,26 @@ fn get_latest_dependency(
|
|||||||
})?;
|
})?;
|
||||||
|
|
||||||
if gctx.cli_unstable().msrv_policy && honor_rust_version {
|
if gctx.cli_unstable().msrv_policy && honor_rust_version {
|
||||||
if let Some(req_msrv) = spec.rust_version() {
|
let req_msrv = spec
|
||||||
|
.rust_version()
|
||||||
|
.cloned()
|
||||||
|
.map(CargoResult::Ok)
|
||||||
|
.unwrap_or_else(|| {
|
||||||
|
let rustc = gctx.load_global_rustc(None)?;
|
||||||
|
|
||||||
|
// 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
|
let msrvs = possibilities
|
||||||
.iter()
|
.iter()
|
||||||
.map(|s| (s, s.rust_version()))
|
.map(|s| (s, s.rust_version()))
|
||||||
@ -625,7 +645,7 @@ fn get_latest_dependency(
|
|||||||
// determine whether or not one rust-version is compatible with another, we
|
// determine whether or not one rust-version is compatible with another, we
|
||||||
// compare the lowest possible versions they could represent, and treat
|
// compare the lowest possible versions they could represent, and treat
|
||||||
// candidates without a rust-version as compatible by default.
|
// candidates without a rust-version as compatible by default.
|
||||||
let latest_msrv = latest_compatible(&msrvs, req_msrv).ok_or_else(|| {
|
let latest_msrv = latest_compatible(&msrvs, &req_msrv).ok_or_else(|| {
|
||||||
let name = spec.name();
|
let name = spec.name();
|
||||||
let dep_name = &dependency.name;
|
let dep_name = &dependency.name;
|
||||||
let latest_version = latest.version();
|
let latest_version = latest.version();
|
||||||
@ -651,7 +671,6 @@ ignoring {dependency}@{latest_version} (which requires rustc {latest_rust_versio
|
|||||||
latest = latest_msrv;
|
latest = latest_msrv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let mut dep = Dependency::from(latest);
|
let mut dep = Dependency::from(latest);
|
||||||
if let Some(reg_name) = dependency.registry.as_deref() {
|
if let Some(reg_name) = dependency.registry.as_deref() {
|
||||||
|
@ -23,7 +23,7 @@ fn case() {
|
|||||||
.current_dir(cwd)
|
.current_dir(cwd)
|
||||||
.masquerade_as_nightly_cargo(&["msrv-policy"])
|
.masquerade_as_nightly_cargo(&["msrv-policy"])
|
||||||
.assert()
|
.assert()
|
||||||
.success()
|
.failure()
|
||||||
.stdout_matches(str![""])
|
.stdout_matches(str![""])
|
||||||
.stderr_matches(file!["stderr.term.svg"]);
|
.stderr_matches(file!["stderr.term.svg"]);
|
||||||
|
|
||||||
|
@ -4,6 +4,3 @@
|
|||||||
name = "cargo-list-test-fixture"
|
name = "cargo-list-test-fixture"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
edition = "2015"
|
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>
|
<style>
|
||||||
.fg { fill: #AAAAAA }
|
.fg { fill: #AAAAAA }
|
||||||
.bg { background: #000000 }
|
.bg { background: #000000 }
|
||||||
.fg-green { fill: #00AA00 }
|
.fg-green { fill: #00AA00 }
|
||||||
|
.fg-red { fill: #AA0000 }
|
||||||
.container {
|
.container {
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
line-height: 18px;
|
line-height: 18px;
|
||||||
@ -20,9 +21,11 @@
|
|||||||
<text xml:space="preserve" class="container fg">
|
<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 x="10px" y="28px"><tspan class="fg-green bold"> Updating</tspan><tspan> `dummy-registry` index</tspan>
|
||||||
</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>
|
||||||
<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>
|
</tspan>
|
||||||
</text>
|
</text>
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 873 B After Width: | Height: | Size: 1.1 KiB |
@ -6,4 +6,4 @@ version = "0.0.0"
|
|||||||
edition = "2015"
|
edition = "2015"
|
||||||
|
|
||||||
[dependencies]
|
[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>
|
<style>
|
||||||
.fg { fill: #AAAAAA }
|
.fg { fill: #AAAAAA }
|
||||||
.bg { background: #000000 }
|
.bg { background: #000000 }
|
||||||
.fg-green { fill: #00AA00 }
|
.fg-green { fill: #00AA00 }
|
||||||
|
.fg-yellow { fill: #AA5500 }
|
||||||
.container {
|
.container {
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
line-height: 18px;
|
line-height: 18px;
|
||||||
@ -20,9 +21,11 @@
|
|||||||
<text xml:space="preserve" class="container fg">
|
<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 x="10px" y="28px"><tspan class="fg-green bold"> Updating</tspan><tspan> `dummy-registry` index</tspan>
|
||||||
</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>
|
||||||
<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>
|
</tspan>
|
||||||
</text>
|
</text>
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 873 B After Width: | Height: | Size: 1.1 KiB |
@ -6,4 +6,4 @@ version = "0.0.0"
|
|||||||
edition = "2015"
|
edition = "2015"
|
||||||
|
|
||||||
[dependencies]
|
[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>
|
<style>
|
||||||
.fg { fill: #AAAAAA }
|
.fg { fill: #AAAAAA }
|
||||||
.bg { background: #000000 }
|
.bg { background: #000000 }
|
||||||
.fg-green { fill: #00AA00 }
|
.fg-green { fill: #00AA00 }
|
||||||
|
.fg-yellow { fill: #AA5500 }
|
||||||
.container {
|
.container {
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
line-height: 18px;
|
line-height: 18px;
|
||||||
@ -20,9 +21,11 @@
|
|||||||
<text xml:space="preserve" class="container fg">
|
<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 x="10px" y="28px"><tspan class="fg-green bold"> Updating</tspan><tspan> `dummy-registry` index</tspan>
|
||||||
</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>
|
||||||
<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>
|
</tspan>
|
||||||
</text>
|
</text>
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 873 B After Width: | Height: | Size: 1.1 KiB |
Loading…
x
Reference in New Issue
Block a user