Make Rcs and Arcs use pointer comparison for unsized types#155579
Make Rcs and Arcs use pointer comparison for unsized types#155579rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Conversation
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Can you provide some context on how this addresses the concerns from @theemathas and @Jules-Bertholet in the issue? Those seem at least plausible to me (i.e., this is a change in behavior). |
|
This implements the idea from #154998 (comment). I included the example from @Jules-Bertholet in a test as well, and confirmed that it is still sound under the changes. |
|
@bors r+ OK, I think this makes sense. Thanks for clarifying! |
Rollup of 12 pull requests Successful merges: - #149624 (Fix requires_lto targets needing lto set in cargo) - #155317 (`std::io::Take`: Clarify & optimize `BorrowedBuf::set_init` usage.) - #155579 (Make Rcs and Arcs use pointer comparison for unsized types) - #155588 (Implement more traits for FRTs) - #155708 (Fix heap overflow in slice::join caused by misbehaving Borrow) - #155778 (Avoid Vec allocation in TyCtxt::mk_place_elem) - #151014 (std: sys: process: uefi: Add program searching) - #155682 (Add boxing suggestions for `impl Trait` return type mismatches) - #155770 (Avoid misleading closure return type note) - #155818 (Convert attribute `FinalizeFn` to fn pointer) - #155829 (rustc_attr_parsing: use a `try {}` in `or_malformed`) - #155835 (couple of `crate_name` cleanups)
| #[inline] | ||
| fn eq(&self, other: &Rc<T, A>) -> bool { | ||
| Rc::ptr_eq(self, other) || **self == **other | ||
| ptr::eq(self.ptr.as_ptr(), other.ptr.as_ptr()) || **self == **other |
There was a problem hiding this comment.
Is this correct? The docs for ptr::eq state that vtable comparisons are unreliable.
There was a problem hiding this comment.
If the vtables are equal, and the pointer is the same, then it will be the same value, as dereferencing either value will get identical results. If the vtables aren't equal, then we get the slow path, but this is the slow path that always happened anyway before this PR.
Rollup merge of #155579 - Gaming32:fix-154998, r=Mark-Simulacrum Make Rcs and Arcs use pointer comparison for unsized types `Rc` and `Arc`s have an `Eq` implementation that first attempt to compare the pointers as an optimization. This, however, was not extended to DSTs, which is what this PR fixes. Fixes #154998.
RcandArcs have anEqimplementation that first attempt to compare the pointers as an optimization. This, however, was not extended to DSTs, which is what this PR fixes.Fixes #154998.