]> git.lizzy.rs Git - rust.git/blob - src/docs/vtable_address_comparisons.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / vtable_address_comparisons.txt
1 ### What it does
2 Checks for comparisons with an address of a trait vtable.
3
4 ### Why is this bad?
5 Comparing trait objects pointers compares an vtable addresses which
6 are not guaranteed to be unique and could vary between different code generation units.
7 Furthermore vtables for different types could have the same address after being merged
8 together.
9
10 ### Example
11 ```
12 let a: Rc<dyn Trait> = ...
13 let b: Rc<dyn Trait> = ...
14 if Rc::ptr_eq(&a, &b) {
15     ...
16 }
17 ```