Skip to content

Commit c7453b4

Browse files
committed
[Clippy] Swap open_options to use diagnostic items instead of paths
1 parent 917775f commit c7453b4

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

clippy_lints/src/methods/open_options.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,17 +126,18 @@ fn get_open_options(
126126
&& let ExprKind::Path(path) = callee.kind
127127
&& let Some(did) = cx.qpath_res(&path, callee.hir_id).opt_def_id()
128128
{
129-
match_any_def_paths(
130-
cx,
131-
did,
132-
&[
133-
&paths::TOKIO_IO_OPEN_OPTIONS_NEW,
134-
&paths::OPEN_OPTIONS_NEW,
135-
&paths::FILE_OPTIONS,
136-
&paths::TOKIO_FILE_OPTIONS,
137-
],
138-
)
139-
.is_some()
129+
let std_file_options = [
130+
sym::file_options,
131+
sym::open_options_new,
132+
];
133+
134+
let tokio_file_options: &[&[&str]] = &[
135+
&paths::TOKIO_IO_OPEN_OPTIONS_NEW,
136+
&paths::TOKIO_FILE_OPTIONS,
137+
];
138+
139+
let is_std_options = std_file_options.into_iter().any(|sym| cx.tcx.is_diagnostic_item(sym, did));
140+
is_std_options || match_any_def_paths(cx, did, tokio_file_options).is_some()
140141
} else {
141142
false
142143
}

clippy_utils/src/paths.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub const APPLICABILITY_VALUES: [[&str; 3]; 4] = [
1414
pub const DIAG: [&str; 2] = ["rustc_errors", "Diag"];
1515
pub const EARLY_CONTEXT: [&str; 2] = ["rustc_lint", "EarlyContext"];
1616
pub const EARLY_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "EarlyLintPass"];
17-
pub const FILE_OPTIONS: [&str; 4] = ["std", "fs", "File", "options"];
1817
#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
1918
pub const FUTURES_IO_ASYNCREADEXT: [&str; 3] = ["futures_util", "io", "AsyncReadExt"];
2019
#[expect(clippy::invalid_paths)] // internal lints do not know about all external crates
@@ -27,7 +26,6 @@ pub const LATE_CONTEXT: [&str; 2] = ["rustc_lint", "LateContext"];
2726
pub const LATE_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "LateLintPass"];
2827
pub const LINT: [&str; 2] = ["rustc_lint_defs", "Lint"];
2928
pub const MSRV: [&str; 3] = ["clippy_config", "msrvs", "Msrv"];
30-
pub const OPEN_OPTIONS_NEW: [&str; 4] = ["std", "fs", "OpenOptions", "new"];
3129
pub const PARKING_LOT_MUTEX_GUARD: [&str; 3] = ["lock_api", "mutex", "MutexGuard"];
3230
pub const PARKING_LOT_RWLOCK_READ_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwLockReadGuard"];
3331
pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 3] = ["lock_api", "rwlock", "RwLockWriteGuard"];

0 commit comments

Comments
 (0)