Skip to content

Commit 1daad87

Browse files
committed
Rollup merge of #27546 - steveklabnik:gh26115, r=brson
Fixes #26115
2 parents 4278b5f + de98a0b commit 1daad87

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/doc/reference.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,29 @@ have an implementation for `Shape`. Multiple supertraits are separated by `+`,
15011501
`trait Circle : Shape + PartialEq { }`. In an implementation of `Circle` for a
15021502
given type `T`, methods can refer to `Shape` methods, since the typechecker
15031503
checks that any type with an implementation of `Circle` also has an
1504-
implementation of `Shape`.
1504+
implementation of `Shape`:
1505+
1506+
```rust
1507+
struct Foo;
1508+
1509+
trait Shape { fn area(&self) -> f64; }
1510+
trait Circle : Shape { fn radius(&self) -> f64; }
1511+
# impl Shape for Foo {
1512+
# fn area(&self) -> f64 {
1513+
# 0.0
1514+
# }
1515+
# }
1516+
impl Circle for Foo {
1517+
fn radius(&self) -> f64 {
1518+
println!("calling area: {}", self.area());
1519+
1520+
0.0
1521+
}
1522+
}
1523+
1524+
let c = Foo;
1525+
c.radius();
1526+
```
15051527

15061528
In type-parameterized functions, methods of the supertrait may be called on
15071529
values of subtrait-bound type parameters. Referring to the previous example of

0 commit comments

Comments
 (0)