2323
2424use crate :: { EarlyContext , EarlyLintPass , LateContext , LateLintPass , LintContext } ;
2525use rustc:: hir:: map:: Map ;
26+ use rustc:: lint:: LintDiagnosticBuilder ;
2627use rustc:: traits:: misc:: can_type_implement_copy;
2728use rustc:: ty:: { self , layout:: VariantIdx , Ty , TyCtxt } ;
2829use rustc_ast_pretty:: pprust:: { self , expr_to_string} ;
2930use rustc_data_structures:: fx:: FxHashSet ;
3031use rustc_errors:: { Applicability , DiagnosticBuilder } ;
31- use rustc:: lint:: LintDiagnosticBuilder ;
3232use rustc_feature:: Stability ;
3333use rustc_feature:: { deprecated_attributes, AttributeGate , AttributeTemplate , AttributeType } ;
3434use rustc_hir as hir;
@@ -107,7 +107,9 @@ impl BoxPointers {
107107 fn check_heap_type ( & self , cx : & LateContext < ' _ , ' _ > , span : Span , ty : Ty < ' _ > ) {
108108 for leaf_ty in ty. walk ( ) {
109109 if leaf_ty. is_box ( ) {
110- cx. struct_span_lint ( BOX_POINTERS , span, |lint| lint. build ( & format ! ( "type uses owned (Box type) pointers: {}" , ty) ) . emit ( ) ) ;
110+ cx. struct_span_lint ( BOX_POINTERS , span, |lint| {
111+ lint. build ( & format ! ( "type uses owned (Box type) pointers: {}" , ty) ) . emit ( )
112+ } ) ;
111113 }
112114 }
113115 }
@@ -214,7 +216,12 @@ declare_lint! {
214216declare_lint_pass ! ( UnsafeCode => [ UNSAFE_CODE ] ) ;
215217
216218impl UnsafeCode {
217- fn report_unsafe ( & self , cx : & EarlyContext < ' _ > , span : Span , decorate : impl for < ' a > FnOnce ( LintDiagnosticBuilder < ' a > ) ) {
219+ fn report_unsafe (
220+ & self ,
221+ cx : & EarlyContext < ' _ > ,
222+ span : Span ,
223+ decorate : impl for < ' a > FnOnce ( LintDiagnosticBuilder < ' a > ) ,
224+ ) {
218225 // This comes from a macro that has `#[allow_internal_unsafe]`.
219226 if span. allows_unsafe ( ) {
220227 return ;
@@ -227,33 +234,40 @@ impl UnsafeCode {
227234impl EarlyLintPass for UnsafeCode {
228235 fn check_attribute ( & mut self , cx : & EarlyContext < ' _ > , attr : & ast:: Attribute ) {
229236 if attr. check_name ( sym:: allow_internal_unsafe) {
230- self . report_unsafe (
231- cx,
232- attr. span ,
233- |lint| lint. build ( "`allow_internal_unsafe` allows defining \
237+ self . report_unsafe ( cx, attr. span , |lint| {
238+ lint. build (
239+ "`allow_internal_unsafe` allows defining \
234240 macros using unsafe without triggering \
235- the `unsafe_code` lint at their call site") . emit ( ) ,
236- ) ;
241+ the `unsafe_code` lint at their call site",
242+ )
243+ . emit ( )
244+ } ) ;
237245 }
238246 }
239247
240248 fn check_expr ( & mut self , cx : & EarlyContext < ' _ > , e : & ast:: Expr ) {
241249 if let ast:: ExprKind :: Block ( ref blk, _) = e. kind {
242250 // Don't warn about generated blocks; that'll just pollute the output.
243251 if blk. rules == ast:: BlockCheckMode :: Unsafe ( ast:: UserProvided ) {
244- self . report_unsafe ( cx, blk. span , |lint| lint. build ( "usage of an `unsafe` block" ) . emit ( ) ) ;
252+ self . report_unsafe ( cx, blk. span , |lint| {
253+ lint. build ( "usage of an `unsafe` block" ) . emit ( )
254+ } ) ;
245255 }
246256 }
247257 }
248258
249259 fn check_item ( & mut self , cx : & EarlyContext < ' _ > , it : & ast:: Item ) {
250260 match it. kind {
251261 ast:: ItemKind :: Trait ( _, ast:: Unsafety :: Unsafe , ..) => {
252- self . report_unsafe ( cx, it. span , |lint| lint. build ( "declaration of an `unsafe` trait" ) . emit ( ) )
262+ self . report_unsafe ( cx, it. span , |lint| {
263+ lint. build ( "declaration of an `unsafe` trait" ) . emit ( )
264+ } )
253265 }
254266
255267 ast:: ItemKind :: Impl { unsafety : ast:: Unsafety :: Unsafe , .. } => {
256- self . report_unsafe ( cx, it. span , |lint| lint. build ( "implementation of an `unsafe` trait" ) . emit ( ) )
268+ self . report_unsafe ( cx, it. span , |lint| {
269+ lint. build ( "implementation of an `unsafe` trait" ) . emit ( )
270+ } )
257271 }
258272
259273 _ => return ,
@@ -360,11 +374,9 @@ impl MissingDoc {
360374
361375 let has_doc = attrs. iter ( ) . any ( |a| has_doc ( a) ) ;
362376 if !has_doc {
363- cx. struct_span_lint (
364- MISSING_DOCS ,
365- cx. tcx . sess . source_map ( ) . def_span ( sp) ,
366- |lint| lint. build ( & format ! ( "missing documentation for {}" , desc) ) . emit ( ) ,
367- ) ;
377+ cx. struct_span_lint ( MISSING_DOCS , cx. tcx . sess . source_map ( ) . def_span ( sp) , |lint| {
378+ lint. build ( & format ! ( "missing documentation for {}" , desc) ) . emit ( )
379+ } ) ;
368380 }
369381 }
370382}
@@ -543,12 +555,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations {
543555 return ;
544556 }
545557 if can_type_implement_copy ( cx. tcx , param_env, ty) . is_ok ( ) {
546- cx. struct_span_lint (
547- MISSING_COPY_IMPLEMENTATIONS ,
548- item. span ,
549- |lint| lint. build ( "type could implement `Copy`; consider adding `impl \
550- Copy`") . emit ( ) ,
551- )
558+ cx. struct_span_lint ( MISSING_COPY_IMPLEMENTATIONS , item. span , |lint| {
559+ lint. build (
560+ "type could implement `Copy`; consider adding `impl \
561+ Copy`",
562+ )
563+ . emit ( )
564+ } )
552565 }
553566 }
554567}
@@ -597,15 +610,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDebugImplementations {
597610 }
598611
599612 if !self . impling_types . as_ref ( ) . unwrap ( ) . contains ( & item. hir_id ) {
600- cx. struct_span_lint (
601- MISSING_DEBUG_IMPLEMENTATIONS ,
602- item. span ,
603- |lint| lint. build ( & format ! (
613+ cx. struct_span_lint ( MISSING_DEBUG_IMPLEMENTATIONS , item. span , |lint| {
614+ lint. build ( & format ! (
604615 "type does not implement `{}`; consider adding `#[derive(Debug)]` \
605616 or a manual implementation",
606617 cx. tcx. def_path_str( debug)
607- ) ) . emit ( ) ,
608- ) ;
618+ ) )
619+ . emit ( )
620+ } ) ;
609621 }
610622 }
611623}
@@ -903,7 +915,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MutableTransmutes {
903915 match get_transmute_from_to ( cx, expr) . map ( |( ty1, ty2) | ( & ty1. kind , & ty2. kind ) ) {
904916 Some ( ( & ty:: Ref ( _, _, from_mt) , & ty:: Ref ( _, _, to_mt) ) ) => {
905917 if to_mt == hir:: Mutability :: Mut && from_mt == hir:: Mutability :: Not {
906- cx. struct_span_lint ( MUTABLE_TRANSMUTES , expr. span , |lint| lint. build ( msg) . emit ( ) ) ;
918+ cx. struct_span_lint ( MUTABLE_TRANSMUTES , expr. span , |lint| {
919+ lint. build ( msg) . emit ( )
920+ } ) ;
907921 }
908922 }
909923 _ => ( ) ,
@@ -953,7 +967,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnstableFeatures {
953967 if attr. check_name ( sym:: feature) {
954968 if let Some ( items) = attr. meta_item_list ( ) {
955969 for item in items {
956- ctx. struct_span_lint ( UNSTABLE_FEATURES , item. span ( ) , |lint| lint. build ( "unstable feature" ) . emit ( ) ) ;
970+ ctx. struct_span_lint ( UNSTABLE_FEATURES , item. span ( ) , |lint| {
971+ lint. build ( "unstable feature" ) . emit ( )
972+ } ) ;
957973 }
958974 }
959975 }
@@ -1235,15 +1251,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TrivialConstraints {
12351251 ConstEvaluatable ( ..) => continue ,
12361252 } ;
12371253 if predicate. is_global ( ) {
1238- cx. struct_span_lint (
1239- TRIVIAL_BOUNDS ,
1240- span,
1241- |lint| lint. build ( & format ! (
1254+ cx. struct_span_lint ( TRIVIAL_BOUNDS , span, |lint| {
1255+ lint. build ( & format ! (
12421256 "{} bound {} does not depend on any type \
12431257 or lifetime parameters",
12441258 predicate_kind_name, predicate
1245- ) ) . emit ( ) ,
1246- ) ;
1259+ ) )
1260+ . emit ( )
1261+ } ) ;
12471262 }
12481263 }
12491264 }
0 commit comments