@@ -20,6 +20,7 @@ mod uninit_assumed_init;
20
20
mod unnecessary_filter_map;
21
21
mod unnecessary_lazy_eval;
22
22
mod unwrap_used;
23
+ mod zst_offset;
23
24
24
25
use std:: borrow:: Cow ;
25
26
use std:: fmt;
@@ -1726,7 +1727,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
1726
1727
manual_saturating_arithmetic:: check ( cx, expr, & arg_lists, & arith[ "checked_" . len ( ) ..] )
1727
1728
} ,
1728
1729
[ "add" | "offset" | "sub" | "wrapping_offset" | "wrapping_add" | "wrapping_sub" ] => {
1729
- check_pointer_offset ( cx, expr, arg_lists[ 0 ] )
1730
+ zst_offset :: check ( cx, expr, arg_lists[ 0 ] )
1730
1731
} ,
1731
1732
[ "is_file" , ..] => filetype_is_file:: check ( cx, expr, arg_lists[ 0 ] ) ,
1732
1733
[ "map" , "as_ref" ] => {
@@ -3801,18 +3802,6 @@ fn is_bool(ty: &hir::Ty<'_>) -> bool {
3801
3802
}
3802
3803
}
3803
3804
3804
- fn check_pointer_offset ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , args : & [ hir:: Expr < ' _ > ] ) {
3805
- if_chain ! {
3806
- if args. len( ) == 2 ;
3807
- if let ty:: RawPtr ( ty:: TypeAndMut { ref ty, .. } ) = cx. typeck_results( ) . expr_ty( & args[ 0 ] ) . kind( ) ;
3808
- if let Ok ( layout) = cx. tcx. layout_of( cx. param_env. and( ty) ) ;
3809
- if layout. is_zst( ) ;
3810
- then {
3811
- span_lint( cx, ZST_OFFSET , expr. span, "offset calculation on zero-sized value" ) ;
3812
- }
3813
- }
3814
- }
3815
-
3816
3805
fn lint_from_iter ( cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > , args : & [ hir:: Expr < ' _ > ] ) {
3817
3806
let ty = cx. typeck_results ( ) . expr_ty ( expr) ;
3818
3807
let arg_ty = cx. typeck_results ( ) . expr_ty ( & args[ 0 ] ) ;
0 commit comments