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

Remove outdated info about impl Trait in parameters and generics in the same function #1495

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

drewtato
Copy link

@drewtato drewtato commented May 1, 2024

When impl Trait in function parameters was added, it was not allowed to specify generics at all when any of the function parameters used impl Trait. That is no longer the case. This restriction was lifted in 1.63.0 by rust-lang/rust#96868, but this instance in the reference was missed. I've removed the outdated sentences.

The original last line:

Therefore, changing the function signature from either one to the other can constitute a breaking change for the callers of a function.

would be correct, but even in the old version, it didn't explain how converting impl Trait to generics could be a breaking change, and I can't think of any way it would've been. It is now, so I've added a short explanation that should be sufficient for understanding.


I have some more thoughts about breaking changes, but I don't think they belong in this part of the reference. I've included them as context for the change, and in case someone wants to incorporate them elsewhere.

These are the situations I know to be breaking changes:

  • A function where a generic parameter is changed to impl Trait, and a caller is specifying generics
  • A function has at least one generic of any kind, an impl Trait parameter is changed to a generic, and a caller is specifying generics

This assumes the trait bound is the same for the generic and its corresponding impl Trait. If a caller isn't specifying generics, any change can be made without causing a break. If a function had no generics and an impl Trait is changed to a generic, this is also fine, since an empty turbofish ::<> seems to be equivalent to complete omission instead of "exactly zero generics". This would only realistically occur in macro expansions. However, I'm unsure if it's intended as part of the language, and I didn't see any mention of it elsewhere in the reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant