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