@@ -88,15 +88,15 @@ impl LateLintPass for Functions {
88
88
self . check_arg_number ( cx, decl, span) ;
89
89
}
90
90
91
- self . check_raw_ptr ( cx, unsafety, decl, block, span , nodeid) ;
91
+ self . check_raw_ptr ( cx, unsafety, decl, block, nodeid) ;
92
92
}
93
93
94
94
fn check_trait_item ( & mut self , cx : & LateContext , item : & hir:: TraitItem ) {
95
95
if let hir:: MethodTraitItem ( ref sig, ref block) = item. node {
96
96
self . check_arg_number ( cx, & sig. decl , item. span ) ;
97
97
98
98
if let Some ( ref block) = * block {
99
- self . check_raw_ptr ( cx, sig. unsafety , & sig. decl , block, item. span , item . id ) ;
99
+ self . check_raw_ptr ( cx, sig. unsafety , & sig. decl , block, item. id ) ;
100
100
}
101
101
}
102
102
}
@@ -113,7 +113,7 @@ impl Functions {
113
113
}
114
114
}
115
115
116
- fn check_raw_ptr ( & self , cx : & LateContext , unsafety : hir:: Unsafety , decl : & hir:: FnDecl , block : & hir:: Block , span : Span , nodeid : ast:: NodeId ) {
116
+ fn check_raw_ptr ( & self , cx : & LateContext , unsafety : hir:: Unsafety , decl : & hir:: FnDecl , block : & hir:: Block , nodeid : ast:: NodeId ) {
117
117
if unsafety == hir:: Unsafety :: Normal && cx. access_levels . is_exported ( nodeid) {
118
118
let raw_ptrs = decl. inputs . iter ( ) . filter_map ( |arg| raw_ptr_arg ( cx, arg) ) . collect :: < HashSet < _ > > ( ) ;
119
119
@@ -144,32 +144,43 @@ struct DerefVisitor<'a, 'tcx: 'a> {
144
144
145
145
impl < ' a , ' tcx , ' v > hir:: intravisit:: Visitor < ' v > for DerefVisitor < ' a , ' tcx > {
146
146
fn visit_expr ( & mut self , expr : & ' v hir:: Expr ) {
147
- let ptr = match expr. node {
148
- hir:: ExprUnary ( hir:: UnDeref , ref ptr) => Some ( ptr) ,
147
+ match expr. node {
148
+ hir:: ExprCall ( ref f, ref args) => {
149
+ let ty = self . cx . tcx . expr_ty ( f) ;
150
+
151
+ if type_is_unsafe_function ( ty) {
152
+ for arg in args {
153
+ self . check_arg ( arg) ;
154
+ }
155
+ }
156
+ }
149
157
hir:: ExprMethodCall ( _, _, ref args) => {
150
158
let method_call = ty:: MethodCall :: expr ( expr. id ) ;
151
159
let base_type = self . cx . tcx . tables . borrow ( ) . method_map [ & method_call] . ty ;
152
160
153
161
if type_is_unsafe_function ( base_type) {
154
- Some ( & args[ 0 ] )
155
- } else {
156
- None
157
- }
158
- }
159
- _ => None ,
160
- } ;
161
-
162
- if let Some ( ptr) = ptr {
163
- if let Some ( def) = self . cx . tcx . def_map . borrow ( ) . get ( & ptr. id ) {
164
- if self . ptrs . contains ( & def. def_id ( ) ) {
165
- span_lint ( self . cx ,
166
- NOT_UNSAFE_PTR_ARG_DEREF ,
167
- ptr. span ,
168
- "this public function dereferences a raw pointer but is not marked `unsafe`" ) ;
162
+ for arg in args {
163
+ self . check_arg ( arg) ;
164
+ }
169
165
}
170
166
}
167
+ hir:: ExprUnary ( hir:: UnDeref , ref ptr) => self . check_arg ( ptr) ,
168
+ _ => ( ) ,
171
169
}
172
170
173
171
hir:: intravisit:: walk_expr ( self , expr) ;
174
172
}
175
173
}
174
+
175
+ impl < ' a , ' tcx : ' a > DerefVisitor < ' a , ' tcx > {
176
+ fn check_arg ( & self , ptr : & hir:: Expr ) {
177
+ if let Some ( def) = self . cx . tcx . def_map . borrow ( ) . get ( & ptr. id ) {
178
+ if self . ptrs . contains ( & def. def_id ( ) ) {
179
+ span_lint ( self . cx ,
180
+ NOT_UNSAFE_PTR_ARG_DEREF ,
181
+ ptr. span ,
182
+ "this public function dereferences a raw pointer but is not marked `unsafe`" ) ;
183
+ }
184
+ }
185
+ }
186
+ }
0 commit comments