@@ -28,6 +28,7 @@ use rustc::ty::{self, layout::VariantIdx, Ty, TyCtxt};
28
28
use rustc_ast_pretty:: pprust:: { self , expr_to_string} ;
29
29
use rustc_data_structures:: fx:: FxHashSet ;
30
30
use rustc_errors:: { Applicability , DiagnosticBuilder } ;
31
+ use rustc:: lint:: LintDiagnosticBuilder ;
31
32
use rustc_feature:: Stability ;
32
33
use rustc_feature:: { deprecated_attributes, AttributeGate , AttributeTemplate , AttributeType } ;
33
34
use rustc_hir as hir;
@@ -106,8 +107,7 @@ impl BoxPointers {
106
107
fn check_heap_type ( & self , cx : & LateContext < ' _ , ' _ > , span : Span , ty : Ty < ' _ > ) {
107
108
for leaf_ty in ty. walk ( ) {
108
109
if leaf_ty. is_box ( ) {
109
- let m = format ! ( "type uses owned (Box type) pointers: {}" , ty) ;
110
- cx. span_lint ( BOX_POINTERS , span, & m) ;
110
+ cx. struct_span_lint ( BOX_POINTERS , span, |lint| lint. build ( & format ! ( "type uses owned (Box type) pointers: {}" , ty) ) . emit ( ) ) ;
111
111
}
112
112
}
113
113
}
@@ -214,13 +214,13 @@ declare_lint! {
214
214
declare_lint_pass ! ( UnsafeCode => [ UNSAFE_CODE ] ) ;
215
215
216
216
impl UnsafeCode {
217
- fn report_unsafe ( & self , cx : & EarlyContext < ' _ > , span : Span , desc : & ' static str ) {
217
+ fn report_unsafe ( & self , cx : & EarlyContext < ' _ > , span : Span , decorate : impl for < ' a > FnOnce ( LintDiagnosticBuilder < ' a > ) ) {
218
218
// This comes from a macro that has `#[allow_internal_unsafe]`.
219
219
if span. allows_unsafe ( ) {
220
220
return ;
221
221
}
222
222
223
- cx. span_lint ( UNSAFE_CODE , span, desc ) ;
223
+ cx. struct_span_lint ( UNSAFE_CODE , span, decorate ) ;
224
224
}
225
225
}
226
226
@@ -230,9 +230,9 @@ impl EarlyLintPass for UnsafeCode {
230
230
self . report_unsafe (
231
231
cx,
232
232
attr. span ,
233
- "`allow_internal_unsafe` allows defining \
233
+ |lint| lint . build ( "`allow_internal_unsafe` allows defining \
234
234
macros using unsafe without triggering \
235
- the `unsafe_code` lint at their call site",
235
+ the `unsafe_code` lint at their call site") . emit ( ) ,
236
236
) ;
237
237
}
238
238
}
@@ -241,19 +241,19 @@ impl EarlyLintPass for UnsafeCode {
241
241
if let ast:: ExprKind :: Block ( ref blk, _) = e. kind {
242
242
// Don't warn about generated blocks; that'll just pollute the output.
243
243
if blk. rules == ast:: BlockCheckMode :: Unsafe ( ast:: UserProvided ) {
244
- self . report_unsafe ( cx, blk. span , "usage of an `unsafe` block" ) ;
244
+ self . report_unsafe ( cx, blk. span , |lint| lint . build ( "usage of an `unsafe` block" ) . emit ( ) ) ;
245
245
}
246
246
}
247
247
}
248
248
249
249
fn check_item ( & mut self , cx : & EarlyContext < ' _ > , it : & ast:: Item ) {
250
250
match it. kind {
251
251
ast:: ItemKind :: Trait ( _, ast:: Unsafety :: Unsafe , ..) => {
252
- self . report_unsafe ( cx, it. span , "declaration of an `unsafe` trait" )
252
+ self . report_unsafe ( cx, it. span , |lint| lint . build ( "declaration of an `unsafe` trait" ) . emit ( ) )
253
253
}
254
254
255
255
ast:: ItemKind :: Impl { unsafety : ast:: Unsafety :: Unsafe , .. } => {
256
- self . report_unsafe ( cx, it. span , "implementation of an `unsafe` trait" )
256
+ self . report_unsafe ( cx, it. span , |lint| lint . build ( "implementation of an `unsafe` trait" ) . emit ( ) )
257
257
}
258
258
259
259
_ => return ,
@@ -275,7 +275,7 @@ impl EarlyLintPass for UnsafeCode {
275
275
FnCtxt :: Assoc ( _) if body. is_none ( ) => "declaration of an `unsafe` method" ,
276
276
FnCtxt :: Assoc ( _) => "implementation of an `unsafe` method" ,
277
277
} ;
278
- self . report_unsafe ( cx, span, msg) ;
278
+ self . report_unsafe ( cx, span, |lint| lint . build ( msg) . emit ( ) ) ;
279
279
}
280
280
}
281
281
}
@@ -360,10 +360,10 @@ impl MissingDoc {
360
360
361
361
let has_doc = attrs. iter ( ) . any ( |a| has_doc ( a) ) ;
362
362
if !has_doc {
363
- cx. span_lint (
363
+ cx. struct_span_lint (
364
364
MISSING_DOCS ,
365
365
cx. tcx . sess . source_map ( ) . def_span ( sp) ,
366
- & format ! ( "missing documentation for {}" , desc) ,
366
+ |lint| lint . build ( & format ! ( "missing documentation for {}" , desc) ) . emit ( ) ,
367
367
) ;
368
368
}
369
369
}
@@ -392,10 +392,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
392
392
for macro_def in krate. exported_macros {
393
393
let has_doc = macro_def. attrs . iter ( ) . any ( |a| has_doc ( a) ) ;
394
394
if !has_doc {
395
- cx. span_lint (
395
+ cx. struct_span_lint (
396
396
MISSING_DOCS ,
397
397
cx. tcx . sess . source_map ( ) . def_span ( macro_def. span ) ,
398
- "missing documentation for macro" ,
398
+ |lint| lint . build ( "missing documentation for macro" ) . emit ( ) ,
399
399
) ;
400
400
}
401
401
}
@@ -543,11 +543,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations {
543
543
return ;
544
544
}
545
545
if can_type_implement_copy ( cx. tcx , param_env, ty) . is_ok ( ) {
546
- cx. span_lint (
546
+ cx. struct_span_lint (
547
547
MISSING_COPY_IMPLEMENTATIONS ,
548
548
item. span ,
549
- "type could implement `Copy`; consider adding `impl \
550
- Copy`",
549
+ |lint| lint . build ( "type could implement `Copy`; consider adding `impl \
550
+ Copy`") . emit ( ) ,
551
551
)
552
552
}
553
553
}
@@ -597,14 +597,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
597
597
}
598
598
599
599
if !self . impling_types . as_ref ( ) . unwrap ( ) . contains ( & item. hir_id ) {
600
- cx. span_lint (
600
+ cx. struct_span_lint (
601
601
MISSING_DEBUG_IMPLEMENTATIONS ,
602
602
item. span ,
603
- & format ! (
603
+ |lint| lint . build ( & format ! (
604
604
"type does not implement `{}`; consider adding `#[derive(Debug)]` \
605
605
or a manual implementation",
606
606
cx. tcx. def_path_str( debug)
607
- ) ,
607
+ ) ) . emit ( ) ,
608
608
) ;
609
609
}
610
610
}
@@ -903,7 +903,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
903
903
match get_transmute_from_to ( cx, expr) . map ( |( ty1, ty2) | ( & ty1. kind , & ty2. kind ) ) {
904
904
Some ( ( & ty:: Ref ( _, _, from_mt) , & ty:: Ref ( _, _, to_mt) ) ) => {
905
905
if to_mt == hir:: Mutability :: Mut && from_mt == hir:: Mutability :: Not {
906
- cx. span_lint ( MUTABLE_TRANSMUTES , expr. span , msg) ;
906
+ cx. struct_span_lint ( MUTABLE_TRANSMUTES , expr. span , |lint| lint . build ( msg) . emit ( ) ) ;
907
907
}
908
908
}
909
909
_ => ( ) ,
@@ -953,7 +953,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnstableFeatures {
953
953
if attr. check_name ( sym:: feature) {
954
954
if let Some ( items) = attr. meta_item_list ( ) {
955
955
for item in items {
956
- ctx. span_lint ( UNSTABLE_FEATURES , item. span ( ) , "unstable feature" ) ;
956
+ ctx. struct_span_lint ( UNSTABLE_FEATURES , item. span ( ) , |lint| lint . build ( "unstable feature" ) . emit ( ) ) ;
957
957
}
958
958
}
959
959
}
@@ -1235,14 +1235,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
1235
1235
ConstEvaluatable ( ..) => continue ,
1236
1236
} ;
1237
1237
if predicate. is_global ( ) {
1238
- cx. span_lint (
1238
+ cx. struct_span_lint (
1239
1239
TRIVIAL_BOUNDS ,
1240
1240
span,
1241
- & format ! (
1241
+ |lint| lint . build ( & format ! (
1242
1242
"{} bound {} does not depend on any type \
1243
1243
or lifetime parameters",
1244
1244
predicate_kind_name, predicate
1245
- ) ,
1245
+ ) ) . emit ( ) ,
1246
1246
) ;
1247
1247
}
1248
1248
}
0 commit comments