Say for example that we would wish, hypothetically, to make uninitialized
not just deprecated in edition 2021, but that we would like to make it go away entirely. Hitherto there hasn’t been any way for the standard library to make such changes because there can only be one standard library and each edition must use it. Thus, it would not be possible to use #[cfg(..)]
for these means.
@eddyb has raised the interesting idea of having a sort of “edition visibility” with which you may hide things from other editions. The straw syntax is pub(2018)
meaning that this is only visible in edition <= 2018.
For example, you could say:
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub(2018) unsafe fn uninitialized<T>() -> T {
intrinsics::uninit()
}
Another case in which this could be useful is:
pub(2015) macro try { .. }
This would make the try!(..)
go bye bye in Rust 2018.
Of course, if you use a <= 2018 crate, then you can still indirectly reach uninitialized
but the goal here is to make it highly unlikely to be used.
I believe it should also be possible (please do double check my reasoning here because I am somewhat unsure…) to change the type signature of a libstd inherent method by doing something like (we would never actually do this with Vec::new
):
impl<T> Vec<T> {
pub(<=2018) const fn new() -> Vec<T> { .. }
pub(>2018) const fn new() -> (Vec<T>, usize) { .. }
}
However, this is not the likely use case.
@eddyb also floated the idea of having an unstabilization mechanism but said that visibility is a stronger method.
One nice thing about pub(2015)
is that we may be able to do this in an unstable way and never stabilize it if we want to. Thus, it may be a mechanism that only the standard library gets to use and so we could even use this for edition 2018 but delay any bikeshedding for quite a bit of time.
For the bikeshed, @kennytm suggested that the syntax
pub(<= 2015)
could be clearer with respect to intent.
@kennytm also noted that the syntax should try to highlight that it is the visibility of the downstream crate and not the defining (current) crate.