]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/types/option_option.rs
42aad70438b5f4dfaee3b4e5a2bd0aa588ba29bd
[rust.git] / clippy_lints / src / types / option_option.rs
1 use rustc_hir::{self as hir, def_id::DefId, QPath};
2 use rustc_lint::LateContext;
3 use rustc_span::symbol::sym;
4
5 use crate::utils::span_lint;
6
7 use super::utils;
8
9 pub(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         if utils::is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some() {
12             span_lint(
13                 cx,
14                 super::OPTION_OPTION,
15                 hir_ty.span,
16                 "consider using `Option<T>` instead of `Option<Option<T>>` or a custom \
17                                  enum if you need to distinguish all 3 cases",
18             );
19             return true;
20         }
21     }
22     false
23 }