You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MarkerEq doesn't specialize on unsized types #154998
If you write the following code, the a == b will not specialize to pointer comparisons purely because str is unsized. If a String were used, the address would be compared.
let a:Rc<str> = "example".into();let b = Rc::clone(a);
a == b;
The bug itself narrows down to, as far as I can see, the following code using T: Eq instead of T: ?Sized + Eq. Notably the code just below uses ?Sized + MarkerEq, which will never occur unless a std type were to manually implement MarkerEq for some reason, leading me to believe that this is likely an unintended for this bound to fail on unsized types.
I think that making this change is probably incorrect, but I'm not sure.
Consider the following, which I believe is a technically legal implementation of Eq:
traitTrait{}implPartialEqfordynTrait + '_{fneq(&self,other:&Self) -> bool{// compare both the data ptr and vtable ptr
std::ptr::eq(self, other)}}implEqfordynTrait + '_{}
It would be possible for two Rcs to point to the same data, and yet have different vtables, so two such Rcs must compare as unequal.
Activity
theemathas commentedon Apr 8, 2026
I think that making this change is probably incorrect, but I'm not sure.
Consider the following, which I believe is a technically legal implementation of
Eq:It would be possible for two
Rcs to point to the same data, and yet have different vtables, so two suchRcs must compare as unequal.Gaming32 commentedon Apr 8, 2026
Would it be sufficient to change
RcEqIdentto useptr::eqinstead ofptr::addr_eqas well then?Jules-Bertholet commentedon Apr 8, 2026
It's not just
dyn; arguably, the following should be sound:Rollup merge of rust-lang#155579 - Gaming32:fix-154998, r=Mark-Simula…
Unrolled build for #155579