From f2818a4b7c1d6717239eda78ff62bc073aec94be Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Sun, 10 Mar 2019 13:06:59 +0100 Subject: [PATCH] Adapt rustc shim code for the new rustc_interface revamp Which was done as a part of https://github.com/rust-lang/rust/pull/56732. --- rls-rustc/Cargo.toml | 2 +- rls-rustc/src/lib.rs | 79 ++++++++------------------------------------ 2 files changed, 14 insertions(+), 67 deletions(-) diff --git a/rls-rustc/Cargo.toml b/rls-rustc/Cargo.toml index 553086f0cf7..82c6ea16b26 100644 --- a/rls-rustc/Cargo.toml +++ b/rls-rustc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rls-rustc" -version = "0.5.0" +version = "0.6.0" authors = ["Nick Cameron "] description = "A simple shim around rustc to allow using save-analysis with a stable toolchain" license = "Apache-2.0/MIT" diff --git a/rls-rustc/src/lib.rs b/rls-rustc/src/lib.rs index b3f4800bb3d..8df70a270f9 100644 --- a/rls-rustc/src/lib.rs +++ b/rls-rustc/src/lib.rs @@ -6,26 +6,20 @@ extern crate rustc; extern crate rustc_codegen_utils; extern crate rustc_driver; extern crate rustc_errors; +extern crate rustc_interface; extern crate rustc_metadata; extern crate syntax; -use rustc::session::config::{self, ErrorOutputType, Input}; -use rustc::session::{early_error, Session}; -use rustc_codegen_utils::codegen_backend::CodegenBackend; -use rustc_driver::driver::CompileController; -use rustc_driver::{ - enable_save_analysis, run_compiler, Compilation, CompilerCalls, RustcDefaultCalls, -}; -use rustc_metadata::cstore::CStore; -use syntax::ast; +use rustc::session::config::ErrorOutputType; +use rustc::session::early_error; +use rustc_driver::{run_compiler, Callbacks}; use std::env; -use std::path::PathBuf; use std::process; pub fn run() { drop(env_logger::init()); - let result = rustc_driver::run(|| { + let result = rustc_driver::report_ices_to_stderr_if_any(|| { let args = env::args_os() .enumerate() .map(|(i, arg)| { @@ -38,64 +32,17 @@ pub fn run() { }) .collect::>(); - run_compiler(&args, Box::new(ShimCalls), None, None) - }); - process::exit(result as i32); + run_compiler(&args, &mut ShimCalls, None, None) + }) + .and_then(|result| result); + process::exit(result.is_err() as i32); } struct ShimCalls; -impl<'a> CompilerCalls<'a> for ShimCalls { - fn early_callback( - &mut self, - a: &getopts::Matches, - b: &config::Options, - c: &ast::CrateConfig, - d: &rustc_errors::registry::Registry, - e: ErrorOutputType, - ) -> Compilation { - RustcDefaultCalls.early_callback(a, b, c, d, e) - } - - fn late_callback( - &mut self, - a: &CodegenBackend, - b: &getopts::Matches, - c: &Session, - d: &CStore, - e: &Input, - f: &Option, - g: &Option, - ) -> Compilation { - RustcDefaultCalls.late_callback(a, b, c, d, e, f, g) - } - - fn some_input(&mut self, a: Input, b: Option) -> (Input, Option) { - RustcDefaultCalls.some_input(a, b) - } - - fn no_input( - &mut self, - a: &getopts::Matches, - b: &config::Options, - c: &ast::CrateConfig, - d: &Option, - e: &Option, - f: &rustc_errors::registry::Registry, - ) -> Option<(Input, Option)> { - RustcDefaultCalls.no_input(a, b, c, d, e, f) - } - - fn build_controller( - self: Box, - a: &Session, - b: &getopts::Matches, - ) -> CompileController<'a> { - let mut result = Box::new(RustcDefaultCalls).build_controller(a, b); - - result.continue_parse_after_error = true; - enable_save_analysis(&mut result); - - result +impl Callbacks for ShimCalls { + fn config(&mut self, config: &mut rustc_interface::Config) { + config.opts.debugging_opts.continue_parse_after_error = true; + config.opts.debugging_opts.save_analysis = true; } }