-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Document default values for primitive types #43252
Conversation
Bikeshedding alternative phrasing: |
Shouldn't @rust-highfive assign a reviewer to this PR? Or do I have to do it manually or just wait? |
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.
A light rewording would be better I think.
default_impl! { char, '\x00' } | ||
default_impl! { (), (), "Returns the default value of `()`" } | ||
default_impl! { bool, false, "Returns the default value of `false`" } | ||
default_impl! { char, '\x00', "Returns the default value of `\\x00`" } |
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.
Shouldn't it be "Returns the default value of char
which is \\x00
?"
default_impl! { bool, false } | ||
default_impl! { char, '\x00' } | ||
default_impl! { (), (), "Returns the default value of `()`" } | ||
default_impl! { bool, false, "Returns the default value of `false`" } |
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.
Shouldn't it be "Returns the default value ofbool
which is false
?"
Hum, actually I think it's good as is. The wording is lighter. I'll go for this one then. Thanks! @bors: r+ rollup |
📌 Commit caf125f has been approved by |
Document default values for primitive types All primitive types implement the `Default` trait but the documentation just says `Returns the "default value" for a type.` and doesn't give a hint about the actual default value. I think it would be good to document the default values in a proper way. I changed the `default_impl` macro to accept a doc string as a third parameter and use this string to overwrite the documentation of `default()` for each primitive type. The generated documentation now looks like this: ![Documentation of default() on the bool primitive](https://i.imgur.com/nK6TApo.png)
☀️ Test successful - status-appveyor, status-travis |
After rust-lang#43252 is merged, building stage0 libcore with -i (--incremental) flag will cause 17 "Quasi-quoting might make incremental compilation very inefficient: NtExpr(..)" warnings, as in rust-lang#40946. Fixing the warning in rust-lang#40946 will take 12 weeks from now to make into the next stage0, so it is quicker to workaround it in libcore instead.
…n-rustbuild, r=alexcrichton Workaround "Quasi-quoting is inefficient" warning in incremental rustbuild introduced in rust-lang#43252. After rust-lang#43252 is merged, building stage0 libcore with `-i` (`--incremental`) flag will cause 17 "Quasi-quoting might make incremental compilation very inefficient: NtExpr(..)" warnings, as in rust-lang#40946. ``` warning: Quasi-quoting might make incremental compilation very inefficient: NtExpr(..) --> src/libcore/default.rs:133:21 | 133 | #[doc = $doc] | ^^^^ ... 139 | default_impl! { (), (), "Returns the default value of `()`" } | ------------------------------------------------------------- in this macro invocation (× 17) ``` True fix for rust-lang#40946 will take at least 12 weeks from now to make into the next stage0, so it is quicker to workaround it in libcore instead. cc @vbrandl @jseyfried
All primitive types implement the
Default
trait but the documentation just saysReturns the "default value" for a type.
and doesn't give a hint about the actual default value. I think it would be good to document the default values in a proper way.I changed the
default_impl
macro to accept a doc string as a third parameter and use this string to overwrite the documentation ofdefault()
for each primitive type.The generated documentation now looks like this: