Merge pull request #2836 from mati865/upcoming_breakage
Upcoming breakage
diff --git a/clippy_lints/src/approx_const.rs b/clippy_lints/src/approx_const.rs
index 704546a..0288176 100644
--- a/clippy_lints/src/approx_const.rs
+++ b/clippy_lints/src/approx_const.rs
@@ -1,9 +1,9 @@
+use crate::utils::span_lint;
use rustc::hir::*;
use rustc::lint::*;
use std::f64::consts as f64;
use syntax::ast::{FloatTy, Lit, LitKind};
use syntax::symbol;
-use crate::utils::span_lint;
/// **What it does:** Checks for floating point literals that approximate
/// constants which are defined in
diff --git a/clippy_lints/src/arithmetic.rs b/clippy_lints/src/arithmetic.rs
index ff32fcb..a9ccc33 100644
--- a/clippy_lints/src/arithmetic.rs
+++ b/clippy_lints/src/arithmetic.rs
@@ -1,7 +1,7 @@
+use crate::utils::span_lint;
use rustc::hir;
use rustc::lint::*;
use syntax::codemap::Span;
-use crate::utils::span_lint;
/// **What it does:** Checks for plain integer arithmetic.
///
diff --git a/clippy_lints/src/array_indexing.rs b/clippy_lints/src/array_indexing.rs
index 6002960..77aa5e8 100644
--- a/clippy_lints/src/array_indexing.rs
+++ b/clippy_lints/src/array_indexing.rs
@@ -1,10 +1,10 @@
use crate::consts::{constant, Constant};
+use crate::utils::higher::Range;
+use crate::utils::{self, higher};
use rustc::hir;
use rustc::lint::*;
use rustc::ty;
use syntax::ast::RangeLimits;
-use crate::utils::higher::Range;
-use crate::utils::{self, higher};
/// **What it does:** Checks for out of bounds array indexing with a constant
/// index.
diff --git a/clippy_lints/src/assign_ops.rs b/clippy_lints/src/assign_ops.rs
index 44398a9..ba40561 100644
--- a/clippy_lints/src/assign_ops.rs
+++ b/clippy_lints/src/assign_ops.rs
@@ -1,9 +1,9 @@
+use crate::utils::{get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, SpanlessEq};
+use crate::utils::{higher, sugg};
use rustc::hir;
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc::lint::*;
use syntax::ast;
-use crate::utils::{get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, SpanlessEq};
-use crate::utils::{higher, sugg};
/// **What it does:** Checks for compound assignment operations (`+=` and
/// similar).
diff --git a/src/driver.rs b/src/driver.rs
index a88d6e5..830c898 100644
--- a/src/driver.rs
+++ b/src/driver.rs
@@ -12,117 +12,8 @@
extern crate rustc_plugin;
extern crate syntax;
-use rustc::session::config::{ErrorOutputType, Input};
-use rustc::session::{config, Session};
-use rustc_codegen_utils::codegen_backend::CodegenBackend;
-use rustc_driver::{driver, Compilation, CompilerCalls, RustcDefaultCalls};
-use std::path::PathBuf;
+use rustc_driver::{driver::CompileController, Compilation};
use std::process::Command;
-use syntax::ast;
-
-struct ClippyCompilerCalls {
- default: RustcDefaultCalls,
- run_lints: bool,
-}
-
-impl ClippyCompilerCalls {
- fn new(run_lints: bool) -> Self {
- Self {
- default: RustcDefaultCalls,
- run_lints,
- }
- }
-}
-
-impl<'a> CompilerCalls<'a> for ClippyCompilerCalls {
- fn early_callback(
- &mut self,
- matches: &getopts::Matches,
- sopts: &config::Options,
- cfg: &ast::CrateConfig,
- descriptions: &rustc_errors::registry::Registry,
- output: ErrorOutputType,
- ) -> Compilation {
- self.default.early_callback(matches, sopts, cfg, descriptions, output)
- }
- fn no_input(
- &mut self,
- matches: &getopts::Matches,
- sopts: &config::Options,
- cfg: &ast::CrateConfig,
- odir: &Option<PathBuf>,
- ofile: &Option<PathBuf>,
- descriptions: &rustc_errors::registry::Registry,
- ) -> Option<(Input, Option<PathBuf>)> {
- self.default.no_input(matches, sopts, cfg, odir, ofile, descriptions)
- }
- fn late_callback(
- &mut self,
- trans_crate: &CodegenBackend,
- matches: &getopts::Matches,
- sess: &Session,
- crate_stores: &rustc::middle::cstore::CrateStore,
- input: &Input,
- odir: &Option<PathBuf>,
- ofile: &Option<PathBuf>,
- ) -> Compilation {
- self.default
- .late_callback(trans_crate, matches, sess, crate_stores, input, odir, ofile)
- }
- fn build_controller(&mut self, sess: &Session, matches: &getopts::Matches) -> driver::CompileController<'a> {
- let mut control = self.default.build_controller(sess, matches);
-
- if self.run_lints {
- let old = std::mem::replace(&mut control.after_parse.callback, box |_| {});
- control.after_parse.callback = Box::new(move |state| {
- {
- let mut registry = rustc_plugin::registry::Registry::new(
- state.session,
- state
- .krate
- .as_ref()
- .expect(
- "at this compilation stage \
- the crate must be parsed",
- )
- .span,
- );
- registry.args_hidden = Some(Vec::new());
- clippy_lints::register_plugins(&mut registry);
-
- let rustc_plugin::registry::Registry {
- early_lint_passes,
- late_lint_passes,
- lint_groups,
- llvm_passes,
- attributes,
- ..
- } = registry;
- let sess = &state.session;
- let mut ls = sess.lint_store.borrow_mut();
- for pass in early_lint_passes {
- ls.register_early_pass(Some(sess), true, pass);
- }
- for pass in late_lint_passes {
- ls.register_late_pass(Some(sess), true, pass);
- }
-
- for (name, to) in lint_groups {
- ls.register_group(Some(sess), true, name, to);
- }
-
- sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes);
- sess.plugin_attributes.borrow_mut().extend(attributes);
- }
- old(state);
- });
-
- control.compilation_done.stop = Compilation::Stop;
- }
-
- control
- }
-}
#[allow(print_stdout)]
fn show_version() {
@@ -198,6 +89,49 @@
}
}
- let mut ccc = ClippyCompilerCalls::new(clippy_enabled);
- rustc_driver::run(move || rustc_driver::run_compiler(&args, &mut ccc, None, None));
+ let mut controller = CompileController::basic();
+ if clippy_enabled {
+ controller.after_parse.callback = Box::new(move |state| {
+ let mut registry = rustc_plugin::registry::Registry::new(
+ state.session,
+ state
+ .krate
+ .as_ref()
+ .expect(
+ "at this compilation stage \
+ the crate must be parsed",
+ )
+ .span,
+ );
+ registry.args_hidden = Some(Vec::new());
+ clippy_lints::register_plugins(&mut registry);
+
+ let rustc_plugin::registry::Registry {
+ early_lint_passes,
+ late_lint_passes,
+ lint_groups,
+ llvm_passes,
+ attributes,
+ ..
+ } = registry;
+ let sess = &state.session;
+ let mut ls = sess.lint_store.borrow_mut();
+ for pass in early_lint_passes {
+ ls.register_early_pass(Some(sess), true, pass);
+ }
+ for pass in late_lint_passes {
+ ls.register_late_pass(Some(sess), true, pass);
+ }
+
+ for (name, to) in lint_groups {
+ ls.register_group(Some(sess), true, name, to);
+ }
+
+ sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes);
+ sess.plugin_attributes.borrow_mut().extend(attributes);
+ });
+ }
+ controller.compilation_done.stop = Compilation::Stop;
+
+ rustc_driver::run_compiler(&args, Box::new(controller), None, None);
}
diff --git a/tests/compile-test.rs b/tests/compile-test.rs
index 236cce0..da5c5bd 100644
--- a/tests/compile-test.rs
+++ b/tests/compile-test.rs
@@ -3,10 +3,10 @@
extern crate compiletest_rs as compiletest;
extern crate test;
-use std::io;
+use std::env::{set_var, var};
use std::ffi::OsStr;
use std::fs;
-use std::env::{set_var, var};
+use std::io;
use std::path::{Path, PathBuf};
fn clippy_driver_path() -> PathBuf {
@@ -93,12 +93,11 @@
relative_dir: dir_path.file_name().unwrap().into(),
};
let test_name = compiletest::make_test_name(&config, &paths);
- let index = tests.iter()
+ let index = tests
+ .iter()
.position(|test| test.desc.name == test_name)
.expect("The test should be in there");
- result &= test::run_tests_console(
- &opts,
- vec![tests.swap_remove(index)])?;
+ result &= test::run_tests_console(&opts, vec![tests.swap_remove(index)])?;
}
}
Ok(result)
@@ -111,11 +110,11 @@
let res = run_ui_toml_tests(&config, tests);
match res {
- Ok(true) => {}
+ Ok(true) => {},
Ok(false) => panic!("Some tests failed"),
Err(e) => {
println!("I/O failure during tests: {:?}", e);
- }
+ },
}
}