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

Can't document rustc-macro crates #36820

Closed
alexcrichton opened this issue Sep 29, 2016 · 4 comments
Closed

Can't document rustc-macro crates #36820

alexcrichton opened this issue Sep 29, 2016 · 4 comments

Comments

@alexcrichton
Copy link
Member

Originally filed as rust-lang/cargo#3132 by @dtolnay

Reported by @neon64 in serde-rs/serde#567: cargo doc cannot document any rustc_macro crate or any crate depending on a rustc_macro crate.

https://docs.rs/crate/serde_derive/0.8.10/builds/31363

error: the `#[rustc_macro_derive]` attribute is only usable with crates of the `rustc-macro` crate type
 --> .cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/serde_derive-0.8.10/src/lib.rs:9:3
  |
9 | #[rustc_macro_derive(Serialize)]
  |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: the `#[rustc_macro_derive]` attribute is only usable with crates of the `rustc-macro` crate type
  --> .cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/serde_derive-0.8.10/src/lib.rs:18:3
   |
18 | #[rustc_macro_derive(Deserialize)]
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: Compilation failed, aborting rustdoc

@alexcrichton I don't know Cargo well enough to tell whether this is a cargo issue or a rustc issue or a rustdoc issue so sorry if this is filed in the wrong place.

@alexcrichton
Copy link
Member Author

@nrc curious about your thoughts on how we might fix this.

The problem here is that rustdoc doesn't have a --crate-type argument, so Cargo doesn't pass it. Instead rustdoc hard codes that all crates are rlibs when we document them. This then doesn't play nicely with the attribute which requires a rustc macro crate type. I see two solutions currently:

  • Cargo never documents rustc-macro crates
  • The compiler ignores requirements of the rustc-macro crate type if we're in "rustdoc mode"

The former seems reasonable for now but eventually rustc-macro crates will grow to perhaps having interesting APIs in them, right? The latter unfortunately doesn't have a great way to do so today but I could always add a random flag to the session.

@nrc
Copy link
Member

nrc commented Sep 29, 2016

Depending on how long "eventually" is we might be best waiting to separate Rustdoc out from the compiler. It might still need something hacked in to the session though (depending on how it is implemented). Given that it is Rustdoc, I'd not be opposed to the hackiest of hacks to get this working.

@dtolnay
Copy link
Member

dtolnay commented Sep 29, 2016

Agreed on a quick hack to get this working if a real fix is further out - not being able to document any crate that transitively depends on serde_derive is a pretty big blocker. I don't think anybody cares whether serde_derive itself is rustdocumented at this point.

@steveklabnik
Copy link
Member

I would really like to separate rustdoc from the compiler. It's on my
"someday" list.

On Thu, Sep 29, 2016 at 5:03 PM, David Tolnay [email protected]
wrote:

Agreed on a quick hack to get this working if a real fix is further out -
not being able to document any crate that transitively depends on
serde_derive is a pretty big blocker. I don't think anybody cares whether
serde_derive itself is rustdocumented at this point.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#36820 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABsinG-Agl5wlBOsMMl9skNjS9lWeniks5qvCe3gaJpZM4KJjtY
.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Sep 30, 2016
This commit adds a "hack" to the session to track whether we're a rustdoc
session or not. If we're rustdoc then we skip the expansion to add the
rustc-macro infrastructure.

Closes rust-lang#36820
bors added a commit that referenced this issue Oct 3, 2016
rustdoc: Fix documenting rustc-macro crates

This commit adds a "hack" to the session to track whether we're a rustdoc
session or not. If we're rustdoc then we skip the expansion to add the
rustc-macro infrastructure.

Closes #36820
emk added a commit to faradayio/cage that referenced this issue Oct 8, 2016
This is vaguely similar to
rust-lang/cargo#3132 and
rust-lang/rust#36820, except it just started
again today, and those issues were closed several days ago.

We don't do this on stable, because we have multiple stable platforms
and we need them to build fast.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants