17
17
//! Cargo begins a normal `cargo check` operation with itself set as a proxy
18
18
//! for rustc by setting `primary_unit_rustc` in the build config. When
19
19
//! cargo launches rustc to check a crate, it is actually launching itself.
20
- //! The `FIX_ENV ` environment variable is set so that cargo knows it is in
20
+ //! The `FIX_ENV_INTERNAL ` environment variable is set so that cargo knows it is in
21
21
//! fix-proxy-mode.
22
22
//!
23
- //! Each proxied cargo-as-rustc detects it is in fix-proxy-mode (via `FIX_ENV `
23
+ //! Each proxied cargo-as-rustc detects it is in fix-proxy-mode (via `FIX_ENV_INTERNAL `
24
24
//! environment variable in `main`) and does the following:
25
25
//!
26
26
//! - Acquire a lock from the `LockServer` from the master cargo process.
@@ -63,10 +63,20 @@ use crate::util::Config;
63
63
use crate :: util:: { existing_vcs_repo, LockServer , LockServerClient } ;
64
64
use crate :: { drop_eprint, drop_eprintln} ;
65
65
66
- const FIX_ENV : & str = "__CARGO_FIX_PLZ" ;
67
- const BROKEN_CODE_ENV : & str = "__CARGO_FIX_BROKEN_CODE" ;
68
- const EDITION_ENV : & str = "__CARGO_FIX_EDITION" ;
69
- const IDIOMS_ENV : & str = "__CARGO_FIX_IDIOMS" ;
66
+ /// **Internal only.**
67
+ /// Indicates Cargo is in fix-proxy-mode if presents.
68
+ /// The value of it is the socket address of the [`LockServer`] being used.
69
+ /// See the [module-level documentation](mod@super::fix) for more.
70
+ const FIX_ENV_INTERNAL : & str = "__CARGO_FIX_PLZ" ;
71
+ /// **Internal only.**
72
+ /// For passing [`FixOptions::broken_code`] through to cargo running in proxy mode.
73
+ const BROKEN_CODE_ENV_INTERNAL : & str = "__CARGO_FIX_BROKEN_CODE" ;
74
+ /// **Internal only.**
75
+ /// For passing [`FixOptions::edition`] through to cargo running in proxy mode.
76
+ const EDITION_ENV_INTERNAL : & str = "__CARGO_FIX_EDITION" ;
77
+ /// **Internal only.**
78
+ /// For passing [`FixOptions::idioms`] through to cargo running in proxy mode.
79
+ const IDIOMS_ENV_INTERNAL : & str = "__CARGO_FIX_IDIOMS" ;
70
80
71
81
pub struct FixOptions {
72
82
pub edition : bool ,
@@ -87,20 +97,20 @@ pub fn fix(ws: &Workspace<'_>, opts: &mut FixOptions) -> CargoResult<()> {
87
97
// Spin up our lock server, which our subprocesses will use to synchronize fixes.
88
98
let lock_server = LockServer :: new ( ) ?;
89
99
let mut wrapper = ProcessBuilder :: new ( env:: current_exe ( ) ?) ;
90
- wrapper. env ( FIX_ENV , lock_server. addr ( ) . to_string ( ) ) ;
100
+ wrapper. env ( FIX_ENV_INTERNAL , lock_server. addr ( ) . to_string ( ) ) ;
91
101
let _started = lock_server. start ( ) ?;
92
102
93
103
opts. compile_opts . build_config . force_rebuild = true ;
94
104
95
105
if opts. broken_code {
96
- wrapper. env ( BROKEN_CODE_ENV , "1" ) ;
106
+ wrapper. env ( BROKEN_CODE_ENV_INTERNAL , "1" ) ;
97
107
}
98
108
99
109
if opts. edition {
100
- wrapper. env ( EDITION_ENV , "1" ) ;
110
+ wrapper. env ( EDITION_ENV_INTERNAL , "1" ) ;
101
111
}
102
112
if opts. idioms {
103
- wrapper. env ( IDIOMS_ENV , "1" ) ;
113
+ wrapper. env ( IDIOMS_ENV_INTERNAL , "1" ) ;
104
114
}
105
115
106
116
* opts
@@ -339,7 +349,10 @@ to prevent this issue from happening.
339
349
/// Returns `None` if `fix` is not being run (not in proxy mode). Returns
340
350
/// `Some(...)` if in `fix` proxy mode
341
351
pub fn fix_get_proxy_lock_addr ( ) -> Option < String > {
342
- env:: var ( FIX_ENV ) . ok ( )
352
+ // ALLOWED: For the internal mechanism of `cargo fix` only.
353
+ // Shouldn't be set directly by anyone.
354
+ #[ allow( clippy:: disallowed_methods) ]
355
+ env:: var ( FIX_ENV_INTERNAL ) . ok ( )
343
356
}
344
357
345
358
/// Entry point for `cargo` running as a proxy for `rustc`.
@@ -360,7 +373,7 @@ pub fn fix_exec_rustc(config: &Config, lock_addr: &str) -> CargoResult<()> {
360
373
. ok ( ) ;
361
374
let mut rustc = ProcessBuilder :: new ( & args. rustc ) . wrapped ( workspace_rustc. as_ref ( ) ) ;
362
375
rustc. retry_with_argfile ( true ) ;
363
- rustc. env_remove ( FIX_ENV ) ;
376
+ rustc. env_remove ( FIX_ENV_INTERNAL ) ;
364
377
args. apply ( & mut rustc) ;
365
378
366
379
trace ! ( "start rustfixing {:?}" , args. file) ;
@@ -404,7 +417,7 @@ pub fn fix_exec_rustc(config: &Config, lock_addr: &str) -> CargoResult<()> {
404
417
// user's code with our changes. Back out everything and fall through
405
418
// below to recompile again.
406
419
if !output. status . success ( ) {
407
- if config. get_env_os ( BROKEN_CODE_ENV ) . is_none ( ) {
420
+ if config. get_env_os ( BROKEN_CODE_ENV_INTERNAL ) . is_none ( ) {
408
421
for ( path, file) in fixes. files . iter ( ) {
409
422
debug ! ( "reverting {:?} due to errors" , path) ;
410
423
paths:: write ( path, & file. original_code ) ?;
@@ -578,7 +591,7 @@ fn rustfix_and_fix(
578
591
// worse by applying fixes where a bug could cause *more* broken code.
579
592
// Instead, punt upwards which will reexec rustc over the original code,
580
593
// displaying pretty versions of the diagnostics we just read out.
581
- if !output. status . success ( ) && config. get_env_os ( BROKEN_CODE_ENV ) . is_none ( ) {
594
+ if !output. status . success ( ) && config. get_env_os ( BROKEN_CODE_ENV_INTERNAL ) . is_none ( ) {
582
595
debug ! (
583
596
"rustfixing `{:?}` failed, rustc exited with {:?}" ,
584
597
filename,
@@ -847,9 +860,15 @@ impl FixArgs {
847
860
}
848
861
849
862
let file = file. ok_or_else ( || anyhow:: anyhow!( "could not find .rs file in rustc args" ) ) ?;
850
- let idioms = env:: var ( IDIOMS_ENV ) . is_ok ( ) ;
851
-
852
- let prepare_for_edition = env:: var ( EDITION_ENV ) . ok ( ) . map ( |_| {
863
+ // ALLOWED: For the internal mechanism of `cargo fix` only.
864
+ // Shouldn't be set directly by anyone.
865
+ #[ allow( clippy:: disallowed_methods) ]
866
+ let idioms = env:: var ( IDIOMS_ENV_INTERNAL ) . is_ok ( ) ;
867
+
868
+ // ALLOWED: For the internal mechanism of `cargo fix` only.
869
+ // Shouldn't be set directly by anyone.
870
+ #[ allow( clippy:: disallowed_methods) ]
871
+ let prepare_for_edition = env:: var ( EDITION_ENV_INTERNAL ) . ok ( ) . map ( |_| {
853
872
enabled_edition
854
873
. unwrap_or ( Edition :: Edition2015 )
855
874
. saturating_next ( )
0 commit comments