Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/test/ui/never-impl-is-reserved.stderr → ...est/ui/never-from-impl-is-reserved.stderr
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
16 changes: 16 additions & 0 deletions
16
src/test/ui/traits/reservation-impls/reservation-impl-coherence-conflict.rs
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,16 @@ | ||
// compile-fail | ||
|
||
// check that reservation impls are accounted for in negative reasoning. | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
trait MyTrait {} | ||
#[rustc_reservation_impl] | ||
impl MyTrait for () {} | ||
|
||
trait OtherTrait {} | ||
impl OtherTrait for () {} | ||
impl<T: MyTrait> OtherTrait for T {} | ||
//~^ ERROR conflicting implementations | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
src/test/ui/traits/reservation-impls/reservation-impl-coherence-conflict.stderr
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,11 @@ | ||
error[E0119]: conflicting implementations of trait `OtherTrait` for type `()`: | ||
--> $DIR/reservation-impl-coherence-conflict.rs:13:1 | ||
| | ||
LL | impl OtherTrait for () {} | ||
| ---------------------- first implementation here | ||
LL | impl<T: MyTrait> OtherTrait for T {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0119`. |
14 changes: 14 additions & 0 deletions
14
src/test/ui/traits/reservation-impls/reservation-impl-no-use.rs
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,14 @@ | ||
// compile-fail | ||
|
||
// check that reservation impls can't be used as normal impls in positive reasoning. | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
trait MyTrait { fn foo(&self); } | ||
#[rustc_reservation_impl] | ||
impl MyTrait for () { fn foo(&self) {} } | ||
|
||
fn main() { | ||
<() as MyTrait>::foo(&()); | ||
//~^ ERROR the trait bound `(): MyTrait` is not satisfied | ||
} |
15 changes: 15 additions & 0 deletions
15
src/test/ui/traits/reservation-impls/reservation-impl-no-use.stderr
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,15 @@ | ||
error[E0277]: the trait bound `(): MyTrait` is not satisfied | ||
--> $DIR/reservation-impl-no-use.rs:12:5 | ||
| | ||
LL | trait MyTrait { fn foo(&self); } | ||
| -------------- required by `MyTrait::foo` | ||
... | ||
LL | <() as MyTrait>::foo(&()); | ||
| ^^^^^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `()` | ||
| | ||
= help: the following implementations were found: | ||
<() as MyTrait> | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
28 changes: 28 additions & 0 deletions
28
src/test/ui/traits/reservation-impls/reservation-impl-ok.rs
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,28 @@ | ||
// run-pass | ||
|
||
// rpass test for reservation impls. Not 100% required because `From` uses them, | ||
// but still. | ||
|
||
#![feature(rustc_attrs)] | ||
|
||
use std::mem; | ||
|
||
trait MyTrait<S> { | ||
fn foo(&self, s: S) -> usize; | ||
} | ||
|
||
#[rustc_reservation_impl] | ||
impl<T> MyTrait<u64> for T { | ||
fn foo(&self, _x: u64) -> usize { 0 } | ||
} | ||
|
||
// reservation impls don't create coherence conflicts, even with | ||
// non-chain overlap. | ||
impl<S> MyTrait<S> for u32 { | ||
fn foo(&self, _x: S) -> usize { mem::size_of::<S>() } | ||
} | ||
|
||
fn main() { | ||
// ...and the non-reservation impl gets picked.XS | ||
assert_eq!(0u32.foo(0u64), mem::size_of::<u64>()); | ||
} |