`cargo doc` shows different return for re-exported methods

I noticed some strange behaviour: type definitions for async fns have a
different return type depending on if they're exported from a dependency.

Example:

smol::UdpSocket shows:

pub async fn bind<A>(addr: A) -> impl Future<Output = Result<UdpSocket, Error>>where
  A: AsyncToSocketAddrs,

async_net::UdpSocket shows:

pub async fn bind<A: AsyncToSocketAddrs>(addr: A) -> Result<UdpSocket>

The same results happen if I run cargo doc locally for the smol and async-net projects.

I would have expected the same type signature here? Is this expected?

2 Likes

Both function signatures are equivalent. In the direct case it is probably what was written in the source code, but in the re-export case the exact thing that was written is lost and rustdoc has to emit a canonical form instead.

No, look at the return type. They're both async, so that first one returns a future that returns a future that returns a result. The second one returns a future that returns a result (which looks like the correct one).

6 Likes

I can reproduce this using the latest nightly, and I couldn’t easily find the issue reported anywhere yet. So someone might want to open a new one.

4 Likes

Excellent. Thanks for the review, all!

I opened cargo doc: shows different return types for re-exported methods · Issue #115760 · rust-lang/rust · GitHub.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.