summaryrefslogtreecommitdiffstats
path: root/tests/ui/traits/reservation-impl/ok.rs
blob: 8ff6645a2b3d38d3398470c80cf9bd4ef2d5edb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// run-pass

// rpass test for reservation impls. Not 100% required because `From` uses them,
// but still.

// revisions: old next
//[next] compile-flags: -Ztrait-solver=next

#![feature(rustc_attrs)]

use std::mem;

trait MyTrait<S> {
    fn foo(&self, s: S) -> usize;
}

#[rustc_reservation_impl = "foo"]
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>());
}