Skip to content

Commit 048ddcd

Browse files
committed
Drop clippy::vtable_address_comparisons
1 parent dc0b7e9 commit 048ddcd

File tree

8 files changed

+70
-247
lines changed

8 files changed

+70
-247
lines changed

Diff for: src/tools/clippy/clippy_lints/src/declared_lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
681681
crate::unit_types::UNIT_ARG_INFO,
682682
crate::unit_types::UNIT_CMP_INFO,
683683
crate::unnamed_address::FN_ADDRESS_COMPARISONS_INFO,
684-
crate::unnamed_address::VTABLE_ADDRESS_COMPARISONS_INFO,
685684
crate::unnecessary_box_returns::UNNECESSARY_BOX_RETURNS_INFO,
686685
crate::unnecessary_map_on_constructor::UNNECESSARY_MAP_ON_CONSTRUCTOR_INFO,
687686
crate::unnecessary_owned_empty_strings::UNNECESSARY_OWNED_EMPTY_STRINGS_INFO,

Diff for: src/tools/clippy/clippy_lints/src/renamed_lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,5 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[
5858
("clippy::undropped_manually_drops", "undropped_manually_drops"),
5959
("clippy::unknown_clippy_lints", "unknown_lints"),
6060
("clippy::unused_label", "unused_labels"),
61+
("clippy::vtable_address_comparisons", "invalid_pointer_trait_comparisons"),
6162
];

Diff for: src/tools/clippy/clippy_lints/src/unnamed_address.rs

+2-69
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
1+
use clippy_utils::diagnostics::span_lint;
22
use if_chain::if_chain;
33
use rustc_hir::{BinOpKind, Expr, ExprKind};
44
use rustc_lint::{LateContext, LateLintPass};
55
use rustc_middle::ty;
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
7-
use rustc_span::sym;
87

98
declare_clippy_lint! {
109
/// ### What it does
@@ -30,31 +29,7 @@ declare_clippy_lint! {
3029
"comparison with an address of a function item"
3130
}
3231

33-
declare_clippy_lint! {
34-
/// ### What it does
35-
/// Checks for comparisons with an address of a trait vtable.
36-
///
37-
/// ### Why is this bad?
38-
/// Comparing trait objects pointers compares an vtable addresses which
39-
/// are not guaranteed to be unique and could vary between different code generation units.
40-
/// Furthermore vtables for different types could have the same address after being merged
41-
/// together.
42-
///
43-
/// ### Example
44-
/// ```rust,ignore
45-
/// let a: Rc<dyn Trait> = ...
46-
/// let b: Rc<dyn Trait> = ...
47-
/// if Rc::ptr_eq(&a, &b) {
48-
/// ...
49-
/// }
50-
/// ```
51-
#[clippy::version = "1.44.0"]
52-
pub VTABLE_ADDRESS_COMPARISONS,
53-
correctness,
54-
"comparison with an address of a trait vtable"
55-
}
56-
57-
declare_lint_pass!(UnnamedAddress => [FN_ADDRESS_COMPARISONS, VTABLE_ADDRESS_COMPARISONS]);
32+
declare_lint_pass!(UnnamedAddress => [FN_ADDRESS_COMPARISONS]);
5833

5934
impl LateLintPass<'_> for UnnamedAddress {
6035
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
@@ -65,52 +40,10 @@ impl LateLintPass<'_> for UnnamedAddress {
6540
)
6641
}
6742

68-
fn is_trait_ptr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
69-
match cx.typeck_results().expr_ty_adjusted(expr).kind() {
70-
ty::RawPtr(ty::TypeAndMut { ty, .. }) => ty.is_trait(),
71-
_ => false,
72-
}
73-
}
74-
7543
fn is_fn_def(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
7644
matches!(cx.typeck_results().expr_ty(expr).kind(), ty::FnDef(..))
7745
}
7846

79-
if_chain! {
80-
if let ExprKind::Binary(binop, left, right) = expr.kind;
81-
if is_comparison(binop.node);
82-
if is_trait_ptr(cx, left) && is_trait_ptr(cx, right);
83-
then {
84-
span_lint_and_help(
85-
cx,
86-
VTABLE_ADDRESS_COMPARISONS,
87-
expr.span,
88-
"comparing trait object pointers compares a non-unique vtable address",
89-
None,
90-
"consider extracting and comparing data pointers only",
91-
);
92-
}
93-
}
94-
95-
if_chain! {
96-
if let ExprKind::Call(func, [ref _left, ref _right]) = expr.kind;
97-
if let ExprKind::Path(ref func_qpath) = func.kind;
98-
if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id();
99-
if cx.tcx.is_diagnostic_item(sym::ptr_eq, def_id);
100-
let ty_param = cx.typeck_results().node_args(func.hir_id).type_at(0);
101-
if ty_param.is_trait();
102-
then {
103-
span_lint_and_help(
104-
cx,
105-
VTABLE_ADDRESS_COMPARISONS,
106-
expr.span,
107-
"comparing trait object pointers compares a non-unique vtable address",
108-
None,
109-
"consider extracting and comparing data pointers only",
110-
);
111-
}
112-
}
113-
11447
if_chain! {
11548
if let ExprKind::Binary(binop, left, right) = expr.kind;
11649
if is_comparison(binop.node);

Diff for: src/tools/clippy/tests/ui/rename.fixed

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#![allow(undropped_manually_drops)]
5252
#![allow(unknown_lints)]
5353
#![allow(unused_labels)]
54+
#![allow(invalid_pointer_trait_comparisons)]
5455
#![warn(clippy::almost_complete_range)]
5556
#![warn(clippy::disallowed_names)]
5657
#![warn(clippy::blocks_in_if_conditions)]
@@ -107,5 +108,6 @@
107108
#![warn(undropped_manually_drops)]
108109
#![warn(unknown_lints)]
109110
#![warn(unused_labels)]
111+
#![warn(invalid_pointer_trait_comparisons)]
110112

111113
fn main() {}

Diff for: src/tools/clippy/tests/ui/rename.rs

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#![allow(undropped_manually_drops)]
5252
#![allow(unknown_lints)]
5353
#![allow(unused_labels)]
54+
#![allow(invalid_pointer_trait_comparisons)]
5455
#![warn(clippy::almost_complete_letter_range)]
5556
#![warn(clippy::blacklisted_name)]
5657
#![warn(clippy::block_in_if_condition_expr)]
@@ -107,5 +108,6 @@
107108
#![warn(clippy::undropped_manually_drops)]
108109
#![warn(clippy::unknown_clippy_lints)]
109110
#![warn(clippy::unused_label)]
111+
#![warn(clippy::vtable_address_comparisons)]
110112

111113
fn main() {}

0 commit comments

Comments
 (0)