@@ -2054,9 +2054,9 @@ name and a double colon. The compiler uses type inference to decide which
2054
2054
implementation to use.
2055
2055
2056
2056
~~~~
2057
- trait Shape { fn new(area: float) -> Self; }
2058
2057
# use core::float::consts::pi;
2059
2058
# use core::float::sqrt;
2059
+ trait Shape { fn new(area: float) -> Self; }
2060
2060
struct Circle { radius: float }
2061
2061
struct Square { length: float }
2062
2062
@@ -2211,11 +2211,11 @@ trait Circle : Shape { fn radius(&self) -> float; }
2211
2211
Now, we can implement ` Circle ` on a type only if we also implement ` Shape ` .
2212
2212
2213
2213
~~~~
2214
+ # use core::float::consts::pi;
2215
+ # use core::float::sqrt;
2214
2216
# trait Shape { fn area(&self) -> float; }
2215
2217
# trait Circle : Shape { fn radius(&self) -> float; }
2216
2218
# struct Point { x: float, y: float }
2217
- # use core::float::consts::pi;
2218
- # use core::float::sqrt;
2219
2219
# fn square(x: float) -> float { x * x }
2220
2220
struct CircleStruct { center: Point, radius: float }
2221
2221
impl Circle for CircleStruct {
@@ -2247,10 +2247,10 @@ fn radius_times_area<T: Circle>(c: T) -> float {
2247
2247
Likewise, supertrait methods may also be called on trait objects.
2248
2248
2249
2249
~~~ {.xfail-test}
2250
- # trait Shape { fn area(&self) -> float; }
2251
- # trait Circle : Shape { fn radius(&self) -> float; }
2252
2250
# use core::float::consts::pi;
2253
2251
# use core::float::sqrt;
2252
+ # trait Shape { fn area(&self) -> float; }
2253
+ # trait Circle : Shape { fn radius(&self) -> float; }
2254
2254
# struct Point { x: float, y: float }
2255
2255
# struct CircleStruct { center: Point, radius: float }
2256
2256
# impl Circle for CircleStruct { fn radius(&self) -> float { sqrt(self.area() / pi) } }
0 commit comments