Skip to content

Commit 52788fa

Browse files
committed
Use #[derive(Default)] for std::option::Option
The impl predates the introduction of `#[default]`, but now we *can* derive it, as it doesn't introduce unnecessary `Default` bounds on enum type parameters.
1 parent 303e05e commit 52788fa

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

library/core/src/option.rs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ use crate::{cmp, convert, hint, mem, slice};
564564

565565
/// The `Option` type. See [the module level documentation](self) for more.
566566
#[doc(search_unbox)]
567-
#[derive(Copy, Eq, Debug, Hash)]
567+
#[derive(Copy, Eq, Debug, Hash, Default)]
568568
#[rustc_diagnostic_item = "Option"]
569569
#[lang = "Option"]
570570
#[stable(feature = "rust1", since = "1.0.0")]
@@ -573,6 +573,7 @@ pub enum Option<T> {
573573
/// No value.
574574
#[lang = "None"]
575575
#[stable(feature = "rust1", since = "1.0.0")]
576+
#[default]
576577
None,
577578
/// Some value of type `T`.
578579
#[lang = "Some"]
@@ -2044,22 +2045,6 @@ where
20442045
}
20452046
}
20462047

2047-
#[stable(feature = "rust1", since = "1.0.0")]
2048-
impl<T> Default for Option<T> {
2049-
/// Returns [`None`][Option::None].
2050-
///
2051-
/// # Examples
2052-
///
2053-
/// ```
2054-
/// let opt: Option<u32> = Option::default();
2055-
/// assert!(opt.is_none());
2056-
/// ```
2057-
#[inline]
2058-
fn default() -> Option<T> {
2059-
None
2060-
}
2061-
}
2062-
20632048
#[stable(feature = "rust1", since = "1.0.0")]
20642049
impl<T> IntoIterator for Option<T> {
20652050
type Item = T;

0 commit comments

Comments
 (0)