@@ -148,16 +148,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
148148 let cast_out = CastTy :: from_ty ( cast_ty) . expect ( "bad output type for cast" ) ;
149149 match ( cast_in, cast_out) {
150150 ( 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 ,
161155 ) ;
162156 }
163157 _ => { }
@@ -171,14 +165,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
171165 if self . const_context && self . tcx . features ( ) . const_compare_raw_pointers =>
172166 {
173167 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 ,
182172 ) ;
183173 }
184174 }
@@ -199,18 +189,12 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
199189 . as_ref ( )
200190 . assert_crate_local ( )
201191 . 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) ,
214198 ) ;
215199 }
216200 }
@@ -434,15 +418,10 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
434418 the field can be changed to invalid values",
435419 )
436420 } ;
437- let source_info = self . source_info ;
438- self . register_violations (
439- & [ UnsafetyViolation {
440- source_info,
441- description : Symbol :: intern ( description) ,
442- details : Symbol :: intern ( details) ,
443- kind : UnsafetyViolationKind :: GeneralAndConstFn ,
444- } ] ,
445- & [ ] ,
421+ self . require_unsafe (
422+ description,
423+ details,
424+ UnsafetyViolationKind :: GeneralAndConstFn ,
446425 ) ;
447426 }
448427 } ,
0 commit comments