Skip to content

Commit 5b55270

Browse files
committed
[Clippy] Swap filter_map_bool_then to use diagnostic item instead of path
1 parent 25da0e2 commit 5b55270

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ symbols! {
501501
black_box,
502502
block,
503503
bool,
504+
bool_then,
504505
borrowck_graphviz_format,
505506
borrowck_graphviz_postflow,
506507
box_new,

library/core/src/bool.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl bool {
5555
/// assert_eq!(a, 1);
5656
/// ```
5757
#[stable(feature = "lazy_bool_to_option", since = "1.50.0")]
58+
#[cfg_attr(not(test), rustc_diagnostic_item = "bool_then")]
5859
#[inline]
5960
pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> {
6061
if self { Some(f()) } else { None }

src/tools/clippy/clippy_lints/src/methods/filter_map_bool_then.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use super::FILTER_MAP_BOOL_THEN;
22
use clippy_utils::diagnostics::span_lint_and_sugg;
3-
use clippy_utils::paths::BOOL_THEN;
43
use clippy_utils::source::SpanRangeExt;
54
use clippy_utils::ty::is_copy;
6-
use clippy_utils::{is_from_proc_macro, is_trait_method, match_def_path, peel_blocks};
5+
use clippy_utils::{is_from_proc_macro, is_trait_method, peel_blocks};
76
use rustc_errors::Applicability;
87
use rustc_hir::{Expr, ExprKind};
98
use rustc_lint::{LateContext, LintContext};
@@ -35,7 +34,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, arg: &
3534
&& let ExprKind::Closure(then_closure) = then_arg.kind
3635
&& let then_body = peel_blocks(cx.tcx.hir().body(then_closure.body).value)
3736
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(value.hir_id)
38-
&& match_def_path(cx, def_id, &BOOL_THEN)
37+
&& cx.tcx.is_diagnostic_item(sym::bool_then, def_id)
3938
&& !is_from_proc_macro(cx, expr)
4039
// Count the number of derefs needed to get to the bool because we need those in the suggestion
4140
&& let needed_derefs = cx.typeck_results().expr_adjustments(recv)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,3 @@ pub const TOKIO_IO_OPEN_OPTIONS: [&str; 4] = ["tokio", "fs", "open_options", "Op
7474
pub const TOKIO_IO_OPEN_OPTIONS_NEW: [&str; 5] = ["tokio", "fs", "open_options", "OpenOptions", "new"];
7575
pub const INSTANT_NOW: [&str; 4] = ["std", "time", "Instant", "now"];
7676
pub const WAKER: [&str; 4] = ["core", "task", "wake", "Waker"];
77-
pub const BOOL_THEN: [&str; 4] = ["core", "bool", "<impl bool>", "then"];

0 commit comments

Comments
 (0)