Skip to content

Commit a674f85

Browse files
committed
Ranges implement Clone where possible
1 parent dcaeb6a commit a674f85

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/libcore/ops.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ pub trait IndexMut<Index: ?Sized> {
880880
}
881881

882882
/// An unbounded range.
883-
#[derive(Copy, PartialEq, Eq)]
883+
#[derive(Copy, Clone, PartialEq, Eq)]
884884
#[lang="full_range"]
885885
#[unstable = "API still in development"]
886886
pub struct FullRange;
@@ -893,7 +893,7 @@ impl fmt::Show for FullRange {
893893
}
894894

895895
/// A (half-open) range which is bounded at both ends.
896-
#[derive(Copy, PartialEq, Eq)]
896+
#[derive(Copy, Clone, PartialEq, Eq)]
897897
#[lang="range"]
898898
#[unstable = "API still in development"]
899899
pub struct Range<Idx> {
@@ -952,7 +952,7 @@ impl<Idx: fmt::Show> fmt::Show for Range<Idx> {
952952
}
953953

954954
/// A range which is only bounded below.
955-
#[derive(Copy, PartialEq, Eq)]
955+
#[derive(Copy, Clone, PartialEq, Eq)]
956956
#[lang="range_from"]
957957
#[unstable = "API still in development"]
958958
pub struct RangeFrom<Idx> {
@@ -981,7 +981,7 @@ impl<Idx: fmt::Show> fmt::Show for RangeFrom<Idx> {
981981
}
982982

983983
/// A range which is only bounded above.
984-
#[derive(Copy, PartialEq, Eq)]
984+
#[derive(Copy, Clone, PartialEq, Eq)]
985985
#[lang="range_to"]
986986
#[unstable = "API still in development"]
987987
pub struct RangeTo<Idx> {

src/test/run-pass/issue-21384.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn test<T : Clone>(arg: T) -> T {
12+
arg.clone()
13+
}
14+
15+
#[derive(PartialEq)]
16+
struct Test(int);
17+
18+
fn main() {
19+
// Check that ranges implement clone
20+
assert!(test(1..5) == (1..5));
21+
assert!(test(..5) == (..5));
22+
assert!(test(1..) == (1..));
23+
assert!(test(FullRange) == (FullRange));
24+
25+
// Check that ranges can still be used with non-clone limits
26+
assert!((Test(1)..Test(5)) == (Test(1)..Test(5)));
27+
}

0 commit comments

Comments
 (0)