@@ -48,29 +48,58 @@ pub fn read_manifest(
4848 source_id : SourceId ,
4949 gctx : & GlobalContext ,
5050) -> CargoResult < EitherManifest > {
51+ let mut warnings = vec ! [ ] ;
52+ let mut errors = vec ! [ ] ;
53+
5154 let contents =
5255 read_toml_string ( path, gctx) . map_err ( |err| ManifestError :: new ( err, path. into ( ) ) ) ?;
5356 let document =
5457 parse_document ( & contents) . map_err ( |e| emit_diagnostic ( e. into ( ) , & contents, path, gctx) ) ?;
5558 let original_toml = deserialize_toml ( & document)
5659 . map_err ( |e| emit_diagnostic ( e. into ( ) , & contents, path, gctx) ) ?;
5760
58- ( || {
61+ let mut manifest = ( || {
5962 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 )
6274 } 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 )
6586 }
6687 } ) ( )
6788 . map_err ( |err| {
6889 ManifestError :: new (
6990 err. context ( format ! ( "failed to parse manifest at `{}`" , path. display( ) ) ) ,
7091 path. into ( ) ,
7192 )
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)
74103}
75104
76105#[ tracing:: instrument( skip_all) ]
@@ -438,6 +467,8 @@ pub fn to_real_manifest(
438467 source_id : SourceId ,
439468 manifest_file : & Path ,
440469 gctx : & GlobalContext ,
470+ warnings : & mut Vec < String > ,
471+ errors : & mut Vec < String > ,
441472) -> CargoResult < Manifest > {
442473 let embedded = is_embedded ( manifest_file) ;
443474 let package_root = manifest_file. parent ( ) . unwrap ( ) ;
@@ -463,13 +494,10 @@ pub fn to_real_manifest(
463494 }
464495 }
465496
466- let mut warnings = vec ! [ ] ;
467- let mut errors = vec ! [ ] ;
468-
469497 // Parse features first so they will be available when parsing other parts of the TOML.
470498 let empty = Vec :: new ( ) ;
471499 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 ( ) ) ?;
473501
474502 let mut package = match ( & original_toml. package , & original_toml. project ) {
475503 ( Some ( _) , Some ( project) ) => {
@@ -494,15 +522,10 @@ pub fn to_real_manifest(
494522
495523 let workspace_config = match ( original_toml. workspace . as_ref ( ) , package. workspace . as_ref ( ) ) {
496524 ( 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) ?;
498526 if let Some ( ws_deps) = & toml_config. dependencies {
499527 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) ;
506529 }
507530 }
508531 let ws_root_config = to_workspace_config ( toml_config, package_root) ;
@@ -649,8 +672,8 @@ pub fn to_real_manifest(
649672 edition,
650673 & package. build ,
651674 & package. metabuild ,
652- & mut warnings,
653- & mut errors,
675+ warnings,
676+ errors,
654677 ) ?;
655678
656679 if targets. iter ( ) . all ( |t| t. is_custom_build ( ) ) {
@@ -689,7 +712,7 @@ pub fn to_real_manifest(
689712 deps : & mut deps,
690713 source_id,
691714 gctx,
692- warnings : & mut warnings ,
715+ warnings,
693716 features : & features,
694717 platform : None ,
695718 root : package_root,
@@ -964,7 +987,7 @@ pub fn to_real_manifest(
964987
965988 if let Some ( profiles) = & original_toml. profile {
966989 let cli_unstable = gctx. cli_unstable ( ) ;
967- validate_profiles ( profiles, cli_unstable, & features, & mut warnings) ?;
990+ validate_profiles ( profiles, cli_unstable, & features, warnings) ?;
968991 }
969992
970993 let publish = package
@@ -1075,7 +1098,7 @@ pub fn to_real_manifest(
10751098 } ) ,
10761099 _unused_keys : Default :: default ( ) ,
10771100 } ;
1078- let mut manifest = Manifest :: new (
1101+ let manifest = Manifest :: new (
10791102 Rc :: new ( contents) ,
10801103 Rc :: new ( document) ,
10811104 Rc :: new ( original_toml) ,
@@ -1114,13 +1137,7 @@ pub fn to_real_manifest(
11141137 . to_owned ( ) ,
11151138 ) ;
11161139 }
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) ;
11241141
11251142 manifest. feature_gate ( ) ?;
11261143
@@ -1239,6 +1256,8 @@ fn to_virtual_manifest(
12391256 source_id : SourceId ,
12401257 manifest_file : & Path ,
12411258 gctx : & GlobalContext ,
1259+ warnings : & mut Vec < String > ,
1260+ _errors : & mut Vec < String > ,
12421261) -> CargoResult < VirtualManifest > {
12431262 let root = manifest_file. parent ( ) . unwrap ( ) ;
12441263
@@ -1263,11 +1282,10 @@ fn to_virtual_manifest(
12631282 bail ! ( "this virtual manifest specifies a `{field}` section, which is not allowed" ) ;
12641283 }
12651284
1266- let mut warnings = Vec :: new ( ) ;
12671285 let mut deps = Vec :: new ( ) ;
12681286 let empty = Vec :: new ( ) ;
12691287 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 ( ) ) ?;
12711289
12721290 resolved_toml. _unused_keys = Default :: default ( ) ;
12731291
@@ -1276,7 +1294,7 @@ fn to_virtual_manifest(
12761294 deps : & mut deps,
12771295 source_id,
12781296 gctx,
1279- warnings : & mut warnings ,
1297+ warnings,
12801298 platform : None ,
12811299 features : & features,
12821300 root,
@@ -1287,7 +1305,7 @@ fn to_virtual_manifest(
12871305 )
12881306 } ;
12891307 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) ?;
12911309 }
12921310 let resolve_behavior = original_toml
12931311 . workspace
@@ -1297,15 +1315,10 @@ fn to_virtual_manifest(
12971315 . transpose ( ) ?;
12981316 let workspace_config = match original_toml. workspace {
12991317 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) ?;
13011319 if let Some ( ws_deps) = & toml_config. dependencies {
13021320 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) ;
13091322 }
13101323 }
13111324 let ws_root_config = to_workspace_config ( toml_config, root) ;
@@ -1318,7 +1331,7 @@ fn to_virtual_manifest(
13181331 bail ! ( "virtual manifests must be configured with [workspace]" ) ;
13191332 }
13201333 } ;
1321- let mut manifest = VirtualManifest :: new (
1334+ let manifest = VirtualManifest :: new (
13221335 Rc :: new ( contents) ,
13231336 Rc :: new ( document) ,
13241337 Rc :: new ( original_toml) ,
@@ -1330,10 +1343,7 @@ fn to_virtual_manifest(
13301343 resolve_behavior,
13311344 ) ;
13321345
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) ;
13371347
13381348 Ok ( manifest)
13391349}
0 commit comments