Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
Adapt rustc shim code for the new rustc_interface revamp
Browse files Browse the repository at this point in the history
Which was done as a part of rust-lang/rust#56732.
  • Loading branch information
Xanewok committed Mar 10, 2019
1 parent 6a1b5a9 commit f2818a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 67 deletions.
2 changes: 1 addition & 1 deletion rls-rustc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rls-rustc"
version = "0.5.0"
version = "0.6.0"
authors = ["Nick Cameron <ncameron@mozilla.com>"]
description = "A simple shim around rustc to allow using save-analysis with a stable toolchain"
license = "Apache-2.0/MIT"
Expand Down
79 changes: 13 additions & 66 deletions rls-rustc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)| {
Expand All @@ -38,64 +32,17 @@ pub fn run() {
})
.collect::<Vec<_>>();

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<PathBuf>,
g: &Option<PathBuf>,
) -> Compilation {
RustcDefaultCalls.late_callback(a, b, c, d, e, f, g)
}

fn some_input(&mut self, a: Input, b: Option<PathBuf>) -> (Input, Option<PathBuf>) {
RustcDefaultCalls.some_input(a, b)
}

fn no_input(
&mut self,
a: &getopts::Matches,
b: &config::Options,
c: &ast::CrateConfig,
d: &Option<PathBuf>,
e: &Option<PathBuf>,
f: &rustc_errors::registry::Registry,
) -> Option<(Input, Option<PathBuf>)> {
RustcDefaultCalls.no_input(a, b, c, d, e, f)
}

fn build_controller(
self: Box<Self>,
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;
}
}

0 comments on commit f2818a4

Please sign in to comment.