Rustdoc considers *const T and *mut T different
https://doc.rust-lang.org/core/ptr/struct.Unique.html
is_null, offset, and as_ref are listed twice. This is confusing and makes the HTML invalid. I'm not sure what's going on here.
The bug here is that
*const Tand*mut Tare classified as the same kind of pointer, so when theDerefimplementation is seen it inlines the inherent methods from those two pointer types, and both have anis_nullmethod. This would likely be dealt by not having both pointer types be represented as the same type in rustdoc.Alex Crichton at 2015-04-28 16:42:53
Uniquechanged, so this specific issue is no longer relevant.Marcell Pardavi at 2016-03-29 22:31:59
So, in attempting to recreate this bug, I first looked at https://doc.rust-lang.org/1.0.0/core/ptr/struct.Unique.html to see what it looked like when
Uniqueexisted. I then used this code:use std::ops::Deref; pub struct Unique<T: ?Sized> { pointer: *const T, } impl<T:?Sized> Deref for Unique<T> { type Target = *mut T; #[inline] fn deref<'a>(&'a self) -> &'a *mut T { unsafe { mem::transmute(&*self.pointer) } } }This gives

with no methods at all! That seems... strange?
Steve Klabnik at 2018-10-31 14:33:38
I spent some time looking into this, and there are a couple of intertwined issues.
- First, we don't seem to properly add the relevant
Dereftargets to the set of implementations that should be displayed, in particular when those targets are primitives. I tried the same example mentioned above and it works with slices andstr, but not with any other primitive. This happens in thecollect-trait-implspass. - Also, even when hacking a bit to make it find the relevant targets, we end up not displaying any methods:
This happens because (almost?) all methods in primitives have by-value self, and we don't show those methods in "Methods fromDeref" blocks.
So it seems that the first issue to solve is to make rustdoc display Deref-inherited methods with by-value
selfwhen the target isCopy. This, however, has been discussed before (https://github.com/rust-lang/rust/issues/30607, https://github.com/rust-lang/rust/pull/33396, https://github.com/rust-lang/rust/issues/39550, https://github.com/rust-lang/rust/pull/45645) and deemed too difficult.Roberto Vidal at 2019-12-07 10:22:55
- First, we don't seem to properly add the relevant