File: borrowck-struct-update-with-dtor.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (64 lines) | stat: -rw-r--r-- 1,362 bytes parent folder | download | duplicates (3)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Issue 4691: Ensure that functional-struct-update can only copy, not
// move, when the struct implements Drop.

struct B;
struct S<K> { a: isize, b: B, c: K }
impl<K> Drop for S<K> { fn drop(&mut self) { } }

struct T { a: isize, b: Box<isize> }
impl Drop for T { fn drop(&mut self) { } }

struct V<K> { a: isize, b: Box<isize>, c: K }
impl<K> Drop for V<K> { fn drop(&mut self) { } }

#[derive(Clone)]
struct Clonable;

mod not_all_clone {
    use super::*;
    fn a(s0: S<()>) {
        let _s2 = S { a: 2, ..s0 };
        //~^ ERROR [E0509]
    }
    fn b(s0: S<B>) {
        let _s2 = S { a: 2, ..s0 };
        //~^ ERROR [E0509]
        //~| ERROR [E0509]
    }
    fn c<K: Clone>(s0: S<K>) {
        let _s2 = S { a: 2, ..s0 };
        //~^ ERROR [E0509]
        //~| ERROR [E0509]
    }
}
mod all_clone {
    use super::*;
    fn a(s0: T) {
        let _s2 = T { a: 2, ..s0 };
        //~^ ERROR [E0509]
    }

    fn b(s0: T) {
        let _s2 = T { ..s0 };
        //~^ ERROR [E0509]
    }

    fn c(s0: T) {
        let _s2 = T { a: 2, b: s0.b };
        //~^ ERROR [E0509]
    }

    fn d<K: Clone>(s0: V<K>) {
        let _s2 = V { a: 2, ..s0 };
        //~^ ERROR [E0509]
        //~| ERROR [E0509]
    }

    fn e(s0: V<Clonable>) {
        let _s2 = V { a: 2, ..s0 };
        //~^ ERROR [E0509]
        //~| ERROR [E0509]
    }
}

fn main() { }