]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/clippy_lints/src/types/option_option.rs
New upstream version 1.53.0+dfsg1
[rustc.git] / src / tools / clippy / clippy_lints / src / types / option_option.rs
CommitLineData
cdc7bbd5
XL
1use clippy_utils::diagnostics::span_lint;
2use clippy_utils::is_ty_param_diagnostic_item;
f20569fa
XL
3use rustc_hir::{self as hir, def_id::DefId, QPath};
4use rustc_lint::LateContext;
5use rustc_span::symbol::sym;
6
f20569fa
XL
7use super::OPTION_OPTION;
8
9pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
10 if cx.tcx.is_diagnostic_item(sym::option_type, def_id)
11 && is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some()
12 {
13 span_lint(
14 cx,
15 OPTION_OPTION,
16 hir_ty.span,
17 "consider using `Option<T>` instead of `Option<Option<T>>` or a custom \
18 enum if you need to distinguish all 3 cases",
19 );
20 true
21 } else {
22 false
23 }
24}