-
Notifications
You must be signed in to change notification settings - Fork 47
Add a policy for inclusion in the prelude #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
joshtriplett
wants to merge
5
commits into
rust-lang:master
Choose a base branch
from
joshtriplett:prelude-policy
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5440911
Add a policy for inclusion in the prelude
joshtriplett e561276
Add information about breaking changes when adding types to the prelude
joshtriplett efac767
Fix typo
joshtriplett dfe0c7b
src/policy/prelude.md: Document other specific kinds of things we can…
joshtriplett ab91546
src/policy/prelude.md: Clarify that these are guidelines, not mandates
joshtriplett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| Policy for inclusion in the prelude | ||
| =================================== | ||
|
|
||
| The Rust standard library provides a "prelude": items that Rust programs can | ||
| use without having to import anything. For instance, the Rust prelude includes | ||
| [`Vec`](https://doc.rust-lang.org/std/vec/struct.Vec.html), so programs can | ||
| write `Vec::with_capacity(4)` without having to first import `Vec` from the | ||
| standard library. | ||
|
|
||
| Each edition of Rust has its own prelude, so that new editions of Rust may add | ||
| items without making those items available to all code in older editions of | ||
| Rust. | ||
|
|
||
| This policy sets out the requirements for what items we add to the prelude, and | ||
| whether we add those items to the prelude for a future edition or to the common | ||
| prelude for all Rust editions. | ||
|
|
||
| When to use editions | ||
| -------------------- | ||
|
|
||
| [Some kinds of additions to the prelude can cause breakage in existing | ||
| code](../breaking-changes/prelude.md), so we must either avoid making such | ||
| changes entirely or check carefully with crater before making them. | ||
|
|
||
| Adding a trait to the prelude can break existing Rust code, by creating name | ||
| resolution ambiguity where none previously existed. While introducing | ||
| resolution ambiguities may be "permitted breakage", doing so is quite | ||
| disruptive, and we want to avoid doing so. Thus, we generally never add a trait | ||
| to the common prelude; we only add traits to the preludes for new editions of | ||
| Rust. | ||
|
|
||
| Likewise, adding a macro to the prelude can break existing code, so we | ||
| generally can't add macros to the common prelude, and can only add macros to | ||
| the preludes for new editions of Rust. | ||
|
|
||
| Finally, in some cases adding a type to the prelude can break existing code. | ||
| The cases in which this arises are narrower, but still require at a minimum | ||
| checking a crater run. | ||
|
|
||
| Adding items other than traits, macros, or types to the prelude will never | ||
| produce conflicts or other compatibility issues with existing code, since we | ||
| allow shadowing and give other sources of names priority over names from the | ||
| prelude. Thus, if we choose to add another kind of item to the prelude, we | ||
| should typically add it to the common prelude for all editions of Rust. | ||
| (Exceptions to this would include names that form part of an edition | ||
| transition, such that the same name resolves to something different in | ||
| different editions.) | ||
|
|
||
| Criteria for including an item | ||
| ------------------------------ | ||
|
|
||
| An item included in the prelude can be used by its unqualified name, by any | ||
| Rust code. Users can look up the item by name, and easily get documentation for | ||
| it. However, in general the name should make sense without any context, such as | ||
| within a diff hunk or code sample. Any name we include in the prelude should be | ||
| one that will not confuse users if they see it unqualified, without anything | ||
| introducing the name. | ||
|
|
||
| In particular, the name should not be something users are likely to | ||
| misunderstand as coming from the local crate or its dependencies. While any | ||
| crate *could* define any name, the names in the prelude should be *unlikely* to | ||
| occur unqualified in another crate. (A conflict with a name typically used | ||
| qualified or in a different context is not a problem; for instance, a common | ||
| method name `Object::name`, commonly called via `expr.name`, does not | ||
| necessarily preclude adding a free function `name` to the prelude.) | ||
|
|
||
| We should only add an item to the prelude if some reasonable number of crates | ||
| are likely to use the item. It need not be an item used by the *majority* of | ||
| crates, but it should be reasonably frequent across the ecosystem. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.