Skip to content

Commit 241374a

Browse files
authored
Rollup merge of #73197 - c410-f3r:ranges, r=dtolnay
Impl Default for ranges Couldn't find an issue about it. `Range` and friends probably can implement `Default` if `Idx: Default`. For example, the following would be possible: ```rust #[derive(Default)] struct Foo(core::ops::RangeToInclusive<u64>); let _ = [1, 2, 3].get(core::ops::Range::default()); core::ops::RangeFrom::<u8>::default().take(20).for_each(|x| { dbg!(x); }); fn stuff<T: Default>() { let instance = T::default(); ... more stuff } stuff::<core::ops::RangeTo<f32>>(); ``` Maybe there are some concerns about safety or misunderstandings?
2 parents 105cd49 + c375692 commit 241374a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Diff for: src/libcore/ops/range.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use crate::hash::Hash;
3939
/// [`Iterator`]: ../iter/trait.IntoIterator.html
4040
/// [slicing index]: ../slice/trait.SliceIndex.html
4141
#[doc(alias = "..")]
42-
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
42+
#[derive(Copy, Clone, Default, PartialEq, Eq, Hash)]
4343
#[stable(feature = "rust1", since = "1.0.0")]
4444
pub struct RangeFull;
4545

@@ -71,7 +71,7 @@ impl fmt::Debug for RangeFull {
7171
/// assert_eq!(arr[1..=3], [ 1,2,3 ]);
7272
/// ```
7373
#[doc(alias = "..")]
74-
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
74+
#[derive(Clone, Default, PartialEq, Eq, Hash)] // not Copy -- see #27186
7575
#[stable(feature = "rust1", since = "1.0.0")]
7676
pub struct Range<Idx> {
7777
/// The lower bound of the range (inclusive).

0 commit comments

Comments
 (0)