File: by-value-self.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 893,176 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; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (46 lines) | stat: -rw-r--r-- 759 bytes parent folder | download | duplicates (14)
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
// Check that a trait with by-value self is considered dyn-compatible.

//@ build-pass (FIXME(62277): could be check-pass?)
#![allow(dead_code)]
#![allow(trivial_casts)]

trait Bar {
    fn bar(self);
}

trait Baz {
    fn baz(self: Self);
}

trait Quux {
    // Legal because of the where clause:
    fn baz(self: Self) where Self : Sized;
}

fn make_bar<T:Bar>(t: &T) -> &dyn Bar {
    t // legal
}

fn make_bar_explicit<T:Bar>(t: &T) -> &dyn Bar {
    t as &dyn Bar // legal
}

fn make_baz<T:Baz>(t: &T) -> &dyn Baz {
    t // legal
}

fn make_baz_explicit<T:Baz>(t: &T) -> &dyn Baz {
    t as &dyn Baz // legal
}

fn make_quux<T:Quux>(t: &T) -> &dyn Quux {
    t
}

fn make_quux_explicit<T:Quux>(t: &T) -> &dyn Quux {
    t as &dyn Quux
}


fn main() {
}