mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-18 11:34:11 +00:00
improve and add tests
This commit is contained in:
parent
5d79e8c4c9
commit
9a94ecde04
@ -1,5 +1,5 @@
|
||||
error[E0119]: conflicting implementations of trait `MyTrait` for type `MyFoo`:
|
||||
--> $DIR/never-impl-is-reserved.rs:10:1
|
||||
--> $DIR/never-from-impl-is-reserved.rs:10:1
|
||||
|
|
||||
LL | impl MyTrait for MyFoo {}
|
||||
| ---------------------- first implementation here
|
@ -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() {}
|
@ -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`.
|
@ -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
|
||||
}
|
@ -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
src/test/ui/traits/reservation-impls/reservation-impl-ok.rs
Normal file
28
src/test/ui/traits/reservation-impls/reservation-impl-ok.rs
Normal file
@ -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>());
|
||||
}
|
Loading…
Reference in New Issue
Block a user