@@ -4,7 +4,7 @@ use std::mem;
44
55use cfg:: { CfgAtom , CfgExpr } ;
66use ide:: { FileId , RunnableKind , TestId } ;
7- use project_model:: { self , ManifestPath , TargetKind } ;
7+ use project_model:: { self , CargoFeatures , ManifestPath , TargetKind } ;
88use vfs:: AbsPathBuf ;
99
1010use crate :: { global_state:: GlobalStateSnapshot , Result } ;
@@ -35,41 +35,41 @@ impl CargoTargetSpec {
3535
3636 match kind {
3737 RunnableKind :: Test { test_id, attr } => {
38- args. push ( "test" . to_string ( ) ) ;
38+ args. push ( "test" . to_owned ( ) ) ;
3939 extra_args. push ( test_id. to_string ( ) ) ;
4040 if let TestId :: Path ( _) = test_id {
41- extra_args. push ( "--exact" . to_string ( ) ) ;
41+ extra_args. push ( "--exact" . to_owned ( ) ) ;
4242 }
43- extra_args. push ( "--nocapture" . to_string ( ) ) ;
43+ extra_args. push ( "--nocapture" . to_owned ( ) ) ;
4444 if attr. ignore {
45- extra_args. push ( "--ignored" . to_string ( ) ) ;
45+ extra_args. push ( "--ignored" . to_owned ( ) ) ;
4646 }
4747 }
4848 RunnableKind :: TestMod { path } => {
49- args. push ( "test" . to_string ( ) ) ;
50- extra_args. push ( path. to_string ( ) ) ;
51- extra_args. push ( "--nocapture" . to_string ( ) ) ;
49+ args. push ( "test" . to_owned ( ) ) ;
50+ extra_args. push ( path. clone ( ) ) ;
51+ extra_args. push ( "--nocapture" . to_owned ( ) ) ;
5252 }
5353 RunnableKind :: Bench { test_id } => {
54- args. push ( "bench" . to_string ( ) ) ;
54+ args. push ( "bench" . to_owned ( ) ) ;
5555 extra_args. push ( test_id. to_string ( ) ) ;
5656 if let TestId :: Path ( _) = test_id {
57- extra_args. push ( "--exact" . to_string ( ) ) ;
57+ extra_args. push ( "--exact" . to_owned ( ) ) ;
5858 }
59- extra_args. push ( "--nocapture" . to_string ( ) ) ;
59+ extra_args. push ( "--nocapture" . to_owned ( ) ) ;
6060 }
6161 RunnableKind :: DocTest { test_id } => {
62- args. push ( "test" . to_string ( ) ) ;
63- args. push ( "--doc" . to_string ( ) ) ;
62+ args. push ( "test" . to_owned ( ) ) ;
63+ args. push ( "--doc" . to_owned ( ) ) ;
6464 extra_args. push ( test_id. to_string ( ) ) ;
65- extra_args. push ( "--nocapture" . to_string ( ) ) ;
65+ extra_args. push ( "--nocapture" . to_owned ( ) ) ;
6666 }
6767 RunnableKind :: Bin => {
6868 let subcommand = match spec {
6969 Some ( CargoTargetSpec { target_kind : TargetKind :: Test , .. } ) => "test" ,
7070 _ => "run" ,
7171 } ;
72- args. push ( subcommand. to_string ( ) ) ;
72+ args. push ( subcommand. to_owned ( ) ) ;
7373 }
7474 }
7575
@@ -82,29 +82,35 @@ impl CargoTargetSpec {
8282 } ;
8383
8484 let cargo_config = snap. config . cargo ( ) ;
85- if cargo_config. all_features {
86- args. push ( "--all-features" . to_string ( ) ) ;
8785
88- for feature in target_required_features {
89- args. push ( "--features" . to_string ( ) ) ;
90- args. push ( feature) ;
91- }
92- } else {
93- let mut features = Vec :: new ( ) ;
94- if let Some ( cfg) = cfg. as_ref ( ) {
95- required_features ( cfg, & mut features) ;
86+ match & cargo_config. features {
87+ CargoFeatures :: All => {
88+ args. push ( "--all-features" . to_owned ( ) ) ;
89+ for feature in target_required_features {
90+ args. push ( "--features" . to_owned ( ) ) ;
91+ args. push ( feature) ;
92+ }
9693 }
94+ CargoFeatures :: Selected { features, no_default_features } => {
95+ let mut feats = Vec :: new ( ) ;
96+ if let Some ( cfg) = cfg. as_ref ( ) {
97+ required_features ( cfg, & mut feats) ;
98+ }
9799
98- features . extend ( cargo_config . features ) ;
99- features . extend ( target_required_features) ;
100+ feats . extend ( features. iter ( ) . cloned ( ) ) ;
101+ feats . extend ( target_required_features) ;
100102
101- features. dedup ( ) ;
102- for feature in features {
103- args. push ( "--features" . to_string ( ) ) ;
104- args. push ( feature) ;
103+ feats. dedup ( ) ;
104+ for feature in feats {
105+ args. push ( "--features" . to_owned ( ) ) ;
106+ args. push ( feature) ;
107+ }
108+
109+ if * no_default_features {
110+ args. push ( "--no-default-features" . to_owned ( ) ) ;
111+ }
105112 }
106113 }
107-
108114 Ok ( ( args, extra_args) )
109115 }
110116
@@ -136,7 +142,7 @@ impl CargoTargetSpec {
136142 }
137143
138144 pub ( crate ) fn push_to ( self , buf : & mut Vec < String > , kind : & RunnableKind ) {
139- buf. push ( "--package" . to_string ( ) ) ;
145+ buf. push ( "--package" . to_owned ( ) ) ;
140146 buf. push ( self . package ) ;
141147
142148 // Can't mix --doc with other target flags
@@ -145,23 +151,23 @@ impl CargoTargetSpec {
145151 }
146152 match self . target_kind {
147153 TargetKind :: Bin => {
148- buf. push ( "--bin" . to_string ( ) ) ;
154+ buf. push ( "--bin" . to_owned ( ) ) ;
149155 buf. push ( self . target ) ;
150156 }
151157 TargetKind :: Test => {
152- buf. push ( "--test" . to_string ( ) ) ;
158+ buf. push ( "--test" . to_owned ( ) ) ;
153159 buf. push ( self . target ) ;
154160 }
155161 TargetKind :: Bench => {
156- buf. push ( "--bench" . to_string ( ) ) ;
162+ buf. push ( "--bench" . to_owned ( ) ) ;
157163 buf. push ( self . target ) ;
158164 }
159165 TargetKind :: Example => {
160- buf. push ( "--example" . to_string ( ) ) ;
166+ buf. push ( "--example" . to_owned ( ) ) ;
161167 buf. push ( self . target ) ;
162168 }
163169 TargetKind :: Lib => {
164- buf. push ( "--lib" . to_string ( ) ) ;
170+ buf. push ( "--lib" . to_owned ( ) ) ;
165171 }
166172 TargetKind :: Other | TargetKind :: BuildScript => ( ) ,
167173 }
0 commit comments