Skip to content

Commit e27511b

Browse files
committed
Use post_expect_filter
1 parent ec9b67e commit e27511b

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

src/driver.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// (Currently there is no way to opt into sysroot crates without `extern crate`.)
1111
extern crate rustc_data_structures;
1212
extern crate rustc_driver;
13+
extern crate rustc_errors;
1314
extern crate rustc_interface;
1415
extern crate rustc_session;
1516
extern crate rustc_span;
@@ -23,6 +24,7 @@ use clippy_config::Conf;
2324
use clippy_utils::sym;
2425
use declare_clippy_lint::LintListBuilder;
2526
use rustc_data_structures::fx::FxHashSet;
27+
use rustc_errors::DiagInner;
2628
use rustc_interface::interface;
2729
use rustc_session::config::ErrorOutputType;
2830
use rustc_session::parse::ParseSess;
@@ -164,7 +166,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
164166

165167
let conf = clippy_config::Conf::read(sess, &conf_path);
166168
let disabled = build_disabled_set(sess, conf, testing);
167-
clippy_utils::diagnostics::set_disabled(disabled);
169+
set_post_expect_filter(sess, disabled);
168170

169171
let mut list_builder = LintListBuilder::default();
170172
list_builder.insert(clippy_lints::declared_lints::LINTS);
@@ -217,6 +219,18 @@ fn build_disabled_set(sess: &Session, conf: &'static Conf, testing: bool) -> FxH
217219
disabled
218220
}
219221

222+
#[allow(clippy::implicit_hasher)]
223+
pub fn set_post_expect_filter(sess: &Session, disabled: FxHashSet<&'static str>) {
224+
if !disabled.is_empty() {
225+
sess.dcx().set_post_expect_filter(Box::new(move |diag: &DiagInner| {
226+
diag.lint_name().is_some_and(|name| {
227+
let name = name.strip_prefix("clippy::").unwrap_or(name);
228+
disabled.contains(name)
229+
})
230+
}));
231+
}
232+
}
233+
220234
#[allow(clippy::ignored_unit_patterns)]
221235
fn display_help() {
222236
println!("{}", help_message());
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
disabled-in-tests = ["unwrap_used"]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@check-pass
2+
//@compile-flags: --test
3+
4+
#![allow(clippy::unnecessary_literal_unwrap)]
5+
#![warn(clippy::unwrap_used)]
6+
7+
fn main() {}
8+
9+
fn foo(opt: Option<i32>) {
10+
#[expect(clippy::unwrap_used)]
11+
opt.unwrap();
12+
}
13+
14+
#[test]
15+
fn unwrap_some() {
16+
Some(()).unwrap();
17+
}

tests/ui-toml/disabled_in_tests_expect/expect.stderr

Whitespace-only changes.

0 commit comments

Comments
 (0)