@@ -38,17 +38,19 @@ impl LateLintPass for UselessVec {
38
38
let TypeVariants :: TySlice ( ..) = ty. ty. sty,
39
39
let ExprAddrOf ( _, ref addressee) = expr. node,
40
40
] , {
41
- check_vec_macro( cx, expr , addressee ) ;
41
+ check_vec_macro( cx, addressee , expr . span ) ;
42
42
} }
43
43
44
44
// search for `for _ in vec![…]`
45
45
if let Some ( ( _, arg, _) ) = recover_for_loop ( expr) {
46
- check_vec_macro ( cx, arg, arg) ;
46
+ // report the error around the `vec!` not inside `<std macros>:`
47
+ let span = cx. sess ( ) . codemap ( ) . source_callsite ( arg. span ) ;
48
+ check_vec_macro ( cx, arg, span) ;
47
49
}
48
50
}
49
51
}
50
52
51
- fn check_vec_macro ( cx : & LateContext , expr : & Expr , vec : & Expr ) {
53
+ fn check_vec_macro ( cx : & LateContext , vec : & Expr , span : Span ) {
52
54
if let Some ( vec_args) = unexpand_vec ( cx, vec) {
53
55
let snippet = match vec_args {
54
56
VecArgs :: Repeat ( elem, len) => {
@@ -69,8 +71,8 @@ fn check_vec_macro(cx: &LateContext, expr: &Expr, vec: &Expr) {
69
71
}
70
72
} ;
71
73
72
- span_lint_and_then ( cx, USELESS_VEC , expr . span , "useless use of `vec!`" , |db| {
73
- db. span_suggestion ( expr . span , "you can use a slice directly" , snippet) ;
74
+ span_lint_and_then ( cx, USELESS_VEC , span, "useless use of `vec!`" , |db| {
75
+ db. span_suggestion ( span, "you can use a slice directly" , snippet) ;
74
76
} ) ;
75
77
}
76
78
}
0 commit comments