@@ -28,6 +28,7 @@ use rustc::ty::{self, layout::VariantIdx, Ty, TyCtxt};
2828use rustc_ast_pretty:: pprust:: { self , expr_to_string} ;
2929use rustc_data_structures:: fx:: FxHashSet ;
3030use rustc_errors:: { Applicability , DiagnosticBuilder } ;
31+ use rustc:: lint:: LintDiagnosticBuilder ;
3132use rustc_feature:: Stability ;
3233use rustc_feature:: { deprecated_attributes, AttributeGate , AttributeTemplate , AttributeType } ;
3334use rustc_hir as hir;
@@ -106,8 +107,7 @@ impl BoxPointers {
106107 fn check_heap_type ( & self , cx : & LateContext < ' _ , ' _ > , span : Span , ty : Ty < ' _ > ) {
107108 for leaf_ty in ty. walk ( ) {
108109 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 ( ) ) ;
111111 }
112112 }
113113 }
@@ -214,13 +214,13 @@ declare_lint! {
214214declare_lint_pass ! ( UnsafeCode => [ UNSAFE_CODE ] ) ;
215215
216216impl 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 > ) ) {
218218 // This comes from a macro that has `#[allow_internal_unsafe]`.
219219 if span. allows_unsafe ( ) {
220220 return ;
221221 }
222222
223- cx. span_lint ( UNSAFE_CODE , span, desc ) ;
223+ cx. struct_span_lint ( UNSAFE_CODE , span, decorate ) ;
224224 }
225225}
226226
@@ -230,9 +230,9 @@ impl EarlyLintPass for UnsafeCode {
230230 self . report_unsafe (
231231 cx,
232232 attr. span ,
233- "`allow_internal_unsafe` allows defining \
233+ |lint| lint . build ( "`allow_internal_unsafe` allows defining \
234234 macros using unsafe without triggering \
235- the `unsafe_code` lint at their call site",
235+ the `unsafe_code` lint at their call site") . emit ( ) ,
236236 ) ;
237237 }
238238 }
@@ -241,19 +241,19 @@ impl EarlyLintPass for UnsafeCode {
241241 if let ast:: ExprKind :: Block ( ref blk, _) = e. kind {
242242 // Don't warn about generated blocks; that'll just pollute the output.
243243 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 ( ) ) ;
245245 }
246246 }
247247 }
248248
249249 fn check_item ( & mut self , cx : & EarlyContext < ' _ > , it : & ast:: Item ) {
250250 match it. kind {
251251 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 ( ) )
253253 }
254254
255255 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 ( ) )
257257 }
258258
259259 _ => return ,
@@ -275,7 +275,7 @@ impl EarlyLintPass for UnsafeCode {
275275 FnCtxt :: Assoc ( _) if body. is_none ( ) => "declaration of an `unsafe` method" ,
276276 FnCtxt :: Assoc ( _) => "implementation of an `unsafe` method" ,
277277 } ;
278- self . report_unsafe ( cx, span, msg) ;
278+ self . report_unsafe ( cx, span, |lint| lint . build ( msg) . emit ( ) ) ;
279279 }
280280 }
281281}
@@ -360,10 +360,10 @@ impl MissingDoc {
360360
361361 let has_doc = attrs. iter ( ) . any ( |a| has_doc ( a) ) ;
362362 if !has_doc {
363- cx. span_lint (
363+ cx. struct_span_lint (
364364 MISSING_DOCS ,
365365 cx. tcx . sess . source_map ( ) . def_span ( sp) ,
366- & format ! ( "missing documentation for {}" , desc) ,
366+ |lint| lint . build ( & format ! ( "missing documentation for {}" , desc) ) . emit ( ) ,
367367 ) ;
368368 }
369369 }
@@ -392,10 +392,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
392392 for macro_def in krate. exported_macros {
393393 let has_doc = macro_def. attrs . iter ( ) . any ( |a| has_doc ( a) ) ;
394394 if !has_doc {
395- cx. span_lint (
395+ cx. struct_span_lint (
396396 MISSING_DOCS ,
397397 cx. tcx . sess . source_map ( ) . def_span ( macro_def. span ) ,
398- "missing documentation for macro" ,
398+ |lint| lint . build ( "missing documentation for macro" ) . emit ( ) ,
399399 ) ;
400400 }
401401 }
@@ -543,11 +543,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations {
543543 return ;
544544 }
545545 if can_type_implement_copy ( cx. tcx , param_env, ty) . is_ok ( ) {
546- cx. span_lint (
546+ cx. struct_span_lint (
547547 MISSING_COPY_IMPLEMENTATIONS ,
548548 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 ( ) ,
551551 )
552552 }
553553 }
@@ -597,14 +597,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
597597 }
598598
599599 if !self . impling_types . as_ref ( ) . unwrap ( ) . contains ( & item. hir_id ) {
600- cx. span_lint (
600+ cx. struct_span_lint (
601601 MISSING_DEBUG_IMPLEMENTATIONS ,
602602 item. span ,
603- & format ! (
603+ |lint| lint . build ( & format ! (
604604 "type does not implement `{}`; consider adding `#[derive(Debug)]` \
605605 or a manual implementation",
606606 cx. tcx. def_path_str( debug)
607- ) ,
607+ ) ) . emit ( ) ,
608608 ) ;
609609 }
610610 }
@@ -903,7 +903,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
903903 match get_transmute_from_to ( cx, expr) . map ( |( ty1, ty2) | ( & ty1. kind , & ty2. kind ) ) {
904904 Some ( ( & ty:: Ref ( _, _, from_mt) , & ty:: Ref ( _, _, to_mt) ) ) => {
905905 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 ( ) ) ;
907907 }
908908 }
909909 _ => ( ) ,
@@ -953,7 +953,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnstableFeatures {
953953 if attr. check_name ( sym:: feature) {
954954 if let Some ( items) = attr. meta_item_list ( ) {
955955 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 ( ) ) ;
957957 }
958958 }
959959 }
@@ -1235,14 +1235,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
12351235 ConstEvaluatable ( ..) => continue ,
12361236 } ;
12371237 if predicate. is_global ( ) {
1238- cx. span_lint (
1238+ cx. struct_span_lint (
12391239 TRIVIAL_BOUNDS ,
12401240 span,
1241- & format ! (
1241+ |lint| lint . build ( & format ! (
12421242 "{} bound {} does not depend on any type \
12431243 or lifetime parameters",
12441244 predicate_kind_name, predicate
1245- ) ,
1245+ ) ) . emit ( ) ,
12461246 ) ;
12471247 }
12481248 }
0 commit comments