rust-lang / reference

The Rust Reference
https://doc.rust-lang.org/nightly/reference/
Apache License 2.0
1.16k stars 452 forks source link

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

Open drewtato opened 1 month ago

drewtato commented 1 month ago

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 https://github.com/rust-lang/rust/pull/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:

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.