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 05fa70e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 72 deletions.
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ path = "rls/src/main.rs"
rls-analysis = "0.16.12"
rls-blacklist = "0.1.3"
rls-data = { version = "0.18.2", features = ["serialize-serde", "serialize-rustc"] }
rls-rustc = "0.5.0"
# FIXME: Release rls-rustc 0.6.0 to crates.io
rls-rustc = { version = "0.6.0", path = "rls-rustc" }
rls-span = { version = "0.4", features = ["serialize-serde"] }
rls-vfs = "0.7"

Expand Down
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 <[email protected]>"]
description = "A simple shim around rustc to allow using save-analysis with a stable toolchain"
license = "Apache-2.0/MIT"
Expand Down
80 changes: 14 additions & 66 deletions rls-rustc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,21 @@ 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 rustc_interface::interface;

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 +33,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 interface::Config) {
config.opts.debugging_opts.continue_parse_after_error = true;
config.opts.debugging_opts.save_analysis = true;
}
}

0 comments on commit 05fa70e

Please sign in to comment.