@@ -63,7 +63,12 @@ pub(crate) enum Target {
6363}
6464
6565impl CargoOptions {
66- pub ( crate ) fn apply_on_command ( & self , cmd : & mut Command , ws_target_dir : Option < & Utf8Path > ) {
66+ pub ( crate ) fn apply_on_command (
67+ & self ,
68+ cmd : & mut Command ,
69+ ws_target_dir : Option < & Utf8Path > ,
70+ package_repr : Option < & str > ,
71+ ) {
6772 for target in & self . target_tuples {
6873 cmd. args ( [ "--target" , target. as_str ( ) ] ) ;
6974 }
@@ -83,8 +88,24 @@ impl CargoOptions {
8388 cmd. arg ( "--no-default-features" ) ;
8489 }
8590 if !self . features . is_empty ( ) {
91+ // If we are scoped to a particular package, filter any features of the form
92+ // `crate/feature` which target other packages.
93+ let features = if let Some ( name) = package_repr {
94+ let filtered = self
95+ . features
96+ . iter ( )
97+ . filter ( |f| match f. split_once ( '/' ) {
98+ Some ( ( c, _) ) => c == name,
99+ None => true ,
100+ } )
101+ . map ( |s| s. as_str ( ) )
102+ . collect :: < Vec < _ > > ( ) ;
103+ filtered. join ( " " )
104+ } else {
105+ self . features . join ( " " )
106+ } ;
86107 cmd. arg ( "--features" ) ;
87- cmd. arg ( self . features . join ( " " ) ) ;
108+ cmd. arg ( features) ;
88109 }
89110 }
90111 if let Some ( target_dir) = self . target_dir_config . target_dir ( ws_target_dir) {
@@ -890,12 +911,18 @@ impl FlycheckActor {
890911 cmd. env ( "CARGO_LOG" , "cargo::core::compiler::fingerprint=info" ) ;
891912 cmd. arg ( & cargo_options. subcommand ) ;
892913
893- match scope {
894- FlycheckScope :: Workspace => cmd. arg ( "--workspace" ) ,
914+ let package_repr = match scope {
915+ FlycheckScope :: Workspace => {
916+ cmd. arg ( "--workspace" ) ;
917+ None
918+ }
895919 FlycheckScope :: Package {
896920 package : PackageSpecifier :: Cargo { package_id } ,
897921 ..
898- } => cmd. arg ( "-p" ) . arg ( & package_id. repr ) ,
922+ } => {
923+ cmd. arg ( "-p" ) . arg ( & package_id. repr ) ;
924+ Some ( package_id. repr . as_str ( ) )
925+ }
899926 FlycheckScope :: Package {
900927 package : PackageSpecifier :: BuildInfo { .. } , ..
901928 } => {
@@ -935,6 +962,7 @@ impl FlycheckActor {
935962 cargo_options. apply_on_command (
936963 & mut cmd,
937964 self . ws_target_dir . as_ref ( ) . map ( Utf8PathBuf :: as_path) ,
965+ package_repr,
938966 ) ;
939967 cmd. args ( & cargo_options. extra_args ) ;
940968 Some ( ( cmd, FlycheckCommandOrigin :: Cargo ) )
0 commit comments