@@ -40,9 +40,9 @@ use syntax_pos::{BytePos, Span, SyntaxContext};
4040use syntax:: symbol:: keywords;
4141use syntax:: errors:: { Applicability , DiagnosticBuilder } ;
4242use syntax:: print:: pprust:: expr_to_string;
43+ use syntax:: visit:: FnKind ;
4344
4445use rustc:: hir:: { self , GenericParamKind , PatKind } ;
45- use rustc:: hir:: intravisit:: FnKind ;
4646
4747use nonstandard_style:: { MethodLateContext , method_context} ;
4848
@@ -216,7 +216,7 @@ impl LintPass for UnsafeCode {
216216}
217217
218218impl 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 ) {
220220 // This comes from a macro that has #[allow_internal_unsafe].
221221 if span. allows_unsafe ( ) {
222222 return ;
@@ -226,31 +226,30 @@ impl UnsafeCode {
226226 }
227227}
228228
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 ) {
231231 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)`") ;
235234 }
236235 }
237236
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 {
240239 // 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 ) {
242241 self . report_unsafe ( cx, blk. span , "usage of an `unsafe` block" ) ;
243242 }
244243 }
245244 }
246245
247- fn check_item ( & mut self , cx : & LateContext , it : & hir :: Item ) {
246+ fn check_item ( & mut self , cx : & EarlyContext , it : & ast :: Item ) {
248247 match it. node {
249- hir :: ItemKind :: Trait ( _, hir :: Unsafety :: Unsafe , ..) => {
248+ ast :: ItemKind :: Trait ( _, ast :: Unsafety :: Unsafe , ..) => {
250249 self . report_unsafe ( cx, it. span , "declaration of an `unsafe` trait" )
251250 }
252251
253- hir :: ItemKind :: Impl ( hir :: Unsafety :: Unsafe , ..) => {
252+ ast :: ItemKind :: Impl ( ast :: Unsafety :: Unsafe , ..) => {
254253 self . report_unsafe ( cx, it. span , "implementation of an `unsafe` trait" )
255254 }
256255
@@ -259,19 +258,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnsafeCode {
259258 }
260259
261260 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 ,
266264 span : Span ,
267265 _: ast:: NodeId ) {
268266 match fk {
269- FnKind :: ItemFn ( _, _ , hir :: FnHeader { unsafety : hir :: Unsafety :: Unsafe , .. } , ..) => {
267+ FnKind :: ItemFn ( _, ast :: FnHeader { unsafety : ast :: Unsafety :: Unsafe , .. } , ..) => {
270268 self . report_unsafe ( cx, span, "declaration of an `unsafe` function" )
271269 }
272270
273271 FnKind :: Method ( _, sig, ..) => {
274- if sig. header . unsafety == hir :: Unsafety :: Unsafe {
272+ if sig. header . unsafety == ast :: Unsafety :: Unsafe {
275273 self . report_unsafe ( cx, span, "implementation of an `unsafe` method" )
276274 }
277275 }
@@ -280,9 +278,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnsafeCode {
280278 }
281279 }
282280
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 {
286284 self . report_unsafe ( cx, item. span , "declaration of an `unsafe` method" )
287285 }
288286 }
0 commit comments