Description
Proposal
Summary and problem statement
To give libs more flexibility, we should allow different preludes per edition.
Motivation, use-cases, and solution sketches
Due to nuances of trait resolution, adding a trait to the prelude is a (technically allowed) breaking change. To help avoid heavy impact, however, it would be nice to be able to make those changes opt-in. The edition mechanism seems like a reasonable place to do this: it means that new code (using cargo new
, which defaults to the new edition) will get the new traits in its prelude, but old code using traits that conflict won't be immediately broken.
The basic change here is easy: instead of putting use std::prelude::v1::*;
in every module, put use std::prelude::v2018::*;
(or analogously for other editions). Giving edition warnings and structured fixes would be much harder, I suspect.
EDIT: petrochenkov points out that preludes for macros may also be hairy.
Out of scope
I would like to leave what, if anything, would change in such a prelude out of scope from this conversation. We can start with all of them being the same as the (could then be deprecated) v1
module. And lang and/or libs can then consider individual changes in a future edition (or existing ones) as separate changes.
Prioritization
This fits decently under "Targeted ergonomic wins and extensions". Having TryInto
available in the prelude, for example, would help the compiler give error messages on conversions mentioning that without the confusion of the suggestion not working until an additional trait is use
d.
Links and related work
Initial people involved
What happens now?
This issue is part of the experimental MCP process described in RFC 2936. Once this issue is filed, a Zulip topic will be opened for discussion, and the lang-team will review open MCPs in its weekly triage meetings. You should receive feedback within a week or two.
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.