Just had this random idea that I quite like, so let's see what others think!
We have a #![no_std]
attribute to opt-out of std
. Why not introduce a #![no_alloc]
attribute that does the same for alloc
? #![no_alloc]
would imply #![no_std]
, so they wouldn't both need to be declared.
One advantage of this is that extern crate alloc;
would no longer be needed as an opt in to allocator support, in the same way that extern crate std;
is not necessary when using std
. The alloc
prelude could be stabilized, being implicit when #![no_alloc]
is not specified in the same way that use std::prelude::v1::*;
is implicit when #![no_std]
is not present.
This is obviously a breaking change, as it makes allocator support opt-out rather than opt-in. As such, I am proposing this for inclusion in the 2021 edition. It couldn't have been done for the 2018 edition, as extern crate alloc
wasn't stabilized until 1.36. As such, I presume it was never even thought of back then.
I am not particularly familiar with MIR, but I believe that it should be possible to have both existing code and my proposal compile to the same IR, which is what's required for an edition.