-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize the code so we can handle multiple supertraits.
- Loading branch information
1 parent
bc9ae36
commit cd50b4e
Showing
10 changed files
with
178 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Test a case of a trait which extends the same supertrait twice, but | ||
// with difference type parameters. Test then that when we don't give | ||
// enough information to pick between these, no selection is made. In | ||
// this particular case, the two choices are i64/u64 -- so when we use | ||
// an integer literal, we wind up falling this literal back to i32. | ||
// See also `run-pass/trait-repeated-supertrait.rs`. | ||
|
||
trait CompareTo<T> { | ||
fn same_as(&self, t: T) -> bool; | ||
} | ||
|
||
trait CompareToInts : CompareTo<i64> + CompareTo<u64> { | ||
} | ||
|
||
impl CompareTo<i64> for i64 { | ||
fn same_as(&self, t: i64) -> bool { *self == t } | ||
} | ||
|
||
impl CompareTo<u64> for i64 { | ||
fn same_as(&self, t: u64) -> bool { *self == (t as i64) } | ||
} | ||
|
||
impl CompareToInts for i64 { } | ||
|
||
fn with_obj(c: &CompareToInts) -> bool { | ||
c.same_as(22) //~ ERROR `CompareTo<i32>` is not implemented | ||
} | ||
|
||
fn with_trait<C:CompareToInts>(c: &C) -> bool { | ||
c.same_as(22) //~ ERROR `CompareTo<i32>` is not implemented | ||
} | ||
|
||
fn with_ufcs1<C:CompareToInts>(c: &C) -> bool { | ||
CompareToInts::same_as(c, 22) //~ ERROR `CompareTo<i32>` is not implemented | ||
} | ||
|
||
fn with_ufcs2<C:CompareToInts>(c: &C) -> bool { | ||
CompareTo::same_as(c, 22) //~ ERROR `CompareTo<i32>` is not implemented | ||
} | ||
|
||
fn main() { | ||
assert_eq!(22_i64.same_as(22), true); //~ ERROR `CompareTo<i32>` is not implemented | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Test a case of a trait which extends the same supertrait twice, but | ||
// with difference type parameters. Test that we can invoke the | ||
// various methods in various ways successfully. | ||
// See also `compile-fail/trait-repeated-supertrait-ambig.rs`. | ||
|
||
trait CompareTo<T> { | ||
fn same_as(&self, t: T) -> bool; | ||
} | ||
|
||
trait CompareToInts : CompareTo<i64> + CompareTo<u64> { | ||
} | ||
|
||
impl CompareTo<i64> for i64 { | ||
fn same_as(&self, t: i64) -> bool { *self == t } | ||
} | ||
|
||
impl CompareTo<u64> for i64 { | ||
fn same_as(&self, t: u64) -> bool { *self == (t as i64) } | ||
} | ||
|
||
impl CompareToInts for i64 { } | ||
|
||
fn with_obj(c: &CompareToInts) -> bool { | ||
c.same_as(22_i64) && c.same_as(22_u64) | ||
} | ||
|
||
fn with_trait<C:CompareToInts>(c: &C) -> bool { | ||
c.same_as(22_i64) && c.same_as(22_u64) | ||
} | ||
|
||
fn with_ufcs1<C:CompareToInts>(c: &C) -> bool { | ||
CompareToInts::same_as(c, 22_i64) && CompareToInts::same_as(c, 22_u64) | ||
} | ||
|
||
fn with_ufcs2<C:CompareToInts>(c: &C) -> bool { | ||
CompareTo::same_as(c, 22_i64) && CompareTo::same_as(c, 22_u64) | ||
} | ||
|
||
fn main() { | ||
assert_eq!(22_i64.same_as(22_i64), true); | ||
assert_eq!(22_i64.same_as(22_u64), true); | ||
assert_eq!(with_trait(&22), true); | ||
assert_eq!(with_obj(&22), true); | ||
assert_eq!(with_ufcs1(&22), true); | ||
assert_eq!(with_ufcs2(&22), true); | ||
} |