@@ -148,16 +148,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
148
148
let cast_out = CastTy :: from_ty ( cast_ty) . expect ( "bad output type for cast" ) ;
149
149
match ( cast_in, cast_out) {
150
150
( CastTy :: Ptr ( _) , CastTy :: Int ( _) ) | ( CastTy :: FnPtr , CastTy :: Int ( _) ) => {
151
- self . register_violations (
152
- & [ UnsafetyViolation {
153
- source_info : self . source_info ,
154
- description : Symbol :: intern ( "cast of pointer to int" ) ,
155
- details : Symbol :: intern (
156
- "casting pointers to integers in constants" ,
157
- ) ,
158
- kind : UnsafetyViolationKind :: General ,
159
- } ] ,
160
- & [ ] ,
151
+ self . require_unsafe (
152
+ "cast of pointer to int" ,
153
+ "casting pointers to integers in constants" ,
154
+ UnsafetyViolationKind :: General ,
161
155
) ;
162
156
}
163
157
_ => { }
@@ -171,14 +165,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
171
165
if self . const_context && self . tcx . features ( ) . const_compare_raw_pointers =>
172
166
{
173
167
if let ty:: RawPtr ( _) | ty:: FnPtr ( ..) = lhs. ty ( self . body , self . tcx ) . kind {
174
- self . register_violations (
175
- & [ UnsafetyViolation {
176
- source_info : self . source_info ,
177
- description : Symbol :: intern ( "pointer operation" ) ,
178
- details : Symbol :: intern ( "operations on pointers in constants" ) ,
179
- kind : UnsafetyViolationKind :: General ,
180
- } ] ,
181
- & [ ] ,
168
+ self . require_unsafe (
169
+ "pointer operation" ,
170
+ "operations on pointers in constants" ,
171
+ UnsafetyViolationKind :: General ,
182
172
) ;
183
173
}
184
174
}
@@ -199,18 +189,12 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
199
189
. as_ref ( )
200
190
. assert_crate_local ( )
201
191
. lint_root ;
202
- self . register_violations (
203
- & [ UnsafetyViolation {
204
- source_info,
205
- description : Symbol :: intern ( "borrow of packed field" ) ,
206
- details : Symbol :: intern (
207
- "fields of packed structs might be misaligned: dereferencing a \
208
- misaligned pointer or even just creating a misaligned reference \
209
- is undefined behavior",
210
- ) ,
211
- kind : UnsafetyViolationKind :: BorrowPacked ( lint_root) ,
212
- } ] ,
213
- & [ ] ,
192
+ self . require_unsafe (
193
+ "borrow of packed field" ,
194
+ "fields of packed structs might be misaligned: dereferencing a \
195
+ misaligned pointer or even just creating a misaligned reference \
196
+ is undefined behavior",
197
+ UnsafetyViolationKind :: BorrowPacked ( lint_root) ,
214
198
) ;
215
199
}
216
200
}
@@ -435,15 +419,10 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
435
419
the field can be changed to invalid values",
436
420
)
437
421
} ;
438
- let source_info = self . source_info ;
439
- self . register_violations (
440
- & [ UnsafetyViolation {
441
- source_info,
442
- description : Symbol :: intern ( description) ,
443
- details : Symbol :: intern ( details) ,
444
- kind : UnsafetyViolationKind :: GeneralAndConstFn ,
445
- } ] ,
446
- & [ ] ,
422
+ self . require_unsafe (
423
+ description,
424
+ details,
425
+ UnsafetyViolationKind :: GeneralAndConstFn ,
447
426
) ;
448
427
}
449
428
} ,
0 commit comments