@@ -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 ,
@@ -270,12 +270,12 @@ impl EarlyLintPass for UnsafeCode {
270
270
) {
271
271
match fk {
272
272
FnKind :: ItemFn ( _, ast:: FnHeader { unsafety : ast:: Unsafety :: Unsafe , .. } , ..) => {
273
- self . report_unsafe ( cx, span, "declaration of an `unsafe` function" )
273
+ self . report_unsafe ( cx, span, |lint| lint . build ( "declaration of an `unsafe` function" ) . emit ( ) )
274
274
}
275
275
276
276
FnKind :: Method ( _, sig, ..) => {
277
277
if sig. header . unsafety == ast:: Unsafety :: Unsafe {
278
- self . report_unsafe ( cx, span, "implementation of an `unsafe` method" )
278
+ self . report_unsafe ( cx, span, |lint| lint . build ( "implementation of an `unsafe` method" ) . emit ( ) )
279
279
}
280
280
}
281
281
@@ -286,7 +286,7 @@ impl EarlyLintPass for UnsafeCode {
286
286
fn check_trait_item ( & mut self , cx : & EarlyContext < ' _ > , item : & ast:: AssocItem ) {
287
287
if let ast:: AssocItemKind :: Fn ( ref sig, None ) = item. kind {
288
288
if sig. header . unsafety == ast:: Unsafety :: Unsafe {
289
- self . report_unsafe ( cx, item. span , "declaration of an `unsafe` method" )
289
+ self . report_unsafe ( cx, item. span , |lint| lint . build ( "declaration of an `unsafe` method" ) . emit ( ) )
290
290
}
291
291
}
292
292
}
@@ -372,10 +372,10 @@ impl MissingDoc {
372
372
373
373
let has_doc = attrs. iter ( ) . any ( |a| has_doc ( a) ) ;
374
374
if !has_doc {
375
- cx. span_lint (
375
+ cx. struct_span_lint (
376
376
MISSING_DOCS ,
377
377
cx. tcx . sess . source_map ( ) . def_span ( sp) ,
378
- & format ! ( "missing documentation for {}" , desc) ,
378
+ |lint| lint . build ( & format ! ( "missing documentation for {}" , desc) ) . emit ( ) ,
379
379
) ;
380
380
}
381
381
}
@@ -404,10 +404,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
404
404
for macro_def in krate. exported_macros {
405
405
let has_doc = macro_def. attrs . iter ( ) . any ( |a| has_doc ( a) ) ;
406
406
if !has_doc {
407
- cx. span_lint (
407
+ cx. struct_span_lint (
408
408
MISSING_DOCS ,
409
409
cx. tcx . sess . source_map ( ) . def_span ( macro_def. span ) ,
410
- "missing documentation for macro" ,
410
+ |lint| lint . build ( "missing documentation for macro" ) . emit ( ) ,
411
411
) ;
412
412
}
413
413
}
@@ -555,11 +555,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations {
555
555
return ;
556
556
}
557
557
if can_type_implement_copy ( cx. tcx , param_env, ty) . is_ok ( ) {
558
- cx. span_lint (
558
+ cx. struct_span_lint (
559
559
MISSING_COPY_IMPLEMENTATIONS ,
560
560
item. span ,
561
- "type could implement `Copy`; consider adding `impl \
562
- Copy`",
561
+ |lint| lint . build ( "type could implement `Copy`; consider adding `impl \
562
+ Copy`") . emit ( ) ,
563
563
)
564
564
}
565
565
}
@@ -609,11 +609,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
609
609
}
610
610
611
611
if !self . impling_types . as_ref ( ) . unwrap ( ) . contains ( & item. hir_id ) {
612
- cx. span_lint (
612
+ cx. struct_span_lint (
613
613
MISSING_DEBUG_IMPLEMENTATIONS ,
614
614
item. span ,
615
- "type does not implement `fmt::Debug`; consider adding `#[derive(Debug)]` \
616
- or a manual implementation",
615
+ |lint| lint . build ( "type does not implement `fmt::Debug`; consider adding `#[derive(Debug)]` \
616
+ or a manual implementation") . emit ( ) ,
617
617
)
618
618
}
619
619
}
@@ -912,7 +912,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
912
912
match get_transmute_from_to ( cx, expr) . map ( |( ty1, ty2) | ( & ty1. kind , & ty2. kind ) ) {
913
913
Some ( ( & ty:: Ref ( _, _, from_mt) , & ty:: Ref ( _, _, to_mt) ) ) => {
914
914
if to_mt == hir:: Mutability :: Mut && from_mt == hir:: Mutability :: Not {
915
- cx. span_lint ( MUTABLE_TRANSMUTES , expr. span , msg) ;
915
+ cx. struct_span_lint ( MUTABLE_TRANSMUTES , expr. span , |lint| lint . build ( msg) . emit ( ) ) ;
916
916
}
917
917
}
918
918
_ => ( ) ,
@@ -962,7 +962,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnstableFeatures {
962
962
if attr. check_name ( sym:: feature) {
963
963
if let Some ( items) = attr. meta_item_list ( ) {
964
964
for item in items {
965
- ctx. span_lint ( UNSTABLE_FEATURES , item. span ( ) , "unstable feature" ) ;
965
+ ctx. struct_span_lint ( UNSTABLE_FEATURES , item. span ( ) , |lint| lint . build ( "unstable feature" ) . emit ( ) ) ;
966
966
}
967
967
}
968
968
}
@@ -1244,14 +1244,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
1244
1244
ConstEvaluatable ( ..) => continue ,
1245
1245
} ;
1246
1246
if predicate. is_global ( ) {
1247
- cx. span_lint (
1247
+ cx. struct_span_lint (
1248
1248
TRIVIAL_BOUNDS ,
1249
1249
span,
1250
- & format ! (
1250
+ |lint| lint . build ( & format ! (
1251
1251
"{} bound {} does not depend on any type \
1252
1252
or lifetime parameters",
1253
1253
predicate_kind_name, predicate
1254
- ) ,
1254
+ ) ) . emit ( ) ,
1255
1255
) ;
1256
1256
}
1257
1257
}
0 commit comments