@@ -3,6 +3,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
3
3
use rustc_data_structures:: sync:: Lrc ;
4
4
use rustc_errors:: { ColorConfig , ErrorReported } ;
5
5
use rustc_hir as hir;
6
+ use rustc_hir:: def_id:: LOCAL_CRATE ;
6
7
use rustc_hir:: intravisit;
7
8
use rustc_hir:: { HirId , CRATE_HIR_ID } ;
8
9
use rustc_interface:: interface;
@@ -13,6 +14,7 @@ use rustc_session::{lint, DiagnosticOutput, Session};
13
14
use rustc_span:: edition:: Edition ;
14
15
use rustc_span:: source_map:: SourceMap ;
15
16
use rustc_span:: symbol:: sym;
17
+ use rustc_span:: Symbol ;
16
18
use rustc_span:: { BytePos , FileName , Pos , Span , DUMMY_SP } ;
17
19
use rustc_target:: spec:: TargetTriple ;
18
20
use tempfile:: Builder as TempFileBuilder ;
@@ -111,8 +113,6 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
111
113
let res = interface:: run_compiler ( config, |compiler| {
112
114
compiler. enter ( |queries| {
113
115
let _lower_to_hir = queries. lower_to_hir ( ) ?;
114
-
115
- let crate_name = queries. crate_name ( ) ?. peek ( ) . to_string ( ) ;
116
116
let mut global_ctxt = queries. global_ctxt ( ) ?. take ( ) ;
117
117
118
118
let collector = global_ctxt. enter ( |tcx| {
@@ -123,7 +123,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
123
123
opts. display_warnings |= options. display_warnings ;
124
124
let enable_per_target_ignores = options. enable_per_target_ignores ;
125
125
let mut collector = Collector :: new (
126
- crate_name,
126
+ tcx . crate_name ( LOCAL_CRATE ) ,
127
127
options,
128
128
false ,
129
129
opts,
@@ -293,7 +293,7 @@ struct UnusedExterns {
293
293
294
294
fn run_test (
295
295
test : & str ,
296
- cratename : & str ,
296
+ crate_name : & str ,
297
297
line : usize ,
298
298
options : Options ,
299
299
should_panic : bool ,
@@ -312,7 +312,7 @@ fn run_test(
312
312
report_unused_externs : impl Fn ( UnusedExterns ) ,
313
313
) -> Result < ( ) , TestFailure > {
314
314
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) ) ;
316
316
317
317
let output_file = outdir. path ( ) . join ( "rust_out" ) ;
318
318
@@ -479,7 +479,7 @@ fn run_test(
479
479
/// lines before the test code begins as well as if the output stream supports colors or not.
480
480
crate fn make_test (
481
481
s : & str ,
482
- cratename : Option < & str > ,
482
+ crate_name : Option < & str > ,
483
483
dont_insert_main : bool ,
484
484
opts : & TestOptions ,
485
485
edition : Edition ,
@@ -540,7 +540,7 @@ crate fn make_test(
540
540
let sess = ParseSess :: with_span_handler ( handler, sm) ;
541
541
542
542
let mut found_main = false ;
543
- let mut found_extern_crate = cratename . is_none ( ) ;
543
+ let mut found_extern_crate = crate_name . is_none ( ) ;
544
544
let mut found_macro = false ;
545
545
546
546
let mut parser = match maybe_new_parser_from_source_str ( & sess, filename, source) {
@@ -567,13 +567,13 @@ crate fn make_test(
567
567
568
568
if !found_extern_crate {
569
569
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
571
571
// `found_extern_crate` is initialized to `true` if it is none.
572
- let cratename = cratename . unwrap ( ) ;
572
+ let crate_name = crate_name . unwrap ( ) ;
573
573
574
574
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 ,
577
577
}
578
578
}
579
579
}
@@ -631,14 +631,14 @@ crate fn make_test(
631
631
632
632
// Don't inject `extern crate std` because it's already injected by the
633
633
// 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 {
636
636
// Don't inject `extern crate` if the crate is never used.
637
637
// NOTE: this is terribly inaccurate because it doesn't actually
638
638
// parse the source, but only has false positives, not false
639
639
// 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 ) ) ;
642
642
line_offset += 1 ;
643
643
}
644
644
}
@@ -797,7 +797,7 @@ crate struct Collector {
797
797
options : Options ,
798
798
use_headers : bool ,
799
799
enable_per_target_ignores : bool ,
800
- cratename : String ,
800
+ crate_name : Symbol ,
801
801
opts : TestOptions ,
802
802
position : Span ,
803
803
source_map : Option < Lrc < SourceMap > > ,
@@ -809,7 +809,7 @@ crate struct Collector {
809
809
810
810
impl Collector {
811
811
crate fn new (
812
- cratename : String ,
812
+ crate_name : Symbol ,
813
813
options : Options ,
814
814
use_headers : bool ,
815
815
opts : TestOptions ,
@@ -823,7 +823,7 @@ impl Collector {
823
823
options,
824
824
use_headers,
825
825
enable_per_target_ignores,
826
- cratename ,
826
+ crate_name ,
827
827
opts,
828
828
position : DUMMY_SP ,
829
829
source_map,
@@ -871,7 +871,7 @@ impl Tester for Collector {
871
871
fn add_test ( & mut self , test : String , config : LangString , line : usize ) {
872
872
let filename = self . get_filename ( ) ;
873
873
let name = self . generate_name ( line, & filename) ;
874
- let cratename = self . cratename . to_string ( ) ;
874
+ let crate_name = self . crate_name . to_string ( ) ;
875
875
let opts = self . opts . clone ( ) ;
876
876
let edition = config. edition . unwrap_or ( self . options . edition ) ;
877
877
let options = self . options . clone ( ) ;
@@ -954,7 +954,7 @@ impl Tester for Collector {
954
954
} ;
955
955
let res = run_test (
956
956
& test,
957
- & cratename ,
957
+ & crate_name ,
958
958
line,
959
959
options,
960
960
config. should_panic ,
0 commit comments