@@ -48,29 +48,58 @@ pub fn read_manifest(
48
48
source_id : SourceId ,
49
49
gctx : & GlobalContext ,
50
50
) -> CargoResult < EitherManifest > {
51
+ let mut warnings = vec ! [ ] ;
52
+ let mut errors = vec ! [ ] ;
53
+
51
54
let contents =
52
55
read_toml_string ( path, gctx) . map_err ( |err| ManifestError :: new ( err, path. into ( ) ) ) ?;
53
56
let document =
54
57
parse_document ( & contents) . map_err ( |e| emit_diagnostic ( e. into ( ) , & contents, path, gctx) ) ?;
55
58
let original_toml = deserialize_toml ( & document)
56
59
. map_err ( |e| emit_diagnostic ( e. into ( ) , & contents, path, gctx) ) ?;
57
60
58
- ( || {
61
+ let mut manifest = ( || {
59
62
if original_toml. package ( ) . is_some ( ) {
60
- to_real_manifest ( contents, document, original_toml, source_id, path, gctx)
61
- . map ( EitherManifest :: Real )
63
+ to_real_manifest (
64
+ contents,
65
+ document,
66
+ original_toml,
67
+ source_id,
68
+ path,
69
+ gctx,
70
+ & mut warnings,
71
+ & mut errors,
72
+ )
73
+ . map ( EitherManifest :: Real )
62
74
} else {
63
- to_virtual_manifest ( contents, document, original_toml, source_id, path, gctx)
64
- . map ( EitherManifest :: Virtual )
75
+ to_virtual_manifest (
76
+ contents,
77
+ document,
78
+ original_toml,
79
+ source_id,
80
+ path,
81
+ gctx,
82
+ & mut warnings,
83
+ & mut errors,
84
+ )
85
+ . map ( EitherManifest :: Virtual )
65
86
}
66
87
} ) ( )
67
88
. map_err ( |err| {
68
89
ManifestError :: new (
69
90
err. context ( format ! ( "failed to parse manifest at `{}`" , path. display( ) ) ) ,
70
91
path. into ( ) ,
71
92
)
72
- . into ( )
73
- } )
93
+ } ) ?;
94
+
95
+ for warning in warnings {
96
+ manifest. warnings_mut ( ) . add_warning ( warning) ;
97
+ }
98
+ for error in errors {
99
+ manifest. warnings_mut ( ) . add_critical_warning ( error) ;
100
+ }
101
+
102
+ Ok ( manifest)
74
103
}
75
104
76
105
#[ tracing:: instrument( skip_all) ]
@@ -438,6 +467,8 @@ pub fn to_real_manifest(
438
467
source_id : SourceId ,
439
468
manifest_file : & Path ,
440
469
gctx : & GlobalContext ,
470
+ warnings : & mut Vec < String > ,
471
+ errors : & mut Vec < String > ,
441
472
) -> CargoResult < Manifest > {
442
473
let embedded = is_embedded ( manifest_file) ;
443
474
let package_root = manifest_file. parent ( ) . unwrap ( ) ;
@@ -463,13 +494,10 @@ pub fn to_real_manifest(
463
494
}
464
495
}
465
496
466
- let mut warnings = vec ! [ ] ;
467
- let mut errors = vec ! [ ] ;
468
-
469
497
// Parse features first so they will be available when parsing other parts of the TOML.
470
498
let empty = Vec :: new ( ) ;
471
499
let cargo_features = original_toml. cargo_features . as_ref ( ) . unwrap_or ( & empty) ;
472
- let features = Features :: new ( cargo_features, gctx, & mut warnings, source_id. is_path ( ) ) ?;
500
+ let features = Features :: new ( cargo_features, gctx, warnings, source_id. is_path ( ) ) ?;
473
501
474
502
let mut package = match ( & original_toml. package , & original_toml. project ) {
475
503
( Some ( _) , Some ( project) ) => {
@@ -494,15 +522,10 @@ pub fn to_real_manifest(
494
522
495
523
let workspace_config = match ( original_toml. workspace . as_ref ( ) , package. workspace . as_ref ( ) ) {
496
524
( Some ( toml_config) , None ) => {
497
- verify_lints ( toml_config. lints . as_ref ( ) , gctx, & mut warnings) ?;
525
+ verify_lints ( toml_config. lints . as_ref ( ) , gctx, warnings) ?;
498
526
if let Some ( ws_deps) = & toml_config. dependencies {
499
527
for ( name, dep) in ws_deps {
500
- unused_dep_keys (
501
- name,
502
- "workspace.dependencies" ,
503
- dep. unused_keys ( ) ,
504
- & mut warnings,
505
- ) ;
528
+ unused_dep_keys ( name, "workspace.dependencies" , dep. unused_keys ( ) , warnings) ;
506
529
}
507
530
}
508
531
let ws_root_config = to_workspace_config ( toml_config, package_root) ;
@@ -649,8 +672,8 @@ pub fn to_real_manifest(
649
672
edition,
650
673
& package. build ,
651
674
& package. metabuild ,
652
- & mut warnings,
653
- & mut errors,
675
+ warnings,
676
+ errors,
654
677
) ?;
655
678
656
679
if targets. iter ( ) . all ( |t| t. is_custom_build ( ) ) {
@@ -689,7 +712,7 @@ pub fn to_real_manifest(
689
712
deps : & mut deps,
690
713
source_id,
691
714
gctx,
692
- warnings : & mut warnings ,
715
+ warnings,
693
716
features : & features,
694
717
platform : None ,
695
718
root : package_root,
@@ -964,7 +987,7 @@ pub fn to_real_manifest(
964
987
965
988
if let Some ( profiles) = & original_toml. profile {
966
989
let cli_unstable = gctx. cli_unstable ( ) ;
967
- validate_profiles ( profiles, cli_unstable, & features, & mut warnings) ?;
990
+ validate_profiles ( profiles, cli_unstable, & features, warnings) ?;
968
991
}
969
992
970
993
let publish = package
@@ -1075,7 +1098,7 @@ pub fn to_real_manifest(
1075
1098
} ) ,
1076
1099
_unused_keys : Default :: default ( ) ,
1077
1100
} ;
1078
- let mut manifest = Manifest :: new (
1101
+ let manifest = Manifest :: new (
1079
1102
Rc :: new ( contents) ,
1080
1103
Rc :: new ( document) ,
1081
1104
Rc :: new ( original_toml) ,
@@ -1114,13 +1137,7 @@ pub fn to_real_manifest(
1114
1137
. to_owned ( ) ,
1115
1138
) ;
1116
1139
}
1117
- warn_on_unused ( & manifest. original_toml ( ) . _unused_keys , & mut warnings) ;
1118
- for warning in warnings {
1119
- manifest. warnings_mut ( ) . add_warning ( warning) ;
1120
- }
1121
- for error in errors {
1122
- manifest. warnings_mut ( ) . add_critical_warning ( error) ;
1123
- }
1140
+ warn_on_unused ( & manifest. original_toml ( ) . _unused_keys , warnings) ;
1124
1141
1125
1142
manifest. feature_gate ( ) ?;
1126
1143
@@ -1239,6 +1256,8 @@ fn to_virtual_manifest(
1239
1256
source_id : SourceId ,
1240
1257
manifest_file : & Path ,
1241
1258
gctx : & GlobalContext ,
1259
+ warnings : & mut Vec < String > ,
1260
+ _errors : & mut Vec < String > ,
1242
1261
) -> CargoResult < VirtualManifest > {
1243
1262
let root = manifest_file. parent ( ) . unwrap ( ) ;
1244
1263
@@ -1263,11 +1282,10 @@ fn to_virtual_manifest(
1263
1282
bail ! ( "this virtual manifest specifies a `{field}` section, which is not allowed" ) ;
1264
1283
}
1265
1284
1266
- let mut warnings = Vec :: new ( ) ;
1267
1285
let mut deps = Vec :: new ( ) ;
1268
1286
let empty = Vec :: new ( ) ;
1269
1287
let cargo_features = original_toml. cargo_features . as_ref ( ) . unwrap_or ( & empty) ;
1270
- let features = Features :: new ( cargo_features, gctx, & mut warnings, source_id. is_path ( ) ) ?;
1288
+ let features = Features :: new ( cargo_features, gctx, warnings, source_id. is_path ( ) ) ?;
1271
1289
1272
1290
resolved_toml. _unused_keys = Default :: default ( ) ;
1273
1291
@@ -1276,7 +1294,7 @@ fn to_virtual_manifest(
1276
1294
deps : & mut deps,
1277
1295
source_id,
1278
1296
gctx,
1279
- warnings : & mut warnings ,
1297
+ warnings,
1280
1298
platform : None ,
1281
1299
features : & features,
1282
1300
root,
@@ -1287,7 +1305,7 @@ fn to_virtual_manifest(
1287
1305
)
1288
1306
} ;
1289
1307
if let Some ( profiles) = & original_toml. profile {
1290
- validate_profiles ( profiles, gctx. cli_unstable ( ) , & features, & mut warnings) ?;
1308
+ validate_profiles ( profiles, gctx. cli_unstable ( ) , & features, warnings) ?;
1291
1309
}
1292
1310
let resolve_behavior = original_toml
1293
1311
. workspace
@@ -1297,15 +1315,10 @@ fn to_virtual_manifest(
1297
1315
. transpose ( ) ?;
1298
1316
let workspace_config = match original_toml. workspace {
1299
1317
Some ( ref toml_config) => {
1300
- verify_lints ( toml_config. lints . as_ref ( ) , gctx, & mut warnings) ?;
1318
+ verify_lints ( toml_config. lints . as_ref ( ) , gctx, warnings) ?;
1301
1319
if let Some ( ws_deps) = & toml_config. dependencies {
1302
1320
for ( name, dep) in ws_deps {
1303
- unused_dep_keys (
1304
- name,
1305
- "workspace.dependencies" ,
1306
- dep. unused_keys ( ) ,
1307
- & mut warnings,
1308
- ) ;
1321
+ unused_dep_keys ( name, "workspace.dependencies" , dep. unused_keys ( ) , warnings) ;
1309
1322
}
1310
1323
}
1311
1324
let ws_root_config = to_workspace_config ( toml_config, root) ;
@@ -1318,7 +1331,7 @@ fn to_virtual_manifest(
1318
1331
bail ! ( "virtual manifests must be configured with [workspace]" ) ;
1319
1332
}
1320
1333
} ;
1321
- let mut manifest = VirtualManifest :: new (
1334
+ let manifest = VirtualManifest :: new (
1322
1335
Rc :: new ( contents) ,
1323
1336
Rc :: new ( document) ,
1324
1337
Rc :: new ( original_toml) ,
@@ -1330,10 +1343,7 @@ fn to_virtual_manifest(
1330
1343
resolve_behavior,
1331
1344
) ;
1332
1345
1333
- warn_on_unused ( & manifest. original_toml ( ) . _unused_keys , & mut warnings) ;
1334
- for warning in warnings {
1335
- manifest. warnings_mut ( ) . add_warning ( warning) ;
1336
- }
1346
+ warn_on_unused ( & manifest. original_toml ( ) . _unused_keys , warnings) ;
1337
1347
1338
1348
Ok ( manifest)
1339
1349
}
0 commit comments