@@ -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 ,
@@ -270,12 +270,12 @@ impl EarlyLintPass for UnsafeCode {
270270 ) {
271271 match fk {
272272 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 ( ) )
274274 }
275275
276276 FnKind :: Method ( _, sig, ..) => {
277277 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 ( ) )
279279 }
280280 }
281281
@@ -286,7 +286,7 @@ impl EarlyLintPass for UnsafeCode {
286286 fn check_trait_item ( & mut self , cx : & EarlyContext < ' _ > , item : & ast:: AssocItem ) {
287287 if let ast:: AssocItemKind :: Fn ( ref sig, None ) = item. kind {
288288 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 ( ) )
290290 }
291291 }
292292 }
@@ -372,10 +372,10 @@ impl MissingDoc {
372372
373373 let has_doc = attrs. iter ( ) . any ( |a| has_doc ( a) ) ;
374374 if !has_doc {
375- cx. span_lint (
375+ cx. struct_span_lint (
376376 MISSING_DOCS ,
377377 cx. tcx . sess . source_map ( ) . def_span ( sp) ,
378- & format ! ( "missing documentation for {}" , desc) ,
378+ |lint| lint . build ( & format ! ( "missing documentation for {}" , desc) ) . emit ( ) ,
379379 ) ;
380380 }
381381 }
@@ -404,10 +404,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc {
404404 for macro_def in krate. exported_macros {
405405 let has_doc = macro_def. attrs . iter ( ) . any ( |a| has_doc ( a) ) ;
406406 if !has_doc {
407- cx. span_lint (
407+ cx. struct_span_lint (
408408 MISSING_DOCS ,
409409 cx. tcx . sess . source_map ( ) . def_span ( macro_def. span ) ,
410- "missing documentation for macro" ,
410+ |lint| lint . build ( "missing documentation for macro" ) . emit ( ) ,
411411 ) ;
412412 }
413413 }
@@ -555,11 +555,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations {
555555 return ;
556556 }
557557 if can_type_implement_copy ( cx. tcx , param_env, ty) . is_ok ( ) {
558- cx. span_lint (
558+ cx. struct_span_lint (
559559 MISSING_COPY_IMPLEMENTATIONS ,
560560 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 ( ) ,
563563 )
564564 }
565565 }
@@ -609,11 +609,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
609609 }
610610
611611 if !self . impling_types . as_ref ( ) . unwrap ( ) . contains ( & item. hir_id ) {
612- cx. span_lint (
612+ cx. struct_span_lint (
613613 MISSING_DEBUG_IMPLEMENTATIONS ,
614614 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 ( ) ,
617617 )
618618 }
619619 }
@@ -912,7 +912,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
912912 match get_transmute_from_to ( cx, expr) . map ( |( ty1, ty2) | ( & ty1. kind , & ty2. kind ) ) {
913913 Some ( ( & ty:: Ref ( _, _, from_mt) , & ty:: Ref ( _, _, to_mt) ) ) => {
914914 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 ( ) ) ;
916916 }
917917 }
918918 _ => ( ) ,
@@ -962,7 +962,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnstableFeatures {
962962 if attr. check_name ( sym:: feature) {
963963 if let Some ( items) = attr. meta_item_list ( ) {
964964 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 ( ) ) ;
966966 }
967967 }
968968 }
@@ -1244,14 +1244,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
12441244 ConstEvaluatable ( ..) => continue ,
12451245 } ;
12461246 if predicate. is_global ( ) {
1247- cx. span_lint (
1247+ cx. struct_span_lint (
12481248 TRIVIAL_BOUNDS ,
12491249 span,
1250- & format ! (
1250+ |lint| lint . build ( & format ! (
12511251 "{} bound {} does not depend on any type \
12521252 or lifetime parameters",
12531253 predicate_kind_name, predicate
1254- ) ,
1254+ ) ) . emit ( ) ,
12551255 ) ;
12561256 }
12571257 }
0 commit comments