@@ -11,10 +11,10 @@ use crate::ops::{common_for_install_and_uninstall::*, FilterRule};
11
11
use crate :: ops:: { CompileFilter , Packages } ;
12
12
use crate :: sources:: { GitSource , PathSource , SourceConfigMap } ;
13
13
use crate :: util:: errors:: CargoResult ;
14
- use crate :: util:: { Config , Filesystem , Rustc , ToSemver , VersionReqExt } ;
14
+ use crate :: util:: { Config , Filesystem , Rustc } ;
15
15
use crate :: { drop_println, ops} ;
16
16
17
- use anyhow:: { bail, format_err , Context as _} ;
17
+ use anyhow:: { bail, Context as _} ;
18
18
use cargo_util:: paths;
19
19
use itertools:: Itertools ;
20
20
use semver:: VersionReq ;
@@ -38,12 +38,12 @@ impl Drop for Transaction {
38
38
}
39
39
}
40
40
41
- struct InstallablePackage < ' cfg , ' a > {
41
+ struct InstallablePackage < ' cfg > {
42
42
config : & ' cfg Config ,
43
43
opts : ops:: CompileOptions ,
44
44
root : Filesystem ,
45
45
source_id : SourceId ,
46
- vers : Option < & ' a str > ,
46
+ vers : Option < VersionReq > ,
47
47
force : bool ,
48
48
no_track : bool ,
49
49
@@ -53,7 +53,7 @@ struct InstallablePackage<'cfg, 'a> {
53
53
target : String ,
54
54
}
55
55
56
- impl < ' cfg , ' a > InstallablePackage < ' cfg , ' a > {
56
+ impl < ' cfg > InstallablePackage < ' cfg > {
57
57
// Returns pkg to install. None if pkg is already installed
58
58
pub fn new (
59
59
config : & ' cfg Config ,
@@ -62,12 +62,12 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
62
62
krate : Option < & str > ,
63
63
source_id : SourceId ,
64
64
from_cwd : bool ,
65
- vers : Option < & ' a str > ,
66
- original_opts : & ' a ops:: CompileOptions ,
65
+ vers : Option < & VersionReq > ,
66
+ original_opts : & ops:: CompileOptions ,
67
67
force : bool ,
68
68
no_track : bool ,
69
69
needs_update_if_source_is_index : bool ,
70
- ) -> CargoResult < Option < InstallablePackage < ' cfg , ' a > > > {
70
+ ) -> CargoResult < Option < Self > > {
71
71
if let Some ( name) = krate {
72
72
if name == "." {
73
73
bail ! (
@@ -82,8 +82,8 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
82
82
let pkg = {
83
83
let dep = {
84
84
if let Some ( krate) = krate {
85
- let vers = if let Some ( vers_flag ) = vers {
86
- Some ( parse_semver_flag ( vers_flag ) ? . to_string ( ) )
85
+ let vers = if let Some ( vers ) = vers {
86
+ Some ( vers . to_string ( ) )
87
87
} else if source_id. is_registry ( ) {
88
88
// Avoid pre-release versions from crate.io
89
89
// unless explicitly asked for
@@ -234,7 +234,7 @@ impl<'cfg, 'a> InstallablePackage<'cfg, 'a> {
234
234
opts,
235
235
root,
236
236
source_id,
237
- vers,
237
+ vers : vers . cloned ( ) ,
238
238
force,
239
239
no_track,
240
240
@@ -604,7 +604,7 @@ Consider enabling some of the needed features by passing, e.g., `--features=\"{e
604
604
pub fn install (
605
605
config : & Config ,
606
606
root : Option < & str > ,
607
- krates : Vec < ( String , Option < String > ) > ,
607
+ krates : Vec < ( String , Option < VersionReq > ) > ,
608
608
source_id : SourceId ,
609
609
from_cwd : bool ,
610
610
opts : & ops:: CompileOptions ,
@@ -619,7 +619,7 @@ pub fn install(
619
619
let ( krate, vers) = krates
620
620
. iter ( )
621
621
. next ( )
622
- . map ( |( k, v) | ( Some ( k. as_str ( ) ) , v. as_deref ( ) ) )
622
+ . map ( |( k, v) | ( Some ( k. as_str ( ) ) , v. as_ref ( ) ) )
623
623
. unwrap_or ( ( None , None ) ) ;
624
624
let installable_pkg = InstallablePackage :: new (
625
625
config, root, map, krate, source_id, from_cwd, vers, opts, force, no_track, true ,
@@ -648,7 +648,7 @@ pub fn install(
648
648
Some ( krate. as_str ( ) ) ,
649
649
source_id,
650
650
from_cwd,
651
- vers. as_deref ( ) ,
651
+ vers. as_ref ( ) ,
652
652
opts,
653
653
force,
654
654
no_track,
@@ -805,54 +805,6 @@ fn make_ws_rustc_target<'cfg>(
805
805
Ok ( ( ws, rustc, target) )
806
806
}
807
807
808
- /// Parses x.y.z as if it were =x.y.z, and gives CLI-specific error messages in the case of invalid
809
- /// values.
810
- fn parse_semver_flag ( v : & str ) -> CargoResult < VersionReq > {
811
- // If the version begins with character <, >, =, ^, ~ parse it as a
812
- // version range, otherwise parse it as a specific version
813
- let first = v
814
- . chars ( )
815
- . next ( )
816
- . ok_or_else ( || format_err ! ( "no version provided for the `--version` flag" ) ) ?;
817
-
818
- let is_req = "<>=^~" . contains ( first) || v. contains ( '*' ) ;
819
- if is_req {
820
- match v. parse :: < VersionReq > ( ) {
821
- Ok ( v) => Ok ( v) ,
822
- Err ( _) => bail ! (
823
- "the `--version` provided, `{}`, is \
824
- not a valid semver version requirement\n \n \
825
- Please have a look at \
826
- https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html \
827
- for the correct format",
828
- v
829
- ) ,
830
- }
831
- } else {
832
- match v. to_semver ( ) {
833
- Ok ( v) => Ok ( VersionReq :: exact ( & v) ) ,
834
- Err ( e) => {
835
- let mut msg = format ! (
836
- "the `--version` provided, `{}`, is \
837
- not a valid semver version: {}\n ",
838
- v, e
839
- ) ;
840
-
841
- // If it is not a valid version but it is a valid version
842
- // requirement, add a note to the warning
843
- if v. parse :: < VersionReq > ( ) . is_ok ( ) {
844
- msg. push_str ( & format ! (
845
- "\n if you want to specify semver range, \
846
- add an explicit qualifier, like ^{}",
847
- v
848
- ) ) ;
849
- }
850
- bail ! ( msg) ;
851
- }
852
- }
853
- }
854
- }
855
-
856
808
/// Display a list of installed binaries.
857
809
pub fn install_list ( dst : Option < & str > , config : & Config ) -> CargoResult < ( ) > {
858
810
let root = resolve_root ( dst, config) ?;
0 commit comments