aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust/execute/torture/impl_rpit2.rs
blob: f7cbbb668649d3a807f763d8b93efdc00a820c74 (plain)
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
#[lang = "sized"]
trait Sized {}

trait Foo {
    fn id(&self) -> i32;
}

struct Thing(i32);

impl Thing {
    fn double(&self) -> i32 {
        // { dg-warning "associated function is never used: .double." "" { target *-*-* } .-1 }
        self.0 * 2
    }
}

impl Foo for Thing {
    fn id(&self) -> i32 {
        self.0
    }
}

fn make_thing(a: i32) -> impl Foo {
    Thing(a)
}

fn use_foo(f: impl Foo) -> i32 {
    f.id()
}

fn main() -> i32 {
    let value = make_thing(21);
    let id = use_foo(value);

    id - 21
}