about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-11-05 22:31:44 +0000
committerbors <bors@rust-lang.org>2014-11-05 22:31:44 +0000
commit63c4f22f2bf9f1c070311cdc08c6ceb279434733 (patch)
tree7815bb12ca160450170b49198e111f71f6818f2e /src/libstd
parent5c1fd5f8b7351085765217b198c6d5a8c0026b74 (diff)
parent81c00e66f564ca67c391a5f24f2ad43189245d75 (diff)
downloadrust-63c4f22f2bf9f1c070311cdc08c6ceb279434733.tar.gz
rust-63c4f22f2bf9f1c070311cdc08c6ceb279434733.zip
auto merge of #18486 : nikomatsakis/rust/operator-dispatch, r=pcwalton
This branch cleans up overloaded operator resolution so that it is strictly based on the traits in `ops`, rather than going through the normal method lookup mechanism. It also adds full support for autoderef to overloaded index (whereas before autoderef only worked for non-overloaded index) as well as for the slicing operators.

This is a [breaking-change]: in the past, we were accepting combinations of operands that were not intended to be accepted. For example, it was possible to compare a fixed-length array and a slice, or apply the `!` operator to a `&int`. See the first two commits in this pull-request for examples.

One downside of this change is that comparing fixed-length arrays doesn't always work as smoothly as it did before. Before this, comparisons sometimes worked due to various coercions to slices. I've added impls for `Eq`, `Ord`, etc for fixed-lengths arrays up to and including length 32, but if the array is longer than that you'll need to either newtype the array or convert to slices. Note that this plays better with deriving in any case than the previous scheme.

Fixes #4920.
Fixes #16821.
Fixes #15757.

cc @alexcrichton 
cc @aturon 
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/bitflags.rs4
-rw-r--r--src/libstd/collections/hash/set.rs2
-rw-r--r--src/libstd/time/duration.rs2
3 files changed, 4 insertions, 4 deletions
diff --git a/src/libstd/bitflags.rs b/src/libstd/bitflags.rs
index 97a1f68606f..d8023dd3e4e 100644
--- a/src/libstd/bitflags.rs
+++ b/src/libstd/bitflags.rs
@@ -177,13 +177,13 @@ macro_rules! bitflags {
             /// Returns `true` if there are flags common to both `self` and `other`.
             #[inline]
             pub fn intersects(&self, other: $BitFlags) -> bool {
-                !(self & other).is_empty()
+                !(*self & other).is_empty()
             }
 
             /// Returns `true` all of the flags in `other` are contained within `self`.
             #[inline]
             pub fn contains(&self, other: $BitFlags) -> bool {
-                (self & other) == other
+                (*self & other) == other
             }
 
             /// Inserts the specified flags in-place.
diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs
index b9758e11bc7..688036d22dd 100644
--- a/src/libstd/collections/hash/set.rs
+++ b/src/libstd/collections/hash/set.rs
@@ -792,7 +792,7 @@ mod test_set {
         };
 
         let v = hs.into_iter().collect::<Vec<char>>();
-        assert!(['a', 'b'] == v.as_slice() || ['b', 'a'] == v.as_slice());
+        assert!(['a', 'b'][] == v.as_slice() || ['b', 'a'][] == v.as_slice());
     }
 
     #[test]
diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs
index 102f0028557..c3adae8cff8 100644
--- a/src/libstd/time/duration.rs
+++ b/src/libstd/time/duration.rs
@@ -319,7 +319,7 @@ impl fmt::Show for Duration {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         // technically speaking, negative duration is not valid ISO 8601,
         // but we need to print it anyway.
-        let (abs, sign) = if self.secs < 0 { (-self, "-") } else { (*self, "") };
+        let (abs, sign) = if self.secs < 0 { (-*self, "-") } else { (*self, "") };
 
         let days = abs.secs / SECS_PER_DAY;
         let secs = abs.secs - days * SECS_PER_DAY;