Skip to content

Commit ff2f745

Browse files
committed
Rollup merge of #29873 - steveklabnik:gh29493, r=nikomatsakis
Fixes #29493
2 parents 98b18f5 + 9e25a1c commit ff2f745

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/doc/trpl/ufcs.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,28 @@ Here’s an example of using the longer form.
109109

110110
```rust
111111
trait Foo {
112-
fn clone(&self);
112+
fn foo() -> i32;
113113
}
114114

115-
#[derive(Clone)]
116115
struct Bar;
117116

118-
impl Foo for Bar {
119-
fn clone(&self) {
120-
println!("Making a clone of Bar");
117+
impl Bar {
118+
fn foo() -> i32 {
119+
20
120+
}
121+
}
121122

122-
<Bar as Clone>::clone(self);
123+
impl Foo for Bar {
124+
fn foo() -> i32 {
125+
10
123126
}
124127
}
128+
129+
fn main() {
130+
assert_eq!(10, <Bar as Foo>::foo());
131+
assert_eq!(20, Bar::foo());
132+
}
125133
```
126134

127-
This will call the `Clone` trait’s `clone()` method, rather than `Foo`’s.
135+
Using the angle bracket syntax lets you call the trait method instead of the
136+
inherent one.

0 commit comments

Comments
 (0)