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: Methods from Deref<Target = T<U>> is imprecise (contains false positives) #24686

Open
ghost opened this issue Apr 22, 2015 · 5 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

@ghost
Copy link

ghost commented Apr 22, 2015

use std::ops::Deref;

pub struct Foo<T>(T);
impl Foo<i32> {
    pub fn get_i32(&self) -> i32 { self.0 }
}
impl Foo<u32> {
    pub fn get_u32(&self) -> u32 { self.0 }
}
pub struct Bar(Foo<i32>);
impl Deref for Bar {
    type Target = Foo<i32>;
    fn deref(&self) -> &Foo<i32> {
        &self.0
    }
}

The Methods from Deref for Bar will contain both get_i32 and get_u32, but should only contain get_i32.

Image

@huonw huonw added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Apr 22, 2015
@tomjakubowski
Copy link
Contributor

Just wondering (to help prioritize this), is there an example of this bug in the standard library docs?

@ghost
Copy link
Author

ghost commented Apr 23, 2015

I don't think there's anything which matches this particular example exactly.

The closest thing that I could find was DerefVec which includes all methods of Vec and doesn't separate them into different bounds like it does for Vec. So someone reading the docs for DerefVec may think that you can dedup on any DerefVec<T>, when in fact you can only do it where T: PartialEq.

http://doc.rust-lang.org/nightly/collections/vec/struct.DerefVec.html

@tomjakubowski
Copy link
Contributor

Ah yeah. Preserving bounds in the deref is related but distinct enough it would be worth creating a new issue for it.

As an aside: when I tried to do the "methods available through Deref" feature myself, a couple months ago, I got stuck enumerating all of these miscellaneous issues and pondering pie in the sky solutions for them. I'm so happy acrichto stepped in to ship something covering the 95% use case :-)


Sent from Mailbox

On Thu, Apr 23, 2015 at 12:09 PM, whataloadofwhat
notifications@github.com wrote:

I don't think there's anything which matches this particular example exactly.
The closest thing that I could find was DerefVec which includes all methods of Vec and doesn't separate them into different bounds like it does for Vec. So someone reading the docs for DerefVec may think that you can dedup on any DerefVec<T>, when in fact you can only do it where T: PartialEq.

http://doc.rust-lang.org/nightly/collections/vec/struct.DerefVec.html

Reply to this email directly or view it on GitHub:
#24686 (comment)

@sfackler
Copy link
Member

sfackler commented Nov 4, 2016

I hit this trying to make a unified Ref<T> wrapper for rust-openssl: https://github.com/sfackler/rust-openssl/blob/ab30ad0ce76ee6fd8cc14ecff2186171c7f610e3/openssl/src/types.rs

I'll probably work around it by dropping the generic Ref wrapper and making a separate FooRef type for each Foo, but it's a bit unfortunate.

@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 added the C-bug Category: This is a bug. label Jul 22, 2017
@QuietMisdreavus
Copy link
Member

Fixing this likely involves figuring out how to filter the impls somewhere around here. That type_ there is the target type, so you'd have to reach into there and make some kind of ,retain() call on non_trait that matched not just on the DefId (which just gets the top container) but also any typarams on the full type itself. The impl's for_ will have the type to match on.

@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
@fmease fmease changed the title Rustdoc: "Methods from Deref<Target=T<U>>" ignores U bound rustdoc: "Methods from Deref<Target=T<U>>" is imprecise (contains false positives) Sep 3, 2024
@fmease fmease changed the title rustdoc: "Methods from Deref<Target=T<U>>" is imprecise (contains false positives) rustdoc: Methods from Deref<Target=T<U>> is imprecise (contains false positives) Sep 3, 2024
@fmease fmease changed the title rustdoc: Methods from Deref<Target=T<U>> is imprecise (contains false positives) rustdoc: Methods from Deref<Target = T<U>> is imprecise (contains false positives) Sep 3, 2024
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