@@ -75,6 +75,7 @@ pub enum lint {
75
75
type_limits,
76
76
type_overflow,
77
77
unused_unsafe,
78
+ unsafe_block,
78
79
79
80
managed_heap_memory,
80
81
owned_heap_memory,
@@ -236,6 +237,13 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[
236
237
default : warn
237
238
} ) ,
238
239
240
+ ( "unsafe_block" ,
241
+ LintSpec {
242
+ lint : unsafe_block,
243
+ desc : "usage of an `unsafe` block" ,
244
+ default : allow
245
+ } ) ,
246
+
239
247
( "unused_variable" ,
240
248
LintSpec {
241
249
lint : unused_variable,
@@ -870,8 +878,7 @@ fn check_pat_non_uppercase_statics(cx: &Context, p: &ast::Pat) {
870
878
871
879
fn check_unused_unsafe ( cx : & Context , e : & ast:: Expr ) {
872
880
match e. node {
873
- // Don't warn about generated blocks, that'll just pollute the
874
- // output.
881
+ // Don't warn about generated blocks, that'll just pollute the output.
875
882
ast:: ExprBlock ( ref blk) => {
876
883
if blk. rules == ast:: UnsafeBlock ( ast:: UserProvided ) &&
877
884
!cx. tcx . used_unsafe . contains ( & blk. id ) {
@@ -883,6 +890,16 @@ fn check_unused_unsafe(cx: &Context, e: &ast::Expr) {
883
890
}
884
891
}
885
892
893
+ fn check_unsafe_block ( cx : & Context , e : & ast:: Expr ) {
894
+ match e. node {
895
+ // Don't warn about generated blocks, that'll just pollute the output.
896
+ ast:: ExprBlock ( ref blk) if blk. rules == ast:: UnsafeBlock ( ast:: UserProvided ) => {
897
+ cx. span_lint ( unsafe_block, blk. span , "usage of an `unsafe` block" ) ;
898
+ }
899
+ _ => ( )
900
+ }
901
+ }
902
+
886
903
fn check_unused_mut_pat ( cx : & Context , p : @ast:: Pat ) {
887
904
match p. node {
888
905
ast:: PatIdent ( ast:: BindByValue ( ast:: MutMutable ) ,
@@ -1126,6 +1143,7 @@ impl<'self> Visitor<()> for Context<'self> {
1126
1143
check_while_true_expr ( self , e) ;
1127
1144
check_stability ( self , e) ;
1128
1145
check_unused_unsafe ( self , e) ;
1146
+ check_unsafe_block ( self , e) ;
1129
1147
check_unnecessary_allocation ( self , e) ;
1130
1148
check_heap_expr ( self , e) ;
1131
1149
0 commit comments