diff --git a/clippy_lints/src/types/mod.rs b/clippy_lints/src/types/mod.rs index 8506f362517..55f1d86bc56 100644 --- a/clippy_lints/src/types/mod.rs +++ b/clippy_lints/src/types/mod.rs @@ -1,6 +1,7 @@ #![allow(rustc::default_hash_types)] mod box_vec; +mod option_option; mod rc_buffer; mod redundant_allocation; mod utils; @@ -327,19 +328,9 @@ impl Types { triggered |= redundant_allocation::check(cx, hir_ty, qpath, def_id); triggered |= rc_buffer::check(cx, hir_ty, qpath, def_id); triggered |= vec_box::check(cx, hir_ty, qpath, def_id, self.vec_box_size_threshold); + triggered |= option_option::check(cx, hir_ty, qpath, def_id); - if cx.tcx.is_diagnostic_item(sym::option_type, def_id) { - if is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some() { - span_lint( - cx, - OPTION_OPTION, - hir_ty.span, - "consider using `Option` instead of `Option>` or a custom \ - enum if you need to distinguish all 3 cases", - ); - return; // don't recurse into the type - } - } else if match_def_path(cx, def_id, &paths::LINKED_LIST) { + if match_def_path(cx, def_id, &paths::LINKED_LIST) { span_lint_and_help( cx, LINKEDLIST, diff --git a/clippy_lints/src/types/option_option.rs b/clippy_lints/src/types/option_option.rs new file mode 100644 index 00000000000..42aad70438b --- /dev/null +++ b/clippy_lints/src/types/option_option.rs @@ -0,0 +1,23 @@ +use rustc_hir::{self as hir, def_id::DefId, QPath}; +use rustc_lint::LateContext; +use rustc_span::symbol::sym; + +use crate::utils::span_lint; + +use super::utils; + +pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool { + if cx.tcx.is_diagnostic_item(sym::option_type, def_id) { + if utils::is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some() { + span_lint( + cx, + super::OPTION_OPTION, + hir_ty.span, + "consider using `Option` instead of `Option>` or a custom \ + enum if you need to distinguish all 3 cases", + ); + return true; + } + } + false +}