Skip to content

Commit f921d2e

Browse files
committed
Use post_expect_filter
1 parent 5d34ac5 commit f921d2e

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;
@@ -165,7 +167,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
165167

166168
let conf = clippy_config::Conf::read(sess, &conf_path);
167169
let disabled = build_disabled_set(sess, conf, testing);
168-
clippy_utils::diagnostics::set_disabled(disabled);
170+
set_post_expect_filter(sess, disabled);
169171

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

223+
#[allow(clippy::implicit_hasher)]
224+
pub fn set_post_expect_filter(sess: &Session, disabled: FxHashSet<&'static str>) {
225+
if !disabled.is_empty() {
226+
sess.dcx().set_post_expect_filter(Box::new(move |diag: &DiagInner| {
227+
diag.lint_name().is_some_and(|name| {
228+
let name = name.strip_prefix("clippy::").unwrap_or(name);
229+
disabled.contains(name)
230+
})
231+
}));
232+
}
233+
}
234+
221235
#[allow(clippy::ignored_unit_patterns)]
222236
fn display_help() {
223237
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)