Skip to content

Commit 1695bc4

Browse files
committed
Address review comments
1 parent 8b36c80 commit 1695bc4

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

clippy_lints/src/size_of_ref.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use clippy_utils::diagnostics::span_lint_and_help;
2-
use clippy_utils::ty::peel_mid_ty_refs;
1+
use clippy_utils::{diagnostics::span_lint_and_help, path_def_id, ty::peel_mid_ty_refs};
32
use rustc_hir::{Expr, ExprKind};
43
use rustc_lint::{LateContext, LateLintPass};
54
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -13,9 +12,9 @@ declare_clippy_lint! {
1312
///
1413
/// ### Why is this bad?
1514
///
16-
/// The result of calling `size_of_val()` with a reference to a reference
17-
/// as the argument will be the size of any generic reference-type, not
18-
/// the size of the value behind the reference.
15+
/// Calling `size_of_val()` with a reference to a reference as the argument
16+
/// yields the size of the reference-type, not the size of the value behind
17+
/// the reference.
1918
///
2019
/// ### Example
2120
/// ```rust
@@ -25,10 +24,10 @@ declare_clippy_lint! {
2524
///
2625
/// impl Foo {
2726
/// fn size(&self) -> usize {
28-
/// // Note that `&self` as an argument is a `&&Foo`: Bacause `self`
29-
/// // is already a reference, `&self` is a double-reference,
30-
/// // and the return value of `size_of_val()` therefor is the
31-
/// // size of any generic reference-type.
27+
/// // Note that `&self` as an argument is a `&&Foo`: Because `self`
28+
/// // is already a reference, `&self` is a double-reference.
29+
/// // The return value of `size_of_val()` therefor is the
30+
/// // size of the reference-type, not the size of `self`.
3231
/// std::mem::size_of_val(&self)
3332
/// }
3433
/// }
@@ -48,16 +47,15 @@ declare_clippy_lint! {
4847
/// ```
4948
#[clippy::version = "1.67.0"]
5049
pub SIZE_OF_REF,
51-
correctness,
50+
suspicious,
5251
"Argument to `std::mem::size_of_val()` is a double-reference, which is almost certainly unintended"
5352
}
5453
declare_lint_pass!(SizeOfRef => [SIZE_OF_REF]);
5554

5655
impl LateLintPass<'_> for SizeOfRef {
5756
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &'_ Expr<'_>) {
5857
if let ExprKind::Call(path, [arg]) = expr.kind
59-
&& let ExprKind::Path(ref qpath) = path.kind
60-
&& let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id()
58+
&& let Some(def_id) = path_def_id(cx, path)
6159
&& cx.tcx.is_diagnostic_item(sym::mem_size_of_val, def_id)
6260
&& let arg_ty = cx.typeck_results().expr_ty(arg)
6361
&& peel_mid_ty_refs(arg_ty).1 > 1

0 commit comments

Comments
 (0)