Skip to content

Commit f133ecc

Browse files
committed
Remove Ordering from the prelude.
1 parent 06c2250 commit f133ecc

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
- Start Date: 2014-12-05
2+
- RFC PR: (leave this empty)
3+
- Rust Issue: (leave this empty)
4+
5+
# Summary
6+
7+
Currently, `Ordering` and its variants are exported in the prelude. We should not
8+
do that any more.
9+
10+
# Motivation
11+
12+
In the past, enums were not namespaced. To use each variant, they must also be
13+
`use`d.
14+
15+
`Ordering` and its variants were in the prelude before my time, and so I'm not 100% sure
16+
why they're in the prelude. I would imagine, like most things, it comes down to
17+
convenience: importing four things to `match` on `==` is kind of a hassle.
18+
19+
The prelude adds names to every Rust program, and so the standard for being in
20+
the prelude is currently 'clearly useful in every Rust program.' However,
21+
`match`ing on an `Ordering` is not particularly common:
22+
23+
```bash
24+
$ git grep --name-only Greater src
25+
src/doc/guide.md
26+
src/doc/reference.md
27+
src/etc/unicode.py
28+
src/etc/vim/syntax/rust.vim
29+
src/liballoc/rc.rs
30+
src/libcollections/bit.rs
31+
src/libcollections/btree/node.rs
32+
src/libcollections/btree/set.rs
33+
src/libcollections/slice.rs
34+
src/libcollections/str.rs
35+
src/libcollections/tree/map.rs
36+
src/libcollections/tree/set.rs
37+
src/libcollections/trie/set.rs
38+
src/libcore/cmp.rs
39+
src/libcore/iter.rs
40+
src/libcore/prelude.rs
41+
src/libcore/ptr.rs
42+
src/libcore/slice.rs
43+
src/libcore/str.rs
44+
src/libcoretest/cmp.rs
45+
src/libcoretest/tuple.rs
46+
src/libregex/vm.rs
47+
src/librustc/middle/typeck/infer/region_inference/mod.rs
48+
src/librustc_trans/trans/_match.rs
49+
src/librustdoc/html/render.rs
50+
src/libstd/prelude.rs
51+
src/libtest/stats.rs
52+
src/libunicode/normalize.rs
53+
src/libunicode/tables.rs
54+
src/test/bench/shootout-k-nucleotide-pipes.rs
55+
src/test/run-pass/bool.rs
56+
src/test/run-pass/deriving-self-lifetime-totalord-totaleq.rs
57+
```
58+
59+
Note the first result there, the Guide. A full quarter of the instances of `Greater` are
60+
used in the Guide, because `Ordering` is used to teach about enums. Due to shadowing,
61+
this leads to https://github.com/rust-lang/rust/issues/17967, which trips up many newbies.
62+
See [this comment](https://github.com/rust-lang/rust/issues/17967#issuecomment-61572399)
63+
from @bstrie, especially. Removing `Ordering` from the prelude fixes this issue
64+
nicely.
65+
66+
# Detailed design
67+
68+
Remove these four lines:
69+
70+
* https://github.com/rust-lang/rust/blob/master/src/libstd/prelude.rs#L66-L67
71+
* https://github.com/rust-lang/rust/blob/master/src/libcore/prelude.rs#L51-L52
72+
73+
And the fix the fallout by adding some `use` statements to the affected files. I would
74+
be willing to do said implementation.
75+
76+
# Drawbacks
77+
78+
This is another `[breaking-change]`. It is easy to fix, though, so I do not consider
79+
this drawback to be significant.
80+
81+
# Alternatives
82+
83+
We could remove the export of just the variants. This would not fix my Guide issue, but
84+
would still be more conformant to our style guidelines.
85+
86+
# Unresolved questions
87+
88+
No technical ones, this is entirely a social change.

0 commit comments

Comments
 (0)