Is it possible to write some edition-aware crate?

I had previously committed an ACP about derive PartialEq/PartialOrd in case Eq/Ord is

pub type True = ();
pub type False = [();0];
#[cfg(if edition >= 2024)] // how to achieve that
type Default = True;
#[cfg(not(if edition >= 2024))] // how to achieve that
type Default = False;
// since Default is False for old code, such line does nothing.
//add type Flag=Default in some traits.
impl<T> ... for ... where ...::Flag:True

IIRC, there's someone who wrote a program that support using different edition syntax(with macro) in one file(with macro support)
But I cannot find that piece of code.

Can I have some edition-aware code?

May I ask what you need such a configuration value for? Because crates are always compiled with the edition specified in their manifest file. So if a crate with a 2021 edition imports your 2018 edition crate as a dependency, your crate will still be built using the 2018 edition. This includes the code generated by macros.

9 Likes

I once wrote an ACP about Ord/PartialOrd.
Currently, impl Ord directly without impl PartialOrd is a logic error. But impl/derive PartialOrd from Ord should be very easy.

It makes sense to automatically generate PartialOrd with Ord impl/derived. But it is a breaking change.

I want to check whether a Default type could be added in Ord trait, which is False in old edition and True in new edition, thus old crate won't use the impl<T:Ord<ImplPartialOrd=True>> PartialOrd for T and thus compatitable, new crate use it automatically thus there's no need to impl PartialOrd and Ord for the same struct.

I assume there are compiler built-ins for detecting the edition, unavailable to normal crates.

Might be worth asking this at internals

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.