@@ -51,6 +51,8 @@ pub struct AddOptions<'a> {
51
51
pub section : DepTable ,
52
52
/// Act as if dependencies will be added
53
53
pub dry_run : bool ,
54
+ /// Whether the minimum supported Rust version should be considered during resolution
55
+ pub honor_rust_version : bool ,
54
56
}
55
57
56
58
/// Add dependencies to a manifest
@@ -88,6 +90,7 @@ pub fn add(workspace: &Workspace<'_>, options: &AddOptions<'_>) -> CargoResult<(
88
90
workspace,
89
91
& options. spec ,
90
92
& options. section ,
93
+ options. honor_rust_version ,
91
94
options. config ,
92
95
& mut registry,
93
96
)
@@ -259,6 +262,7 @@ fn resolve_dependency(
259
262
ws : & Workspace < ' _ > ,
260
263
spec : & Package ,
261
264
section : & DepTable ,
265
+ honor_rust_version : bool ,
262
266
config : & Config ,
263
267
registry : & mut PackageRegistry < ' _ > ,
264
268
) -> CargoResult < DependencyUI > {
@@ -370,7 +374,14 @@ fn resolve_dependency(
370
374
}
371
375
dependency = dependency. set_source ( src) ;
372
376
} else {
373
- let latest = get_latest_dependency ( spec, & dependency, false , config, registry) ?;
377
+ let latest = get_latest_dependency (
378
+ spec,
379
+ & dependency,
380
+ false ,
381
+ honor_rust_version,
382
+ config,
383
+ registry,
384
+ ) ?;
374
385
375
386
if dependency. name != latest. name {
376
387
config. shell ( ) . warn ( format ! (
@@ -523,6 +534,7 @@ fn get_latest_dependency(
523
534
spec : & Package ,
524
535
dependency : & Dependency ,
525
536
_flag_allow_prerelease : bool ,
537
+ honor_rust_version : bool ,
526
538
config : & Config ,
527
539
registry : & mut PackageRegistry < ' _ > ,
528
540
) -> CargoResult < Dependency > {
@@ -554,7 +566,7 @@ fn get_latest_dependency(
554
566
)
555
567
} ) ?;
556
568
557
- if config. cli_unstable ( ) . msrv_policy {
569
+ if config. cli_unstable ( ) . msrv_policy && honor_rust_version {
558
570
fn parse_msrv ( rust_version : impl AsRef < str > ) -> ( u64 , u64 , u64 ) {
559
571
// HACK: `rust-version` is a subset of the `VersionReq` syntax that only ever
560
572
// has one comparator with a required minor and optional patch, and uses no
@@ -602,7 +614,7 @@ fn get_latest_dependency(
602
614
config. shell ( ) . warn ( format_args ! (
603
615
"ignoring `{dependency}@{latest_version}` (which has a rust-version of \
604
616
{latest_rust_version}) to satisfy this package's rust-version of \
605
- {rust_version}",
617
+ {rust_version} (use `--ignore-rust-version` to override) ",
606
618
latest_version = latest. version( ) ,
607
619
latest_rust_version = latest. rust_version( ) . unwrap( ) ,
608
620
rust_version = spec. rust_version( ) . unwrap( ) ,
@@ -629,7 +641,8 @@ fn rust_version_incompat_error(
629
641
) -> anyhow:: Error {
630
642
let mut error_msg = format ! (
631
643
"could not find version of crate `{dep}` that satisfies this package's rust-version of \
632
- {rust_version}"
644
+ {rust_version}\n \
645
+ help: use `--ignore-rust-version` to override this behavior"
633
646
) ;
634
647
635
648
if let Some ( lowest) = lowest_rust_version {
0 commit comments