@@ -3,6 +3,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
33use rustc_data_structures:: sync:: Lrc ;
44use rustc_errors:: { ColorConfig , ErrorReported } ;
55use rustc_hir as hir;
6+ use rustc_hir:: def_id:: LOCAL_CRATE ;
67use rustc_hir:: intravisit;
78use rustc_hir:: { HirId , CRATE_HIR_ID } ;
89use rustc_interface:: interface;
@@ -13,6 +14,7 @@ use rustc_session::{lint, DiagnosticOutput, Session};
1314use rustc_span:: edition:: Edition ;
1415use rustc_span:: source_map:: SourceMap ;
1516use rustc_span:: symbol:: sym;
17+ use rustc_span:: Symbol ;
1618use rustc_span:: { BytePos , FileName , Pos , Span , DUMMY_SP } ;
1719use rustc_target:: spec:: TargetTriple ;
1820use tempfile:: Builder as TempFileBuilder ;
@@ -111,8 +113,6 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
111113 let res = interface:: run_compiler ( config, |compiler| {
112114 compiler. enter ( |queries| {
113115 let _lower_to_hir = queries. lower_to_hir ( ) ?;
114-
115- let crate_name = queries. crate_name ( ) ?. peek ( ) . to_string ( ) ;
116116 let mut global_ctxt = queries. global_ctxt ( ) ?. take ( ) ;
117117
118118 let collector = global_ctxt. enter ( |tcx| {
@@ -123,7 +123,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
123123 opts. display_warnings |= options. display_warnings ;
124124 let enable_per_target_ignores = options. enable_per_target_ignores ;
125125 let mut collector = Collector :: new (
126- crate_name,
126+ tcx . crate_name ( LOCAL_CRATE ) ,
127127 options,
128128 false ,
129129 opts,
@@ -293,7 +293,7 @@ struct UnusedExterns {
293293
294294fn run_test (
295295 test : & str ,
296- cratename : & str ,
296+ crate_name : & str ,
297297 line : usize ,
298298 options : Options ,
299299 should_panic : bool ,
@@ -312,7 +312,7 @@ fn run_test(
312312 report_unused_externs : impl Fn ( UnusedExterns ) ,
313313) -> Result < ( ) , TestFailure > {
314314 let ( test, line_offset, supports_color) =
315- make_test ( test, Some ( cratename ) , as_test_harness, opts, edition, Some ( test_id) ) ;
315+ make_test ( test, Some ( crate_name ) , as_test_harness, opts, edition, Some ( test_id) ) ;
316316
317317 let output_file = outdir. path ( ) . join ( "rust_out" ) ;
318318
@@ -479,7 +479,7 @@ fn run_test(
479479/// lines before the test code begins as well as if the output stream supports colors or not.
480480crate fn make_test (
481481 s : & str ,
482- cratename : Option < & str > ,
482+ crate_name : Option < & str > ,
483483 dont_insert_main : bool ,
484484 opts : & TestOptions ,
485485 edition : Edition ,
@@ -540,7 +540,7 @@ crate fn make_test(
540540 let sess = ParseSess :: with_span_handler ( handler, sm) ;
541541
542542 let mut found_main = false ;
543- let mut found_extern_crate = cratename . is_none ( ) ;
543+ let mut found_extern_crate = crate_name . is_none ( ) ;
544544 let mut found_macro = false ;
545545
546546 let mut parser = match maybe_new_parser_from_source_str ( & sess, filename, source) {
@@ -567,13 +567,13 @@ crate fn make_test(
567567
568568 if !found_extern_crate {
569569 if let ast:: ItemKind :: ExternCrate ( original) = item. kind {
570- // This code will never be reached if `cratename ` is none because
570+ // This code will never be reached if `crate_name ` is none because
571571 // `found_extern_crate` is initialized to `true` if it is none.
572- let cratename = cratename . unwrap ( ) ;
572+ let crate_name = crate_name . unwrap ( ) ;
573573
574574 match original {
575- Some ( name) => found_extern_crate = name. as_str ( ) == cratename ,
576- None => found_extern_crate = item. ident . as_str ( ) == cratename ,
575+ Some ( name) => found_extern_crate = name. as_str ( ) == crate_name ,
576+ None => found_extern_crate = item. ident . as_str ( ) == crate_name ,
577577 }
578578 }
579579 }
@@ -631,14 +631,14 @@ crate fn make_test(
631631
632632 // Don't inject `extern crate std` because it's already injected by the
633633 // compiler.
634- if !already_has_extern_crate && !opts. no_crate_inject && cratename != Some ( "std" ) {
635- if let Some ( cratename ) = cratename {
634+ if !already_has_extern_crate && !opts. no_crate_inject && crate_name != Some ( "std" ) {
635+ if let Some ( crate_name ) = crate_name {
636636 // Don't inject `extern crate` if the crate is never used.
637637 // NOTE: this is terribly inaccurate because it doesn't actually
638638 // parse the source, but only has false positives, not false
639639 // negatives.
640- if s. contains ( cratename ) {
641- prog. push_str ( & format ! ( "extern crate r#{};\n " , cratename ) ) ;
640+ if s. contains ( crate_name ) {
641+ prog. push_str ( & format ! ( "extern crate r#{};\n " , crate_name ) ) ;
642642 line_offset += 1 ;
643643 }
644644 }
@@ -797,7 +797,7 @@ crate struct Collector {
797797 options : Options ,
798798 use_headers : bool ,
799799 enable_per_target_ignores : bool ,
800- cratename : String ,
800+ crate_name : Symbol ,
801801 opts : TestOptions ,
802802 position : Span ,
803803 source_map : Option < Lrc < SourceMap > > ,
@@ -809,7 +809,7 @@ crate struct Collector {
809809
810810impl Collector {
811811 crate fn new (
812- cratename : String ,
812+ crate_name : Symbol ,
813813 options : Options ,
814814 use_headers : bool ,
815815 opts : TestOptions ,
@@ -823,7 +823,7 @@ impl Collector {
823823 options,
824824 use_headers,
825825 enable_per_target_ignores,
826- cratename ,
826+ crate_name ,
827827 opts,
828828 position : DUMMY_SP ,
829829 source_map,
@@ -871,7 +871,7 @@ impl Tester for Collector {
871871 fn add_test ( & mut self , test : String , config : LangString , line : usize ) {
872872 let filename = self . get_filename ( ) ;
873873 let name = self . generate_name ( line, & filename) ;
874- let cratename = self . cratename . to_string ( ) ;
874+ let crate_name = self . crate_name . to_string ( ) ;
875875 let opts = self . opts . clone ( ) ;
876876 let edition = config. edition . unwrap_or ( self . options . edition ) ;
877877 let options = self . options . clone ( ) ;
@@ -954,7 +954,7 @@ impl Tester for Collector {
954954 } ;
955955 let res = run_test (
956956 & test,
957- & cratename ,
957+ & crate_name ,
958958 line,
959959 options,
960960 config. should_panic ,
0 commit comments