@@ -11,6 +11,8 @@ pub struct TypePass;
11
11
12
12
declare_lint ! ( CLIPPY_BOX_VEC , Warn ,
13
13
"Warn on usage of Box<Vec<T>>" )
14
+ declare_lint ! ( CLIPPY_DLIST , Warn ,
15
+ "Warn on usage of DList" )
14
16
15
17
/// Matches a type with a provided string, and returns its type parameters if successful
16
18
pub fn match_ty_unwrap < ' a > ( ty : & ' a Ty , segments : & [ & str ] ) -> Option < & ' a [ P < Ty > ] > {
@@ -45,16 +47,38 @@ pub fn span_note_and_lint(cx: &Context, lint: &'static Lint, span: Span, msg: &s
45
47
46
48
impl LintPass for TypePass {
47
49
fn get_lints ( & self ) -> LintArray {
48
- lint_array ! ( CLIPPY_BOX_VEC )
50
+ lint_array ! ( CLIPPY_BOX_VEC , CLIPPY_DLIST )
49
51
}
50
52
51
53
fn check_ty ( & mut self , cx : & Context , ty : & ast:: Ty ) {
54
+ {
55
+ // In case stuff gets moved around
56
+ use std:: boxed:: Box ;
57
+ use std:: vec:: Vec ;
58
+ }
52
59
match_ty_unwrap ( ty, & [ "std" , "boxed" , "Box" ] ) . and_then ( |t| t. head ( ) )
53
60
. map ( |t| match_ty_unwrap ( & * * t, & [ "std" , "vec" , "Vec" ] ) )
54
61
. map ( |_| {
55
62
span_note_and_lint ( cx, CLIPPY_BOX_VEC , ty. span ,
56
63
"You seem to be trying to use Box<Vec<T>>. Did you mean to use Vec<T>?" ,
57
64
"Vec<T> is already on the heap, Box<Vec<T>> makes an extra allocation" ) ;
58
65
} ) ;
66
+ {
67
+ // In case stuff gets moved around
68
+ use collections:: dlist:: DList as DL1 ;
69
+ use std:: collections:: dlist:: DList as DL2 ;
70
+ use std:: collections:: DList as DL3 ;
71
+ }
72
+ let dlists = [ vec ! [ "std" , "collections" , "dlist" , "DList" ] ,
73
+ vec ! [ "std" , "collections" , "DList" ] ,
74
+ vec ! [ "collections" , "dlist" , "DList" ] ] ;
75
+ for path in dlists. iter ( ) {
76
+ if match_ty_unwrap ( ty, path. as_slice ( ) ) . is_some ( ) {
77
+ span_note_and_lint ( cx, CLIPPY_DLIST , ty. span ,
78
+ "You seem to be trying to use a DList. Perhaps you meant some other data structure?" ,
79
+ "A RingBuf might work." ) ;
80
+ return ;
81
+ }
82
+ }
59
83
}
60
84
}
0 commit comments