aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/rust/compile/torture/methods2.rs
blob: d63211bdf8aac4d2aea13c0f459787b1fc3a1479 (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
37
38
39
40
41
42
43
struct Point {
    x: f64,
    y: f64,
// { dg-warning "field is never read" "" { target *-*-* } .-1 }
}

impl Point {
    fn origin() -> Point {
        Point { x: 0.0, y: 0.0 }
    }

    fn new(x: f64, y: f64) -> Point {
        Point { x: x, y: y }
    }
}

struct Rectangle {
    p1: Point,
    p2: Point,
}

impl Rectangle {
    fn from(p1: Point, p2: Point) -> Self {
        Self { p1, p2 }
    }
}

fn main() {
    let p1 = Point::origin();
    let p2 = Point::new(3.0, 4.0);
    let rect = Rectangle::from(p1, p2);

    let sum = rect.sum_x();
    // { dg-warning "unused name" "" { target *-*-* } .-1 }
}

impl Rectangle {
    fn sum_x(self) -> f64 {
        let p1 = self.p1;
        let p2 = self.p2;
        p1.x + p2.x
    }
}