@@ -621,9 +621,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
621
621
}
622
622
623
623
fn is_questionmark_desugar_marked_call ( expr : & Expr ) -> bool {
624
- use syntax_pos:: hygiene:: CompilerDesugaringKind ;
624
+ use syntax_pos:: hygiene:: DesugaringKind ;
625
625
if let ExprKind :: Call ( ref callee, _) = expr. node {
626
- callee. span . is_compiler_desugaring ( CompilerDesugaringKind :: QuestionMark )
626
+ callee. span . is_desugaring ( DesugaringKind :: QuestionMark )
627
627
} else {
628
628
false
629
629
}
@@ -789,7 +789,8 @@ declare_clippy_lint! {
789
789
/// **Why is this bad?** Dereferencing the resulting pointer may be undefined
790
790
/// behavior.
791
791
///
792
- /// **Known problems:** None.
792
+ /// **Known problems:** Using `std::ptr::read_unaligned` and `std::ptr::write_unaligned` or similar
793
+ /// on the resulting pointer is fine.
793
794
///
794
795
/// **Example:**
795
796
/// ```rust
@@ -1210,17 +1211,25 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts {
1210
1211
if_chain ! {
1211
1212
if let ty:: RawPtr ( from_ptr_ty) = & cast_from. sty;
1212
1213
if let ty:: RawPtr ( to_ptr_ty) = & cast_to. sty;
1213
- if let Some ( from_align ) = cx. layout_of( from_ptr_ty. ty) . ok ( ) . map ( |a| a . align . abi ) ;
1214
- if let Some ( to_align ) = cx. layout_of( to_ptr_ty. ty) . ok ( ) . map ( |a| a . align . abi ) ;
1215
- if from_align < to_align ;
1214
+ if let Ok ( from_layout ) = cx. layout_of( from_ptr_ty. ty) ;
1215
+ if let Ok ( to_layout ) = cx. layout_of( to_ptr_ty. ty) ;
1216
+ if from_layout . align . abi < to_layout . align . abi ;
1216
1217
// with c_void, we inherently need to trust the user
1217
1218
if !is_c_void( cx, from_ptr_ty. ty) ;
1219
+ // when casting from a ZST, we don't know enough to properly lint
1220
+ if !from_layout. is_zst( ) ;
1218
1221
then {
1219
1222
span_lint(
1220
1223
cx,
1221
1224
CAST_PTR_ALIGNMENT ,
1222
1225
expr. span,
1223
- & format!( "casting from `{}` to a more-strictly-aligned pointer (`{}`)" , cast_from, cast_to)
1226
+ & format!(
1227
+ "casting from `{}` to a more-strictly-aligned pointer (`{}`) ({} < {} bytes)" ,
1228
+ cast_from,
1229
+ cast_to,
1230
+ from_layout. align. abi. bytes( ) ,
1231
+ to_layout. align. abi. bytes( ) ,
1232
+ ) ,
1224
1233
) ;
1225
1234
}
1226
1235
}
0 commit comments