2021-03-25 13:29:11 -05:00
|
|
|
use clippy_utils::diagnostics::span_lint;
|
2021-03-12 08:30:50 -06:00
|
|
|
use if_chain::if_chain;
|
|
|
|
use rustc_hir as hir;
|
|
|
|
use rustc_lint::LateContext;
|
|
|
|
use rustc_middle::ty;
|
|
|
|
|
|
|
|
use super::ZST_OFFSET;
|
|
|
|
|
2021-04-08 10:50:13 -05:00
|
|
|
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
|
2021-03-12 08:30:50 -06:00
|
|
|
if_chain! {
|
2021-04-08 10:50:13 -05:00
|
|
|
if let ty::RawPtr(ty::TypeAndMut { ty, .. }) = cx.typeck_results().expr_ty(recv).kind();
|
2021-03-12 08:30:50 -06:00
|
|
|
if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty));
|
|
|
|
if layout.is_zst();
|
|
|
|
then {
|
|
|
|
span_lint(cx, ZST_OFFSET, expr.span, "offset calculation on zero-sized value");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|