@@ -11,7 +11,7 @@ extern crate rustc_driver as _;
1111
1212mod rustc_wrapper;
1313
14- use std:: { env, fs, path:: PathBuf , process, sync:: Arc } ;
14+ use std:: { env, fs, path:: PathBuf , process:: ExitCode , sync:: Arc } ;
1515
1616use anyhow:: Context ;
1717use lsp_server:: Connection ;
@@ -27,21 +27,15 @@ static ALLOC: mimalloc::MiMalloc = mimalloc::MiMalloc;
2727#[ global_allocator]
2828static ALLOC : jemallocator:: Jemalloc = jemallocator:: Jemalloc ;
2929
30- fn main ( ) -> anyhow:: Result < ( ) > {
30+ fn main ( ) -> anyhow:: Result < ExitCode > {
3131 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 ( )
4335 }
36+ }
4437
38+ fn actual_main ( ) -> anyhow:: Result < ExitCode > {
4539 let flags = flags:: RustAnalyzer :: from_env_or_exit ( ) ;
4640
4741 #[ cfg( debug_assertions) ]
@@ -58,14 +52,14 @@ fn main() -> anyhow::Result<()> {
5852 let verbosity = flags. verbosity ( ) ;
5953
6054 match flags. subcommand {
61- flags:: RustAnalyzerCmd :: LspServer ( cmd) => {
55+ flags:: RustAnalyzerCmd :: LspServer ( cmd) => ' lsp_server : {
6256 if cmd. print_config_schema {
6357 println ! ( "{:#}" , Config :: json_schema( ) ) ;
64- return Ok ( ( ) ) ;
58+ break ' lsp_server ;
6559 }
6660 if cmd. version {
6761 println ! ( "rust-analyzer {}" , rust_analyzer:: version( ) ) ;
68- return Ok ( ( ) ) ;
62+ break ' lsp_server ;
6963 }
7064
7165 // rust-analyzer’s “main thread” is actually
@@ -90,7 +84,7 @@ fn main() -> anyhow::Result<()> {
9084 flags:: RustAnalyzerCmd :: RunTests ( cmd) => cmd. run ( ) ?,
9185 flags:: RustAnalyzerCmd :: RustcTests ( cmd) => cmd. run ( ) ?,
9286 }
93- Ok ( ( ) )
87+ Ok ( ExitCode :: SUCCESS )
9488}
9589
9690fn setup_logging ( log_file_flag : Option < PathBuf > ) -> anyhow:: Result < ( ) > {
0 commit comments