Skip to content

Commit

Permalink
std: Rename {Eq,Ord} to Partial{Eq,Ord}
Browse files Browse the repository at this point in the history
This is part of the ongoing renaming of the equality traits. See rust-lang#12517 for more
details. All code using Eq/Ord will temporarily need to move to Partial{Eq,Ord}
or the Total{Eq,Ord} traits. The Total traits will soon be renamed to {Eq,Ord}.

cc rust-lang#12517

[breaking-change]
  • Loading branch information
alexcrichton committed May 30, 2014
1 parent f4fa7c8 commit 748bc3c
Show file tree
Hide file tree
Showing 256 changed files with 834 additions and 831 deletions.
2 changes: 1 addition & 1 deletion src/compiletest/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::from_str::FromStr;
use std::fmt;
use regex::Regex;

#[deriving(Clone, Eq)]
#[deriving(Clone, PartialEq)]
pub enum Mode {
CompileFail,
RunFail,
Expand Down
26 changes: 13 additions & 13 deletions src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ trait Circle : Shape { fn radius() -> f64; }
~~~~

the syntax `Circle : Shape` means that types that implement `Circle` must also have an implementation for `Shape`.
Multiple supertraits are separated by `+`, `trait Circle : Shape + Eq { }`.
Multiple supertraits are separated by `+`, `trait Circle : Shape + PartialEq { }`.
In an implementation of `Circle` for a given type `T`, methods can refer to `Shape` methods,
since the typechecker checks that any type with an implementation of `Circle` also has an implementation of `Shape`.

Expand Down Expand Up @@ -2159,23 +2159,23 @@ There are three different types of inline attributes:

The `deriving` attribute allows certain traits to be automatically
implemented for data structures. For example, the following will
create an `impl` for the `Eq` and `Clone` traits for `Foo`, the type
parameter `T` will be given the `Eq` or `Clone` constraints for the
create an `impl` for the `PartialEq` and `Clone` traits for `Foo`, the type
parameter `T` will be given the `PartialEq` or `Clone` constraints for the
appropriate `impl`:

~~~~
#[deriving(Eq, Clone)]
#[deriving(PartialEq, Clone)]
struct Foo<T> {
a: int,
b: T
}
~~~~

The generated `impl` for `Eq` is equivalent to
The generated `impl` for `PartialEq` is equivalent to

~~~~
# struct Foo<T> { a: int, b: T }
impl<T: Eq> Eq for Foo<T> {
impl<T: PartialEq> PartialEq for Foo<T> {
fn eq(&self, other: &Foo<T>) -> bool {
self.a == other.a && self.b == other.b
}
Expand All @@ -2188,7 +2188,7 @@ impl<T: Eq> Eq for Foo<T> {

Supported traits for `deriving` are:

* Comparison traits: `Eq`, `TotalEq`, `Ord`, `TotalOrd`.
* Comparison traits: `PartialEq`, `TotalEq`, `PartialOrd`, `TotalOrd`.
* Serialization: `Encodable`, `Decodable`. These require `serialize`.
* `Clone`, to create `T` from `&T` via a copy.
* `Hash`, to iterate over the bytes in a data type.
Expand Down Expand Up @@ -2734,22 +2734,22 @@ The default meaning of the operators on standard types is given here.

* `==`
: Equal to.
Calls the `eq` method on the `std::cmp::Eq` trait.
Calls the `eq` method on the `std::cmp::PartialEq` trait.
* `!=`
: Unequal to.
Calls the `ne` method on the `std::cmp::Eq` trait.
Calls the `ne` method on the `std::cmp::PartialEq` trait.
* `<`
: Less than.
Calls the `lt` method on the `std::cmp::Ord` trait.
Calls the `lt` method on the `std::cmp::PartialOrd` trait.
* `>`
: Greater than.
Calls the `gt` method on the `std::cmp::Ord` trait.
Calls the `gt` method on the `std::cmp::PartialOrd` trait.
* `<=`
: Less than or equal.
Calls the `le` method on the `std::cmp::Ord` trait.
Calls the `le` method on the `std::cmp::PartialOrd` trait.
* `>=`
: Greater than or equal.
Calls the `ge` method on the `std::cmp::Ord` trait.
Calls the `ge` method on the `std::cmp::PartialOrd` trait.

#### Type cast expressions

Expand Down
30 changes: 15 additions & 15 deletions src/doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ There are two ways to install the Rust compiler: by building from source or
by downloading prebuilt binaries or installers for your platform. The
[install page][rust-install] contains links to download binaries for both
the nightly build and the most current Rust major release. For Windows and
OS X, the install page provides links to native installers.
OS X, the install page provides links to native installers.

> *Note:* Windows users should read the detailed
> [Getting started][wiki-start] notes on the wiki. Even when using
> the binary installer, the Windows build requires a MinGW installation,
> the precise details of which are not discussed here.
For Linux and OS X, the install page provides links to binary tarballs.
To install the Rust compiler from the from a binary tarball, download
the binary package, extract it, and execute the `install.sh` script in
To install the Rust compiler from the from a binary tarball, download
the binary package, extract it, and execute the `install.sh` script in
the root directory of the package.

To build the Rust compiler from source, you will need to obtain the source through
Expand Down Expand Up @@ -1303,15 +1303,15 @@ be specified up-front. Our previous definition of list equality relied on the el
the `==` operator available, and took advantage of the lack of a destructor on `u32` to copy it
without a move of ownership.

We can add a *trait bound* on the `Eq` trait to require that the type implement the `==` operator.
We can add a *trait bound* on the `PartialEq` trait to require that the type implement the `==` operator.
Two more `ref` annotations need to be added to avoid attempting to move out the element types:

~~~
# enum List<T> {
# Cons(T, Box<List<T>>),
# Nil
# }
fn eq<T: Eq>(xs: &List<T>, ys: &List<T>) -> bool {
fn eq<T: PartialEq>(xs: &List<T>, ys: &List<T>) -> bool {
// Match on the next node in both lists.
match (xs, ys) {
// If we have reached the end of both lists, they are equal.
Expand All @@ -1329,8 +1329,8 @@ let ys = Cons('c', box Cons('a', box Cons('t', box Nil)));
assert!(eq(&xs, &ys));
~~~

This would be a good opportunity to implement the `Eq` trait for our list type, making the `==` and
`!=` operators available. We'll need to provide an `impl` for the `Eq` trait and a definition of the
This would be a good opportunity to implement the `PartialEq` trait for our list type, making the `==` and
`!=` operators available. We'll need to provide an `impl` for the `PartialEq` trait and a definition of the
`eq` method. In a method, the `self` parameter refers to an instance of the type we're implementing
on.

Expand All @@ -1339,7 +1339,7 @@ on.
# Cons(T, Box<List<T>>),
# Nil
# }
impl<T: Eq> Eq for List<T> {
impl<T: PartialEq> PartialEq for List<T> {
fn eq(&self, ys: &List<T>) -> bool {
// Match on the next node in both lists.
match (self, ys) {
Expand All @@ -1356,12 +1356,12 @@ impl<T: Eq> Eq for List<T> {
let xs = Cons(5, box Cons(10, box Nil));
let ys = Cons(5, box Cons(10, box Nil));
// The methods below are part of the Eq trait,
// The methods below are part of the PartialEq trait,
// which we implemented on our linked list.
assert!(xs.eq(&ys));
assert!(!xs.ne(&ys));
// The Eq trait also allows us to use the shorthand infix operators.
// The PartialEq trait also allows us to use the shorthand infix operators.
assert!(xs == ys); // `xs == ys` is short for `xs.eq(&ys)`
assert!(!(xs != ys)); // `xs != ys` is short for `xs.ne(&ys)`
~~~
Expand Down Expand Up @@ -2345,12 +2345,12 @@ trait describes types that support an equality operation:
~~~~
// In a trait, `self` refers to the self argument.
// `Self` refers to the type implementing the trait.
trait Eq {
trait PartialEq {
fn equals(&self, other: &Self) -> bool;
}
// In an impl, `self` refers just to the value of the receiver
impl Eq for int {
impl PartialEq for int {
fn equals(&self, other: &int) -> bool { *other == *self }
}
~~~~
Expand Down Expand Up @@ -2600,13 +2600,13 @@ A small number of traits in `std` and `extra` can have implementations
that can be automatically derived. These instances are specified by
placing the `deriving` attribute on a data type declaration. For
example, the following will mean that `Circle` has an implementation
for `Eq` and can be used with the equality operators, and that a value
for `PartialEq` and can be used with the equality operators, and that a value
of type `ABC` can be randomly generated and converted to a string:

~~~
extern crate rand;
#[deriving(Eq)]
#[deriving(PartialEq)]
struct Circle { radius: f64 }
#[deriving(Rand, Show)]
Expand All @@ -2618,7 +2618,7 @@ fn main() {
}
~~~

The full list of derivable traits is `Eq`, `TotalEq`, `Ord`,
The full list of derivable traits is `PartialEq`, `TotalEq`, `Ord`,
`TotalOrd`, `Encodable`, `Decodable`, `Clone`,
`Hash`, `Rand`, `Default`, `Zero`, `FromPrimitive` and `Show`.

Expand Down
8 changes: 5 additions & 3 deletions src/etc/generate-deriving-span-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// This file was auto-generated using 'src/etc/generate-keyword-span-tests.py'
// This file was auto-generated using 'src/etc/generate-deriving-span-tests.py'
#![feature(struct_variant)]
extern crate rand;
Expand Down Expand Up @@ -117,8 +117,10 @@ def write_file(name, string):

for (trait, supers, errs) in [('Rand', [], 1),
('Clone', [], 1),
('Eq', [], 2), ('Ord', [], 8),
('TotalEq', [], 1), ('TotalOrd', ['TotalEq'], 1),
('PartialEq', [], 2),
('PartialOrd', ['PartialEq'], 8),
('TotalEq', ['PartialEq'], 1),
('TotalOrd', ['TotalEq', 'PartialOrd', 'PartialEq'], 1),
('Show', [], 1),
('Hash', [], 1)]:
traits[trait] = (ALL, supers, errs)
Expand Down
6 changes: 3 additions & 3 deletions src/liballoc/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

use core::any::{Any, AnyRefExt};
use core::clone::Clone;
use core::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering};
use core::cmp::{PartialEq, PartialOrd, TotalEq, TotalOrd, Ordering};
use core::default::Default;
use core::fmt;
use core::intrinsics;
Expand Down Expand Up @@ -51,13 +51,13 @@ impl<T: Clone> Clone for Box<T> {
}

// box pointers
impl<T:Eq> Eq for Box<T> {
impl<T:PartialEq> PartialEq for Box<T> {
#[inline]
fn eq(&self, other: &Box<T>) -> bool { *(*self) == *(*other) }
#[inline]
fn ne(&self, other: &Box<T>) -> bool { *(*self) != *(*other) }
}
impl<T:Ord> Ord for Box<T> {
impl<T:PartialOrd> PartialOrd for Box<T> {
#[inline]
fn lt(&self, other: &Box<T>) -> bool { *(*self) < *(*other) }
#[inline]
Expand Down
6 changes: 3 additions & 3 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pointers, and then storing the parent pointers as `Weak` pointers.
use core::mem::transmute;
use core::cell::Cell;
use core::clone::Clone;
use core::cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering};
use core::cmp::{PartialEq, PartialOrd, TotalEq, TotalOrd, Ordering};
use core::kinds::marker;
use core::ops::{Deref, Drop};
use core::option::{Option, Some, None};
Expand Down Expand Up @@ -150,7 +150,7 @@ impl<T> Clone for Rc<T> {
}
}

impl<T: Eq> Eq for Rc<T> {
impl<T: PartialEq> PartialEq for Rc<T> {
#[inline(always)]
fn eq(&self, other: &Rc<T>) -> bool { **self == **other }
#[inline(always)]
Expand All @@ -159,7 +159,7 @@ impl<T: Eq> Eq for Rc<T> {

impl<T: TotalEq> TotalEq for Rc<T> {}

impl<T: Ord> Ord for Rc<T> {
impl<T: PartialOrd> PartialOrd for Rc<T> {
#[inline(always)]
fn lt(&self, other: &Rc<T>) -> bool { **self < **other }

Expand Down
2 changes: 1 addition & 1 deletion src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use std::rt::heap::allocate;
// The way arena uses arrays is really deeply awful. The arrays are
// allocated, and have capacities reserved, but the fill for the array
// will always stay at 0.
#[deriving(Clone, Eq)]
#[deriving(Clone, PartialEq)]
struct Chunk {
data: Rc<RefCell<Vec<u8> >>,
fill: Cell<uint>,
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ impl BitvSet {
}
}

impl cmp::Eq for BitvSet {
impl cmp::PartialEq for BitvSet {
fn eq(&self, other: &BitvSet) -> bool {
if self.size != other.size {
return false;
Expand Down
24 changes: 12 additions & 12 deletions src/libcollections/btree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for BTree<K, V> {
}
}

impl<K: TotalOrd, V: TotalEq> Eq for BTree<K, V> {
impl<K: TotalOrd, V: TotalEq> PartialEq for BTree<K, V> {
fn eq(&self, other: &BTree<K, V>) -> bool {
self.root.cmp(&other.root) == Equal
}
}

impl<K: TotalOrd, V: TotalEq> TotalEq for BTree<K, V> {}

impl<K: TotalOrd, V: TotalEq> Ord for BTree<K, V> {
impl<K: TotalOrd, V: TotalEq> PartialOrd for BTree<K, V> {
fn lt(&self, other: &BTree<K, V>) -> bool {
self.cmp(other) == Less
}
Expand Down Expand Up @@ -198,7 +198,7 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for Node<K, V> {
}
}

impl<K: TotalOrd, V: TotalEq> Eq for Node<K, V> {
impl<K: TotalOrd, V: TotalEq> PartialEq for Node<K, V> {
fn eq(&self, other: &Node<K, V>) -> bool {
match *self{
BranchNode(ref branch) => {
Expand All @@ -222,7 +222,7 @@ impl<K: TotalOrd, V: TotalEq> Eq for Node<K, V> {

impl<K: TotalOrd, V: TotalEq> TotalEq for Node<K, V> {}

impl<K: TotalOrd, V: TotalEq> Ord for Node<K, V> {
impl<K: TotalOrd, V: TotalEq> PartialOrd for Node<K, V> {
fn lt(&self, other: &Node<K, V>) -> bool {
self.cmp(other) == Less
}
Expand Down Expand Up @@ -393,15 +393,15 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for Leaf<K, V> {
}
}

impl<K: TotalOrd, V: TotalEq> Eq for Leaf<K, V> {
impl<K: TotalOrd, V: TotalEq> PartialEq for Leaf<K, V> {
fn eq(&self, other: &Leaf<K, V>) -> bool {
self.elts == other.elts
}
}

impl<K: TotalOrd, V: TotalEq> TotalEq for Leaf<K, V> {}

impl<K: TotalOrd, V: TotalEq> Ord for Leaf<K, V> {
impl<K: TotalOrd, V: TotalEq> PartialOrd for Leaf<K, V> {
fn lt(&self, other: &Leaf<K, V>) -> bool {
self.cmp(other) == Less
}
Expand Down Expand Up @@ -623,15 +623,15 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for Branch<K, V> {
}
}

impl<K: TotalOrd, V: TotalEq> Eq for Branch<K, V> {
impl<K: TotalOrd, V: TotalEq> PartialEq for Branch<K, V> {
fn eq(&self, other: &Branch<K, V>) -> bool {
self.elts == other.elts
}
}

impl<K: TotalOrd, V: TotalEq> TotalEq for Branch<K, V> {}

impl<K: TotalOrd, V: TotalEq> Ord for Branch<K, V> {
impl<K: TotalOrd, V: TotalEq> PartialOrd for Branch<K, V> {
fn lt(&self, other: &Branch<K, V>) -> bool {
self.cmp(other) == Less
}
Expand Down Expand Up @@ -691,15 +691,15 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for LeafElt<K, V> {
}
}

impl<K: TotalOrd, V: TotalEq> Eq for LeafElt<K, V> {
impl<K: TotalOrd, V: TotalEq> PartialEq for LeafElt<K, V> {
fn eq(&self, other: &LeafElt<K, V>) -> bool {
self.key == other.key && self.value == other.value
}
}

impl<K: TotalOrd, V: TotalEq> TotalEq for LeafElt<K, V> {}

impl<K: TotalOrd, V: TotalEq> Ord for LeafElt<K, V> {
impl<K: TotalOrd, V: TotalEq> PartialOrd for LeafElt<K, V> {
fn lt(&self, other: &LeafElt<K, V>) -> bool {
self.cmp(other) == Less
}
Expand Down Expand Up @@ -740,15 +740,15 @@ impl<K: Clone + TotalOrd, V: Clone> Clone for BranchElt<K, V> {
}
}

impl<K: TotalOrd, V: TotalEq> Eq for BranchElt<K, V>{
impl<K: TotalOrd, V: TotalEq> PartialEq for BranchElt<K, V>{
fn eq(&self, other: &BranchElt<K, V>) -> bool {
self.key == other.key && self.value == other.value
}
}

impl<K: TotalOrd, V: TotalEq> TotalEq for BranchElt<K, V>{}

impl<K: TotalOrd, V: TotalEq> Ord for BranchElt<K, V> {
impl<K: TotalOrd, V: TotalEq> PartialOrd for BranchElt<K, V> {
fn lt(&self, other: &BranchElt<K, V>) -> bool {
self.cmp(other) == Less
}
Expand Down
Loading

0 comments on commit 748bc3c

Please sign in to comment.