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

Higher-Rank Trait Bounds (HRTB) not properly rendered #88

Closed
Enselic opened this issue May 1, 2022 · 2 comments
Closed

Higher-Rank Trait Bounds (HRTB) not properly rendered #88

Enselic opened this issue May 1, 2022 · 2 comments
Labels
limitation A current limitation of the library, e.g. due to an upstream bug. waiting-on-upstream Some other project needs to make a change before we can make a change.

Comments

@Enselic
Copy link
Owner

Enselic commented May 1, 2022

Comparing the rustdoc HTML output of https://github.com/rust-lang/rust/blob/master/src/test/rustdoc/higher-ranked-trait-bounds.rs with the output of public-api, there are differences. To see them, first generate rustdoc HTML output for that file:

% ~/.rustup/toolchains/nightly-2022-03-31-aarch64-apple-darwin/bin/rustdoc ~/src/rust/src/test/rustdoc/higher-ranked-trait-bounds.rs -Z unstable-options --output-format html -o /tmp/hrtb

and then look at e.g. open /tmp/hrtb/foo/fn.test3.html which looks like this:

pub fn test3<F>() 
where
    F: for<'a, 'b> Fn(&'a u8, &'b u8), 

and then generate output with public-api:

% ~/.rustup/toolchains/nightly-2022-03-31-aarch64-apple-darwin/bin/rustdoc ~/src/rust/src/test/rustdoc/higher-ranked-trait-bounds.rs -Z unstable-options --output-format json -o /tmp/hrtb
% public-api /tmp/hrtb/foo.json 
pub fn foo::Foo::bar<T>() where T: Trait<'a>
pub fn foo::test1<T>() where &'a T: Iterator
pub fn foo::test2<T>() where &'a T: Trait<'b>
pub fn foo::test3<F>() where F: Fn(&'a u8, &'b u8)<'a, 'b>
pub mod foo
pub struct field foo::Bar::bar: &'a Trait<'b> + Unpin
pub struct field foo::Bar::baz: &'a Unpin + Trait<'b><'b>
pub struct field foo::Foo::some_func: fn(&'c i32) -> i32
pub struct field foo::Foo::some_trait: &'a Trait<'b>
pub struct foo::Bar<'a>
pub struct foo::Foo<'a>
pub trait foo::B<'x>
pub trait foo::Trait<'x>

Normalizing whitespace and linewlines and aligning, we have this vs that:

pub fn      test3<F>() where F: for<'a, 'b> Fn(&'a u8, &'b u8), 
pub fn foo::test3<F>() where F:             Fn(&'a u8, &'b u8)<'a, 'b>

There is a FIXME related to HRTB in rust-lang/rust/src/librustdoc/json/conversions.rs, so not sure we can fix them all, but it looks like we can fix the particular example I brought up.

For reference HRTB, didn't work properly in rustdoc HTML either for quite a while (see rust-lang/rust#78482), but was fixed quite recently, which also added the FIXME (see rust-lang/rust#84814).

To fix HRTBs in rustdoc HTML, the DynTrait object was introduced in the above PR. So fixing all HRTB problems might be related to fixing Enselic/cargo-public-api#40, in case it requires upstream changes.

@Enselic Enselic added the limitation A current limitation of the library, e.g. due to an upstream bug. label May 1, 2022
Enselic added a commit that referenced this issue May 2, 2022
rustdoc HTML looks like this:

    pub fn test3<F>()
    where
        F: for<'a, 'b> Fn(&'a u8, &'b u8),

and with this fix, our output looks like this:

    pub fn comprehensive_api::higher_ranked_trait_bounds::test3<F>() where F: for<'a, 'b> Fn(&'a u8, &'b u8)

normalizing and putting them next to each other, we can see that we now
render correctly in this case:

    pub fn                                                test3<F>() where F: for<'a, 'b> Fn(&'a u8, &'b u8),
    pub fn comprehensive_api::higher_ranked_trait_bounds::test3<F>() where F: for<'a, 'b> Fn(&'a u8, &'b u8)

This is part of fixing #88.
@Enselic
Copy link
Owner Author

Enselic commented May 12, 2022

We are waiting on a change to rustdoc JSON, see rust-lang/rust#96647.

@Enselic Enselic added the waiting-on-upstream Some other project needs to make a change before we can make a change. label May 12, 2022
@Enselic
Copy link
Owner Author

Enselic commented May 21, 2022

Closed by #92. I believe remaining HRTB related work can be scoped to Enselic/cargo-public-api#40

@Enselic Enselic closed this as completed May 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
limitation A current limitation of the library, e.g. due to an upstream bug. waiting-on-upstream Some other project needs to make a change before we can make a change.
Projects
None yet
Development

No branches or pull requests

1 participant