]> git.lizzy.rs Git - rust.git/blob - tests/ui/span/issue-24895-copy-clone-dropck.rs
Rollup merge of #106441 - mllken:abstract-socket-noref, r=joshtriplett
[rust.git] / tests / ui / span / issue-24895-copy-clone-dropck.rs
1 // Check that one cannot subvert Drop Check rule via a user-defined
2 // Clone implementation.
3
4 #![allow(unused_variables, unused_assignments)]
5
6 struct D<T:Copy>(T, &'static str);
7
8 #[derive(Copy)]
9 struct S<'a>(&'a D<i32>, &'static str);
10 impl<'a> Clone for S<'a> {
11     fn clone(&self) -> S<'a> {
12         println!("cloning `S(_, {})` and thus accessing: {}", self.1, (self.0).0);
13         S(self.0, self.1)
14     }
15 }
16
17 impl<T:Copy> Drop for D<T> {
18     fn drop(&mut self) {
19         println!("calling Drop for {}", self.1);
20         let _call = self.0.clone();
21     }
22 }
23
24 fn main() {
25     let (d2, d1);
26     d1 = D(34, "d1");
27     d2 = D(S(&d1, "inner"), "d2");
28 }
29 //~^^ ERROR `d1` does not live long enough