diff options
| author | Yoshitomo Nakanishi <yurayura.rounin.3@gmail.com> | 2021-02-12 14:24:02 +0900 |
|---|---|---|
| committer | Yoshitomo Nakanishi <yurayura.rounin.3@gmail.com> | 2021-03-09 00:49:04 +0900 |
| commit | b59c879fc9e508b4e9a08babf2e4004f396833bb (patch) | |
| tree | 73667a77546642ccd73eb31f58903458c998aa80 | |
| parent | fbd25e93a4ab7b7d357452f7c59f846e984b5d74 (diff) | |
| download | rust-b59c879fc9e508b4e9a08babf2e4004f396833bb.tar.gz rust-b59c879fc9e508b4e9a08babf2e4004f396833bb.zip | |
Move option_option to its own module
| -rw-r--r-- | clippy_lints/src/types/mod.rs | 15 | ||||
| -rw-r--r-- | clippy_lints/src/types/option_option.rs | 23 |
2 files changed, 26 insertions, 12 deletions
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<T>` instead of `Option<Option<T>>` 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<T>` instead of `Option<Option<T>>` or a custom \ + enum if you need to distinguish all 3 cases", + ); + return true; + } + } + false +} |
