Skip to content

Commit 4e2494e

Browse files
committedMay 22, 2023
Merge pull request #1360 from eegli/patch-1
Fix example code in `impl` docs
2 parents e2f733d + cfe7e66 commit 4e2494e

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed
 

‎src/types/impl-trait.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ The caller must provide a type that satisfies the bounds declared by the anonymo
3131

3232
For example, these two forms are almost equivalent:
3333

34-
```rust,ignore
34+
```rust
3535
trait Trait {}
3636

3737
// generic type parameter
38-
fn foo<T: Trait>(arg: T) {
38+
fn with_generic_type<T: Trait>(arg: T) {
3939
}
4040

4141
// impl Trait in argument position
42-
fn foo(arg: impl Trait) {
42+
fn with_impl_trait(arg: impl Trait) {
4343
}
4444
```
4545

@@ -96,16 +96,24 @@ With `impl Trait`, unlike with a generic type parameter, the function chooses th
9696

9797
The function:
9898

99-
```rust,ignore
99+
```rust
100+
# trait Trait {}
100101
fn foo<T: Trait>() -> T {
102+
// ...
103+
# panic!()
104+
}
101105
```
102106

103107
allows the caller to determine the return type, `T`, and the function returns that type.
104108

105109
The function:
106110

107-
```rust,ignore
111+
```rust
112+
# trait Trait {}
113+
# impl Trait for () {}
108114
fn foo() -> impl Trait {
115+
// ...
116+
}
109117
```
110118

111119
doesn't allow the caller to determine the return type.

0 commit comments

Comments
 (0)
Please sign in to comment.