@@ -3,7 +3,7 @@ use rustc::middle::ty::TypeVariants;
3
3
use rustc_front:: hir:: * ;
4
4
use syntax:: codemap:: Span ;
5
5
use syntax:: ptr:: P ;
6
- use utils:: { BOX_NEW_PATH , VEC_FROM_ELEM_PATH } ;
6
+ use utils:: VEC_FROM_ELEM_PATH ;
7
7
use utils:: { is_expn_of, match_path, snippet, span_lint_and_then} ;
8
8
9
9
/// **What it does:** This lint warns about using `&vec![..]` when using `&[..]` would be possible.
@@ -33,9 +33,7 @@ impl LintPass for UselessVec {
33
33
34
34
impl LateLintPass for UselessVec {
35
35
fn check_expr ( & mut self , cx : & LateContext , expr : & Expr ) {
36
- unexpand_vec ( cx, expr) ;
37
-
38
- // search for `&!vec[_]` expressions where the adjusted type is `&[_]`
36
+ // search for `&vec![_]` expressions where the adjusted type is `&[_]`
39
37
if_let_chain ! { [
40
38
let TypeVariants :: TyRef ( _, ref ty) = cx. tcx. expr_ty_adjusted( expr) . sty,
41
39
let TypeVariants :: TySlice ( ..) = ty. ty. sty,
@@ -71,7 +69,7 @@ impl LateLintPass for UselessVec {
71
69
72
70
/// Represent the pre-expansion arguments of a `vec!` invocation.
73
71
pub enum VecArgs < ' a > {
74
- /// `vec![elem, len]`
72
+ /// `vec![elem; len]`
75
73
Repeat ( & ' a P < Expr > , & ' a P < Expr > ) ,
76
74
/// `vec![a, b, c]`
77
75
Vec ( & ' a [ P < Expr > ] ) ,
@@ -91,10 +89,8 @@ pub fn unexpand_vec<'e>(cx: &LateContext, expr: &'e Expr) -> Option<VecArgs<'e>>
91
89
else if match_path( path, & [ "into_vec" ] ) && args. len( ) == 1 {
92
90
// `vec![a, b, c]` case
93
91
if_let_chain!{ [
94
- let ExprCall ( ref fun, ref args) = args[ 0 ] . node,
95
- let ExprPath ( _, ref path) = fun. node,
96
- match_path( path, & BOX_NEW_PATH ) && args. len( ) == 1 ,
97
- let ExprVec ( ref args) = args[ 0 ] . node
92
+ let ExprBox ( ref boxed) = args[ 0 ] . node,
93
+ let ExprVec ( ref args) = boxed. node
98
94
] , {
99
95
return Some ( VecArgs :: Vec ( & * args) ) ;
100
96
} }
0 commit comments