@@ -816,11 +816,8 @@ fn mk(config: &Config, opts: &MkOptions<'_>) -> CargoResult<()> {
816
816
// This should not block the creation of the new project. It is only a best effort to
817
817
// inherit the workspace package keys.
818
818
if let Ok ( mut workspace_document) = root_manifest. parse :: < toml_edit:: Document > ( ) {
819
- let ( display_path, can_be_a_member) = get_display_path_and_check_membership (
820
- & root_manifest_path,
821
- & path,
822
- & workspace_document,
823
- ) ?;
819
+ let display_path = get_display_path ( & root_manifest_path, & path) ?;
820
+ let can_be_a_member = can_be_workspace_member ( & display_path, & workspace_document) ?;
824
821
// Only try to inherit the workspace stuff if the new package can be a member of the workspace.
825
822
if can_be_a_member {
826
823
if let Some ( workspace_package_keys) = workspace_document
@@ -1003,11 +1000,7 @@ fn update_manifest_with_new_member(
1003
1000
)
1004
1001
}
1005
1002
1006
- fn get_display_path_and_check_membership (
1007
- root_manifest_path : & Path ,
1008
- package_path : & Path ,
1009
- workspace_document : & toml_edit:: Document ,
1010
- ) -> CargoResult < ( String , bool ) > {
1003
+ fn get_display_path ( root_manifest_path : & Path , package_path : & Path ) -> CargoResult < String > {
1011
1004
// Find the relative path for the package from the workspace root directory.
1012
1005
let workspace_root = root_manifest_path. parent ( ) . with_context ( || {
1013
1006
format ! (
@@ -1031,7 +1024,14 @@ fn get_display_path_and_check_membership(
1031
1024
components. push ( comp) ;
1032
1025
}
1033
1026
let display_path = components. join ( "/" ) ;
1027
+ Ok ( display_path)
1028
+ }
1034
1029
1030
+ // Check if the package can be a member of the workspace.
1031
+ fn can_be_workspace_member (
1032
+ display_path : & str ,
1033
+ workspace_document : & toml_edit:: Document ,
1034
+ ) -> CargoResult < bool > {
1035
1035
if let Some ( exclude) = workspace_document
1036
1036
. get ( "workspace" )
1037
1037
. and_then ( |workspace| workspace. get ( "exclude" ) )
@@ -1042,10 +1042,9 @@ fn get_display_path_and_check_membership(
1042
1042
. as_str ( )
1043
1043
. with_context ( || format ! ( "invalid non-string exclude path `{}`" , member) ) ?;
1044
1044
if pat == display_path {
1045
- return Ok ( ( display_path , false ) ) ;
1045
+ return Ok ( false ) ;
1046
1046
}
1047
1047
}
1048
1048
}
1049
-
1050
- Ok ( ( display_path, true ) )
1049
+ Ok ( true )
1051
1050
}
0 commit comments