@@ -11,7 +11,7 @@ extern crate rustc_driver as _;
11
11
12
12
mod rustc_wrapper;
13
13
14
- use std:: { env, fs, path:: PathBuf , process, sync:: Arc } ;
14
+ use std:: { env, fs, path:: PathBuf , process:: ExitCode , sync:: Arc } ;
15
15
16
16
use anyhow:: Context ;
17
17
use lsp_server:: Connection ;
@@ -27,21 +27,15 @@ static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
27
27
#[ global_allocator]
28
28
static ALLOC : jemallocator:: Jemalloc = jemallocator:: Jemalloc ;
29
29
30
- fn main ( ) -> anyhow:: Result < ( ) > {
30
+ fn main ( ) -> anyhow:: Result < ExitCode > {
31
31
if std:: env:: var ( "RA_RUSTC_WRAPPER" ) . is_ok ( ) {
32
- let mut args = std:: env:: args_os ( ) ;
33
- let _me = args. next ( ) . unwrap ( ) ;
34
- let rustc = args. next ( ) . unwrap ( ) ;
35
- let code = match rustc_wrapper:: run_rustc_skipping_cargo_checking ( rustc, args. collect ( ) ) {
36
- Ok ( rustc_wrapper:: ExitCode ( code) ) => code. unwrap_or ( 102 ) ,
37
- Err ( err) => {
38
- eprintln ! ( "{err}" ) ;
39
- 101
40
- }
41
- } ;
42
- process:: exit ( code) ;
32
+ rustc_wrapper:: main ( ) . map_err ( Into :: into)
33
+ } else {
34
+ actual_main ( )
43
35
}
36
+ }
44
37
38
+ fn actual_main ( ) -> anyhow:: Result < ExitCode > {
45
39
let flags = flags:: RustAnalyzer :: from_env_or_exit ( ) ;
46
40
47
41
#[ cfg( debug_assertions) ]
@@ -58,14 +52,14 @@ fn main() -> anyhow::Result<()> {
58
52
let verbosity = flags. verbosity ( ) ;
59
53
60
54
match flags. subcommand {
61
- flags:: RustAnalyzerCmd :: LspServer ( cmd) => {
55
+ flags:: RustAnalyzerCmd :: LspServer ( cmd) => ' lsp_server : {
62
56
if cmd. print_config_schema {
63
57
println ! ( "{:#}" , Config :: json_schema( ) ) ;
64
- return Ok ( ( ) ) ;
58
+ break ' lsp_server ;
65
59
}
66
60
if cmd. version {
67
61
println ! ( "rust-analyzer {}" , rust_analyzer:: version( ) ) ;
68
- return Ok ( ( ) ) ;
62
+ break ' lsp_server ;
69
63
}
70
64
71
65
// rust-analyzer’s “main thread” is actually
@@ -90,7 +84,7 @@ fn main() -> anyhow::Result<()> {
90
84
flags:: RustAnalyzerCmd :: RunTests ( cmd) => cmd. run ( ) ?,
91
85
flags:: RustAnalyzerCmd :: RustcTests ( cmd) => cmd. run ( ) ?,
92
86
}
93
- Ok ( ( ) )
87
+ Ok ( ExitCode :: SUCCESS )
94
88
}
95
89
96
90
fn setup_logging ( log_file_flag : Option < PathBuf > ) -> anyhow:: Result < ( ) > {
0 commit comments