Skip to content

Commit f358152

Browse files
committed
improve and add tests
1 parent 5560b8c commit f358152

7 files changed

+91
-8
lines changed

src/test/ui/never-impl-is-reserved.rs renamed to src/test/ui/never-from-impl-is-reserved.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ pub trait MyTrait {}
88
impl MyTrait for MyFoo {}
99
// This will conflict with the first impl if we impl `for<T> T: From<!>`.
1010
impl<T> MyTrait for T where T: From<!> {} //~ ERROR conflicting implementation
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
error[E0601]: `main` function not found in crate `never_impl_is_reserved`
2-
|
3-
= note: consider adding a `main` function to `$DIR/never-impl-is-reserved.rs`
4-
51
error[E0119]: conflicting implementations of trait `MyTrait` for type `MyFoo`:
6-
--> $DIR/never-impl-is-reserved.rs:10:1
2+
--> $DIR/never-from-impl-is-reserved.rs:10:1
73
|
84
LL | impl MyTrait for MyFoo {}
95
| ---------------------- first implementation here
106
LL | // This will conflict with the first impl if we impl `for<T> T: From<!>`.
117
LL | impl<T> MyTrait for T where T: From<!> {}
128
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyFoo`
139

14-
error: aborting due to 2 previous errors
10+
error: aborting due to previous error
1511

16-
Some errors have detailed explanations: E0119, E0601.
17-
For more information about an error, try `rustc --explain E0119`.
12+
For more information about this error, try `rustc --explain E0119`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// compile-fail
2+
3+
// check that reservation impls are accounted for in negative reasoning.
4+
5+
#![feature(rustc_attrs)]
6+
7+
trait MyTrait {}
8+
#[rustc_reservation_impl]
9+
impl MyTrait for () {}
10+
11+
trait OtherTrait {}
12+
impl OtherTrait for () {}
13+
impl<T: MyTrait> OtherTrait for T {}
14+
//~^ ERROR conflicting implementations
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0119]: conflicting implementations of trait `OtherTrait` for type `()`:
2+
--> $DIR/reservation-impl-coherence-conflict.rs:13:1
3+
|
4+
LL | impl OtherTrait for () {}
5+
| ---------------------- first implementation here
6+
LL | impl<T: MyTrait> OtherTrait for T {}
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0119`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// compile-fail
2+
3+
// check that reservation impls can't be used as normal impls in positive reasoning.
4+
5+
#![feature(rustc_attrs)]
6+
7+
trait MyTrait { fn foo(&self); }
8+
#[rustc_reservation_impl]
9+
impl MyTrait for () { fn foo(&self) {} }
10+
11+
fn main() {
12+
<() as MyTrait>::foo(&());
13+
//~^ ERROR the trait bound `(): MyTrait` is not satisfied
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0277]: the trait bound `(): MyTrait` is not satisfied
2+
--> $DIR/reservation-impl-no-use.rs:12:5
3+
|
4+
LL | <() as MyTrait>::foo(&());
5+
| ^^^^^^^^^^^^^^^^^^^^ the trait `MyTrait` is not implemented for `()`
6+
|
7+
= help: the following implementations were found:
8+
<() as MyTrait>
9+
note: required by `MyTrait::foo`
10+
--> $DIR/reservation-impl-no-use.rs:7:17
11+
|
12+
LL | trait MyTrait { fn foo(&self); }
13+
| ^^^^^^^^^^^^^^
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// run-pass
2+
3+
// rpass test for reservation impls. Not 100% required because `From` uses them,
4+
// but still.
5+
6+
#![feature(rustc_attrs)]
7+
8+
use std::mem;
9+
10+
trait MyTrait<S> {
11+
fn foo(&self, s: S) -> usize;
12+
}
13+
14+
#[rustc_reservation_impl]
15+
impl<T> MyTrait<u64> for T {
16+
fn foo(&self, _x: u64) -> usize { 0 }
17+
}
18+
19+
// reservation impls don't create coherence conflicts, even with
20+
// non-chain overlap.
21+
impl<S> MyTrait<S> for u32 {
22+
fn foo(&self, _x: S) -> usize { mem::size_of::<S>() }
23+
}
24+
25+
fn main() {
26+
// ...and the non-reservation impl gets picked.XS
27+
assert_eq!(0u32.foo(0u64), mem::size_of::<u64>());
28+
}

0 commit comments

Comments
 (0)