Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustdoc considers *const T and *mut T different #24897

Open
jruderman opened this issue Apr 28, 2015 · 4 comments
Open

Rustdoc considers *const T and *mut T different #24897

jruderman opened this issue Apr 28, 2015 · 4 comments
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@jruderman
Copy link
Contributor

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.

@steveklabnik steveklabnik added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Apr 28, 2015
@alexcrichton
Copy link
Member

The bug here is that *const T and *mut T are classified as the same kind of pointer, so when the Deref implementation is seen it inlines the inherent methods from those two pointer types, and both have an is_null method. This would likely be dealt by not having both pointer types be represented as the same type in rustdoc.

@pmarcelll
Copy link
Contributor

Unique changed, so this specific issue is no longer relevant.

@steveklabnik steveklabnik added T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. and removed T-tools labels May 18, 2017
@Mark-Simulacrum Mark-Simulacrum changed the title Docs for core::ptr::Unique list several methods twice Rustdoc considers *const T and *mut T different Jul 22, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@steveklabnik
Copy link
Member

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 Unique existed. 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

image

with no methods at all! That seems... strange?

@jrvidal
Copy link
Contributor

jrvidal commented Dec 7, 2019

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 Deref targets 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 and str, but not with any other primitive. This happens in the collect-trait-impls pass.
  • Also, even when hacking a bit to make it find the relevant targets, we end up not displaying any methods:
    Screenshot at 2019-12-07 11:16:37
    This happens because (almost?) all methods in primitives have by-value self, and we don't show those methods in "Methods from Deref" blocks.

So it seems that the first issue to solve is to make rustdoc display Deref-inherited methods with by-value self when the target is Copy. This, however, has been discussed before (#30607, #33396, #39550, #45645) and deemed too difficult.

@ehuss ehuss removed the T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. label Jan 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants