@@ -520,28 +520,12 @@ pub fn to_real_manifest(
520
520
( None , None ) => bail ! ( "no `package` section found" ) ,
521
521
} ;
522
522
523
- let workspace_config = match ( original_toml. workspace . as_ref ( ) , package. workspace . as_ref ( ) ) {
524
- ( Some ( toml_config) , None ) => {
525
- verify_lints ( toml_config. lints . as_ref ( ) , gctx, warnings) ?;
526
- if let Some ( ws_deps) = & toml_config. dependencies {
527
- for ( name, dep) in ws_deps {
528
- unused_dep_keys ( name, "workspace.dependencies" , dep. unused_keys ( ) , warnings) ;
529
- }
530
- }
531
- let ws_root_config = to_workspace_config ( toml_config, package_root) ;
532
- gctx. ws_roots
533
- . borrow_mut ( )
534
- . insert ( package_root. to_path_buf ( ) , ws_root_config. clone ( ) ) ;
535
- WorkspaceConfig :: Root ( ws_root_config)
536
- }
537
- ( None , root) => WorkspaceConfig :: Member {
538
- root : root. cloned ( ) ,
539
- } ,
540
- ( Some ( ..) , Some ( ..) ) => bail ! (
541
- "cannot configure both `package.workspace` and \
542
- `[workspace]`, only one can be specified"
543
- ) ,
544
- } ;
523
+ let workspace_config = to_workspace_config ( & original_toml, package_root, gctx, warnings) ?;
524
+ if let WorkspaceConfig :: Root ( ws_root_config) = & workspace_config {
525
+ gctx. ws_roots
526
+ . borrow_mut ( )
527
+ . insert ( package_root. to_owned ( ) , ws_root_config. clone ( ) ) ;
528
+ }
545
529
let inherit_cell: LazyCell < InheritableFields > = LazyCell :: new ( ) ;
546
530
let inherit = || {
547
531
inherit_cell
@@ -1229,6 +1213,37 @@ fn resolve_and_validate_dependencies(
1229
1213
}
1230
1214
1231
1215
fn to_workspace_config (
1216
+ original_toml : & manifest:: TomlManifest ,
1217
+ package_root : & Path ,
1218
+ gctx : & GlobalContext ,
1219
+ warnings : & mut Vec < String > ,
1220
+ ) -> CargoResult < WorkspaceConfig > {
1221
+ let workspace_config = match (
1222
+ original_toml. workspace . as_ref ( ) ,
1223
+ original_toml. package ( ) . and_then ( |p| p. workspace . as_ref ( ) ) ,
1224
+ ) {
1225
+ ( Some ( toml_config) , None ) => {
1226
+ verify_lints ( toml_config. lints . as_ref ( ) , gctx, warnings) ?;
1227
+ if let Some ( ws_deps) = & toml_config. dependencies {
1228
+ for ( name, dep) in ws_deps {
1229
+ unused_dep_keys ( name, "workspace.dependencies" , dep. unused_keys ( ) , warnings) ;
1230
+ }
1231
+ }
1232
+ let ws_root_config = to_workspace_root_config ( toml_config, package_root) ;
1233
+ WorkspaceConfig :: Root ( ws_root_config)
1234
+ }
1235
+ ( None , root) => WorkspaceConfig :: Member {
1236
+ root : root. cloned ( ) ,
1237
+ } ,
1238
+ ( Some ( ..) , Some ( ..) ) => bail ! (
1239
+ "cannot configure both `package.workspace` and \
1240
+ `[workspace]`, only one can be specified"
1241
+ ) ,
1242
+ } ;
1243
+ Ok ( workspace_config)
1244
+ }
1245
+
1246
+ fn to_workspace_root_config (
1232
1247
resolved_toml : & manifest:: TomlWorkspace ,
1233
1248
package_root : & Path ,
1234
1249
) -> WorkspaceRootConfig {
@@ -1313,24 +1328,14 @@ fn to_virtual_manifest(
1313
1328
. and_then ( |ws| ws. resolver . as_deref ( ) )
1314
1329
. map ( |r| ResolveBehavior :: from_manifest ( r) )
1315
1330
. transpose ( ) ?;
1316
- let workspace_config = match original_toml. workspace {
1317
- Some ( ref toml_config) => {
1318
- verify_lints ( toml_config. lints . as_ref ( ) , gctx, warnings) ?;
1319
- if let Some ( ws_deps) = & toml_config. dependencies {
1320
- for ( name, dep) in ws_deps {
1321
- unused_dep_keys ( name, "workspace.dependencies" , dep. unused_keys ( ) , warnings) ;
1322
- }
1323
- }
1324
- let ws_root_config = to_workspace_config ( toml_config, root) ;
1325
- gctx. ws_roots
1326
- . borrow_mut ( )
1327
- . insert ( root. to_path_buf ( ) , ws_root_config. clone ( ) ) ;
1328
- WorkspaceConfig :: Root ( ws_root_config)
1329
- }
1330
- None => {
1331
- bail ! ( "virtual manifests must be configured with [workspace]" ) ;
1332
- }
1333
- } ;
1331
+ let workspace_config = to_workspace_config ( & original_toml, root, gctx, warnings) ?;
1332
+ if let WorkspaceConfig :: Root ( ws_root_config) = & workspace_config {
1333
+ gctx. ws_roots
1334
+ . borrow_mut ( )
1335
+ . insert ( root. to_owned ( ) , ws_root_config. clone ( ) ) ;
1336
+ } else {
1337
+ bail ! ( "virtual manifests must be configured with [workspace]" ) ;
1338
+ }
1334
1339
let manifest = VirtualManifest :: new (
1335
1340
Rc :: new ( contents) ,
1336
1341
Rc :: new ( document) ,
0 commit comments