diff options
| author | bors <bors@rust-lang.org> | 2017-07-16 10:22:00 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-07-16 10:22:00 +0000 |
| commit | be18613281e590fdb16f40b10c871abfd4bc9653 (patch) | |
| tree | e362ba3dd9226e00d6be0e4fede5490e564467d2 | |
| parent | 086eaa78ea70075abe4e6b7fb9dc76259867b4be (diff) | |
| parent | caf125f414cc7bcdacdbfeab5c3b62eba772c8a3 (diff) | |
| download | rust-be18613281e590fdb16f40b10c871abfd4bc9653.tar.gz rust-be18613281e590fdb16f40b10c871abfd4bc9653.zip | |
Auto merge of #43252 - vbrandl:doc/default-values, r=GuillaumeGomez
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: 
| -rw-r--r-- | src/libcore/default.rs | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/libcore/default.rs b/src/libcore/default.rs index 0d7c1672fbc..244df1a9966 100644 --- a/src/libcore/default.rs +++ b/src/libcore/default.rs @@ -126,32 +126,33 @@ pub trait Default: Sized { } macro_rules! default_impl { - ($t:ty, $v:expr) => { + ($t:ty, $v:expr, $doc:expr) => { #[stable(feature = "rust1", since = "1.0.0")] impl Default for $t { #[inline] + #[doc = $doc] fn default() -> $t { $v } } } } -default_impl! { (), () } -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`" } +default_impl! { char, '\x00', "Returns the default value of `\\x00`" } -default_impl! { usize, 0 } -default_impl! { u8, 0 } -default_impl! { u16, 0 } -default_impl! { u32, 0 } -default_impl! { u64, 0 } -default_impl! { u128, 0 } +default_impl! { usize, 0, "Returns the default value of `0`" } +default_impl! { u8, 0, "Returns the default value of `0`" } +default_impl! { u16, 0, "Returns the default value of `0`" } +default_impl! { u32, 0, "Returns the default value of `0`" } +default_impl! { u64, 0, "Returns the default value of `0`" } +default_impl! { u128, 0, "Returns the default value of `0`" } -default_impl! { isize, 0 } -default_impl! { i8, 0 } -default_impl! { i16, 0 } -default_impl! { i32, 0 } -default_impl! { i64, 0 } -default_impl! { i128, 0 } +default_impl! { isize, 0, "Returns the default value of `0`" } +default_impl! { i8, 0, "Returns the default value of `0`" } +default_impl! { i16, 0, "Returns the default value of `0`" } +default_impl! { i32, 0, "Returns the default value of `0`" } +default_impl! { i64, 0, "Returns the default value of `0`" } +default_impl! { i128, 0, "Returns the default value of `0`" } -default_impl! { f32, 0.0f32 } -default_impl! { f64, 0.0f64 } +default_impl! { f32, 0.0f32, "Returns the default value of `0.0`" } +default_impl! { f64, 0.0f64, "Returns the default value of `0.0`" } |
