mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 15:14:29 +00:00
Make {Arc,Rc,Weak}::ptr_eq
ignore pointer metadata
This commit is contained in:
parent
331c5471d7
commit
9a61550e78
4 changed files with 8 additions and 28 deletions
|
@ -96,9 +96,7 @@ impl LateLintPass<'_> for UnnamedAddress {
|
|||
if let ExprKind::Call(func, [ref _left, ref _right]) = expr.kind;
|
||||
if let ExprKind::Path(ref func_qpath) = func.kind;
|
||||
if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id();
|
||||
if match_def_path(cx, def_id, &paths::PTR_EQ) ||
|
||||
match_def_path(cx, def_id, &paths::RC_PTR_EQ) ||
|
||||
match_def_path(cx, def_id, &paths::ARC_PTR_EQ);
|
||||
if match_def_path(cx, def_id, &paths::PTR_EQ);
|
||||
let ty_param = cx.typeck_results().node_substs(func.hir_id).type_at(0);
|
||||
if ty_param.is_trait();
|
||||
then {
|
||||
|
|
|
@ -15,7 +15,6 @@ pub const APPLICABILITY_VALUES: [[&str; 3]; 4] = [
|
|||
];
|
||||
#[cfg(feature = "internal")]
|
||||
pub const DIAGNOSTIC_BUILDER: [&str; 3] = ["rustc_errors", "diagnostic_builder", "DiagnosticBuilder"];
|
||||
pub const ARC_PTR_EQ: [&str; 4] = ["alloc", "sync", "Arc", "ptr_eq"];
|
||||
pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"];
|
||||
pub const BTREEMAP_INSERT: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "insert"];
|
||||
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"];
|
|||
pub const PTR_WRITE_VOLATILE: [&str; 3] = ["core", "ptr", "write_volatile"];
|
||||
pub const PUSH_STR: [&str; 4] = ["alloc", "string", "String", "push_str"];
|
||||
pub const RANGE_ARGUMENT_TRAIT: [&str; 3] = ["core", "ops", "RangeBounds"];
|
||||
pub const RC_PTR_EQ: [&str; 4] = ["alloc", "rc", "Rc", "ptr_eq"];
|
||||
pub const REFCELL_REF: [&str; 3] = ["core", "cell", "Ref"];
|
||||
pub const REFCELL_REFMUT: [&str; 3] = ["core", "cell", "RefMut"];
|
||||
pub const REGEX_BUILDER_NEW: [&str; 5] = ["regex", "re_builder", "unicode", "RegexBuilder", "new"];
|
||||
|
|
|
@ -23,12 +23,6 @@ fn main() {
|
|||
let b = &1 as &dyn Debug;
|
||||
ptr::eq(a, b);
|
||||
|
||||
let a: Rc<dyn Debug> = Rc::new(1);
|
||||
Rc::ptr_eq(&a, &a);
|
||||
|
||||
let a: Arc<dyn Debug> = Arc::new(1);
|
||||
Arc::ptr_eq(&a, &a);
|
||||
|
||||
// These should be fine:
|
||||
let a = &1;
|
||||
ptr::eq(a, a);
|
||||
|
@ -39,6 +33,12 @@ fn main() {
|
|||
let a = Arc::new(1);
|
||||
Arc::ptr_eq(&a, &a);
|
||||
|
||||
let a: Rc<dyn Debug> = Rc::new(1);
|
||||
Rc::ptr_eq(&a, &a);
|
||||
|
||||
let a: Arc<dyn Debug> = Arc::new(1);
|
||||
Arc::ptr_eq(&a, &a);
|
||||
|
||||
let a: &[u8] = b"";
|
||||
ptr::eq(a, a);
|
||||
}
|
||||
|
|
|
@ -63,21 +63,5 @@ LL | ptr::eq(a, b);
|
|||
|
|
||||
= help: consider extracting and comparing data pointers only
|
||||
|
||||
error: comparing trait object pointers compares a non-unique vtable address
|
||||
--> $DIR/vtable_address_comparisons.rs:27:5
|
||||
|
|
||||
LL | Rc::ptr_eq(&a, &a);
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider extracting and comparing data pointers only
|
||||
|
||||
error: comparing trait object pointers compares a non-unique vtable address
|
||||
--> $DIR/vtable_address_comparisons.rs:30:5
|
||||
|
|
||||
LL | Arc::ptr_eq(&a, &a);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider extracting and comparing data pointers only
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
error: aborting due to 8 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue