]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/methods/zst_offset.rs
Auto merge of #6957 - camsteffen:eq-ty-kind, r=flip1995
[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<'_>, args: &[hir::Expr<'_>]) {
10     if_chain! {
11         if args.len() == 2;
12         if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.typeck_results().expr_ty(&args[0]).kind();
13         if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty));
14         if layout.is_zst();
15         then {
16             span_lint(cx, ZST_OFFSET, expr.span, "offset calculation on zero-sized value");
17         }
18     }
19 }