[Clippy] Swap lines_filter_map_ok
to use a diagnostic item instead of path
This commit is contained in:
parent
a786be5d06
commit
3ebff28f80
@ -1575,6 +1575,7 @@
|
|||||||
residual,
|
residual,
|
||||||
result,
|
result,
|
||||||
result_ffi_guarantees,
|
result_ffi_guarantees,
|
||||||
|
result_ok_method,
|
||||||
resume,
|
resume,
|
||||||
return_position_impl_trait_in_trait,
|
return_position_impl_trait_in_trait,
|
||||||
return_type_notation,
|
return_type_notation,
|
||||||
|
@ -653,6 +653,7 @@ pub fn is_err_and(self, f: impl FnOnce(E) -> bool) -> bool {
|
|||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "result_ok_method")]
|
||||||
pub fn ok(self) -> Option<T> {
|
pub fn ok(self) -> Option<T> {
|
||||||
match self {
|
match self {
|
||||||
Ok(x) => Some(x),
|
Ok(x) => Some(x),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use clippy_utils::diagnostics::span_lint_and_then;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::ty::is_type_diagnostic_item;
|
use clippy_utils::ty::is_type_diagnostic_item;
|
||||||
use clippy_utils::{is_diag_item_method, is_trait_method, match_def_path, path_to_local_id, paths};
|
use clippy_utils::{is_diag_item_method, is_trait_method, path_to_local_id};
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::{Body, Closure, Expr, ExprKind};
|
use rustc_hir::{Body, Closure, Expr, ExprKind};
|
||||||
use rustc_lint::{LateContext, LateLintPass};
|
use rustc_lint::{LateContext, LateLintPass};
|
||||||
@ -96,7 +96,7 @@ fn should_lint(cx: &LateContext<'_>, args: &[Expr<'_>], method_str: &str) -> boo
|
|||||||
ExprKind::Path(qpath) => cx
|
ExprKind::Path(qpath) => cx
|
||||||
.qpath_res(qpath, fm_arg.hir_id)
|
.qpath_res(qpath, fm_arg.hir_id)
|
||||||
.opt_def_id()
|
.opt_def_id()
|
||||||
.is_some_and(|did| match_def_path(cx, did, &paths::CORE_RESULT_OK_METHOD)),
|
.is_some_and(|did| cx.tcx.is_diagnostic_item(sym::result_ok_method, did)),
|
||||||
// Detect `|x| x.ok()`
|
// Detect `|x| x.ok()`
|
||||||
ExprKind::Closure(Closure { body, .. }) => {
|
ExprKind::Closure(Closure { body, .. }) => {
|
||||||
if let Body {
|
if let Body {
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
["rustc_lint_defs", "Applicability", "MachineApplicable"],
|
["rustc_lint_defs", "Applicability", "MachineApplicable"],
|
||||||
];
|
];
|
||||||
pub const DIAG: [&str; 2] = ["rustc_errors", "Diag"];
|
pub const DIAG: [&str; 2] = ["rustc_errors", "Diag"];
|
||||||
pub const CORE_RESULT_OK_METHOD: [&str; 4] = ["core", "result", "Result", "ok"];
|
|
||||||
pub const CSTRING_AS_C_STR: [&str; 5] = ["alloc", "ffi", "c_str", "CString", "as_c_str"];
|
pub const CSTRING_AS_C_STR: [&str; 5] = ["alloc", "ffi", "c_str", "CString", "as_c_str"];
|
||||||
pub const EARLY_CONTEXT: [&str; 2] = ["rustc_lint", "EarlyContext"];
|
pub const EARLY_CONTEXT: [&str; 2] = ["rustc_lint", "EarlyContext"];
|
||||||
pub const EARLY_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "EarlyLintPass"];
|
pub const EARLY_LINT_PASS: [&str; 3] = ["rustc_lint", "passes", "EarlyLintPass"];
|
||||||
|
Loading…
Reference in New Issue
Block a user