-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
RFC 2008 non-exhaustive enums/structs: Rustdoc #51854
Conversation
Mind sharing a screenshot of what this looks like? |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Ah, looks good! Although the message is a bit odd, and personally I'd recommend customising the message depending on whether it's a struct or enum. I'm also a bit confused on the microscope icon, as I get the sentiment behind "a closer look" although it looks a bit off for me. Although without an icon it'd look worse, so, idk. |
I've made it say what it is (struct, enum, etc.). I only included the microscope icon as that is (as far as I can tell) always included in the little boxes like that one. I agree that the message is a bit off, I can't think of a better one at the moment (else I'd have included it) but if anyone reading this can think of one, I'll happily change it. |
What I thought of for enums: This enum is marked as non-exhaustive, and additional variants may be added in the future. When However, for structs, I think that it might be better to do the opposite and only add a message if all of these things can be done normally. Something along the lines of "all of this struct's fields are public, and it can be constructed normally with the The RFC suggested using the |
(I edited that comment enough times I'm going to add a comment that I did so for people viewing the response via email) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @rust-lang/rustdoc for the implementation and @rust-lang/docs for the placement of the "non-exhaustive" disclaimer and its wording. I'm not totally sure what was agreed upon for how #[non_exhaustive]
was supposed to be noted in docs, but i'd like to make sure there's some agreement in the docs team for how we do it.
src/librustdoc/clean/mod.rs
Outdated
@@ -366,6 +368,7 @@ pub struct Item { | |||
pub def_id: DefId, | |||
pub stability: Option<Stability>, | |||
pub deprecation: Option<Deprecation>, | |||
pub non_exhaustive: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think i'd prefer seeing the non_exhaustive
marker just on the kinds where it's relevant, so just Struct
/Enum
/etc, instead of on Item
here where literally everything has to care about it.
On the other hand, if i remember right we do keep all the ast::Attribute
s around in the Attributes
struct, so we could just query them as needed, rather than passing this flag around all the way from clean_ast
to html/render
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be resolved now.
src/librustdoc/html/render.rs
Outdated
@@ -2194,6 +2194,7 @@ fn document(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Re | |||
info!("Documenting {}", name); | |||
} | |||
document_stability(w, cx, item)?; | |||
document_non_exhaustive(w, item)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...though now i see why you did it this way. I commented in #51860 (comment) that this marker could go into the "Fields" or "Variants" sections of the struct/enum pages, rather than at the top of the full docs.
@QuietMisdreavus @clarcharr I've updated this to move the message to the suggested location. |
bfd2b55
to
9527d6a
Compare
src/librustdoc/clean/mod.rs
Outdated
pub fn is_non_exhaustive(&self) -> bool { | ||
self.attrs.other_attrs.iter() | ||
.filter(|a| a.name().as_str() == "non_exhaustive") | ||
.count() > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be more peformant to use .any()
instead of .count() > 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed this.
@rust-lang/rustdoc @rust-lang/docs Would appreciate some feedback on whether the message and placement are appropriate so we can get this landed! |
This is very confusing and it takes a lot of place. Not very convinced by the current add... |
…psed by default and easier to understand.
With the message hidden by default, it's a bit better. However, why do we have a |
@GuillaumeGomez |
Ah I didn't know. Then no problem with it. If messages are hidden by default, then all good for me. |
src/librustdoc/html/render.rs
Outdated
Therefore, non-exhaustive structs cannot be constructed in external crates \ | ||
using the traditional <code>Struct {{ .. }}</code> syntax; cannot be \ | ||
matched against without a wildcard <code>..</code>; and \ | ||
functional-record-updates do not work.")?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is "functional-record-updates" a term we use elsewhere? I'm not familiar with what it could mean.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like the book refers to it as struct update syntax, I'll change the PR to reflect this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a commit that changes this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The book actually didn't mention FRU at all so I was equally confused when the RFC came about. Struct update syntax is a much better way of putting it, and I'm glad it's finally in the book now.
This looks really nice! Thanks so much for working on this. I just have the one terminology question, but once that's done i'm ready to push the button on this! |
Thanks for updating! Let's get this rolling! @bors r+ |
📌 Commit b671bdc has been approved by |
RFC 2008 non-exhaustive enums/structs: Rustdoc Part of #44109. Not sure how those who maintain rustdoc primarily would prefer this addition look or where it should be placed, happy to make any changes required. r? @QuietMisdreavus (not sure if this is the right person, just guessing)
☀️ Test successful - status-appveyor, status-travis |
Part of #44109. Not sure how those who maintain rustdoc primarily would prefer this addition look or where it should be placed, happy to make any changes required.
r? @QuietMisdreavus (not sure if this is the right person, just guessing)