Skip to content

Commit 27ec2df

Browse files
committed
move zst_offset to its own module
1 parent 84ab59c commit 27ec2df

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ mod uninit_assumed_init;
2020
mod unnecessary_filter_map;
2121
mod unnecessary_lazy_eval;
2222
mod unwrap_used;
23+
mod zst_offset;
2324

2425
use std::borrow::Cow;
2526
use std::fmt;
@@ -1726,7 +1727,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
17261727
manual_saturating_arithmetic::check(cx, expr, &arg_lists, &arith["checked_".len()..])
17271728
},
17281729
["add" | "offset" | "sub" | "wrapping_offset" | "wrapping_add" | "wrapping_sub"] => {
1729-
check_pointer_offset(cx, expr, arg_lists[0])
1730+
zst_offset::check(cx, expr, arg_lists[0])
17301731
},
17311732
["is_file", ..] => filetype_is_file::check(cx, expr, arg_lists[0]),
17321733
["map", "as_ref"] => {
@@ -3801,18 +3802,6 @@ fn is_bool(ty: &hir::Ty<'_>) -> bool {
38013802
}
38023803
}
38033804

3804-
fn check_pointer_offset(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
3805-
if_chain! {
3806-
if args.len() == 2;
3807-
if let ty::RawPtr(ty::TypeAndMut { ref ty, .. }) = cx.typeck_results().expr_ty(&args[0]).kind();
3808-
if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty));
3809-
if layout.is_zst();
3810-
then {
3811-
span_lint(cx, ZST_OFFSET, expr.span, "offset calculation on zero-sized value");
3812-
}
3813-
}
3814-
}
3815-
38163805
fn lint_from_iter(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
38173806
let ty = cx.typeck_results().expr_ty(expr);
38183807
let arg_ty = cx.typeck_results().expr_ty(&args[0]);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::utils::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+
}

0 commit comments

Comments
 (0)