Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix example code in impl docs #1360

Merged
merged 2 commits into from
May 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/types/impl-trait.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ The caller must provide a type that satisfies the bounds declared by the anonymo

For example, these two forms are almost equivalent:

```rust,ignore
```rust
trait Trait {}

// generic type parameter
fn foo<T: Trait>(arg: T) {
fn with_generic_type<T: Trait>(arg: T) {
}

// impl Trait in argument position
fn foo(arg: impl Trait) {
fn with_impl_trait(arg: impl Trait) {
}
```

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

The function:

```rust,ignore
```rust
# trait Trait {}
fn foo<T: Trait>() -> T {
// ...
# panic!()
}
```

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

The function:

```rust,ignore
```rust
# trait Trait {}
# impl Trait for () {}
fn foo() -> impl Trait {
// ...
}
```

doesn't allow the caller to determine the return type.
Expand Down