]> git.lizzy.rs Git - rust.git/blob - tests/ui/kindck/kindck-impl-type-params.rs
Rollup merge of #106733 - DebugSteven:revert-104552-warn-newer-x, r=jyn514
[rust.git] / tests / ui / kindck / kindck-impl-type-params.rs
1 // Issue #14061: tests the interaction between generic implementation
2 // parameter bounds and trait objects.
3
4 use std::marker;
5
6 struct S<T>(marker::PhantomData<T>);
7
8 trait Gettable<T> {
9     fn get(&self) -> T { panic!() }
10 }
11
12 impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}
13
14 fn f<T>(val: T) {
15     let t: S<T> = S(marker::PhantomData);
16     let a = &t as &dyn Gettable<T>;
17     //~^ ERROR `T` cannot be sent between threads safely
18     //~| ERROR : Copy` is not satisfied
19 }
20
21 fn g<T>(val: T) {
22     let t: S<T> = S(marker::PhantomData);
23     let a: &dyn Gettable<T> = &t;
24     //~^ ERROR `T` cannot be sent between threads safely
25     //~| ERROR : Copy` is not satisfied
26 }
27
28 fn foo<'a>() {
29     let t: S<&'a isize> = S(marker::PhantomData);
30     let a = &t as &dyn Gettable<&'a isize>;
31 }
32
33 fn foo2<'a>() {
34     let t: Box<S<String>> = Box::new(S(marker::PhantomData));
35     let a = t as Box<dyn Gettable<String>>;
36     //~^ ERROR : Copy` is not satisfied
37 }
38
39 fn foo3<'a>() {
40     struct Foo; // does not impl Copy
41
42     let t: Box<S<Foo>> = Box::new(S(marker::PhantomData));
43     let a: Box<dyn Gettable<Foo>> = t;
44     //~^ ERROR : Copy` is not satisfied
45 }
46
47 fn main() { }