Re-exported types have confusingly different documentation

08dfa38
Opened by David Tolnay at 2023-10-30 22:07:39

Re-exported types seem to have more confusing documentation than the original type. I noticed this while reviewing rayon::Configuration which is re-exported from rayon-core.


original/src/lib.rs

pub trait T {}
pub struct S;

impl S {
    pub fn f<F>(_: F, _: Box<T>) -> Self
        where F: Fn()
    {
        unimplemented!()
    }
}

This is documented basically like what I wrote, which is what I would expect:

selection_063


src/lib.rs

extern crate original;
pub use original::S;

This is documented with a couple changes, all of which are technically correct but unexpected.

  • The Box<T> is now Box<T + 'static>.
  • The return type has changed from Self to S.
  • The where clause gives an explicit -> ().
  • The parameter name placeholders are gone (which I prefer, but it is a difference).

selection_062

I am using rustc 1.22.0-nightly (f861b6ee4 2017-09-01).

@GuillaumeGomez

<!-- TRIAGEBOT_START --> <!-- TRIAGEBOT_ASSIGN_START --> <!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"fmease"}$$TRIAGEBOT_ASSIGN_DATA_END --> <!-- TRIAGEBOT_ASSIGN_END --> <!-- TRIAGEBOT_END -->
  1. Re-exported types seem to have more confusing documentation than the original type. I noticed this while reviewing rayon::Configuration which is re-exported from rayon-core.


    original/src/lib.rs

    pub trait T {}
    pub struct S;
    
    impl S {
        pub fn f<F>(_: F, _: Box<T>) -> Self
            where F: Fn()
        {
            unimplemented!()
        }
    }
    

    This is documented basically like what I wrote, which is what I would expect:

    selection_063


    src/lib.rs

    extern crate original;
    pub use original::S;
    

    This is documented with a couple changes, all of which are technically correct but unexpected.

    • The Box<T> is now Box<T + 'static>.
    • The return type has changed from Self to S.
    • ~~The where clause gives an explicit -> ().~~ fixed as of 1.50
    • The parameter name placeholders are gone (which I prefer, but it is a difference).

    selection_062

    I am using rustc 1.22.0-nightly (f861b6ee4 2017-09-01).

    @GuillaumeGomez

    <!-- TRIAGEBOT_START --> <!-- TRIAGEBOT_ASSIGN_START --> <!-- TRIAGEBOT_ASSIGN_DATA_START$${"user":"fmease"}$$TRIAGEBOT_ASSIGN_DATA_END --> <!-- TRIAGEBOT_ASSIGN_END --> <!-- TRIAGEBOT_END -->

    jyn at 2022-10-31 16:16:05

  2. Dark magic! :laughing:

    I'll take a look later.

    Guillaume Gomez at 2017-09-04 08:27:08

  3. cc #24305

    Lukas H. at 2017-09-04 21:31:18

  4. I think this is a cross-crate reexports issue, so labeling as such.

    Noah Lev at 2020-10-12 04:36:51

  5. Triage as of rustdoc 1.50.0-nightly (0f6f2d681 2020-12-06): This bug has gone away:

    The where clause gives an explicit -> ().

    The rest are still changed from the inner crate.

    Inner: image Outer: image

    jyn at 2020-12-16 01:53:29

  6. I expect this is an inconsistency between how clean treats HIR and rustc_middle::ty somewhere (the difference being that ty works off serialized metadata).

    jyn at 2020-12-16 01:54:33

  7. Temporarily assigning myself to this issue since I am working on fixing several issues related to the handling of cross-crate trait object types in rustdoc and other minor cross-crate things. I won't fix everything mentioned in this issue however, hence this is only a temporary assignment until the PR is open.

    @rustbot claim @rustbot label -C-enhancement +C-bug

    León Orell Valerian Liehr at 2022-10-27 15:08:06

  8. Update: Thanks to #103885, #107637 & #112463, the output is finally very close to acceptable (source vs. rendered):

    - pub fn f<F>(_: F, _: Box<dyn T>) -> Self
    - where F: Fn()
    + pub fn f<F>(_: F, _: Box<dyn T>) -> S
    + where
    +     F: Fn(),
    

    The remaining issue concerns Self types in cross-crate scenarios. I'm not gonna work on a PR for that in the foreseeable future but at some point I will probably submit a PR for it. I predict it to be a bit nasty performance-wise since it requires performing type unification on every Ty inside an impl.

    León Orell Valerian Liehr at 2023-10-30 18:32:56