]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/methods/zst_offset.rs
Auto merge of #96098 - JakobDegen:always-return-place, r=oli-obk
[rust.git] / clippy_lints / src / methods / zst_offset.rs
1 use clippy_utils::diagnostics::span_lint;
2 use if_chain::if_chain;
3 use rustc_hir as hir;
4 use rustc_lint::LateContext;
5 use rustc_middle::ty;
6
7 use super::ZST_OFFSET;
8
9 pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
10     if_chain! {
11         if let ty::RawPtr(ty::TypeAndMut { ty, .. }) = cx.typeck_results().expr_ty(recv).kind();
12         if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(*ty));
13         if layout.is_zst();
14         then {
15             span_lint(cx, ZST_OFFSET, expr.span, "offset calculation on zero-sized value");
16         }
17     }
18 }