@@ -4,7 +4,6 @@ use crate::core::compiler::context::Metadata;
44use crate :: core:: compiler:: job_queue:: JobState ;
55use crate :: core:: { profiles:: ProfileRoot , PackageId } ;
66use crate :: util:: errors:: CargoResult ;
7- use crate :: util:: interning:: InternedString ;
87use crate :: util:: machine_message:: { self , Message } ;
98use crate :: util:: { internal, profile} ;
109use anyhow:: Context as _;
@@ -270,7 +269,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
270269 }
271270 } )
272271 . collect :: < Vec < _ > > ( ) ;
273- let pkg_name = unit. pkg . name ( ) ;
272+ let crate_name = unit. target . crate_name ( ) ;
274273 let pkg_descr = unit. pkg . to_string ( ) ;
275274 let build_script_outputs = Arc :: clone ( & cx. build_script_outputs ) ;
276275 let id = unit. pkg . package_id ( ) ;
@@ -280,7 +279,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
280279 let host_target_root = cx. files ( ) . host_dest ( ) . to_path_buf ( ) ;
281280 let all = (
282281 id,
283- pkg_name ,
282+ crate_name . clone ( ) ,
284283 pkg_descr. clone ( ) ,
285284 Arc :: clone ( & build_script_outputs) ,
286285 output_file. clone ( ) ,
@@ -400,7 +399,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
400399 paths:: write ( & root_output_file, paths:: path2bytes ( & script_out_dir) ?) ?;
401400 let parsed_output = BuildOutput :: parse (
402401 & output. stdout ,
403- pkg_name ,
402+ crate_name ,
404403 & pkg_descr,
405404 & script_out_dir,
406405 & script_out_dir,
@@ -422,12 +421,12 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
422421 // itself to run when we actually end up just discarding what we calculated
423422 // above.
424423 let fresh = Work :: new ( move |state| {
425- let ( id, pkg_name , pkg_descr, build_script_outputs, output_file, script_out_dir) = all;
424+ let ( id, crate_name , pkg_descr, build_script_outputs, output_file, script_out_dir) = all;
426425 let output = match prev_output {
427426 Some ( output) => output,
428427 None => BuildOutput :: parse_file (
429428 & output_file,
430- pkg_name ,
429+ crate_name ,
431430 & pkg_descr,
432431 & prev_script_out_dir,
433432 & script_out_dir,
@@ -479,7 +478,7 @@ fn insert_warnings_in_build_outputs(
479478impl BuildOutput {
480479 pub fn parse_file (
481480 path : & Path ,
482- pkg_name : InternedString ,
481+ crate_name : String ,
483482 pkg_descr : & str ,
484483 script_out_dir_when_generated : & Path ,
485484 script_out_dir : & Path ,
@@ -489,7 +488,7 @@ impl BuildOutput {
489488 let contents = paths:: read_bytes ( path) ?;
490489 BuildOutput :: parse (
491490 & contents,
492- pkg_name ,
491+ crate_name ,
493492 pkg_descr,
494493 script_out_dir_when_generated,
495494 script_out_dir,
@@ -499,10 +498,12 @@ impl BuildOutput {
499498 }
500499
501500 // Parses the output of a script.
502- // The `pkg_name` is used for error messages.
501+ // The `pkg_descr` is used for error messages.
502+ // The `crate_name` is used for determining if RUSTC_BOOTSTRAP should be allowed.
503503 pub fn parse (
504504 input : & [ u8 ] ,
505- pkg_name : InternedString ,
505+ // Takes String instead of InternedString so passing `unit.pkg.name()` will give a compile error.
506+ crate_name : String ,
506507 pkg_descr : & str ,
507508 script_out_dir_when_generated : & Path ,
508509 script_out_dir : & Path ,
@@ -591,13 +592,12 @@ impl BuildOutput {
591592 // behavior, so still only give a warning.
592593 // NOTE: cargo only allows nightly features on RUSTC_BOOTSTRAP=1, but we
593594 // want setting any value of RUSTC_BOOTSTRAP to downgrade this to a warning
594- // (so that `RUSTC_BOOTSTRAP=pkg_name ` will work)
595+ // (so that `RUSTC_BOOTSTRAP=crate_name ` will work)
595596 let rustc_bootstrap_allows = |name : & str | {
596- std:: env:: var ( "RUSTC_BOOTSTRAP" ) . map_or ( false , |var| {
597- var. split ( ',' ) . any ( |s| s == name)
598- } )
597+ std:: env:: var ( "RUSTC_BOOTSTRAP" )
598+ . map_or ( false , |var| var. split ( ',' ) . any ( |s| s == name) )
599599 } ;
600- if nightly_features_allowed || rustc_bootstrap_allows ( & * pkg_name ) {
600+ if nightly_features_allowed || rustc_bootstrap_allows ( & * crate_name ) {
601601 warnings. push ( format ! ( "Cannot set `RUSTC_BOOTSTRAP={}` from {}.\n \
602602 note: Crates cannot set `RUSTC_BOOTSTRAP` themselves, as doing so would subvert the stability guarantees of Rust for your project.",
603603 val, whence
@@ -610,7 +610,7 @@ impl BuildOutput {
610610 help: If you're sure you want to do this in your project, set the environment variable `RUSTC_BOOTSTRAP={}` before running cargo instead.",
611611 val,
612612 whence,
613- pkg_name ,
613+ crate_name ,
614614 ) ;
615615 }
616616 } else {
@@ -867,7 +867,7 @@ fn prev_build_output(cx: &mut Context<'_, '_>, unit: &Unit) -> (Option<BuildOutp
867867 (
868868 BuildOutput :: parse_file (
869869 & output_file,
870- unit. pkg . name ( ) ,
870+ unit. target . crate_name ( ) ,
871871 & unit. pkg . to_string ( ) ,
872872 & prev_script_out_dir,
873873 & script_out_dir,
0 commit comments