cargo-public-api icon indicating copy to clipboard operation
cargo-public-api copied to clipboard

Re-exporting an external module does not include its public API

Open repi opened this issue 3 years ago • 4 comments

One of our crates, cervo, is a basic wrapper crate that depends on 4 other crates and just use them like this to have a single convenient crate with that includes the API of all of the 4 ones it depends on.

pub use cervo_asset as asset;
pub use cervo_core as core;
pub use cervo_nnef as nnef;
pub use cervo_onnx as onnx;

This results in this output:

pub mod cervo
pub use cervo::asset
pub use cervo::core
pub use cervo::nnef
pub use cervo::onnx

which is similar to the rustdoc output:

image

but it is not correct in the case of exhaustively describing the public API of the crate.

Think it would have to for re-exports instead of listing that just as a use statement in the output instead include the entire module output for each re-export?

repi avatar Aug 20 '22 18:08 repi

Hmm which version of cargo-public-api are you using? It seems to work with 0.14.0:

% cargo install cargo-public-api
  Installing cargo-public-api v0.14.0
% cat src/lib.rs
pub mod v0 {
    pub fn hej() {
    }
}
pub use v0 as v0_reexported;
% cargo public-api
pub fn public_api_experiments::v0::hej()
pub fn public_api_experiments::v0_reexported::hej()
pub mod public_api_experiments
pub mod public_api_experiments::v0
pub mod public_api_experiments::v0_reexported

(Note that you need a recent nightly with 0.14.0)

Enselic avatar Aug 20 '22 19:08 Enselic

I'm on 0.14.0 also. And your example works, but if I add a re-export of an external crate, for example just adding this to your lib.rs:

pub use cervo_asset as asset;
pub use cervo_core as core;

and Cargo.toml:

[dependencies]
cervo-asset = { version = "0.2.0" }
cervo-core = { version = "0.2.0" }

then those crate module re-exports do not show up expanded (while the local modules do):

pub fn public_api_experiments::v0::hej()
pub fn public_api_experiments::v0_reexported::hej()
pub mod public_api_experiments
pub mod public_api_experiments::v0
pub mod public_api_experiments::v0_reexported
pub use public_api_experiments::asset
pub use public_api_experiments::core

repi avatar Aug 20 '22 19:08 repi

Aha, then this is most likely a variant of an upstream limitation I have encountered before, which is that information about the items of the re-exported external modules are not part of the rustdoc JSON that is built. This used to work, but about one month ago it stopped working as part of fixing a bunch of ICEs, and I brought it up: https://github.com/rust-lang/rust/pull/99287#issuecomment-1186586518

I don't think there currently is a plan to make this work again, but I think it could happen at some point, so I think we should keep this issue open to track that.

Enselic avatar Aug 20 '22 19:08 Enselic

Related upstream issues:

  • https://github.com/rust-lang/rust/issues/99513
  • https://github.com/rust-lang/rust/issues/101059

Enselic avatar Aug 25 '22 18:08 Enselic