@@ -40,9 +40,9 @@ use syntax_pos::{BytePos, Span, SyntaxContext};
40
40
use syntax:: symbol:: keywords;
41
41
use syntax:: errors:: { Applicability , DiagnosticBuilder } ;
42
42
use syntax:: print:: pprust:: expr_to_string;
43
+ use syntax:: visit:: FnKind ;
43
44
44
45
use rustc:: hir:: { self , GenericParamKind , PatKind } ;
45
- use rustc:: hir:: intravisit:: FnKind ;
46
46
47
47
use nonstandard_style:: { MethodLateContext , method_context} ;
48
48
@@ -216,7 +216,7 @@ impl LintPass for UnsafeCode {
216
216
}
217
217
218
218
impl UnsafeCode {
219
- fn report_unsafe ( & self , cx : & LateContext , span : Span , desc : & ' static str ) {
219
+ fn report_unsafe ( & self , cx : & EarlyContext , span : Span , desc : & ' static str ) {
220
220
// This comes from a macro that has #[allow_internal_unsafe].
221
221
if span. allows_unsafe ( ) {
222
222
return ;
@@ -226,31 +226,30 @@ impl UnsafeCode {
226
226
}
227
227
}
228
228
229
- impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for UnsafeCode {
230
- fn check_attribute ( & mut self , cx : & LateContext , attr : & ast:: Attribute ) {
229
+ impl EarlyLintPass for UnsafeCode {
230
+ fn check_attribute ( & mut self , cx : & EarlyContext , attr : & ast:: Attribute ) {
231
231
if attr. check_name ( "allow_internal_unsafe" ) {
232
- self . report_unsafe ( cx, attr. span , "`allow_internal_unsafe` allows defining \
233
- macros using unsafe without triggering \
234
- the `unsafe_code` lint at their call site") ;
232
+ self . report_unsafe ( cx, attr. span , "cannot use `allow_internal_unsafe` \
233
+ with `forbid(unsafe_code)`") ;
235
234
}
236
235
}
237
236
238
- fn check_expr ( & mut self , cx : & LateContext , e : & hir :: Expr ) {
239
- if let hir :: ExprKind :: Block ( ref blk, _) = e. node {
237
+ fn check_expr ( & mut self , cx : & EarlyContext , e : & ast :: Expr ) {
238
+ if let ast :: ExprKind :: Block ( ref blk, _) = e. node {
240
239
// Don't warn about generated blocks, that'll just pollute the output.
241
- if blk. rules == hir :: UnsafeBlock ( hir :: UserProvided ) {
240
+ if blk. rules == ast :: BlockCheckMode :: Unsafe ( ast :: UserProvided ) {
242
241
self . report_unsafe ( cx, blk. span , "usage of an `unsafe` block" ) ;
243
242
}
244
243
}
245
244
}
246
245
247
- fn check_item ( & mut self , cx : & LateContext , it : & hir :: Item ) {
246
+ fn check_item ( & mut self , cx : & EarlyContext , it : & ast :: Item ) {
248
247
match it. node {
249
- hir :: ItemKind :: Trait ( _, hir :: Unsafety :: Unsafe , ..) => {
248
+ ast :: ItemKind :: Trait ( _, ast :: Unsafety :: Unsafe , ..) => {
250
249
self . report_unsafe ( cx, it. span , "declaration of an `unsafe` trait" )
251
250
}
252
251
253
- hir :: ItemKind :: Impl ( hir :: Unsafety :: Unsafe , ..) => {
252
+ ast :: ItemKind :: Impl ( ast :: Unsafety :: Unsafe , ..) => {
254
253
self . report_unsafe ( cx, it. span , "implementation of an `unsafe` trait" )
255
254
}
256
255
@@ -259,19 +258,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnsafeCode {
259
258
}
260
259
261
260
fn check_fn ( & mut self ,
262
- cx : & LateContext ,
263
- fk : FnKind < ' tcx > ,
264
- _: & hir:: FnDecl ,
265
- _: & hir:: Body ,
261
+ cx : & EarlyContext ,
262
+ fk : FnKind ,
263
+ _: & ast:: FnDecl ,
266
264
span : Span ,
267
265
_: ast:: NodeId ) {
268
266
match fk {
269
- FnKind :: ItemFn ( _, _ , hir :: FnHeader { unsafety : hir :: Unsafety :: Unsafe , .. } , ..) => {
267
+ FnKind :: ItemFn ( _, ast :: FnHeader { unsafety : ast :: Unsafety :: Unsafe , .. } , ..) => {
270
268
self . report_unsafe ( cx, span, "declaration of an `unsafe` function" )
271
269
}
272
270
273
271
FnKind :: Method ( _, sig, ..) => {
274
- if sig. header . unsafety == hir :: Unsafety :: Unsafe {
272
+ if sig. header . unsafety == ast :: Unsafety :: Unsafe {
275
273
self . report_unsafe ( cx, span, "implementation of an `unsafe` method" )
276
274
}
277
275
}
@@ -280,9 +278,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnsafeCode {
280
278
}
281
279
}
282
280
283
- fn check_trait_item ( & mut self , cx : & LateContext , item : & hir :: TraitItem ) {
284
- if let hir :: TraitItemKind :: Method ( ref sig, hir :: TraitMethod :: Required ( _ ) ) = item. node {
285
- if sig. header . unsafety == hir :: Unsafety :: Unsafe {
281
+ fn check_trait_item ( & mut self , cx : & EarlyContext , item : & ast :: TraitItem ) {
282
+ if let ast :: TraitItemKind :: Method ( ref sig, _ ) = item. node {
283
+ if sig. header . unsafety == ast :: Unsafety :: Unsafe {
286
284
self . report_unsafe ( cx, item. span , "declaration of an `unsafe` method" )
287
285
}
288
286
}
0 commit comments