rustdoc: reexported type aliases are not preserved in function signatures

d2ac9d8
Opened by Deleted user at 2023-07-03 09:20:20

The recently added iterate function uses the Iterate type alias as its result type. It is correctly displayed in http://static.rust-lang.org/doc/master/core/iter/fn.iterate.html but not in http://static.rust-lang.org/doc/master/std/iter/fn.iterate.html.

  1. Also, the lifetime 'a is dropped from the list of parameters for iterate.

    Deleted user at 2014-07-20 11:46:04

  2. Related to #15099

    bluss at 2014-07-20 12:16:44

  3. This must be fixed because it makes writing portable programs impossible.

    mahkoh at 2014-10-06 14:23:42

  4. @mahkoh, how does a rustdoc rendering bug affect the portability of a program?

    Huon Wilson at 2014-10-06 14:40:11

  5. @huonw: Type aliases are often used to hide platform specific types. If the documentation shows that a function takes a i64, but it actually takes a c_long, then it won't compile on platforms where c_long is not i64.

    mahkoh at 2014-10-06 14:44:50

  6. I just run into this issue. In my case, the types being show by the doc are not even public.

    You can see the problem on this doc output. Note that Command_Algorithm should read Algorithm. The title of the types are always correct, its the method and impl signature that show wrong.

    I don't know if it helps, but the types are being aliased here in my code.

    Ignacio Corderi at 2014-11-24 02:03:27

  7. This file:

    pub use std::result::Result as Lol;
    

    still mis-renders:

    2015-11-07-081909_380x121_scrot

    though as @icorderi mentions, the titles are correct.

    Steve Klabnik at 2015-11-07 07:19:08

  8. Triage: no changes since my last comment

    Steve Klabnik at 2018-09-24 17:15:52

  9. Seems to be working now so closing.

    Guillaume Gomez at 2019-12-20 09:20:57

  10. I don't think this issue is fully fixed (correct me if I'm wrong); for example, for heim docs.rs does not render type alias correctly, resulting in a weirdly gibberish output: https://docs.rs/heim/0.0.10/heim/cpu/struct.CpuFrequency.html#method.current

    Type alias is used in the sub-crate code: https://github.com/heim-rs/heim/blob/095768ff6a580b27727b6958521392bb5f86a443/heim-cpu/src/freq.rs#L20-L22

    And whole this crate is re-exported with #[doc(inline)] later at the facade crate: https://github.com/heim-rs/heim/blob/v0.0.10/heim/src/lib.rs#L59-L61

    Docs for sub-crate are rendered almost correctly: https://docs.rs/heim-cpu/0.0.10/heim_cpu/struct.CpuFrequency.html#method.current It does not has an active link, though, which might be part of the problem.

    svartalf at 2020-02-16 11:46:57

  11. Here is a minimally working example for this issue: https://github.com/svartalf/rust-issue-15823

    svartalf at 2020-02-29 07:01:49

  12. It works fine for me? Version 1.43.

    Guillaume Gomez at 2020-03-04 14:27:41

  13. @GuillaumeGomez thanks for getting back to this issue!

    Unfortunately, I still can reproduce it with the example from my previous comment and rust version 1.43.0-nightly (4ad624882 2020-03-03): image. You can check the example repo for additional details and screenshots.

    Same happens at docs.rs for heim crate: https://docs.rs/heim/0.1.0-alpha.1/heim/cpu/struct.CpuFrequency.html; I would expect to see Frequency type alias instead of Quantity<dyn Dimension<M = Z0, I = Z0, N = Z0, .. as it is shown right now.

    svartalf at 2020-03-04 14:43:08

  14. This is still an issue for me on rust 1.60.0-nightly.

    Alice Cecile at 2022-03-22 20:05:05

  15. It seems to be a tricky issue to fix. I opened https://github.com/rust-lang/compiler-team/issues/504 so we'll see if it'll be able to fix this problem.

    In the meantime, to add a test for this in rustdoc:

    <details>

    src/test/rustdoc/alias-reexport.rs

    // aux-build:alias-reexport.rs
    // aux-build:alias-reexport2.rs
    
    #![crate_name = "foo"]
    
    extern crate alias_reexport2;
    
    // @has 'foo/reexport/fn.foo.html'
    // @has - '//*[@class="docblock item-decl"]' 'pub fn foo() -> Reexport'
    // @has 'foo/reexport/fn.foo2.html'
    // @has - '//*[@class="docblock item-decl"]' 'pub fn foo2() -> Result<Reexport, ()>'
    // @has 'foo/reexport/type.Reexported.html'
    // @has - '//*[@class="docblock item-decl"]' 'pub type Reexported'
    #[doc(inline)]
    pub use alias_reexport2 as reexport;
    

    src/test/rustdoc/alias-reexport2.rs

    // aux-build:alias-reexport.rs
    
    #![crate_name = "foo"]
    
    extern crate alias_reexport;
    
    use alias_reexport::Reexported;
    
    // @has 'foo/fn.foo.html'
    // @has - '//*[@class="docblock item-decl"]' 'pub fn foo() -> Reexported'
    pub fn foo() -> Reexported { 0 }
    // @has 'foo/fn.foo2.html'
    // @has - '//*[@class="docblock item-decl"]' 'pub fn foo2() -> Result<Reexported, ()>'
    pub fn foo2() -> Result<Reexported, ()> { Ok(0) }
    

    src/test/rustdoc/auxiliary/alias-reexport.rs

    pub type Reexported = u8;
    

    src/test/rustdoc/auxiliary/alias-reexport2.rs

    extern crate alias_reexport;
    
    pub use alias_reexport::Reexported;
    
    // @has 'foo/fn.foo.html'
    // @has - '//*[@class="docblock item-decl"]' 'pub fn foo() -> Reexported'
    pub fn foo() -> Reexported { 0 }
    // @has 'foo/fn.foo2.html'
    // @has - '//*[@class="docblock item-decl"]' 'pub fn foo2() -> Result<Reexported, ()>'
    pub fn foo2() -> Result<Reexported, ()> { Ok(0) }
    
    </details>

    Guillaume Gomez at 2022-04-04 13:23:02

  16. https://github.com/rust-lang/rust/pull/112853 allowed to make a great step forward into fixing this issue.

    Guillaume Gomez at 2023-07-03 09:20:20