| 1 |
struct Point { |
| 2 |
x: f64, |
| 3 |
y: f64, |
| 4 |
// { dg-warning "field is never read" "" { target *-*-* } .-1 } |
| 5 |
} |
| 6 |
|
| 7 |
impl Point { |
| 8 |
fn origin() -> Point { |
| 9 |
Point { x: 0.0, y: 0.0 } |
| 10 |
} |
| 11 |
|
| 12 |
fn new(x: f64, y: f64) -> Point { |
| 13 |
Point { x: x, y: y } |
| 14 |
} |
| 15 |
} |
| 16 |
|
| 17 |
struct Rectangle { |
| 18 |
p1: Point, |
| 19 |
p2: Point, |
| 20 |
} |
| 21 |
|
| 22 |
impl Rectangle { |
| 23 |
fn from(p1: Point, p2: Point) -> Self { |
| 24 |
Self { p1, p2 } |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
fn main() { |
| 29 |
let p1 = Point::origin(); |
| 30 |
let p2 = Point::new(3.0, 4.0); |
| 31 |
let rect = Rectangle::from(p1, p2); |
| 32 |
|
| 33 |
let sum = rect.sum_x(); |
| 34 |
// { dg-warning "unused name" "" { target *-*-* } .-1 } |
| 35 |
} |
| 36 |
|
| 37 |
impl Rectangle { |
| 38 |
fn sum_x(self) -> f64 { |
| 39 |
let p1 = self.p1; |
| 40 |
let p2 = self.p2; |
| 41 |
p1.x + p2.x |
| 42 |
} |
| 43 |
} |