]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/types/option_option.rs
Rollup merge of #93613 - crlf0710:rename_to_async_iter, r=yaahc
[rust.git] / src / tools / clippy / clippy_lints / src / types / option_option.rs
1 use clippy_utils::diagnostics::span_lint;
2 use clippy_utils::{path_def_id, qpath_generic_tys};
3 use if_chain::if_chain;
4 use rustc_hir::{self as hir, def_id::DefId, QPath};
5 use rustc_lint::LateContext;
6 use rustc_span::symbol::sym;
7
8 use super::OPTION_OPTION;
9
10 pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
11     if_chain! {
12         if cx.tcx.is_diagnostic_item(sym::Option, def_id);
13         if let Some(arg) = qpath_generic_tys(qpath).next();
14         if path_def_id(cx, arg) == Some(def_id);
15         then {
16             span_lint(
17                 cx,
18                 OPTION_OPTION,
19                 hir_ty.span,
20                 "consider using `Option<T>` instead of `Option<Option<T>>` or a custom \
21                                      enum if you need to distinguish all 3 cases",
22             );
23             true
24         } else {
25             false
26         }
27     }
28 }