diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2020-07-20 12:30:14 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-20 12:30:14 -0700 |
| commit | 241374a93b4fe45daf2783b78415ba9a7928c790 (patch) | |
| tree | 8b5110c1429374fb736b3220659accfb099e8cb6 /src/libcore | |
| parent | 105cd4955425de2613ac2ae6c2d2d1baf17ebd2b (diff) | |
| parent | c3756927478afe8d3a880edc469afd766c2f9e82 (diff) | |
| download | rust-241374a93b4fe45daf2783b78415ba9a7928c790.tar.gz rust-241374a93b4fe45daf2783b78415ba9a7928c790.zip | |
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?
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/ops/range.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs index d86f39c4550..179038d1977 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -39,7 +39,7 @@ use crate::hash::Hash; /// [`Iterator`]: ../iter/trait.IntoIterator.html /// [slicing index]: ../slice/trait.SliceIndex.html #[doc(alias = "..")] -#[derive(Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Copy, Clone, Default, PartialEq, Eq, Hash)] #[stable(feature = "rust1", since = "1.0.0")] pub struct RangeFull; @@ -71,7 +71,7 @@ impl fmt::Debug for RangeFull { /// assert_eq!(arr[1..=3], [ 1,2,3 ]); /// ``` #[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")] pub struct Range<Idx> { /// The lower bound of the range (inclusive). |
