Skip to content

Commit a948815

Browse files
authored
Auto merge of #34180 - durka:patch-24, r=brson
derive Hash (and not Copy) for ranges Fixes #34170. Also, `RangeInclusive` was `Copy` by mistake -- fix that, which is a [breaking-change] to that unstable type.
2 parents c5f3706 + df924ca commit a948815

8 files changed

+212
-6
lines changed

src/libcore/ops.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
14751475
/// assert_eq!(arr[1..3], [ 1,2 ]);
14761476
/// }
14771477
/// ```
1478-
#[derive(Copy, Clone, PartialEq, Eq)]
1478+
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
14791479
#[stable(feature = "rust1", since = "1.0.0")]
14801480
pub struct RangeFull;
14811481

@@ -1506,7 +1506,7 @@ impl fmt::Debug for RangeFull {
15061506
/// assert_eq!(arr[1..3], [ 1,2 ]); // Range
15071507
/// }
15081508
/// ```
1509-
#[derive(Clone, PartialEq, Eq)]
1509+
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
15101510
#[stable(feature = "rust1", since = "1.0.0")]
15111511
pub struct Range<Idx> {
15121512
/// The lower bound of the range (inclusive).
@@ -1570,7 +1570,7 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
15701570
/// assert_eq!(arr[1..3], [ 1,2 ]);
15711571
/// }
15721572
/// ```
1573-
#[derive(Clone, PartialEq, Eq)]
1573+
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
15741574
#[stable(feature = "rust1", since = "1.0.0")]
15751575
pub struct RangeFrom<Idx> {
15761576
/// The lower bound of the range (inclusive).
@@ -1619,7 +1619,7 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
16191619
/// assert_eq!(arr[1..3], [ 1,2 ]);
16201620
/// }
16211621
/// ```
1622-
#[derive(Copy, Clone, PartialEq, Eq)]
1622+
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
16231623
#[stable(feature = "rust1", since = "1.0.0")]
16241624
pub struct RangeTo<Idx> {
16251625
/// The upper bound of the range (exclusive).
@@ -1669,7 +1669,7 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
16691669
/// assert_eq!(arr[1...2], [ 1,2 ]); // RangeInclusive
16701670
/// }
16711671
/// ```
1672-
#[derive(Copy, Clone, PartialEq, Eq)]
1672+
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
16731673
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
16741674
pub enum RangeInclusive<Idx> {
16751675
/// Empty range (iteration has finished)
@@ -1774,7 +1774,7 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
17741774
/// assert_eq!(arr[1...2], [ 1,2 ]);
17751775
/// }
17761776
/// ```
1777-
#[derive(Copy, Clone, PartialEq, Eq)]
1777+
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
17781778
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
17791779
pub struct RangeToInclusive<Idx> {
17801780
/// The upper bound of the range (inclusive)
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// Copyright 2016 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+
#![feature(inclusive_range)]
12+
13+
use std::ops::*;
14+
15+
// FIXME #34229 duplicated errors
16+
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
17+
struct AllTheRanges {
18+
a: Range<usize>,
19+
//~^ ERROR PartialOrd
20+
//~^^ ERROR PartialOrd
21+
//~^^^ ERROR Ord
22+
//~^^^^ ERROR binary operation
23+
//~^^^^^ ERROR binary operation
24+
//~^^^^^^ ERROR binary operation
25+
//~^^^^^^^ ERROR binary operation
26+
//~^^^^^^^^ ERROR binary operation
27+
//~^^^^^^^^^ ERROR binary operation
28+
//~^^^^^^^^^^ ERROR binary operation
29+
//~^^^^^^^^^^^ ERROR binary operation
30+
b: RangeTo<usize>,
31+
//~^ ERROR PartialOrd
32+
//~^^ ERROR PartialOrd
33+
//~^^^ ERROR Ord
34+
//~^^^^ ERROR binary operation
35+
//~^^^^^ ERROR binary operation
36+
//~^^^^^^ ERROR binary operation
37+
//~^^^^^^^ ERROR binary operation
38+
//~^^^^^^^^ ERROR binary operation
39+
//~^^^^^^^^^ ERROR binary operation
40+
//~^^^^^^^^^^ ERROR binary operation
41+
//~^^^^^^^^^^^ ERROR binary operation
42+
c: RangeFrom<usize>,
43+
//~^ ERROR PartialOrd
44+
//~^^ ERROR PartialOrd
45+
//~^^^ ERROR Ord
46+
//~^^^^ ERROR binary operation
47+
//~^^^^^ ERROR binary operation
48+
//~^^^^^^ ERROR binary operation
49+
//~^^^^^^^ ERROR binary operation
50+
//~^^^^^^^^ ERROR binary operation
51+
//~^^^^^^^^^ ERROR binary operation
52+
//~^^^^^^^^^^ ERROR binary operation
53+
//~^^^^^^^^^^^ ERROR binary operation
54+
d: RangeFull,
55+
//~^ ERROR PartialOrd
56+
//~^^ ERROR PartialOrd
57+
//~^^^ ERROR Ord
58+
//~^^^^ ERROR binary operation
59+
//~^^^^^ ERROR binary operation
60+
//~^^^^^^ ERROR binary operation
61+
//~^^^^^^^ ERROR binary operation
62+
//~^^^^^^^^ ERROR binary operation
63+
//~^^^^^^^^^ ERROR binary operation
64+
//~^^^^^^^^^^ ERROR binary operation
65+
//~^^^^^^^^^^^ ERROR binary operation
66+
e: RangeInclusive<usize>,
67+
//~^ ERROR PartialOrd
68+
//~^^ ERROR PartialOrd
69+
//~^^^ ERROR Ord
70+
//~^^^^ ERROR binary operation
71+
//~^^^^^ ERROR binary operation
72+
//~^^^^^^ ERROR binary operation
73+
//~^^^^^^^ ERROR binary operation
74+
//~^^^^^^^^ ERROR binary operation
75+
//~^^^^^^^^^ ERROR binary operation
76+
//~^^^^^^^^^^ ERROR binary operation
77+
//~^^^^^^^^^^^ ERROR binary operation
78+
f: RangeToInclusive<usize>,
79+
//~^ ERROR PartialOrd
80+
//~^^ ERROR PartialOrd
81+
//~^^^ ERROR Ord
82+
//~^^^^ ERROR binary operation
83+
//~^^^^^ ERROR binary operation
84+
//~^^^^^^ ERROR binary operation
85+
//~^^^^^^^ ERROR binary operation
86+
//~^^^^^^^^ ERROR binary operation
87+
//~^^^^^^^^^ ERROR binary operation
88+
//~^^^^^^^^^^ ERROR binary operation
89+
//~^^^^^^^^^^^ ERROR binary operation
90+
}
91+
92+
fn main() {}
93+
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 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+
use std::ops::*;
12+
13+
#[derive(Copy, Clone)] //~ ERROR Copy
14+
struct R(Range<usize>);
15+
16+
fn main() {}
17+
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 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+
use std::ops::*;
12+
13+
#[derive(Copy, Clone)] //~ ERROR Copy
14+
struct R(RangeFrom<usize>);
15+
16+
fn main() {}
17+
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 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+
#![feature(rustc_attrs)]
12+
13+
use std::ops::*;
14+
15+
#[derive(Copy, Clone)]
16+
struct R(RangeTo<usize>);
17+
18+
#[rustc_error]
19+
fn main() {} //~ ERROR success
20+
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 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+
#![feature(rustc_attrs)]
12+
13+
use std::ops::*;
14+
15+
#[derive(Copy, Clone)]
16+
struct R(RangeFull);
17+
18+
#[rustc_error]
19+
fn main() {} //~ ERROR success
20+
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 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+
#![feature(inclusive_range)]
12+
13+
use std::ops::*;
14+
15+
#[derive(Copy, Clone)] //~ ERROR Copy
16+
struct R(RangeInclusive<usize>);
17+
18+
fn main() {}
19+
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 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+
#![feature(rustc_attrs, inclusive_range)]
12+
13+
use std::ops::*;
14+
15+
#[derive(Copy, Clone)]
16+
struct R(RangeToInclusive<usize>);
17+
18+
#[rustc_error]
19+
fn main() {} //~ ERROR success
20+

0 commit comments

Comments
 (0)