Tidy, mainly documentation links#827
Conversation
b040faf to
8c3e2af
Compare
|
For this push, I've abandoned the idea of cleaning up all the I'm tempted to suggest that we put a CI check in place to flag documentation warnings, though I suppose that would add a little bit of friction to documenting which isn't great... |
|
No worries. I thought about it a bit, and I feel like it would be beneficial to have all docs enabled all the time, even if a specific feature is disabled. Ie, if the I'm not too sure what would be the best approach to achieve this. Thoughts? |
|
The main snag I'm seeing, is when there's module level documentation like this: //! Module level docs talk about the library
//! that has some sort of [`async-method`]
//! and maybe some sort of [`dma-type`]
//! [`async-method`] and [`dma-type`] can be used together!
And code like: /// A hypothetical method that's not synchronous
#[cfg(feature="async")]
fn async-method() {}
...
#[cfg(feature="dma")]
mod dma {
/// The type used for DMA
struct dma-type {}then cargo doc spits out a lot of warnings about dead links when it's run without those features. One option is to make the docs change according to the features, like this (same //! Module level docs talk about the library
//! that has some sort of
#![cfg_attr(not(feature = "async"), doc = "`async-method`")]
#![cfg_attr(feature = "async", doc = "[`async-method`]")]
//! and maybe some sort of
#![cfg_attr(not(feature = "dma"), doc = "`dma-type`")]
#![cfg_attr(feature = "dma", doc = "[`dma-type`]")]
//! #![cfg_attr(not(feature = "async"), doc = "`async-method`")]
#![cfg_attr(feature = "async", doc = "[`async-method`]")]
//! and
#![cfg_attr(not(feature = "dma"), doc = "`dma-type`")]
#![cfg_attr(feature = "dma", doc = "[`dma-type`]")]
can be used together!
//!
Another is to leave the docs unchanged, but add placeholders as in the original comment. I guess after typing this, I'm wondering what the downside is to mostly leaving out the docs for the feature-gated stuff - in the case of people generating their own docs it's trivial to re-do with features enabled, and we can turn them on in CI. |
|
Another related problem: we have some API differences depending on the target chip, so simply enabling gated features isn't quite enough. |
|
n.b. we can combine #[cfg(doc)]
#[hal_cfg("eic-d5x")]
/// This method is not present with the selected feature set, defined for documentation only
pub fn into_future(self) {
unimplemented!()
} |
ba97466 to
7df33b5
Compare
|
This PR is now to a point where I think it would be good to look at the documentation macro as discussed in matrix, before merging this. n.b. there's a known bug in rustdoc which basically means that we can't reliably link to specific versions of dependencies - links to embedded-hal 0.2 will resolve to embedded-hal 1.0 for instance. I opened a bug for this, but don't get the impression it'll be fixed anytime soon. |
48b20ab to
e7e396f
Compare
|
I've extended the HAL macros to support #[cfg(doc)]
#[hal_cfg(not("sercom0-d5x"))]
/// This trait is not present with the selected feature set, defined for
/// documentation only
pub trait IoSet {}There was a little bit of discussion on Matrix about whether it's a good idea to support/use #[hal_doc_not("sercom0-d5x")]
/// This trait is not present with the selected feature set, defined for
/// documentation only
pub trait IoSet {}Personally, I feel this is a bit too deep in the weeds. |
cb103af to
a2d05eb
Compare
|
Now that we've got CI documentation generation working again, I'm keen to finish up this work. Just a few questions/tasks:
|
|
@bradleyharden if you've got a chunk of time to skim over this, it would be nice to get the thumbs-up on the macro changes (and I think the only wording changes were in SERCOMv2 docs but it's been a while) |
|
Hey @ianrrees, sorry I was just now able to get around to this. Some thoughts I have:
|
|
Of course, another option is to merge this as-is while we look for a better solution (if we want to). We can always remove the dummy items later, I wouldn't consider their removal a breaking change since we don't consider them a part of the public API. |
|
Yeah, I tend to agree about the dummy items being a bit ugly, however I don't think they have a negative impact other than adding a little bit of clutter. TBH, there are a couple things about the way Cargo/rustdoc handle documentation that aren't a great fit for our project, and to me this the dummy items seem like not the worst of those - I'd say the thing about not being able to document multiple versions of a crate with the same name is worse. The dummy items are the lest offensive of the options I could think of:
I'm also in favour of CI building docs and flagging any introduced issues with the documentation, so I don't think ignoring the warnings is viable once that's in place. |
|
Sounds good to me. Did you want to add the extra CI doc checks in this PR? Otherwise I'm ready to merge when everything will be lined up. |
6ce5d0b to
5f4cd86
Compare
|
I'm probably going to be a bit short on atsamd time for the next while, so would rather not hold this up for CI documentation checks. Unless, of course, someone else wants to do it :) . This work only fixes the doc warnings for some particular combinations of features, so there could be a little more docstring tidy-up to do as part of that CI work, depending on how the check is implemented. This one might be best merged without squashing, so we can revert the dummy types more easily if we come up with a better solution. |
Summary
Mostly warning cleanup, a few typos etc.
I'm finding the documentation of feature-gated APIs to be quite awkward... Wondering if it might be easier to add dummy methods/types that are conditional on documentation builds with the feature not enabled, so that rustdoc has something to link to. Eg