@@ -31,8 +31,8 @@ use crate::{
31
31
BuiltinMutablesTransmutes , BuiltinNoMangleGeneric , BuiltinNonShorthandFieldPatterns ,
32
32
BuiltinSpecialModuleNameUsed , BuiltinTrivialBounds , BuiltinUnexpectedCliConfigName ,
33
33
BuiltinUnexpectedCliConfigValue , BuiltinUnnameableTestItems , BuiltinUnreachablePub ,
34
- BuiltinUnstableFeatures , BuiltinUnusedDocComment , BuiltinUnusedDocCommentSub ,
35
- BuiltinWhileTrue ,
34
+ BuiltinUnsafe , BuiltinUnstableFeatures , BuiltinUnusedDocComment ,
35
+ BuiltinUnusedDocCommentSub , BuiltinWhileTrue ,
36
36
} ,
37
37
types:: { transparent_newtype_field, CItemKind } ,
38
38
EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext ,
@@ -46,8 +46,7 @@ use rustc_ast_pretty::pprust::{self, expr_to_string};
46
46
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
47
47
use rustc_data_structures:: stack:: ensure_sufficient_stack;
48
48
use rustc_errors:: {
49
- fluent, Applicability , DelayDm , Diagnostic , DiagnosticBuilder , DiagnosticMessage ,
50
- DiagnosticStyledString , MultiSpan ,
49
+ fluent, Applicability , DecorateLint , DelayDm , Diagnostic , DiagnosticStyledString , MultiSpan ,
51
50
} ;
52
51
use rustc_feature:: { deprecated_attributes, AttributeGate , BuiltinAttribute , GateIssue , Stability } ;
53
52
use rustc_hir as hir;
@@ -314,48 +313,21 @@ impl UnsafeCode {
314
313
& self ,
315
314
cx : & EarlyContext < ' _ > ,
316
315
span : Span ,
317
- msg : impl Into < DiagnosticMessage > ,
318
- decorate : impl for <' a , ' b > FnOnce (
319
- & ' b mut DiagnosticBuilder < ' a , ( ) > ,
320
- ) -> & ' b mut DiagnosticBuilder < ' a , ( ) > ,
316
+ decorate : impl for < ' a > DecorateLint < ' a , ( ) > ,
321
317
) {
322
318
// This comes from a macro that has `#[allow_internal_unsafe]`.
323
319
if span. allows_unsafe ( ) {
324
320
return ;
325
321
}
326
322
327
- cx. struct_span_lint ( UNSAFE_CODE , span, msg, decorate) ;
328
- }
329
-
330
- fn report_overridden_symbol_name (
331
- & self ,
332
- cx : & EarlyContext < ' _ > ,
333
- span : Span ,
334
- msg : DiagnosticMessage ,
335
- ) {
336
- self . report_unsafe ( cx, span, msg, |lint| {
337
- lint. note ( fluent:: lint_builtin_overridden_symbol_name)
338
- } )
339
- }
340
-
341
- fn report_overridden_symbol_section (
342
- & self ,
343
- cx : & EarlyContext < ' _ > ,
344
- span : Span ,
345
- msg : DiagnosticMessage ,
346
- ) {
347
- self . report_unsafe ( cx, span, msg, |lint| {
348
- lint. note ( fluent:: lint_builtin_overridden_symbol_section)
349
- } )
323
+ cx. emit_spanned_lint ( UNSAFE_CODE , span, decorate) ;
350
324
}
351
325
}
352
326
353
327
impl EarlyLintPass for UnsafeCode {
354
328
fn check_attribute ( & mut self , cx : & EarlyContext < ' _ > , attr : & ast:: Attribute ) {
355
329
if attr. has_name ( sym:: allow_internal_unsafe) {
356
- self . report_unsafe ( cx, attr. span , fluent:: lint_builtin_allow_internal_unsafe, |lint| {
357
- lint
358
- } ) ;
330
+ self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: AllowInternalUnsafe ) ;
359
331
}
360
332
}
361
333
@@ -364,70 +336,46 @@ impl EarlyLintPass for UnsafeCode {
364
336
if let ast:: ExprKind :: Block ( ref blk, _) = e. kind {
365
337
// Don't warn about generated blocks; that'll just pollute the output.
366
338
if blk. rules == ast:: BlockCheckMode :: Unsafe ( ast:: UserProvided ) {
367
- self . report_unsafe ( cx, blk. span , fluent :: lint_builtin_unsafe_block , |lint| lint ) ;
339
+ self . report_unsafe ( cx, blk. span , BuiltinUnsafe :: UnsafeBlock ) ;
368
340
}
369
341
}
370
342
}
371
343
372
344
fn check_item ( & mut self , cx : & EarlyContext < ' _ > , it : & ast:: Item ) {
373
345
match it. kind {
374
346
ast:: ItemKind :: Trait ( box ast:: Trait { unsafety : ast:: Unsafe :: Yes ( _) , .. } ) => {
375
- self . report_unsafe ( cx, it. span , fluent :: lint_builtin_unsafe_trait , |lint| lint )
347
+ self . report_unsafe ( cx, it. span , BuiltinUnsafe :: UnsafeTrait ) ;
376
348
}
377
349
378
350
ast:: ItemKind :: Impl ( box ast:: Impl { unsafety : ast:: Unsafe :: Yes ( _) , .. } ) => {
379
- self . report_unsafe ( cx, it. span , fluent :: lint_builtin_unsafe_impl , |lint| lint )
351
+ self . report_unsafe ( cx, it. span , BuiltinUnsafe :: UnsafeImpl ) ;
380
352
}
381
353
382
354
ast:: ItemKind :: Fn ( ..) => {
383
355
if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: no_mangle) {
384
- self . report_overridden_symbol_name (
385
- cx,
386
- attr. span ,
387
- fluent:: lint_builtin_no_mangle_fn,
388
- ) ;
356
+ self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: NoMangleFn ) ;
389
357
}
390
358
391
359
if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: export_name) {
392
- self . report_overridden_symbol_name (
393
- cx,
394
- attr. span ,
395
- fluent:: lint_builtin_export_name_fn,
396
- ) ;
360
+ self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: ExportNameFn ) ;
397
361
}
398
362
399
363
if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: link_section) {
400
- self . report_overridden_symbol_section (
401
- cx,
402
- attr. span ,
403
- fluent:: lint_builtin_link_section_fn,
404
- ) ;
364
+ self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: LinkSectionFn ) ;
405
365
}
406
366
}
407
367
408
368
ast:: ItemKind :: Static ( ..) => {
409
369
if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: no_mangle) {
410
- self . report_overridden_symbol_name (
411
- cx,
412
- attr. span ,
413
- fluent:: lint_builtin_no_mangle_static,
414
- ) ;
370
+ self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: NoMangleStatic ) ;
415
371
}
416
372
417
373
if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: export_name) {
418
- self . report_overridden_symbol_name (
419
- cx,
420
- attr. span ,
421
- fluent:: lint_builtin_export_name_static,
422
- ) ;
374
+ self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: ExportNameStatic ) ;
423
375
}
424
376
425
377
if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: link_section) {
426
- self . report_overridden_symbol_section (
427
- cx,
428
- attr. span ,
429
- fluent:: lint_builtin_link_section_static,
430
- ) ;
378
+ self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: LinkSectionStatic ) ;
431
379
}
432
380
}
433
381
@@ -438,18 +386,10 @@ impl EarlyLintPass for UnsafeCode {
438
386
fn check_impl_item ( & mut self , cx : & EarlyContext < ' _ > , it : & ast:: AssocItem ) {
439
387
if let ast:: AssocItemKind :: Fn ( ..) = it. kind {
440
388
if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: no_mangle) {
441
- self . report_overridden_symbol_name (
442
- cx,
443
- attr. span ,
444
- fluent:: lint_builtin_no_mangle_method,
445
- ) ;
389
+ self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: NoMangleMethod ) ;
446
390
}
447
391
if let Some ( attr) = cx. sess ( ) . find_by_name ( & it. attrs , sym:: export_name) {
448
- self . report_overridden_symbol_name (
449
- cx,
450
- attr. span ,
451
- fluent:: lint_builtin_export_name_method,
452
- ) ;
392
+ self . report_unsafe ( cx, attr. span , BuiltinUnsafe :: ExportNameMethod ) ;
453
393
}
454
394
}
455
395
}
@@ -464,13 +404,13 @@ impl EarlyLintPass for UnsafeCode {
464
404
body,
465
405
) = fk
466
406
{
467
- let msg = match ctxt {
407
+ let decorator = match ctxt {
468
408
FnCtxt :: Foreign => return ,
469
- FnCtxt :: Free => fluent :: lint_builtin_decl_unsafe_fn ,
470
- FnCtxt :: Assoc ( _) if body. is_none ( ) => fluent :: lint_builtin_decl_unsafe_method ,
471
- FnCtxt :: Assoc ( _) => fluent :: lint_builtin_impl_unsafe_method ,
409
+ FnCtxt :: Free => BuiltinUnsafe :: DeclUnsafeFn ,
410
+ FnCtxt :: Assoc ( _) if body. is_none ( ) => BuiltinUnsafe :: DeclUnsafeMethod ,
411
+ FnCtxt :: Assoc ( _) => BuiltinUnsafe :: ImplUnsafeMethod ,
472
412
} ;
473
- self . report_unsafe ( cx, span, msg , |lint| lint ) ;
413
+ self . report_unsafe ( cx, span, decorator ) ;
474
414
}
475
415
}
476
416
}
0 commit comments