@@ -257,12 +257,7 @@ impl Toolchain {
257
257
}
258
258
( None , None ) => {
259
259
let mut cmd = Command :: new ( "cargo" ) ;
260
- cmd. arg ( & format ! ( "+{}" , self . rustup_name( ) ) ) ;
261
- if cfg. args . command_args . is_empty ( ) {
262
- cmd. arg ( "build" ) ;
263
- } else {
264
- cmd. args ( & cfg. args . command_args ) ;
265
- }
260
+ self . set_cargo_args_and_envs ( & mut cmd, cfg) ;
266
261
cmd
267
262
}
268
263
( Some ( script) , Some ( timeout) ) => {
@@ -277,12 +272,7 @@ impl Toolchain {
277
272
let mut cmd = Command :: new ( "timeout" ) ;
278
273
cmd. arg ( timeout. to_string ( ) ) ;
279
274
cmd. arg ( "cargo" ) ;
280
- cmd. arg ( format ! ( "+{}" , self . rustup_name( ) ) ) ;
281
- if cfg. args . command_args . is_empty ( ) {
282
- cmd. arg ( "build" ) ;
283
- } else {
284
- cmd. args ( & cfg. args . command_args ) ;
285
- }
275
+ self . set_cargo_args_and_envs ( & mut cmd, cfg) ;
286
276
cmd
287
277
}
288
278
} ;
@@ -326,6 +316,32 @@ impl Toolchain {
326
316
output
327
317
}
328
318
319
+ fn set_cargo_args_and_envs ( & self , cmd : & mut Command , cfg : & Config ) {
320
+ let rustup_name = format ! ( "+{}" , self . rustup_name( ) ) ;
321
+ cmd. arg ( & rustup_name) ;
322
+ if cfg. args . command_args . is_empty ( ) {
323
+ cmd. arg ( "build" ) ;
324
+ } else {
325
+ cmd. args ( & cfg. args . command_args ) ;
326
+ }
327
+ if cfg. args . pretend_to_be_stable && self . is_current_nightly ( ) {
328
+ // Forbid using features
329
+ cmd. env (
330
+ "RUSTFLAGS" ,
331
+ format ! (
332
+ "{} -Zallow-features=" ,
333
+ std:: env:: var( "RUSTFLAGS" ) . unwrap_or_default( )
334
+ ) ,
335
+ ) ;
336
+ // Make rustc report a stable version string derived from the current nightly's version string.
337
+ let version = rustc_version:: version_meta ( ) . unwrap ( ) . semver ;
338
+ cmd. env (
339
+ "RUSTC_OVERRIDE_VERSION_STRING" ,
340
+ format ! ( "{}.{}.{}" , version. major, version. minor, version. patch) ,
341
+ ) ;
342
+ }
343
+ }
344
+
329
345
pub ( crate ) fn test ( & self , cfg : & Config ) -> TestOutcome {
330
346
eprintln ! ( "testing..." ) ;
331
347
let outcome = if cfg. args . prompt {
0 commit comments