@@ -621,9 +621,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnitArg {
621621}
622622
623623fn is_questionmark_desugar_marked_call ( expr : & Expr ) -> bool {
624- use syntax_pos:: hygiene:: CompilerDesugaringKind ;
624+ use syntax_pos:: hygiene:: DesugaringKind ;
625625 if let ExprKind :: Call ( ref callee, _) = expr. node {
626- callee. span . is_compiler_desugaring ( CompilerDesugaringKind :: QuestionMark )
626+ callee. span . is_desugaring ( DesugaringKind :: QuestionMark )
627627 } else {
628628 false
629629 }
@@ -789,7 +789,8 @@ declare_clippy_lint! {
789789 /// **Why is this bad?** Dereferencing the resulting pointer may be undefined
790790 /// behavior.
791791 ///
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.
793794 ///
794795 /// **Example:**
795796 /// ```rust
@@ -1210,17 +1211,25 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Casts {
12101211 if_chain ! {
12111212 if let ty:: RawPtr ( from_ptr_ty) = & cast_from. sty;
12121213 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 ;
12161217 // with c_void, we inherently need to trust the user
12171218 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( ) ;
12181221 then {
12191222 span_lint(
12201223 cx,
12211224 CAST_PTR_ALIGNMENT ,
12221225 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+ ) ,
12241233 ) ;
12251234 }
12261235 }
0 commit comments