-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Rustdoc needs to handle conditional compilation somehow #1998
Comments
I think the latter case is probably best, yes. Collapse-same-name is a bit of a kludge but not entirely unexpected. |
Not backwards-compatible. Nominating for milestone 4, well-covered (having documentation tools work the way we expect is helpful in making sure the documentation covers everything...) |
doc-coverage can be assured elsewhere, but this is embarrassing. should be fixed before production ready. |
accepted for production-ready milestone |
Nothing new to say except to link to #5413. |
This is not yet fixed by rustdoc_ng, and requires a bit of thought. |
This is a hard problem with no good solution. If I use the AST before configuration, I can't have any hyperlinking for those items. Is that worth it? |
Low, no milestone |
My current thinking:
Then, later, when cleaning, check if the item's nodeid is in the sidetable of cfg'd things. If so, add them to a vec of "alternatives" in the item, cleaning each. This depends on:
When rendered, we'd have a list of "alternative definitions", listing the cfg's that would have enabled them. This of course doesn't handle things that are actually conditionally enabled/disabled, just things that are defined multiple times. |
I'm not sure about AST renumberings off the top of my head. |
Please fix. It's really confusing to see missing/wrong documentation if working on non-linux. This is one more 'gotcha' that you need to know, so this makes it harder to start working with rust on non-linux platform. Thank you for you consideration! :) |
@KostaCitrix this is a challenging issue to fix and we're all aware of the usability impacts this has. Demanding "please fix" doesn't really help solve the technical issues. |
This is potentially less of a problem now that docs are installed with the distribution. It does seem, though, like this fact isn't particularly well known to newcomers. |
In some ways, but it still doesn't lay out a good welcome mat to those who aren't using Linux. |
I ran out of fingers to count the number of times I've seen people not find Windows specific extension traits because the online docs were linux-only. |
How about building docs on all three supported platforms and uploading to doc.rust-lang.org/nightly/windows, nightly/linux, etc? Of course this doesn't solve the general problem of rustdoc and conditional compilation.
|
One potential problem with trying to do the AST approach is if the same function/type is defined for multiple platforms with different doc comments, which doc comment do we show for the item? Or maybe even more importantly, same function with different types, or same type with different public fields? One possible solution might be to add a selector somewhere on the page that lets you pick the platform you wish to view, and it would use that to show the correct documentation/types/fields. It could still show AST elements that aren't available on that platform but perhaps greyed out, to indicate that they're not available. Another solution is to do what @tomjakubowski suggested and just upload docs for each platform to a different path. The main rustdoc UI could then still have the selector, which changes the URL to view that platform's documentation (and sets a cookie that is used by the non-platform-specific documentation path to automatically jump to the platform-specific path). One downside to this is every documentation URL that people share would then be a platform-specific URL. |
In this case, I think we should emit a warning (that can be made into an error via a command line flag, to make this useful for CI or local testing, but still preserves compatibility) and just pick one (maybe the native one for compatibility). If only one of these item has docs, this is a non-issue (which should be the preferred way to document this IMO).
I'm not sure about what a type means to Rustdoc, but I don't think it uses type information. This would mean that at least type aliases are handled automatically: The type can be something like Now all remaining cases should be rare, so we could emit a warning for them as well. Which item we actually pick... no idea, maybe the same item we would pick today (like above). I could also imagine solving these 2 issues by just adding docs for both items and marking them with their cfg attribute (something that would be nice in any case).
http://doc.rust-lang.org/libc is apparently doing that already, but it's not the best from a usability perspective, and I don't think |
Note that this also has an effect on the cc @nrc |
crates.fyi is another solution to this issue /cc @onur |
I don't think there is a good answer to this in rustdoc itself. The better answer (which Steve hints at) is that we should build and host docs for every platform, not just Linux. |
Tell me when winapi's docs are finally up on crates.fyi |
…ichton Expose all OS-specific modules in libstd doc. 1. Uses the special `--cfg dox` configuration passed by rustbuild when running `rustdoc`. Changes the `#[cfg(platform)]` into `#[cfg(any(dox, platform))]` so that platform-specific API are visible to rustdoc. 2. Since platform-specific implementations often won't compile correctly on other platforms, `rustdoc` is changed to apply `everybody_loops` to the functions during documentation and doc-test harness. 3. Since platform-specific code are documented on all platforms now, it could confuse users who found a useful API but is non-portable. Also, their examples will be doc-tested, so must be excluded when not testing on the native platform. An undocumented attribute `#[doc(cfg(...))]` is introduced to serve the above purposed. Fixes #24658 (Does _not_ fully implement #1998).
Triage: this is still the holy grail. |
With the |
@jonas-schievink in #1998 (comment):
It's not just doc comments. Definitions can vary (significantly) too. And what about modules? For example, suppose we have: #[cfg(foo)]
pub mod host {
pub struct Foo(pub usize);
pub struct Bar;
}
#[cfg(not(foo))]
pub mod host {
pub struct Foo(pub i8);
pub struct Qux;
}
fn foo() -> host::Foo { host::Foo(0) } Are you saying we should arbitrarily choose one Or do we generate separate documentation for both modules, in which case to what will the documentation for the (non-conditionally compiled) function I think the only sensible options are as set out by @lilyball in #1998 (comment):
|
I'm not really sure what I was thinking 4.5 years ago :) |
Perhaps an intermediate solution would be to separately compile docs for each (crate-configurable, tier 1s by default) target platform, then perform a diff/merge on the results? Indeed, rather than performing the diff/merge operation on HTML it could be time to add a more machine-readable output format to rustdoc and perform the operation on that? JSON perhaps? Edit I see rustdoc had JSON output historically, but it was removed: #32698 contains some discussion around it. |
Reading my comment from back then again, it seems fairly clear that it doesn't apply to the example given above:
It only concerns different versions of an item that both have different documentation, but @eggyal's example does not contain any documentation. This doesn't solve the issue with different item definitions depending on |
(checking oldest issues for fun and profit) Should this be closed in favor of tracking in #43781? |
@CAD97 No. #43781 is one possible solution to this issue, which has not be stabilized and has design concerns (https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/Discussion.20about.20.60doc_cfg*.60.20features.20stabilization/near/304190110). This tracks the general issue of conditional compilation, not a specific feature. |
We have some functions that are reimplemented per architecture, with docs only on one implementation. Rustdoc should ideally be able to merge these docs.
More seriously though a bunch of our libc hierarchy can't be viewed because it's conditionally compiled and the docs are built on linux.
Probably rustdoc should extract its documentation before pruning the AST for conditional compilation, collapse things with the same name into a single document, then run resolve.
The text was updated successfully, but these errors were encountered: