@@ -68,6 +68,7 @@ impl<'cfg> InstallablePackage<'cfg> {
68
68
force : bool ,
69
69
no_track : bool ,
70
70
needs_update_if_source_is_index : bool ,
71
+ current_rust_version : Option < & semver:: Version > ,
71
72
) -> CargoResult < Option < Self > > {
72
73
if let Some ( name) = krate {
73
74
if name == "." {
@@ -105,6 +106,7 @@ impl<'cfg> InstallablePackage<'cfg> {
105
106
dep,
106
107
|git : & mut GitSource < ' _ > | git. read_packages ( ) ,
107
108
config,
109
+ current_rust_version,
108
110
) ?
109
111
} else if source_id. is_path ( ) {
110
112
let mut src = path_source ( source_id, config) ?;
@@ -142,6 +144,7 @@ impl<'cfg> InstallablePackage<'cfg> {
142
144
dep,
143
145
|path : & mut PathSource < ' _ > | path. read_packages ( ) ,
144
146
config,
147
+ current_rust_version,
145
148
) ?
146
149
} else if let Some ( dep) = dep {
147
150
let mut source = map. load ( source_id, & HashSet :: new ( ) ) ?;
@@ -161,7 +164,13 @@ impl<'cfg> InstallablePackage<'cfg> {
161
164
config. shell ( ) . status ( "Ignored" , & msg) ?;
162
165
return Ok ( None ) ;
163
166
}
164
- select_dep_pkg ( & mut source, dep, config, needs_update_if_source_is_index) ?
167
+ select_dep_pkg (
168
+ & mut source,
169
+ dep,
170
+ config,
171
+ needs_update_if_source_is_index,
172
+ current_rust_version,
173
+ ) ?
165
174
} else {
166
175
bail ! (
167
176
"must specify a crate to install from \
@@ -611,19 +620,46 @@ pub fn install(
611
620
opts : & ops:: CompileOptions ,
612
621
force : bool ,
613
622
no_track : bool ,
623
+ honor_rust_version : bool ,
614
624
) -> CargoResult < ( ) > {
615
625
let root = resolve_root ( root, config) ?;
616
626
let dst = root. join ( "bin" ) . into_path_unlocked ( ) ;
617
627
let map = SourceConfigMap :: new ( config) ?;
618
628
629
+ let current_rust_version = if honor_rust_version {
630
+ let rustc = config. load_global_rustc ( None ) ?;
631
+
632
+ // Remove any pre-release identifiers for easier comparison
633
+ let current_version = & rustc. version ;
634
+ let untagged_version = semver:: Version :: new (
635
+ current_version. major ,
636
+ current_version. minor ,
637
+ current_version. patch ,
638
+ ) ;
639
+ Some ( untagged_version)
640
+ } else {
641
+ None
642
+ } ;
643
+
619
644
let ( installed_anything, scheduled_error) = if krates. len ( ) <= 1 {
620
645
let ( krate, vers) = krates
621
646
. iter ( )
622
647
. next ( )
623
648
. map ( |( k, v) | ( Some ( k. as_str ( ) ) , v. as_ref ( ) ) )
624
649
. unwrap_or ( ( None , None ) ) ;
625
650
let installable_pkg = InstallablePackage :: new (
626
- config, root, map, krate, source_id, from_cwd, vers, opts, force, no_track, true ,
651
+ config,
652
+ root,
653
+ map,
654
+ krate,
655
+ source_id,
656
+ from_cwd,
657
+ vers,
658
+ opts,
659
+ force,
660
+ no_track,
661
+ true ,
662
+ current_rust_version. as_ref ( ) ,
627
663
) ?;
628
664
let mut installed_anything = true ;
629
665
if let Some ( installable_pkg) = installable_pkg {
@@ -654,6 +690,7 @@ pub fn install(
654
690
force,
655
691
no_track,
656
692
!did_update,
693
+ current_rust_version. as_ref ( ) ,
657
694
) {
658
695
Ok ( Some ( installable_pkg) ) => {
659
696
did_update = true ;
@@ -773,7 +810,7 @@ where
773
810
// expensive network call in the case that the package is already installed.
774
811
// If this fails, the caller will possibly do an index update and try again, this is just a
775
812
// best-effort check to see if we can avoid hitting the network.
776
- if let Ok ( pkg) = select_dep_pkg ( source, dep, config, false ) {
813
+ if let Ok ( pkg) = select_dep_pkg ( source, dep, config, false , None ) {
777
814
let ( _ws, rustc, target) =
778
815
make_ws_rustc_target ( config, opts, & source. source_id ( ) , pkg. clone ( ) ) ?;
779
816
if let Ok ( true ) = is_installed ( & pkg, config, opts, & rustc, & target, root, dst, force) {
0 commit comments