Skip to content

Suggest std::mem::size_of_val instead of std::mem::size_of_value #10659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clippy_lints/src/manual_slice_size_calculation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ declare_lint_pass!(ManualSliceSizeCalculation => [MANUAL_SLICE_SIZE_CALCULATION]

impl<'tcx> LateLintPass<'tcx> for ManualSliceSizeCalculation {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
// Does not apply inside const because size_of_value is not cost in stable.
// Does not apply inside const because size_of_val is not cost in stable.
if !in_constant(cx, expr.hir_id)
&& let ExprKind::Binary(ref op, left, right) = expr.kind
&& BinOpKind::Mul == op.node
Expand All @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualSliceSizeCalculation {
expr.span,
"manual slice size calculation",
None,
"consider using std::mem::size_of_value instead");
"consider using std::mem::size_of_val instead");
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/manual_slice_size_calculation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: manual slice size calculation
LL | let _ = s_i32.len() * size_of::<i32>(); // WARNING
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using std::mem::size_of_value instead
= help: consider using std::mem::size_of_val instead
= note: `-D clippy::manual-slice-size-calculation` implied by `-D warnings`

error: manual slice size calculation
Expand All @@ -13,39 +13,39 @@ error: manual slice size calculation
LL | let _ = size_of::<i32>() * s_i32.len(); // WARNING
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using std::mem::size_of_value instead
= help: consider using std::mem::size_of_val instead

error: manual slice size calculation
--> $DIR/manual_slice_size_calculation.rs:13:13
|
LL | let _ = size_of::<i32>() * s_i32.len() * 5; // WARNING
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using std::mem::size_of_value instead
= help: consider using std::mem::size_of_val instead

error: manual slice size calculation
--> $DIR/manual_slice_size_calculation.rs:17:13
|
LL | let _ = len * size_of::<i32>(); // WARNING
| ^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider using std::mem::size_of_value instead
= help: consider using std::mem::size_of_val instead

error: manual slice size calculation
--> $DIR/manual_slice_size_calculation.rs:18:13
|
LL | let _ = s_i32.len() * size; // WARNING
| ^^^^^^^^^^^^^^^^^^
|
= help: consider using std::mem::size_of_value instead
= help: consider using std::mem::size_of_val instead

error: manual slice size calculation
--> $DIR/manual_slice_size_calculation.rs:19:13
|
LL | let _ = len * size; // WARNING
| ^^^^^^^^^^
|
= help: consider using std::mem::size_of_value instead
= help: consider using std::mem::size_of_val instead

error: aborting due to 6 previous errors