2018-08-30 14:18:55 +02:00
|
|
|
// run-pass
|
2012-10-24 18:32:36 +03:00
|
|
|
// Issue #3656
|
2015-01-06 20:54:54 -05:00
|
|
|
// Issue Name: pub method preceded by attribute can't be parsed
|
2012-10-24 18:32:36 +03:00
|
|
|
// Abstract: Visibility parsing failed when compiler parsing
|
|
|
|
|
2013-09-26 02:26:09 -04:00
|
|
|
use std::f64;
|
2013-05-24 19:35:29 -07:00
|
|
|
|
2015-03-30 09:38:27 -04:00
|
|
|
#[derive(Copy, Clone)]
|
2014-09-19 12:30:07 -07:00
|
|
|
pub struct Point {
|
2013-09-26 02:26:09 -04:00
|
|
|
x: f64,
|
|
|
|
y: f64
|
2012-10-24 18:32:36 +03:00
|
|
|
}
|
|
|
|
|
2015-03-30 09:38:27 -04:00
|
|
|
#[derive(Copy, Clone)]
|
2012-10-24 18:32:36 +03:00
|
|
|
pub enum Shape {
|
2013-09-26 02:26:09 -04:00
|
|
|
Circle(Point, f64),
|
2012-10-24 18:32:36 +03:00
|
|
|
Rectangle(Point, Point)
|
|
|
|
}
|
|
|
|
|
2013-05-31 15:17:22 -07:00
|
|
|
impl Shape {
|
2013-09-26 02:26:09 -04:00
|
|
|
pub fn area(&self, sh: Shape) -> f64 {
|
2012-10-24 18:32:36 +03:00
|
|
|
match sh {
|
2014-11-06 00:05:53 -08:00
|
|
|
Shape::Circle(_, size) => f64::consts::PI * size * size,
|
|
|
|
Shape::Rectangle(Point {x, y}, Point {x: x2, y: y2}) => (x2 - x) * (y2 - y)
|
2012-10-24 18:32:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main(){
|
2014-11-06 00:05:53 -08:00
|
|
|
let s = Shape::Circle(Point { x: 1.0, y: 2.0 }, 3.0);
|
2013-09-24 22:16:43 -07:00
|
|
|
println!("{}", s.area(s));
|
2013-02-14 11:47:00 -08:00
|
|
|
}
|