@@ -69,12 +69,12 @@ pub(crate) fn rustc(
69
69
70
70
let changed = vfs. get_cached_files ( ) ;
71
71
72
- let mut local_envs = envs. clone ( ) ;
72
+ let mut envs = envs. clone ( ) ;
73
73
74
74
let clippy_preference = {
75
75
let config = rls_config. lock ( ) . unwrap ( ) ;
76
76
if config. clear_env_rust_log {
77
- local_envs . insert ( String :: from ( "RUST_LOG" ) , None ) ;
77
+ envs . insert ( String :: from ( "RUST_LOG" ) , None ) ;
78
78
}
79
79
80
80
config. clippy_preference
@@ -89,15 +89,16 @@ pub(crate) fn rustc(
89
89
"RLS_OUT_OF_PROCESS" ,
90
90
) {
91
91
#[ cfg( feature = "ipc" ) ]
92
- Ok ( ..) => run_out_of_process ( changed, & args, & local_envs, clippy_preference) ,
92
+ Ok ( ..) => run_out_of_process ( changed. clone ( ) , & args, & envs, clippy_preference)
93
+ . unwrap_or_else ( |_| {
94
+ run_in_process ( changed, & args, clippy_preference, lock_environment ( & envs, cwd) )
95
+ } ) ,
93
96
#[ cfg( not( feature = "ipc" ) ) ]
94
97
Ok ( ..) => {
95
- log:: warn!( "Support for out-of-process compilation was not compiled. Re-build with 'ipc' feature enabled" ) ;
96
- run_in_process ( changed, & args, clippy_preference, lock_environment ( & local_envs, cwd) )
97
- }
98
- Err ( ..) => {
99
- run_in_process ( changed, & args, clippy_preference, lock_environment ( & local_envs, cwd) )
98
+ log:: warn!( "Support for out-of-process compilation was not compiled. Rebuild with 'ipc' feature enabled" ) ;
99
+ run_in_process ( changed, & args, clippy_preference, lock_environment ( & envs, cwd) )
100
100
}
101
+ Err ( ..) => run_in_process ( changed, & args, clippy_preference, lock_environment ( & envs, cwd) ) ,
101
102
} ;
102
103
103
104
let stderr = String :: from_utf8 ( stderr) . unwrap ( ) ;
@@ -128,13 +129,12 @@ fn run_out_of_process(
128
129
args : & [ String ] ,
129
130
envs : & HashMap < String , Option < OsString > > ,
130
131
clippy_preference : ClippyPreference ,
131
- ) -> CompilationResult {
132
+ ) -> Result < CompilationResult , ( ) > {
132
133
let analysis = Arc :: default ( ) ;
133
134
let input_files = Arc :: default ( ) ;
134
135
135
136
let ipc_server =
136
- super :: ipc:: start_with_all ( changed, Arc :: clone ( & analysis) , Arc :: clone ( & input_files) ) ;
137
- let ipc_server = ipc_server. unwrap ( ) ; // TODO: Handle unwrap
137
+ super :: ipc:: start_with_all ( changed, Arc :: clone ( & analysis) , Arc :: clone ( & input_files) ) ?;
138
138
139
139
// Compiling out of process is only supported by our own shim
140
140
let rustc_shim = env:: current_exe ( )
@@ -143,13 +143,11 @@ fn run_out_of_process(
143
143
. expect ( "Couldn't set executable for RLS rustc shim" ) ;
144
144
145
145
let output = Command :: new ( rustc_shim)
146
- // In case RLS is set as the rustc shim signal to `main_inner()` to call
147
- // `rls_rustc::run()`.
148
146
. env ( crate :: RUSTC_SHIM_ENV_VAR_NAME , "1" )
149
147
. env ( "RLS_IPC_ENDPOINT" , ipc_server. endpoint ( ) )
150
148
. env ( "RLS_CLIPPY_PREFERENCE" , clippy_preference. to_string ( ) )
151
149
. args ( args. iter ( ) . skip ( 1 ) )
152
- . envs ( envs. clone ( ) . into_iter ( ) . filter_map ( |( k, v) | v. map ( |v| ( k, v) ) ) )
150
+ . envs ( envs. iter ( ) . filter_map ( |( k, v) | v. as_ref ( ) . map ( |v| ( k, v) ) ) )
153
151
. output ( )
154
152
. map_err ( |_| ( ) ) ;
155
153
@@ -166,7 +164,7 @@ fn run_out_of_process(
166
164
let analysis = unwrap_shared ( analysis, "Other ref dropped by closed IPC server" ) ;
167
165
// FIXME(#25): given that we are running the compiler directly, there is no need
168
166
// to serialize the error messages -- we should pass them in memory.
169
- CompilationResult { result, stderr, analysis, input_files }
167
+ Ok ( CompilationResult { result, stderr, analysis, input_files } )
170
168
}
171
169
172
170
fn run_in_process (
0 commit comments