Skip to content

Commit 3043a7b

Browse files
committed
Improve warnings on incompatible options involving -Zinstrument-coverage
Adds checks for: * `no_core` attribute * explicitly-enabled `legacy` symbol mangling * mir_opt_level > 1 (which enables inlining) I removed code from the `Inline` MIR pass that forcibly disabled inlining if `-Zinstrument-coverage` was set. The default `mir_opt_level` does not enable inlining anyway. But if the level is explicitly set and is greater than 1, I issue a warning. The new warnings show up in tests, which is much better for diagnosing potential option conflicts in these cases.
1 parent 0e527ba commit 3043a7b

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/driver.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn arg_value<'a, T: Deref<Target = str>>(
4141

4242
match arg.next().or_else(|| args.next()) {
4343
Some(v) if pred(v) => return Some(v),
44-
_ => {},
44+
_ => {}
4545
}
4646
}
4747
None
@@ -85,7 +85,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
8585
// run on the unoptimized MIR. On the other hand this results in some false negatives. If
8686
// MIR passes can be enabled / disabled separately, we should figure out, what passes to
8787
// use for Clippy.
88-
config.opts.debugging_opts.mir_opt_level = 0;
88+
config.opts.debugging_opts.mir_opt_level = Some(0);
8989
}
9090
}
9191

@@ -121,11 +121,12 @@ You can use tool lints to allow or deny lints from your code, eg.:
121121

122122
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/new";
123123

124-
static ICE_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> = SyncLazy::new(|| {
125-
let hook = panic::take_hook();
126-
panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL)));
127-
hook
128-
});
124+
static ICE_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> =
125+
SyncLazy::new(|| {
126+
let hook = panic::take_hook();
127+
panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL)));
128+
hook
129+
});
129130

130131
fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
131132
// Invoke our ICE handler, which prints the actual panic message and optionally a backtrace
@@ -257,14 +258,17 @@ pub fn main() {
257258

258259
// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
259260
// We're invoking the compiler programmatically, so we ignore this/
260-
let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref());
261+
let wrapper_mode =
262+
orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref());
261263

262264
if wrapper_mode {
263265
// we still want to be able to invoke it normally though
264266
orig_args.remove(1);
265267
}
266268

267-
if !wrapper_mode && (orig_args.iter().any(|a| a == "--help" || a == "-h") || orig_args.len() == 1) {
269+
if !wrapper_mode
270+
&& (orig_args.iter().any(|a| a == "--help" || a == "-h") || orig_args.len() == 1)
271+
{
268272
display_help();
269273
exit(0);
270274
}
@@ -285,13 +289,11 @@ pub fn main() {
285289
if clippy_enabled {
286290
args.extend(vec!["--cfg".into(), r#"feature="cargo-clippy""#.into()]);
287291
if let Ok(extra_args) = env::var("CLIPPY_ARGS") {
288-
args.extend(extra_args.split("__CLIPPY_HACKERY__").filter_map(|s| {
289-
if s.is_empty() {
290-
None
291-
} else {
292-
Some(s.to_string())
293-
}
294-
}));
292+
args.extend(
293+
extra_args
294+
.split("__CLIPPY_HACKERY__")
295+
.filter_map(|s| if s.is_empty() { None } else { Some(s.to_string()) }),
296+
);
295297
}
296298
}
297299
let mut clippy = ClippyCallbacks;

0 commit comments

Comments
 (0)