mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
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?
This commit is contained in:
commit
241374a93b
@ -39,7 +39,7 @@ use crate::hash::Hash;
|
|||||||
/// [`Iterator`]: ../iter/trait.IntoIterator.html
|
/// [`Iterator`]: ../iter/trait.IntoIterator.html
|
||||||
/// [slicing index]: ../slice/trait.SliceIndex.html
|
/// [slicing index]: ../slice/trait.SliceIndex.html
|
||||||
#[doc(alias = "..")]
|
#[doc(alias = "..")]
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, Default, PartialEq, Eq, Hash)]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct RangeFull;
|
pub struct RangeFull;
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ impl fmt::Debug for RangeFull {
|
|||||||
/// assert_eq!(arr[1..=3], [ 1,2,3 ]);
|
/// assert_eq!(arr[1..=3], [ 1,2,3 ]);
|
||||||
/// ```
|
/// ```
|
||||||
#[doc(alias = "..")]
|
#[doc(alias = "..")]
|
||||||
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
|
#[derive(Clone, Default, PartialEq, Eq, Hash)] // not Copy -- see #27186
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct Range<Idx> {
|
pub struct Range<Idx> {
|
||||||
/// The lower bound of the range (inclusive).
|
/// The lower bound of the range (inclusive).
|
||||||
|
Loading…
Reference in New Issue
Block a user