5
5
use rustc:: lint:: * ;
6
6
use rustc_front:: hir:: * ;
7
7
use rustc:: middle:: ty;
8
+ use rustc:: front:: map:: Node ;
8
9
9
10
use utils:: { span_lint, match_type} ;
10
11
use utils:: { STRING_PATH , VEC_PATH } ;
@@ -34,6 +35,11 @@ impl LateLintPass for PtrArg {
34
35
35
36
fn check_impl_item ( & mut self , cx : & LateContext , item : & ImplItem ) {
36
37
if let & MethodImplItem ( ref sig, _) = & item. node {
38
+ if let Some ( Node :: NodeItem ( it) ) = cx. tcx . map . find ( cx. tcx . map . get_parent ( item. id ) ) {
39
+ if let ItemImpl ( _, _, _, Some ( _) , _, _) = it. node {
40
+ return ; // ignore trait impls
41
+ }
42
+ }
37
43
check_fn ( cx, & sig. decl ) ;
38
44
}
39
45
}
@@ -47,8 +53,8 @@ impl LateLintPass for PtrArg {
47
53
48
54
fn check_fn ( cx : & LateContext , decl : & FnDecl ) {
49
55
for arg in & decl. inputs {
50
- if let Some ( pat_ty ) = cx. tcx . pat_ty_opt ( & arg. pat ) {
51
- if let ty:: TyRef ( _, ty:: TypeAndMut { ty, mutbl : MutImmutable } ) = pat_ty . sty {
56
+ if let Some ( ty ) = cx. tcx . ast_ty_to_ty_cache . borrow ( ) . get ( & arg. ty . id ) {
57
+ if let ty:: TyRef ( _, ty:: TypeAndMut { ty, mutbl : MutImmutable } ) = ty . sty {
52
58
if match_type ( cx, ty, & VEC_PATH ) {
53
59
span_lint ( cx, PTR_ARG , arg. ty . span ,
54
60
"writing `&Vec<_>` instead of `&[_]` involves one more reference \
0 commit comments