Skip to content

Commit 70c2d0c

Browse files
committed
Auto merge of rust-lang#106450 - albertlarsan68:fix-arc-ptr-eq, r=Amanieu
Make `{Arc,Rc,Weak}::ptr_eq` ignore pointer metadata FCP completed in rust-lang#103763 (comment) Closes rust-lang#103763
2 parents 9a65f46 + 9a61550 commit 70c2d0c

File tree

4 files changed

+8
-28
lines changed

4 files changed

+8
-28
lines changed

clippy_lints/src/unnamed_address.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ impl LateLintPass<'_> for UnnamedAddress {
9696
if let ExprKind::Call(func, [ref _left, ref _right]) = expr.kind;
9797
if let ExprKind::Path(ref func_qpath) = func.kind;
9898
if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id();
99-
if match_def_path(cx, def_id, &paths::PTR_EQ) ||
100-
match_def_path(cx, def_id, &paths::RC_PTR_EQ) ||
101-
match_def_path(cx, def_id, &paths::ARC_PTR_EQ);
99+
if match_def_path(cx, def_id, &paths::PTR_EQ);
102100
let ty_param = cx.typeck_results().node_substs(func.hir_id).type_at(0);
103101
if ty_param.is_trait();
104102
then {

clippy_utils/src/paths.rs

-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub const APPLICABILITY_VALUES: [[&str; 3]; 4] = [
1515
];
1616
#[cfg(feature = "internal")]
1717
pub const DIAGNOSTIC_BUILDER: [&str; 3] = ["rustc_errors", "diagnostic_builder", "DiagnosticBuilder"];
18-
pub const ARC_PTR_EQ: [&str; 4] = ["alloc", "sync", "Arc", "ptr_eq"];
1918
pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"];
2019
pub const BTREEMAP_INSERT: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "insert"];
2120
pub const BTREESET_ITER: [&str; 6] = ["alloc", "collections", "btree", "set", "BTreeSet", "iter"];
@@ -93,7 +92,6 @@ pub const PTR_WRITE_UNALIGNED: [&str; 3] = ["core", "ptr", "write_unaligned"];
9392
pub const PTR_WRITE_VOLATILE: [&str; 3] = ["core", "ptr", "write_volatile"];
9493
pub const PUSH_STR: [&str; 4] = ["alloc", "string", "String", "push_str"];
9594
pub const RANGE_ARGUMENT_TRAIT: [&str; 3] = ["core", "ops", "RangeBounds"];
96-
pub const RC_PTR_EQ: [&str; 4] = ["alloc", "rc", "Rc", "ptr_eq"];
9795
pub const REFCELL_REF: [&str; 3] = ["core", "cell", "Ref"];
9896
pub const REFCELL_REFMUT: [&str; 3] = ["core", "cell", "RefMut"];
9997
pub const REGEX_BUILDER_NEW: [&str; 5] = ["regex", "re_builder", "unicode", "RegexBuilder", "new"];

tests/ui/vtable_address_comparisons.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ fn main() {
2323
let b = &1 as &dyn Debug;
2424
ptr::eq(a, b);
2525

26-
let a: Rc<dyn Debug> = Rc::new(1);
27-
Rc::ptr_eq(&a, &a);
28-
29-
let a: Arc<dyn Debug> = Arc::new(1);
30-
Arc::ptr_eq(&a, &a);
31-
3226
// These should be fine:
3327
let a = &1;
3428
ptr::eq(a, a);
@@ -39,6 +33,12 @@ fn main() {
3933
let a = Arc::new(1);
4034
Arc::ptr_eq(&a, &a);
4135

36+
let a: Rc<dyn Debug> = Rc::new(1);
37+
Rc::ptr_eq(&a, &a);
38+
39+
let a: Arc<dyn Debug> = Arc::new(1);
40+
Arc::ptr_eq(&a, &a);
41+
4242
let a: &[u8] = b"";
4343
ptr::eq(a, a);
4444
}

tests/ui/vtable_address_comparisons.stderr

+1-17
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,5 @@ LL | ptr::eq(a, b);
6363
|
6464
= help: consider extracting and comparing data pointers only
6565

66-
error: comparing trait object pointers compares a non-unique vtable address
67-
--> $DIR/vtable_address_comparisons.rs:27:5
68-
|
69-
LL | Rc::ptr_eq(&a, &a);
70-
| ^^^^^^^^^^^^^^^^^^
71-
|
72-
= help: consider extracting and comparing data pointers only
73-
74-
error: comparing trait object pointers compares a non-unique vtable address
75-
--> $DIR/vtable_address_comparisons.rs:30:5
76-
|
77-
LL | Arc::ptr_eq(&a, &a);
78-
| ^^^^^^^^^^^^^^^^^^^
79-
|
80-
= help: consider extracting and comparing data pointers only
81-
82-
error: aborting due to 10 previous errors
66+
error: aborting due to 8 previous errors
8367

0 commit comments

Comments
 (0)