]> git.lizzy.rs Git - rust.git/blob - src/test/ui/generic-associated-types/issue-68641-check-gat-bounds.rs
Rollup merge of #104024 - noeddl:unused-must-use, r=compiler-errors
[rust.git] / src / test / ui / generic-associated-types / issue-68641-check-gat-bounds.rs
1 // Regression test for #68641
2
3 trait UnsafeCopy {
4     type Item<'a>: Copy;
5
6     fn copy<'a>(item: &Self::Item<'a>) -> Self::Item<'a> {
7         *item
8     }
9 }
10
11 impl<T> UnsafeCopy for T {
12     type Item<'a> = T;
13     //~^ ERROR the trait bound `T: Copy` is not satisfied
14 }
15
16 fn main() {
17     let mut s = String::from("Hello world!");
18
19     let copy = String::copy(&s);
20
21     // Do we indeed point to the samme memory?
22     assert!(s.as_ptr() == copy.as_ptr());
23
24     // Any use of `copy` is certeinly UB after this
25     drop(s);
26
27     // UB UB UB UB UB!!
28     println!("{}", copy);
29 }