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: Wrong documentation in case of types that only implement Deref, but not DerefMut #35169

Closed
Sawyer47 opened this issue Aug 1, 2016 · 2 comments
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Sawyer47
Copy link
Contributor

Sawyer47 commented Aug 1, 2016

Wrong documentation is generated for types that only implement Deref, but not DerefMut. It inherits methods from both Deref and DerefMut.

Steps to reproduce:
cargo new deref-doc-bug

/// lib.rs
pub struct Foo;

impl std::ops::Deref for Foo {
    type Target = [char];
    fn deref(&self) -> &[char] { &[] }
}

cargo doc --open

Generated documentation has methods for both &[char] and &mut [char], for examplefn get_mut.

Version

rustc 1.12.0-nightly (1225e122f 2016-07-30)
rustdoc 1.12.0-nightly (1225e122f 2016-07-30)
@Mark-Simulacrum
Copy link
Member

Cannot reproduce, versions below:

cargo:
cargo 0.13.0-nightly (c205132 2016-08-09)

rustc:

rustc 1.12.0-nightly (1deb02ea6 2016-08-12)
binary: rustc
commit-hash: 1deb02ea69a7ca3fd8011a45bb75ff22c3f7579a
commit-date: 2016-08-12
host: x86_64-apple-darwin
release: 1.12.0-nightly

rustdoc:

rustdoc 1.12.0-nightly (1deb02ea6 2016-08-12)
binary: rustdoc
commit-hash: 1deb02ea69a7ca3fd8011a45bb75ff22c3f7579a
commit-date: 2016-08-12
host: x86_64-apple-darwin
release: 1.12.0-nightly

@Sawyer47
Copy link
Contributor Author

Sawyer47 commented Sep 2, 2016

I still reproduce it. Maybe my description was not entirely clear. If a type implements the std::ops::Deref trait then there is an additional section in its documentation page Methods from Deref<Target=...>.
Even though Deref::deref returns an immutable reference, the generated documentation contains all methods, including those that would require DerefMut implementation for the code to compile.

So, considering the example code from my previous message :

    let mut foo = Foo;
    assert_eq!(foo.len(), 0);      // ok
    assert_eq!(foo.get(0), None);  // ok
    // compile error, but generated documentation lists get_mut as an available function
    assert_eq!(foo.get_mut(0), None); 

I quickly grepped the source code and it looks like rustdoc only checks for the implementation of Deref
(link to code).

@steveklabnik steveklabnik added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Sep 2, 2016
bors added a commit that referenced this issue Sep 7, 2016
rustdoc: Filter more incorrect methods inherited through Deref

Old code filtered out only static methods. This code also excludes &mut self methods if there is no DerefMut implementation.

Fixes #35169
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

3 participants