Skip to content

Update E0562 to account for the new impl trait positions #144816

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

Merged
merged 1 commit into from
Aug 4, 2025
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
9 changes: 4 additions & 5 deletions compiler/rustc_error_codes/src/error_codes/E0562.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Abstract return types (written `impl Trait` for some trait `Trait`) are only
allowed as function and inherent impl return types.
`impl Trait` is only allowed as a function return and argument type.

Erroneous code example:

Expand All @@ -14,7 +13,7 @@ fn main() {
}
```

Make sure `impl Trait` only appears in return-type position.
Make sure `impl Trait` appears in a function signature.

```
fn count_to_n(n: usize) -> impl Iterator<Item=usize> {
Expand All @@ -28,6 +27,6 @@ fn main() {
}
```

See [RFC 1522] for more details.
See the [reference] for more details on `impl Trait`.

[RFC 1522]: https://github.com/rust-lang/rfcs/blob/master/text/1522-conservative-impl-trait.md
[reference]: https://doc.rust-lang.org/stable/reference/types/impl-trait.html
Loading