Skip to content

Commit b59c879

Browse files
committed
Move option_option to its own module
1 parent fbd25e9 commit b59c879

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

clippy_lints/src/types/mod.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![allow(rustc::default_hash_types)]
22

33
mod box_vec;
4+
mod option_option;
45
mod rc_buffer;
56
mod redundant_allocation;
67
mod utils;
@@ -327,19 +328,9 @@ impl Types {
327328
triggered |= redundant_allocation::check(cx, hir_ty, qpath, def_id);
328329
triggered |= rc_buffer::check(cx, hir_ty, qpath, def_id);
329330
triggered |= vec_box::check(cx, hir_ty, qpath, def_id, self.vec_box_size_threshold);
331+
triggered |= option_option::check(cx, hir_ty, qpath, def_id);
330332

331-
if cx.tcx.is_diagnostic_item(sym::option_type, def_id) {
332-
if is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some() {
333-
span_lint(
334-
cx,
335-
OPTION_OPTION,
336-
hir_ty.span,
337-
"consider using `Option<T>` instead of `Option<Option<T>>` or a custom \
338-
enum if you need to distinguish all 3 cases",
339-
);
340-
return; // don't recurse into the type
341-
}
342-
} else if match_def_path(cx, def_id, &paths::LINKED_LIST) {
333+
if match_def_path(cx, def_id, &paths::LINKED_LIST) {
343334
span_lint_and_help(
344335
cx,
345336
LINKEDLIST,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}

0 commit comments

Comments
 (0)