# Utilizing the versioned prelude

**URL:** <https://internals.rust-lang.org/t/utilizing-the-versioned-prelude/10682>\
**Category:** language design\
**Created:** [August 9, 2019, 3:20pm UTC](https://internals.rust-lang.org/t/utilizing-the-versioned-prelude/10682 "2019-08-09T15:20:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)\
**Post date:** [August 9, 2019, 3:20pm UTC](https://internals.rust-lang.org/t/utilizing-the-versioned-prelude/10682/1 "2019-08-09T15:20:53Z")

</div>

Add a new key to `Cargo.toml`, `package.prelude` (optionally, `lib.prelude` and `bin.prelude`, but matching `edition` and only setting in one place makes sense). The default value when unset is `v1`, which retains today's prelude import of `::[std|core]::prelude::v1::*`. It can be set to "any" other identifier string, which will make the prelude instead be `::[std|core]::prelude::{package.prelude}::*`.

Alternatively, make `package.prelude` an array of anchored paths (the default being `["::[std|core]::prelude::v1"]`), all of which are imported as prelude for the package. This would give full custom prelude powers.

Implementation: `rustc` grows a new flag to pass the used prelude path(s), rather than always using `::[std|core]::prelude::v1`. Some magic identifier is used to select `std`/`core`.

* * *

Tying the prelude to the edition would also make sense, but if we were going to do that then it should probably have been done when the 2018 edition was published. We could still make `std::prelude::e2015`/`e2018` aliases for `v1` and add `e2021` if we wanted to tie default prelude to the edition with this scheme, however.

---

<div class="post-metadata">

**Author:** ![Centril](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/centril/32/3334_2.png) [@Centril](https://internals.rust-lang.org/u/Centril)\
**Post date:** [August 9, 2019, 3:40pm UTC](https://internals.rust-lang.org/t/utilizing-the-versioned-prelude/10682/2 "2019-08-09T15:40:22Z")

</div>

> [@CAD97](#):
>
> Implementation: `rustc` grows a new flag to pass the used prelude path(s), rather than always using `::[std|core]::prelude::v1` . Some magic identifier is used to select `std` / `core` .

I'm not a fan of having these things as flags / cargo rather than in code; that seems less self-contained.

If we want to pursue user defined preludes then @aturon's RFC [https://github.com/rust-lang/rfcs/pull/890](https://github.com/rust-lang/rfcs/pull/890) seems like the better option.

> [@CAD97](#):
>
> Tying the prelude to the edition would also make sense, but if we were going to do that then it should probably have been done when the 2018 edition was published.

Where there's a need, I think we should try extending the `v1` prelude using crater data. I think it's pretty premature to talk about splitting the prelude into more versions when we don't even have a proposal for adding things to that prelude nor have we checked what parts of that proposal can be done in `v1`. Once we know what things cannot go into `v1` let's then make a list for Edition.Next's prelude.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [November 7, 2019, 3:52pm UTC](https://internals.rust-lang.org/t/utilizing-the-versioned-prelude/10682/3 "2019-11-07T15:52:27Z")

</div>

Closed on November 7, 2019, 3:52pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
