Skip to content

Commit 3ebff28

Browse files
committed
[Clippy] Swap lines_filter_map_ok to use a diagnostic item instead of path
1 parent a786be5 commit 3ebff28

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,7 @@ symbols! {
15751575
residual,
15761576
result,
15771577
result_ffi_guarantees,
1578+
result_ok_method,
15781579
resume,
15791580
return_position_impl_trait_in_trait,
15801581
return_type_notation,

library/core/src/result.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ impl<T, E> Result<T, E> {
653653
/// ```
654654
#[inline]
655655
#[stable(feature = "rust1", since = "1.0.0")]
656+
#[cfg_attr(not(test), rustc_diagnostic_item = "result_ok_method")]
656657
pub fn ok(self) -> Option<T> {
657658
match self {
658659
Ok(x) => Some(x),

src/tools/clippy/clippy_lints/src/lines_filter_map_ok.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::ty::is_type_diagnostic_item;
3-
use clippy_utils::{is_diag_item_method, is_trait_method, match_def_path, path_to_local_id, paths};
3+
use clippy_utils::{is_diag_item_method, is_trait_method, path_to_local_id};
44
use rustc_errors::Applicability;
55
use rustc_hir::{Body, Closure, Expr, ExprKind};
66
use rustc_lint::{LateContext, LateLintPass};
@@ -96,7 +96,7 @@ fn should_lint(cx: &LateContext<'_>, args: &[Expr<'_>], method_str: &str) -> boo
9696
ExprKind::Path(qpath) => cx
9797
.qpath_res(qpath, fm_arg.hir_id)
9898
.opt_def_id()
99-
.is_some_and(|did| match_def_path(cx, did, &paths::CORE_RESULT_OK_METHOD)),
99+
.is_some_and(|did| cx.tcx.is_diagnostic_item(sym::result_ok_method, did)),
100100
// Detect `|x| x.ok()`
101101
ExprKind::Closure(Closure { body, .. }) => {
102102
if let Body {

src/tools/clippy/clippy_utils/src/paths.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub const APPLICABILITY_VALUES: [[&str; 3]; 4] = [
1212
["rustc_lint_defs", "Applicability", "MachineApplicable"],
1313
];
1414
pub const DIAG: [&str; 2] = ["rustc_errors", "Diag"];
15-
pub const CORE_RESULT_OK_METHOD: [&str; 4] = ["core", "result", "Result", "ok"];
1615
pub const CSTRING_AS_C_STR: [&str; 5] = ["alloc", "ffi", "c_str", "CString", "as_c_str"];
1716
pub const EARLY_CONTEXT: [&str; 2] = ["rustc_lint", "EarlyContext"];
1817
pub const EARLY_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "EarlyLintPass"];

0 commit comments

Comments
 (0)