@@ -1199,7 +1199,6 @@ impl Config {
11991199 }
12001200
12011201 pub fn cargo ( & self ) -> CargoConfig {
1202- let target_directory = self . target_dir_from_config ( ) ;
12031202 let rustc_source = self . data . rustc_source . as_ref ( ) . map ( |rustc_src| {
12041203 if rustc_src == "discover" {
12051204 RustLibSource :: Discover
@@ -1217,10 +1216,6 @@ impl Config {
12171216 let sysroot_src =
12181217 self . data . cargo_sysrootSrc . as_ref ( ) . map ( |sysroot| self . root_path . join ( sysroot) ) ;
12191218
1220- let mut extra_args = self . data . cargo_extraArgs . clone ( ) ;
1221-
1222- add_target_dir_to_args ( & mut extra_args, target_directory) ;
1223-
12241219 CargoConfig {
12251220 features : match & self . data . cargo_features {
12261221 CargoFeaturesDef :: All => CargoFeatures :: All ,
@@ -1273,8 +1268,9 @@ impl Config {
12731268 InvocationLocation :: Workspace => project_model:: InvocationLocation :: Workspace ,
12741269 } ,
12751270 run_build_script_command : self . data . cargo_buildScripts_overrideCommand . clone ( ) ,
1276- extra_args,
1271+ extra_args : self . data . cargo_extraArgs . clone ( ) ,
12771272 extra_env : self . data . cargo_extraEnv . clone ( ) ,
1273+ target_dir : self . target_dir_from_config ( ) ,
12781274 }
12791275 }
12801276
@@ -1293,14 +1289,10 @@ impl Config {
12931289 }
12941290
12951291 pub fn flycheck ( & self ) -> FlycheckConfig {
1296- let target_directory = self . target_dir_from_config ( ) ;
1297-
12981292 match & self . data . check_overrideCommand {
12991293 Some ( args) if !args. is_empty ( ) => {
13001294 let mut args = args. clone ( ) ;
13011295 let command = args. remove ( 0 ) ;
1302- add_target_dir_to_args ( & mut args, target_directory) ;
1303-
13041296 FlycheckConfig :: CustomCommand {
13051297 command,
13061298 args,
@@ -1319,54 +1311,50 @@ impl Config {
13191311 } ,
13201312 }
13211313 }
1322- Some ( _) | None => {
1323- let mut extra_args = self . check_extra_args ( ) ;
1324- add_target_dir_to_args ( & mut extra_args, target_directory) ;
1325-
1326- FlycheckConfig :: CargoCommand {
1327- command : self . data . check_command . clone ( ) ,
1328- target_triples : self
1329- . data
1330- . check_targets
1331- . clone ( )
1332- . and_then ( |targets| match & targets. 0 [ ..] {
1333- [ ] => None ,
1334- targets => Some ( targets. into ( ) ) ,
1335- } )
1336- . unwrap_or_else ( || self . data . cargo_target . clone ( ) . into_iter ( ) . collect ( ) ) ,
1337- all_targets : self . data . check_allTargets ,
1338- no_default_features : self
1339- . data
1340- . check_noDefaultFeatures
1341- . unwrap_or ( self . data . cargo_noDefaultFeatures ) ,
1342- all_features : matches ! (
1343- self . data. check_features. as_ref( ) . unwrap_or( & self . data. cargo_features) ,
1344- CargoFeaturesDef :: All
1345- ) ,
1346- features : match self
1347- . data
1348- . check_features
1349- . clone ( )
1350- . unwrap_or_else ( || self . data . cargo_features . clone ( ) )
1351- {
1352- CargoFeaturesDef :: All => vec ! [ ] ,
1353- CargoFeaturesDef :: Selected ( it) => it,
1354- } ,
1355- extra_args,
1356- extra_env : self . check_extra_env ( ) ,
1357- ansi_color_output : self . color_diagnostic_output ( ) ,
1358- }
1359- }
1314+ Some ( _) | None => FlycheckConfig :: CargoCommand {
1315+ command : self . data . check_command . clone ( ) ,
1316+ target_triples : self
1317+ . data
1318+ . check_targets
1319+ . clone ( )
1320+ . and_then ( |targets| match & targets. 0 [ ..] {
1321+ [ ] => None ,
1322+ targets => Some ( targets. into ( ) ) ,
1323+ } )
1324+ . unwrap_or_else ( || self . data . cargo_target . clone ( ) . into_iter ( ) . collect ( ) ) ,
1325+ all_targets : self . data . check_allTargets ,
1326+ no_default_features : self
1327+ . data
1328+ . check_noDefaultFeatures
1329+ . unwrap_or ( self . data . cargo_noDefaultFeatures ) ,
1330+ all_features : matches ! (
1331+ self . data. check_features. as_ref( ) . unwrap_or( & self . data. cargo_features) ,
1332+ CargoFeaturesDef :: All
1333+ ) ,
1334+ features : match self
1335+ . data
1336+ . check_features
1337+ . clone ( )
1338+ . unwrap_or_else ( || self . data . cargo_features . clone ( ) )
1339+ {
1340+ CargoFeaturesDef :: All => vec ! [ ] ,
1341+ CargoFeaturesDef :: Selected ( it) => it,
1342+ } ,
1343+ extra_args : self . check_extra_args ( ) ,
1344+ extra_env : self . check_extra_env ( ) ,
1345+ ansi_color_output : self . color_diagnostic_output ( ) ,
1346+ target_dir : self . target_dir_from_config ( ) ,
1347+ } ,
13601348 }
13611349 }
13621350
1363- fn target_dir_from_config ( & self ) -> Option < String > {
1351+ fn target_dir_from_config ( & self ) -> Option < PathBuf > {
13641352 self . data
13651353 . rust_analyzerTargetDir
13661354 . as_ref ( )
13671355 . map ( |target_dir| match target_dir {
13681356 TargetDirectory :: UseSubdirectory ( yes) if * yes => {
1369- Some ( String :: from ( "target/rust-analyzer" ) )
1357+ Some ( PathBuf :: from ( "target/rust-analyzer" ) )
13701358 }
13711359 TargetDirectory :: UseSubdirectory ( _) => None ,
13721360 TargetDirectory :: Directory ( dir) => Some ( dir. clone ( ) ) ,
@@ -1725,13 +1713,6 @@ impl Config {
17251713 self . is_visual_studio_code
17261714 }
17271715}
1728-
1729- fn add_target_dir_to_args ( args : & mut Vec < String > , target_dir : Option < String > ) {
1730- if let Some ( target_dir) = target_dir {
1731- args. push ( format ! ( "--target-dir={}" , target_dir) ) ;
1732- }
1733- }
1734-
17351716// Deserialization definitions
17361717
17371718macro_rules! create_bool_or_string_de {
@@ -2084,7 +2065,7 @@ pub enum MemoryLayoutHoverRenderKindDef {
20842065#[ serde( untagged) ]
20852066pub enum TargetDirectory {
20862067 UseSubdirectory ( bool ) ,
2087- Directory ( String ) ,
2068+ Directory ( PathBuf ) ,
20882069}
20892070
20902071macro_rules! _config_data {
@@ -2703,9 +2684,8 @@ mod tests {
27032684 } ) )
27042685 . unwrap ( ) ;
27052686 assert_eq ! ( config. data. rust_analyzerTargetDir, None ) ;
2706- assert_eq ! ( config. cargo( ) . extra_args. len( ) , 0 ) ;
27072687 assert ! (
2708- matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { extra_args , .. } if extra_args . is_empty ( ) )
2688+ matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { target_dir , .. } if target_dir == None )
27092689 ) ;
27102690 }
27112691
@@ -2726,12 +2706,8 @@ mod tests {
27262706 config. data. rust_analyzerTargetDir,
27272707 Some ( TargetDirectory :: UseSubdirectory ( true ) )
27282708 ) ;
2729- assert_eq ! (
2730- config. cargo( ) . extra_args,
2731- vec![ "--target-dir=target/rust-analyzer" . to_string( ) ]
2732- ) ;
27332709 assert ! (
2734- matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { extra_args , .. } if extra_args == vec! [ "-- target-dir=target /rust-analyzer". to_string ( ) ] )
2710+ matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { target_dir , .. } if target_dir == Some ( PathBuf :: from ( " target/rust-analyzer") ) )
27352711 ) ;
27362712 }
27372713
@@ -2750,11 +2726,10 @@ mod tests {
27502726 . unwrap ( ) ;
27512727 assert_eq ! (
27522728 config. data. rust_analyzerTargetDir,
2753- Some ( TargetDirectory :: Directory ( "other_folder" . to_string ( ) ) )
2729+ Some ( TargetDirectory :: Directory ( PathBuf :: from ( "other_folder" ) ) )
27542730 ) ;
2755- assert_eq ! ( config. cargo( ) . extra_args, vec![ "--target-dir=other_folder" . to_string( ) ] ) ;
27562731 assert ! (
2757- matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { extra_args , .. } if extra_args == vec! [ "--target-dir= other_folder". to_string ( ) ] )
2732+ matches!( config. flycheck( ) , FlycheckConfig :: CargoCommand { target_dir , .. } if target_dir == Some ( PathBuf :: from ( " other_folder") ) )
27582733 ) ;
27592734 }
27602735}
0 commit comments