@@ -91,17 +91,16 @@ fn main() {
91
91
cmd. args ( & args)
92
92
. env ( bootstrap:: util:: dylib_path_var ( ) ,
93
93
env:: join_paths ( & dylib_path) . unwrap ( ) ) ;
94
- let mut maybe_crate = None ;
95
94
96
95
// Get the name of the crate we're compiling, if any.
97
- let maybe_crate_name = args. windows ( 2 )
98
- . find ( |a| & * a [ 0 ] == "--crate-name" )
99
- . map ( |crate_name| & * crate_name [ 1 ] ) ;
96
+ let crate_name = args. windows ( 2 )
97
+ . find ( |args| args [ 0 ] == "--crate-name" )
98
+ . and_then ( |args| args [ 1 ] . to_str ( ) ) ;
100
99
101
- if let Some ( current_crate ) = maybe_crate_name {
100
+ if let Some ( crate_name ) = crate_name {
102
101
if let Some ( target) = env:: var_os ( "RUSTC_TIME" ) {
103
102
if target == "all" ||
104
- target. into_string ( ) . unwrap ( ) . split ( "," ) . any ( |c| c. trim ( ) == current_crate )
103
+ target. into_string ( ) . unwrap ( ) . split ( "," ) . any ( |c| c. trim ( ) == crate_name )
105
104
{
106
105
cmd. arg ( "-Ztime" ) ;
107
106
}
@@ -125,6 +124,19 @@ fn main() {
125
124
cmd. arg ( format ! ( "-Cdebuginfo={}" , debuginfo_level) ) ;
126
125
}
127
126
127
+ if env:: var_os ( "RUSTC_DENY_WARNINGS" ) . is_some ( ) &&
128
+ env:: var_os ( "RUSTC_EXTERNAL_TOOL" ) . is_none ( ) {
129
+ cmd. arg ( "-Dwarnings" ) ;
130
+ cmd. arg ( "-Drust_2018_idioms" ) ;
131
+ // cfg(not(bootstrap)): Remove this during the next stage 0 compiler update.
132
+ // `-Drustc::internal` is a new feature and `rustc_version` mis-reports the `stage`.
133
+ let cfg_not_bootstrap = stage != "0" && crate_name != Some ( "rustc_version" ) ;
134
+ if cfg_not_bootstrap && use_internal_lints ( crate_name) {
135
+ cmd. arg ( "-Zunstable-options" ) ;
136
+ cmd. arg ( "-Drustc::internal" ) ;
137
+ }
138
+ }
139
+
128
140
if let Some ( target) = target {
129
141
// The stage0 compiler has a special sysroot distinct from what we
130
142
// actually downloaded, so we just always pass the `--sysroot` option.
@@ -167,9 +179,6 @@ fn main() {
167
179
cmd. arg ( format ! ( "-Clinker={}" , target_linker) ) ;
168
180
}
169
181
170
- let crate_name = maybe_crate_name. unwrap ( ) ;
171
- maybe_crate = Some ( crate_name) ;
172
-
173
182
// If we're compiling specifically the `panic_abort` crate then we pass
174
183
// the `-C panic=abort` option. Note that we do not do this for any
175
184
// other crate intentionally as this is the only crate for now that we
@@ -182,8 +191,8 @@ fn main() {
182
191
// `compiler_builtins` are unconditionally compiled with panic=abort to
183
192
// workaround undefined references to `rust_eh_unwind_resume` generated
184
193
// otherwise, see issue https://github.com/rust-lang/rust/issues/43095.
185
- if crate_name == "panic_abort" ||
186
- crate_name == "compiler_builtins" && stage != "0" {
194
+ if crate_name == Some ( "panic_abort" ) ||
195
+ crate_name == Some ( "compiler_builtins" ) && stage != "0" {
187
196
cmd. arg ( "-C" ) . arg ( "panic=abort" ) ;
188
197
}
189
198
@@ -196,7 +205,7 @@ fn main() {
196
205
197
206
// The compiler builtins are pretty sensitive to symbols referenced in
198
207
// libcore and such, so we never compile them with debug assertions.
199
- if crate_name == "compiler_builtins" {
208
+ if crate_name == Some ( "compiler_builtins" ) {
200
209
cmd. arg ( "-C" ) . arg ( "debug-assertions=no" ) ;
201
210
} else {
202
211
cmd. arg ( "-C" ) . arg ( format ! ( "debug-assertions={}" , debug_assertions) ) ;
@@ -305,22 +314,6 @@ fn main() {
305
314
}
306
315
}
307
316
308
- // This is required for internal lints.
309
- if let Some ( crate_name) = args. windows ( 2 ) . find ( |a| & * a[ 0 ] == "--crate-name" ) {
310
- let crate_name = crate_name[ 1 ] . to_string_lossy ( ) ;
311
- if crate_name != "rustc_version"
312
- && ( crate_name. starts_with ( "rustc" )
313
- || crate_name. starts_with ( "syntax" )
314
- || crate_name == "arena"
315
- || crate_name == "fmt_macros" )
316
- {
317
- cmd. arg ( "-Zunstable-options" ) ;
318
- if stage != "0" {
319
- cmd. arg ( "-Wrustc::internal" ) ;
320
- }
321
- }
322
- }
323
-
324
317
// Force all crates compiled by this compiler to (a) be unstable and (b)
325
318
// allow the `rustc_private` feature to link to other unstable crates
326
319
// also in the sysroot. We also do this for host crates, since those
@@ -333,13 +326,6 @@ fn main() {
333
326
cmd. arg ( "--cfg" ) . arg ( "parallel_compiler" ) ;
334
327
}
335
328
336
- if env:: var_os ( "RUSTC_DENY_WARNINGS" ) . is_some ( ) && env:: var_os ( "RUSTC_EXTERNAL_TOOL" ) . is_none ( )
337
- {
338
- cmd. arg ( "-Dwarnings" ) ;
339
- cmd. arg ( "-Dbare_trait_objects" ) ;
340
- cmd. arg ( "-Drust_2018_idioms" ) ;
341
- }
342
-
343
329
if verbose > 1 {
344
330
eprintln ! (
345
331
"rustc command: {:?}={:?} {:?}" ,
@@ -362,7 +348,7 @@ fn main() {
362
348
}
363
349
364
350
if env:: var_os ( "RUSTC_PRINT_STEP_TIMINGS" ) . is_some ( ) {
365
- if let Some ( krate ) = maybe_crate {
351
+ if let Some ( crate_name ) = crate_name {
366
352
let start = Instant :: now ( ) ;
367
353
let status = cmd
368
354
. status ( )
@@ -371,7 +357,7 @@ fn main() {
371
357
372
358
let is_test = args. iter ( ) . any ( |a| a == "--test" ) ;
373
359
eprintln ! ( "[RUSTC-TIMING] {} test:{} {}.{:03}" ,
374
- krate . to_string_lossy ( ) ,
360
+ crate_name ,
375
361
is_test,
376
362
dur. as_secs( ) ,
377
363
dur. subsec_nanos( ) / 1_000_000 ) ;
@@ -390,6 +376,14 @@ fn main() {
390
376
std:: process:: exit ( code) ;
391
377
}
392
378
379
+ // Rustc crates for which internal lints are in effect.
380
+ fn use_internal_lints ( crate_name : Option < & str > ) -> bool {
381
+ crate_name. map_or ( false , |crate_name| {
382
+ crate_name. starts_with ( "rustc" ) || crate_name. starts_with ( "syntax" ) ||
383
+ [ "arena" , "fmt_macros" ] . contains ( & crate_name)
384
+ } )
385
+ }
386
+
393
387
#[ cfg( unix) ]
394
388
fn exec_cmd ( cmd : & mut Command ) -> io:: Result < i32 > {
395
389
use std:: os:: unix:: process:: CommandExt ;
0 commit comments