@@ -7,6 +7,7 @@ use std::io::prelude::*;
7
7
use std:: io:: SeekFrom ;
8
8
use std:: path:: { Path , PathBuf } ;
9
9
10
+ use semver:: Version ;
10
11
use tempdir:: TempDir ;
11
12
use toml;
12
13
@@ -57,7 +58,7 @@ pub fn install(root: Option<&str>,
57
58
let map = SourceConfigMap :: new ( config) ?;
58
59
let ( pkg, source) = if source_id. is_git ( ) {
59
60
select_pkg ( GitSource :: new ( source_id, config) , source_id,
60
- krate, vers, & mut |git| git. read_packages ( ) ) ?
61
+ krate, vers, config , & mut |git| git. read_packages ( ) ) ?
61
62
} else if source_id. is_path ( ) {
62
63
let path = source_id. url ( ) . to_file_path ( ) . ok ( )
63
64
. expect ( "path sources must have a valid path" ) ;
@@ -68,11 +69,11 @@ pub fn install(root: Option<&str>,
68
69
specify an alternate source", path. display( ) ) )
69
70
} ) ?;
70
71
select_pkg ( PathSource :: new ( & path, source_id, config) ,
71
- source_id, krate, vers,
72
+ source_id, krate, vers, config ,
72
73
& mut |path| path. read_packages ( ) ) ?
73
74
} else {
74
75
select_pkg ( map. load ( source_id) ?,
75
- source_id, krate, vers,
76
+ source_id, krate, vers, config ,
76
77
& mut |_| Err ( human ( "must specify a crate to install from \
77
78
crates.io, or use --path or --git to \
78
79
specify alternate source") ) ) ?
@@ -251,13 +252,34 @@ fn select_pkg<'a, T>(mut source: T,
251
252
source_id : & SourceId ,
252
253
name : Option < & str > ,
253
254
vers : Option < & str > ,
255
+ config : & Config ,
254
256
list_all : & mut FnMut ( & mut T ) -> CargoResult < Vec < Package > > )
255
257
-> CargoResult < ( Package , Box < Source + ' a > ) >
256
258
where T : Source + ' a
257
259
{
258
260
source. update ( ) ?;
259
261
match name {
260
262
Some ( name) => {
263
+ let vers = match vers {
264
+ Some ( v) => {
265
+ match v. parse :: < Version > ( ) {
266
+ Ok ( v) => Some ( format ! ( "={}" , v) ) ,
267
+ Err ( _) => {
268
+ let msg = format ! ( "the `--vers` provided, `{}`, is \
269
+ not a valid semver version\n \n \
270
+ historically Cargo treated this \
271
+ as a semver version requirement \
272
+ accidentally\n and will continue \
273
+ to do so, but this behavior \
274
+ will be removed eventually", v) ;
275
+ config. shell ( ) . warn ( & msg) ?;
276
+ Some ( v. to_string ( ) )
277
+ }
278
+ }
279
+ }
280
+ None => None ,
281
+ } ;
282
+ let vers = vers. as_ref ( ) . map ( |s| & * * s) ;
261
283
let dep = Dependency :: parse_no_deprecated ( name, vers, source_id) ?;
262
284
let deps = source. query ( & dep) ?;
263
285
match deps. iter ( ) . map ( |p| p. package_id ( ) ) . max ( ) {
0 commit comments