-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop creating references unnecessarily to compare pointers by-address
The test `common::deque::basics` contains several lines that look like this: ``` assert!(std::ptr::eq(head_d, unsafe { node1_ptr.as_ref() })); ``` What is happening is that we assert that `head_c`, a reference, is equal by-address to `node1_ptr`, a `NonNull<_>`. However, the way we do this is by creating a reference, instead of using `as_ptr`. The current way has several downsides: * It requires an `unsafe` block. Comparing pointer addresses is safe so this should be unnecessary. * **It is unsound**, at least under Tree Borrows rules. The references created there violate the uniqueness of references/Boxes created internally in the `Deque`, which trips the `Deque` later when it tries to use these internally-held references. * It is unnecessary -- comparing the result of `as_ptr` works just the same, maybe even faster due to less intermediary methods. As such, the test should be updated to only use `as_ptr`. When done, it actually makes the tests pass under Tree Borrows. (cherry picked from commit af40a12)
- Loading branch information
1 parent
7a4df31
commit df115b9
Showing
1 changed file
with
38 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters