Skip to content

Commit cc3ab1c

Browse files
committed
Move linked_list to its own module
1 parent b59c879 commit cc3ab1c

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

clippy_lints/src/types/linked_list.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
use rustc_hir::{self as hir, def_id::DefId};
2+
use rustc_lint::LateContext;
3+
4+
use crate::utils::{match_def_path, paths, span_lint_and_help};
5+
6+
pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, def_id: DefId) -> bool {
7+
if match_def_path(cx, def_id, &paths::LINKED_LIST) {
8+
span_lint_and_help(
9+
cx,
10+
super::LINKEDLIST,
11+
hir_ty.span,
12+
"you seem to be using a `LinkedList`! Perhaps you meant some other data structure?",
13+
None,
14+
"a `VecDeque` might work",
15+
);
16+
true
17+
} else {
18+
false
19+
}
20+
}

clippy_lints/src/types/mod.rs

Lines changed: 5 additions & 18 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 linked_list;
45
mod option_option;
56
mod rc_buffer;
67
mod redundant_allocation;
@@ -39,10 +40,9 @@ use crate::utils::paths;
3940
use crate::utils::sugg::Sugg;
4041
use crate::utils::{
4142
clip, comparisons, differing_macro_contexts, higher, in_constant, indent_of, int_bits, is_hir_ty_cfg_dependant,
42-
is_ty_param_diagnostic_item, is_type_diagnostic_item, match_def_path, match_path, meets_msrv, method_chain_args,
43-
multispan_sugg, numeric_literal::NumericLiteral, reindent_multiline, sext, snippet, snippet_opt,
44-
snippet_with_applicability, snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg,
45-
span_lint_and_then, unsext,
43+
is_type_diagnostic_item, match_path, meets_msrv, method_chain_args, multispan_sugg,
44+
numeric_literal::NumericLiteral, reindent_multiline, sext, snippet, snippet_opt, snippet_with_applicability,
45+
snippet_with_macro_callsite, span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then, unsext,
4646
};
4747

4848
declare_clippy_lint! {
@@ -313,7 +313,6 @@ impl Types {
313313
///
314314
/// The parameter `is_local` distinguishes the context of the type; types from
315315
/// local bindings should only be checked for the `BORROWED_BOX` lint.
316-
#[allow(clippy::too_many_lines)]
317316
fn check_ty(&mut self, cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, is_local: bool) {
318317
if hir_ty.span.from_expansion() {
319318
return;
@@ -329,18 +328,7 @@ impl Types {
329328
triggered |= rc_buffer::check(cx, hir_ty, qpath, def_id);
330329
triggered |= vec_box::check(cx, hir_ty, qpath, def_id, self.vec_box_size_threshold);
331330
triggered |= option_option::check(cx, hir_ty, qpath, def_id);
332-
333-
if match_def_path(cx, def_id, &paths::LINKED_LIST) {
334-
span_lint_and_help(
335-
cx,
336-
LINKEDLIST,
337-
hir_ty.span,
338-
"you seem to be using a `LinkedList`! Perhaps you meant some other data structure?",
339-
None,
340-
"a `VecDeque` might work",
341-
);
342-
return; // don't recurse into the type
343-
}
331+
triggered |= linked_list::check(cx, hir_ty, def_id);
344332

345333
if triggered {
346334
return;
@@ -389,7 +377,6 @@ impl Types {
389377
}
390378
},
391379
TyKind::Rptr(ref lt, ref mut_ty) => self.check_ty_rptr(cx, hir_ty, is_local, lt, mut_ty),
392-
// recurse
393380
TyKind::Slice(ref ty) | TyKind::Array(ref ty, _) | TyKind::Ptr(MutTy { ref ty, .. }) => {
394381
self.check_ty(cx, ty, is_local)
395382
},

clippy_lints/src/types/option_option.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ use rustc_hir::{self as hir, def_id::DefId, QPath};
22
use rustc_lint::LateContext;
33
use rustc_span::symbol::sym;
44

5-
use crate::utils::span_lint;
6-
7-
use super::utils;
5+
use crate::utils::{is_ty_param_diagnostic_item, span_lint};
86

97
pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, qpath: &QPath<'_>, def_id: DefId) -> bool {
108
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() {
9+
if is_ty_param_diagnostic_item(cx, qpath, sym::option_type).is_some() {
1210
span_lint(
1311
cx,
1412
super::OPTION_OPTION,

0 commit comments

Comments
 (0)