@@ -971,38 +971,40 @@ fn update_manifest_with_new_member(
971
971
workspace_document : & mut toml_edit:: DocumentMut ,
972
972
display_path : & str ,
973
973
) -> CargoResult < bool > {
974
+ let Some ( workspace) = workspace_document. get_mut ( "workspace" ) else {
975
+ return Ok ( false ) ;
976
+ } ;
977
+
974
978
// If the members element already exist, check if one of the patterns
975
979
// in the array already includes the new package's relative path.
976
980
// - Add the relative path if the members don't match the new package's path.
977
981
// - Create a new members array if there are no members element in the workspace yet.
978
- if let Some ( workspace) = workspace_document. get_mut ( "workspace" ) {
979
- if let Some ( members) = workspace
980
- . get_mut ( "members" )
981
- . and_then ( |members| members. as_array_mut ( ) )
982
- {
983
- for member in members. iter ( ) {
984
- let pat = member
985
- . as_str ( )
986
- . with_context ( || format ! ( "invalid non-string member `{}`" , member) ) ?;
987
- let pattern = glob:: Pattern :: new ( pat)
988
- . with_context ( || format ! ( "cannot build glob pattern from `{}`" , pat) ) ?;
989
-
990
- if pattern. matches ( & display_path) {
991
- return Ok ( false ) ;
992
- }
993
- }
982
+ if let Some ( members) = workspace
983
+ . get_mut ( "members" )
984
+ . and_then ( |members| members. as_array_mut ( ) )
985
+ {
986
+ for member in members. iter ( ) {
987
+ let pat = member
988
+ . as_str ( )
989
+ . with_context ( || format ! ( "invalid non-string member `{}`" , member) ) ?;
990
+ let pattern = glob:: Pattern :: new ( pat)
991
+ . with_context ( || format ! ( "cannot build glob pattern from `{}`" , pat) ) ?;
994
992
995
- let was_sorted = is_sorted ( members. iter ( ) . map ( Value :: as_str) ) ;
996
- members. push ( display_path) ;
997
- if was_sorted {
998
- members. sort_by ( |lhs, rhs| lhs. as_str ( ) . cmp ( & rhs. as_str ( ) ) ) ;
993
+ if pattern. matches ( & display_path) {
994
+ return Ok ( false ) ;
999
995
}
1000
- } else {
1001
- let mut array = Array :: new ( ) ;
1002
- array. push ( display_path) ;
996
+ }
1003
997
1004
- workspace[ "members" ] = toml_edit:: value ( array) ;
998
+ let was_sorted = is_sorted ( members. iter ( ) . map ( Value :: as_str) ) ;
999
+ members. push ( display_path) ;
1000
+ if was_sorted {
1001
+ members. sort_by ( |lhs, rhs| lhs. as_str ( ) . cmp ( & rhs. as_str ( ) ) ) ;
1005
1002
}
1003
+ } else {
1004
+ let mut array = Array :: new ( ) ;
1005
+ array. push ( display_path) ;
1006
+
1007
+ workspace[ "members" ] = toml_edit:: value ( array) ;
1006
1008
}
1007
1009
1008
1010
write_atomic (
0 commit comments