@@ -68,6 +68,7 @@ impl<'cfg> InstallablePackage<'cfg> {
6868 force : bool ,
6969 no_track : bool ,
7070 needs_update_if_source_is_index : bool ,
71+ current_rust_version : Option < & semver:: Version > ,
7172 ) -> CargoResult < Option < Self > > {
7273 if let Some ( name) = krate {
7374 if name == "." {
@@ -105,6 +106,7 @@ impl<'cfg> InstallablePackage<'cfg> {
105106 dep,
106107 |git : & mut GitSource < ' _ > | git. read_packages ( ) ,
107108 config,
109+ current_rust_version,
108110 ) ?
109111 } else if source_id. is_path ( ) {
110112 let mut src = path_source ( source_id, config) ?;
@@ -142,6 +144,7 @@ impl<'cfg> InstallablePackage<'cfg> {
142144 dep,
143145 |path : & mut PathSource < ' _ > | path. read_packages ( ) ,
144146 config,
147+ current_rust_version,
145148 ) ?
146149 } else if let Some ( dep) = dep {
147150 let mut source = map. load ( source_id, & HashSet :: new ( ) ) ?;
@@ -161,7 +164,13 @@ impl<'cfg> InstallablePackage<'cfg> {
161164 config. shell ( ) . status ( "Ignored" , & msg) ?;
162165 return Ok ( None ) ;
163166 }
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+ ) ?
165174 } else {
166175 bail ! (
167176 "must specify a crate to install from \
@@ -611,19 +620,46 @@ pub fn install(
611620 opts : & ops:: CompileOptions ,
612621 force : bool ,
613622 no_track : bool ,
623+ honor_rust_version : bool ,
614624) -> CargoResult < ( ) > {
615625 let root = resolve_root ( root, config) ?;
616626 let dst = root. join ( "bin" ) . into_path_unlocked ( ) ;
617627 let map = SourceConfigMap :: new ( config) ?;
618628
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+
619644 let ( installed_anything, scheduled_error) = if krates. len ( ) <= 1 {
620645 let ( krate, vers) = krates
621646 . iter ( )
622647 . next ( )
623648 . map ( |( k, v) | ( Some ( k. as_str ( ) ) , v. as_ref ( ) ) )
624649 . unwrap_or ( ( None , None ) ) ;
625650 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 ( ) ,
627663 ) ?;
628664 let mut installed_anything = true ;
629665 if let Some ( installable_pkg) = installable_pkg {
@@ -654,6 +690,7 @@ pub fn install(
654690 force,
655691 no_track,
656692 !did_update,
693+ current_rust_version. as_ref ( ) ,
657694 ) {
658695 Ok ( Some ( installable_pkg) ) => {
659696 did_update = true ;
@@ -773,7 +810,7 @@ where
773810 // expensive network call in the case that the package is already installed.
774811 // If this fails, the caller will possibly do an index update and try again, this is just a
775812 // 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 ) {
777814 let ( _ws, rustc, target) =
778815 make_ws_rustc_target ( config, opts, & source. source_id ( ) , pkg. clone ( ) ) ?;
779816 if let Ok ( true ) = is_installed ( & pkg, config, opts, & rustc, & target, root, dst, force) {
0 commit comments