Skip to content

Commit 91986fa

Browse files
authored
Merge pull request #2836 from mati865/upcoming_breakage
Upcoming breakage
2 parents d68b8ce + b45fb35 commit 91986fa

File tree

6 files changed

+59
-126
lines changed

6 files changed

+59
-126
lines changed

clippy_lints/src/approx_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
use crate::utils::span_lint;
12
use rustc::hir::*;
23
use rustc::lint::*;
34
use std::f64::consts as f64;
45
use syntax::ast::{FloatTy, Lit, LitKind};
56
use syntax::symbol;
6-
use crate::utils::span_lint;
77

88
/// **What it does:** Checks for floating point literals that approximate
99
/// constants which are defined in

clippy_lints/src/arithmetic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
use crate::utils::span_lint;
12
use rustc::hir;
23
use rustc::lint::*;
34
use syntax::codemap::Span;
4-
use crate::utils::span_lint;
55

66
/// **What it does:** Checks for plain integer arithmetic.
77
///

clippy_lints/src/array_indexing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::consts::{constant, Constant};
2+
use crate::utils::higher::Range;
3+
use crate::utils::{self, higher};
24
use rustc::hir;
35
use rustc::lint::*;
46
use rustc::ty;
57
use syntax::ast::RangeLimits;
6-
use crate::utils::higher::Range;
7-
use crate::utils::{self, higher};
88

99
/// **What it does:** Checks for out of bounds array indexing with a constant
1010
/// index.

clippy_lints/src/assign_ops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
use crate::utils::{get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, SpanlessEq};
2+
use crate::utils::{higher, sugg};
13
use rustc::hir;
24
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
35
use rustc::lint::*;
46
use syntax::ast;
5-
use crate::utils::{get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, SpanlessEq};
6-
use crate::utils::{higher, sugg};
77

88
/// **What it does:** Checks for compound assignment operations (`+=` and
99
/// similar).

src/driver.rs

Lines changed: 46 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -12,117 +12,8 @@ extern crate rustc_errors;
1212
extern crate rustc_plugin;
1313
extern crate syntax;
1414

15-
use rustc::session::config::{ErrorOutputType, Input};
16-
use rustc::session::{config, Session};
17-
use rustc_codegen_utils::codegen_backend::CodegenBackend;
18-
use rustc_driver::{driver, Compilation, CompilerCalls, RustcDefaultCalls};
19-
use std::path::PathBuf;
15+
use rustc_driver::{driver::CompileController, Compilation};
2016
use std::process::Command;
21-
use syntax::ast;
22-
23-
struct ClippyCompilerCalls {
24-
default: RustcDefaultCalls,
25-
run_lints: bool,
26-
}
27-
28-
impl ClippyCompilerCalls {
29-
fn new(run_lints: bool) -> Self {
30-
Self {
31-
default: RustcDefaultCalls,
32-
run_lints,
33-
}
34-
}
35-
}
36-
37-
impl<'a> CompilerCalls<'a> for ClippyCompilerCalls {
38-
fn early_callback(
39-
&mut self,
40-
matches: &getopts::Matches,
41-
sopts: &config::Options,
42-
cfg: &ast::CrateConfig,
43-
descriptions: &rustc_errors::registry::Registry,
44-
output: ErrorOutputType,
45-
) -> Compilation {
46-
self.default.early_callback(matches, sopts, cfg, descriptions, output)
47-
}
48-
fn no_input(
49-
&mut self,
50-
matches: &getopts::Matches,
51-
sopts: &config::Options,
52-
cfg: &ast::CrateConfig,
53-
odir: &Option<PathBuf>,
54-
ofile: &Option<PathBuf>,
55-
descriptions: &rustc_errors::registry::Registry,
56-
) -> Option<(Input, Option<PathBuf>)> {
57-
self.default.no_input(matches, sopts, cfg, odir, ofile, descriptions)
58-
}
59-
fn late_callback(
60-
&mut self,
61-
trans_crate: &CodegenBackend,
62-
matches: &getopts::Matches,
63-
sess: &Session,
64-
crate_stores: &rustc::middle::cstore::CrateStore,
65-
input: &Input,
66-
odir: &Option<PathBuf>,
67-
ofile: &Option<PathBuf>,
68-
) -> Compilation {
69-
self.default
70-
.late_callback(trans_crate, matches, sess, crate_stores, input, odir, ofile)
71-
}
72-
fn build_controller(&mut self, sess: &Session, matches: &getopts::Matches) -> driver::CompileController<'a> {
73-
let mut control = self.default.build_controller(sess, matches);
74-
75-
if self.run_lints {
76-
let old = std::mem::replace(&mut control.after_parse.callback, box |_| {});
77-
control.after_parse.callback = Box::new(move |state| {
78-
{
79-
let mut registry = rustc_plugin::registry::Registry::new(
80-
state.session,
81-
state
82-
.krate
83-
.as_ref()
84-
.expect(
85-
"at this compilation stage \
86-
the crate must be parsed",
87-
)
88-
.span,
89-
);
90-
registry.args_hidden = Some(Vec::new());
91-
clippy_lints::register_plugins(&mut registry);
92-
93-
let rustc_plugin::registry::Registry {
94-
early_lint_passes,
95-
late_lint_passes,
96-
lint_groups,
97-
llvm_passes,
98-
attributes,
99-
..
100-
} = registry;
101-
let sess = &state.session;
102-
let mut ls = sess.lint_store.borrow_mut();
103-
for pass in early_lint_passes {
104-
ls.register_early_pass(Some(sess), true, pass);
105-
}
106-
for pass in late_lint_passes {
107-
ls.register_late_pass(Some(sess), true, pass);
108-
}
109-
110-
for (name, to) in lint_groups {
111-
ls.register_group(Some(sess), true, name, to);
112-
}
113-
114-
sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes);
115-
sess.plugin_attributes.borrow_mut().extend(attributes);
116-
}
117-
old(state);
118-
});
119-
120-
control.compilation_done.stop = Compilation::Stop;
121-
}
122-
123-
control
124-
}
125-
}
12617

12718
#[allow(print_stdout)]
12819
fn show_version() {
@@ -198,6 +89,49 @@ pub fn main() {
19889
}
19990
}
20091

201-
let mut ccc = ClippyCompilerCalls::new(clippy_enabled);
202-
rustc_driver::run(move || rustc_driver::run_compiler(&args, &mut ccc, None, None));
92+
let mut controller = CompileController::basic();
93+
if clippy_enabled {
94+
controller.after_parse.callback = Box::new(move |state| {
95+
let mut registry = rustc_plugin::registry::Registry::new(
96+
state.session,
97+
state
98+
.krate
99+
.as_ref()
100+
.expect(
101+
"at this compilation stage \
102+
the crate must be parsed",
103+
)
104+
.span,
105+
);
106+
registry.args_hidden = Some(Vec::new());
107+
clippy_lints::register_plugins(&mut registry);
108+
109+
let rustc_plugin::registry::Registry {
110+
early_lint_passes,
111+
late_lint_passes,
112+
lint_groups,
113+
llvm_passes,
114+
attributes,
115+
..
116+
} = registry;
117+
let sess = &state.session;
118+
let mut ls = sess.lint_store.borrow_mut();
119+
for pass in early_lint_passes {
120+
ls.register_early_pass(Some(sess), true, pass);
121+
}
122+
for pass in late_lint_passes {
123+
ls.register_late_pass(Some(sess), true, pass);
124+
}
125+
126+
for (name, to) in lint_groups {
127+
ls.register_group(Some(sess), true, name, to);
128+
}
129+
130+
sess.plugin_llvm_passes.borrow_mut().extend(llvm_passes);
131+
sess.plugin_attributes.borrow_mut().extend(attributes);
132+
});
133+
}
134+
controller.compilation_done.stop = Compilation::Stop;
135+
136+
rustc_driver::run_compiler(&args, Box::new(controller), None, None);
203137
}

tests/compile-test.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
extern crate compiletest_rs as compiletest;
44
extern crate test;
55

6-
use std::io;
6+
use std::env::{set_var, var};
77
use std::ffi::OsStr;
88
use std::fs;
9-
use std::env::{set_var, var};
9+
use std::io;
1010
use std::path::{Path, PathBuf};
1111

1212
fn clippy_driver_path() -> PathBuf {
@@ -93,12 +93,11 @@ fn run_ui_toml_tests(config: &compiletest::Config, mut tests: Vec<test::TestDesc
9393
relative_dir: dir_path.file_name().unwrap().into(),
9494
};
9595
let test_name = compiletest::make_test_name(&config, &paths);
96-
let index = tests.iter()
96+
let index = tests
97+
.iter()
9798
.position(|test| test.desc.name == test_name)
9899
.expect("The test should be in there");
99-
result &= test::run_tests_console(
100-
&opts,
101-
vec![tests.swap_remove(index)])?;
100+
result &= test::run_tests_console(&opts, vec![tests.swap_remove(index)])?;
102101
}
103102
}
104103
Ok(result)
@@ -111,11 +110,11 @@ fn run_ui_toml() {
111110

112111
let res = run_ui_toml_tests(&config, tests);
113112
match res {
114-
Ok(true) => {}
113+
Ok(true) => {},
115114
Ok(false) => panic!("Some tests failed"),
116115
Err(e) => {
117116
println!("I/O failure during tests: {:?}", e);
118-
}
117+
},
119118
}
120119
}
121120

0 commit comments

Comments
 (0)