> this would rely on the compiler effectively implementing some kind of unbreakable firewall, to prevent a type that does not implement Leak from ever getting used with pre-2024 code
Couldn't this be done just by changing how 2021 code is compiled, such that:
All types impl Leak
All generic type parameters have a Leak constraint added
All trait objects are changed to include "+ Leak"
In other words, treat pre 2024 code as if it was the equivalent code in the presense of the Leak trait, requiring that all types are Leak.
Ariel Ben-Yehuda has sent me an example which shows how much harder it is than that, and which this wouldn't cover. I'm going to write a follow up blog post.
With the solution I imagine, this example wouldn't compile. In the crate bar, edition 2021, the code written as:
fn foo<T>(input: T)
would actually parse as if:
fn foo<T: Leak>(input: T)
An implicit Leak bound would be inserted into AST of every trait bound in the 2021 edition. Then all code from all editions would be interpreted the same.
This way, the 2021 code wouldn't compile, because the 2024 trait requires `<T>` bound, and the 2021 code can only express `<T: Leak>` and nothing less.
2021 code could not work at all with any 2024 code that allows !Leak. libstd would have to add `+ Leak` to all existing APIs. Upgrading to 2024 edition would need a migration to change the bounds.
With what I described, bar would not compile, because the compiler would add a "+ Leak" bound to T.
The unfortunate part is that means that upgrading foo to the 2024 edition means you either have to break backwards compatibility (at least for 2021 code) or add Leak bounds to type parameters and trait objects. There could be a cargo fix rule to do that update for you.
It is really unfortunate that existing APIs can't be made more general without breaking compatibility though.
Couldn't this be done just by changing how 2021 code is compiled, such that:
All types impl Leak
All generic type parameters have a Leak constraint added
All trait objects are changed to include "+ Leak"
In other words, treat pre 2024 code as if it was the equivalent code in the presense of the Leak trait, requiring that all types are Leak.