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