Skip to content
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

Rolling up PRs in the queue #23654

Merged
merged 131 commits into from
Mar 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
9c906da
std: Fix create_dir_all for empty paths
alexcrichton Mar 15, 2015
a7f00cb
Fix a bug in inline assembly codegen where host clobbers were always …
woehr Mar 18, 2015
b92fee9
Remove unnecessary vector creation.
woehr Mar 18, 2015
959a0e6
std: Stabilize marker::MarkerTrait
alexcrichton Mar 18, 2015
f945190
rustc: Remove some long deprecated features:
alexcrichton Mar 18, 2015
6f693e9
Stabilize Entry types
aturon Mar 19, 2015
a848ce4
Adding sys/socket.h constants for iOS/Mac, particularly for SO_SOCKET…
drewcrawford Mar 15, 2015
6f09dfc
Socket options constants for *BSD/Linux/Windows
vhbit Mar 19, 2015
6a5148b
Introduce rsplit
shepmaster Mar 14, 2015
c6ca220
StrExt::splitn should not require a DoubleEndedSearcher
shepmaster Mar 15, 2015
19fef72
Added panic-on-overflow for rhs of left and right shift expressions.
pnkfelix Mar 19, 2015
61ff823
Test suite for overflowing shift operators.
pnkfelix Mar 19, 2015
9ae144f
Add default impls for Send/Sync
flaper87 Mar 9, 2015
01d2429
Feature gate defaulted traits
flaper87 Mar 11, 2015
38dbcb2
Check trait unsafety for defaulted traits
flaper87 Mar 11, 2015
04d5772
fix fallout
flaper87 Mar 20, 2015
0c040b0
guide: minor copy edits
ches Mar 2, 2015
92294e7
guide: Improvements to language covering enums
ches Mar 2, 2015
c175b35
fix the attributes sytax
FuGangqiang Mar 21, 2015
bc9d9f2
add lifetime for `while` and `for` expression
FuGangqiang Mar 21, 2015
5e47c66
workaround bugs in pretty-printer so that we can pass check-stage2-pr…
pnkfelix Mar 21, 2015
e24fe5b
std: Remove deprecated ptr functions
alexcrichton Mar 19, 2015
1381249
implement `Clone` for `btree` iterators
apasel422 Mar 22, 2015
90c8592
Refine Cursor docstring
nagisa Mar 22, 2015
cfe7a8d
Reduce code bloat in closure
dotdash Mar 22, 2015
5321d22
Remove bad reference to std::io
steveklabnik Mar 22, 2015
fbc823d
Document how to document macros
steveklabnik Mar 22, 2015
29aca83
Remove an unsafe function definition in __thread_local_inner.
Ms2ger Mar 21, 2015
81801f2
Re-word explanation on closures in intro
steveklabnik Mar 22, 2015
8a500de
book: some Crates and Modules nits
tshepang Mar 14, 2015
4dfec6c
placate check-pretty and pretty-printer bug; see also issue 23623.
pnkfelix Mar 22, 2015
0090e01
Get __pthread_get_minstack at runtime with dlsym
andersk Mar 23, 2015
b6641c1
min_stack_size: update non-Linux implementation comment
andersk Mar 23, 2015
737bb30
min_stack_size: clarify both reasons to use dlsym
andersk Mar 23, 2015
50ea6f6
Remove incorrect subtyping for `&mut Trait` and introduce coercion
nikomatsakis Mar 19, 2015
45fae88
When matching against a pattern (either via `match` or `let`) that
nikomatsakis Mar 6, 2015
d944689
Fix dead link for std::sync::mpsc.
WiSaGaN Mar 23, 2015
64532f7
implement `Clone` for various iterators
apasel422 Mar 23, 2015
7934d52
implement `ExactSizeIterator` for `linked_list::IntoIter`
apasel422 Mar 23, 2015
88edf97
document iteration order for `vec_deque::IntoIter`
apasel422 Mar 23, 2015
bb9d210
Fix shift-overflow in very old run-pass test.
pnkfelix Mar 23, 2015
2750e3c
Add note about pointer state after the call.
steveklabnik Mar 20, 2015
d6fb7e9
derive missing trait implementations for cursor
mahkoh Mar 22, 2015
2625bf9
Fix regression in -C rpath that causes failures with symlinks
brson Mar 10, 2015
9ec9bc6
Clarify behavior of Path::relative_from
brson Mar 11, 2015
a5e1cbe
Beef up BufRead::consume documentation.
steveklabnik Mar 22, 2015
d52c362
Clarify that slices don't just point to arrays
steveklabnik Mar 23, 2015
d29d554
prctl instead of pthread on linux for name setup
nagisa Mar 23, 2015
9231ceb
Stabilize the Error trait
aturon Mar 19, 2015
6bd3ab0
Implement RFC 909: move thread_local into thread
aturon Mar 20, 2015
05c9728
Don't conflate regions and affine types
steveklabnik Mar 23, 2015
1be8fcb
Make note of str in 'more strings' chapter
steveklabnik Mar 23, 2015
bc1dde4
Compiler and trait changes to make indexing by value.
nikomatsakis Mar 21, 2015
b4d4daf
Adjust Index/IndexMut impls. For generic collections, we take
nikomatsakis Mar 21, 2015
8e58af4
Fallout in stdlib, rustdoc, rustc, etc. For most maps, converted uses of
nikomatsakis Mar 22, 2015
57cf2de
Update borrowck tests to test that index is by-move now
nikomatsakis Mar 22, 2015
2df8830
rustdoc: Support for "array" primitive
tomjakubowski Mar 23, 2015
4a81e66
Rollup merge of #22954 - ches:docs, r=steveklabnik
steveklabnik Mar 23, 2015
f788159
Rollup merge of #23119 - nikomatsakis:issue-23116-ref-mut, r=pnkfelix
steveklabnik Mar 23, 2015
84f760b
Rollup merge of #23509 - aturon:stab-entry, r=Gankro
steveklabnik Mar 23, 2015
61e6904
Rollup merge of #23561 - steveklabnik:gh23422, r=alexcrichton
steveklabnik Mar 23, 2015
73b30db
Rollup merge of #23590 - FuGangqiang:attr, r=alexcrichton
steveklabnik Mar 23, 2015
9299446
Rollup merge of #23607 - mahkoh:cursor, r=alexcrichton
steveklabnik Mar 23, 2015
8b6c0fd
Rollup merge of #23608 - nagisa:refine-cursor-docstring, r=steveklabnik
steveklabnik Mar 23, 2015
71b9ba1
Rollup merge of #23618 - steveklabnik:gh23571, r=alexcrichton
steveklabnik Mar 23, 2015
1c25aec
Rollup merge of #23622 - steveklabnik:gh23196, r=alexcrichton
steveklabnik Mar 23, 2015
68af512
Rollup merge of #23639 - steveklabnik:gh21305, r=alexcrichton
steveklabnik Mar 23, 2015
6a5b1e9
Rollup merge of #23641 - steveklabnik:gh23632, r=alexcrichton
steveklabnik Mar 23, 2015
1aa75ce
configure: Fix detection of 32-bit Linux userspace
brson Mar 23, 2015
3d365f6
rustdoc: interpret all leading feature attributes in examples as crat…
brson Mar 12, 2015
7770ea7
rustdoc: Add #[doc(test(no_inject_crate))] attribute
brson Mar 16, 2015
df290f1
Require feature attributes, and add them where necessary
brson Mar 6, 2015
e901910
Add #![feature] attributes to doctests
brson Mar 13, 2015
8c93a79
rustdoc: Replace no-pretty-expanded with pretty-expanded
brson Mar 22, 2015
8389253
Add generic conversion traits
aturon Mar 18, 2015
d97d538
std: Stabilize the `Hasher::finish` method
alexcrichton Mar 23, 2015
8bd8466
Refactor how we handle overflow so that it is a fatal error that aborts
nikomatsakis Mar 20, 2015
76ead08
Remove auto-deref'ing Pattern impl because it conflicts with other
nikomatsakis Mar 21, 2015
d6054e4
rollup merge of #22954: ches/docs
alexcrichton Mar 23, 2015
ad41e7c
rollup merge of #23119: nikomatsakis/issue-23116-ref-mut
alexcrichton Mar 23, 2015
ec1a85a
rollup merge of #23211: FlaPer87/oibit-send-and-friends
alexcrichton Mar 23, 2015
67e516c
rollup merge of #23269: shepmaster/split-not-double-ended
alexcrichton Mar 23, 2015
e98d4d9
rollup merge of #23283: brson/rpathfix
alexcrichton Mar 23, 2015
d3fbc14
rollup merge of #23401: tshepang/crates-and-modules-doc-nits
alexcrichton Mar 23, 2015
4f74376
rollup merge of #23466: woehr/master
alexcrichton Mar 23, 2015
0678f0b
rollup merge of #23515: nikomatsakis/issue-14985-trait-subtyping
alexcrichton Mar 23, 2015
68cf9e0
rollup merge of #23517: vhbit/ext-socket-options
alexcrichton Mar 23, 2015
c77af69
rollup merge of #23536: pnkfelix/arith-oflo-shifts
alexcrichton Mar 23, 2015
fd13400
rollup merge of #23538: aturon/conversion
alexcrichton Mar 23, 2015
b97e1cc
rollup merge of #23541: aturon/stab-error
alexcrichton Mar 23, 2015
2153c58
rollup merge of #23557: aturon/rfc-909
alexcrichton Mar 23, 2015
88ae218
rollup merge of #23561: steveklabnik/gh23422
alexcrichton Mar 23, 2015
9e347b3
rollup merge of #23579: Ms2ger/thread_local-unsafe
alexcrichton Mar 23, 2015
bed7740
rollup merge of #23580: nikomatsakis/pattern-and-overflow
alexcrichton Mar 23, 2015
388e5ae
rollup merge of #23590: FuGangqiang/attr
alexcrichton Mar 23, 2015
753efb5
rollup merge of #23601: nikomatsakis/by-value-index
alexcrichton Mar 23, 2015
68fb3ac
rollup merge of #23604: apasel422/btree
alexcrichton Mar 23, 2015
71c705d
rollup merge of #23607: mahkoh/cursor
alexcrichton Mar 23, 2015
c999707
rollup merge of #23608: nagisa/refine-cursor-docstring
alexcrichton Mar 23, 2015
010895e
rollup merge of #23612: dotdash/closure_bloat
alexcrichton Mar 23, 2015
5a6a905
rollup merge of #23615: steveklabnik/gh23540
alexcrichton Mar 23, 2015
a78eb53
rollup merge of #23618: steveklabnik/gh23571
alexcrichton Mar 23, 2015
b03939b
rollup merge of #23619: steveklabnik/gh23220
alexcrichton Mar 23, 2015
ef07e07
rollup merge of #23622: steveklabnik/gh23196
alexcrichton Mar 23, 2015
28fcdc0
rollup merge of #23631: andersk/minstack-dlsym
alexcrichton Mar 23, 2015
19510ac
rollup merge of #23633: tomjakubowski/rustdoc-array-prim
alexcrichton Mar 23, 2015
c7509bb
rollup merge of #23634: WiSaGaN/bugfix/fix_dead_link
alexcrichton Mar 23, 2015
ca7f7cf
rollup merge of #23637: apasel422/iter
alexcrichton Mar 23, 2015
5e06ebb
rollup merge of #23639: steveklabnik/gh21305
alexcrichton Mar 23, 2015
8a15868
rollup merge of #23640: nagisa/thread-less-weak
alexcrichton Mar 23, 2015
fcf2ba7
rollup merge of #23641: steveklabnik/gh23632
alexcrichton Mar 23, 2015
7101ff4
rollup merge of #23648: steveklabnik/rollup
alexcrichton Mar 23, 2015
d8b0628
rollup merge of #23650: brson/32-bit-userspace
alexcrichton Mar 23, 2015
c608084
rollup merge of #23598: brson/gate
alexcrichton Mar 23, 2015
7d07f70
rollup merge of #23383: alexcrichton/fs-create-dir-all
alexcrichton Mar 23, 2015
04e667a
Test fixes and rebase conflicts, round 1
alexcrichton Mar 23, 2015
6e0f1d3
rollup merge of #23484: alexcrichton/marker-trait-stable
alexcrichton Mar 23, 2015
aea8226
rollup merge of #23503: alexcrichton/fix-ptr-docs
alexcrichton Mar 23, 2015
3112716
rollup merge of #23506: alexcrichton/remove-some-deprecated-things
alexcrichton Mar 23, 2015
28a0b25
Auto merge of #23536 - pnkfelix:arith-oflo-shifts, r=nikomatsakis
bors Mar 23, 2015
248b2ec
Stabilize Entry types
aturon Mar 19, 2015
3f52d71
Update docs for ptr module.
mbrubeck Mar 23, 2015
29b5438
Test fixes and rebase conflicts, round 2
alexcrichton Mar 23, 2015
690ee16
rollup merge of #23509: aturon/stab-entry
alexcrichton Mar 24, 2015
6a44f24
rollup merge of #23644: mbrubeck/doc-edit
alexcrichton Mar 24, 2015
7380b6f
rollup merge of #23645: steveklabnik/gh23642
alexcrichton Mar 24, 2015
1588cac
rollup merge of #23652: alexcrichton/stabilize-hasher-finish
alexcrichton Mar 24, 2015
253992e
rollup merge of #23653: dhuseby/bitrig-stage0-c64d671
alexcrichton Mar 24, 2015
c5c3de0
Test fixes and rebase conflicts, round 3
alexcrichton Mar 24, 2015
a7e2049
Merge remote-tracking branch 'origin/master' into rollup
alexcrichton Mar 24, 2015
d252d0a
Test fixes and rebase conflicts, round 4
alexcrichton Mar 24, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 12 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,19 @@ esac
# Detect 64 bit linux systems with 32 bit userland and force 32 bit compilation
if [ $CFG_OSTYPE = unknown-linux-gnu -a $CFG_CPUTYPE = x86_64 ]
then
file -L "$SHELL" | grep -q "x86[_-]64"
if [ $? != 0 ]; then
CFG_CPUTYPE=i686
# $SHELL does not exist in standard 'sh', so probably only exists
# if configure is running in an interactive bash shell. /usr/bin/env
# exists *everywhere*.
BIN_TO_PROBE="$SHELL"
if [ -z "$BIN_TO_PROBE" -a -e "/usr/bin/env" ]; then
BIN_TO_PROBE="/usr/bin/env"
fi
if [ -n "$BIN_TO_PROBE" ]; then
file -L "$BIN_TO_PROBE" | grep -q "x86[_-]64"
if [ $? != 0 ]; then
CFG_CPUTYPE=i686
fi
fi
fi


Expand Down
10 changes: 6 additions & 4 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#![feature(std_misc)]
#![feature(test)]
#![feature(path_ext)]
#![feature(convert)]
#![feature(str_char)]

#![deny(warnings)]

Expand Down Expand Up @@ -115,7 +117,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {

fn opt_path(m: &getopts::Matches, nm: &str) -> PathBuf {
match m.opt_str(nm) {
Some(s) => PathBuf::new(&s),
Some(s) => PathBuf::from(&s),
None => panic!("no option (=path) found for {}", nm),
}
}
Expand All @@ -130,18 +132,18 @@ pub fn parse_config(args: Vec<String> ) -> Config {
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
rustc_path: opt_path(matches, "rustc-path"),
clang_path: matches.opt_str("clang-path").map(|s| PathBuf::new(&s)),
clang_path: matches.opt_str("clang-path").map(|s| PathBuf::from(&s)),
valgrind_path: matches.opt_str("valgrind-path"),
force_valgrind: matches.opt_present("force-valgrind"),
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| PathBuf::new(&s)),
llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| PathBuf::from(&s)),
src_base: opt_path(matches, "src-base"),
build_base: opt_path(matches, "build-base"),
aux_base: opt_path(matches, "aux-base"),
stage_id: matches.opt_str("stage-id").unwrap(),
mode: matches.opt_str("mode").unwrap().parse().ok().expect("invalid mode"),
run_ignored: matches.opt_present("ignored"),
filter: filter,
logfile: matches.opt_str("logfile").map(|s| PathBuf::new(&s)),
logfile: matches.opt_str("logfile").map(|s| PathBuf::from(&s)),
runtool: matches.opt_str("runtool"),
host_rustcflags: matches.opt_str("host-rustcflags"),
target_rustcflags: matches.opt_str("target-rustcflags"),
Expand Down
23 changes: 12 additions & 11 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ pub struct TestProps {
pub check_stdout: bool,
// Don't force a --crate-type=dylib flag on the command line
pub no_prefer_dynamic: bool,
// Don't run --pretty expanded when running pretty printing tests
pub no_pretty_expanded: bool,
// Run --pretty expanded when running pretty printing tests
pub pretty_expanded: bool,
// Which pretty mode are we testing with, default to 'normal'
pub pretty_mode: String,
// Only compare pretty output and don't try compiling
Expand All @@ -62,7 +62,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
let mut force_host = false;
let mut check_stdout = false;
let mut no_prefer_dynamic = false;
let mut no_pretty_expanded = false;
let mut pretty_expanded = false;
let mut pretty_mode = None;
let mut pretty_compare_only = false;
let mut forbid_output = Vec::new();
Expand Down Expand Up @@ -96,8 +96,8 @@ pub fn load_props(testfile: &Path) -> TestProps {
no_prefer_dynamic = parse_no_prefer_dynamic(ln);
}

if !no_pretty_expanded {
no_pretty_expanded = parse_no_pretty_expanded(ln);
if !pretty_expanded {
pretty_expanded = parse_pretty_expanded(ln);
}

if pretty_mode.is_none() {
Expand Down Expand Up @@ -152,7 +152,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
force_host: force_host,
check_stdout: check_stdout,
no_prefer_dynamic: no_prefer_dynamic,
no_pretty_expanded: no_pretty_expanded,
pretty_expanded: pretty_expanded,
pretty_mode: pretty_mode.unwrap_or("normal".to_string()),
pretty_compare_only: pretty_compare_only,
forbid_output: forbid_output,
Expand Down Expand Up @@ -295,8 +295,8 @@ fn parse_no_prefer_dynamic(line: &str) -> bool {
parse_name_directive(line, "no-prefer-dynamic")
}

fn parse_no_pretty_expanded(line: &str) -> bool {
parse_name_directive(line, "no-pretty-expanded")
fn parse_pretty_expanded(line: &str) -> bool {
parse_name_directive(line, "pretty-expanded")
}

fn parse_pretty_mode(line: &str) -> Option<String> {
Expand Down Expand Up @@ -328,10 +328,10 @@ fn parse_exec_env(line: &str) -> Option<(String, String)> {

fn parse_pp_exact(line: &str, testfile: &Path) -> Option<PathBuf> {
match parse_name_value_directive(line, "pp-exact") {
Some(s) => Some(PathBuf::new(&s)),
Some(s) => Some(PathBuf::from(&s)),
None => {
if parse_name_directive(line, "pp-exact") {
testfile.file_name().map(|s| PathBuf::new(s))
testfile.file_name().map(|s| PathBuf::from(s))
} else {
None
}
Expand All @@ -340,7 +340,8 @@ fn parse_pp_exact(line: &str, testfile: &Path) -> Option<PathBuf> {
}

fn parse_name_directive(line: &str, directive: &str) -> bool {
line.contains(directive)
// This 'no-' rule is a quick hack to allow pretty-expanded and no-pretty-expanded to coexist
line.contains(directive) && !line.contains(&("no-".to_string() + directive))
}

pub fn parse_name_value_directive(line: &str, directive: &str)
Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
if !proc_res.status.success() {
fatal_proc_rec("pretty-printed source does not typecheck", &proc_res);
}
if props.no_pretty_expanded { return }
if !props.pretty_expanded { return }

// additionally, run `--pretty expanded` and try to build it.
let proc_res = print_source(config, props, testfile, srcs[round].clone(), "expanded");
Expand Down Expand Up @@ -1440,7 +1440,7 @@ fn aux_output_dir_name(config: &Config, testfile: &Path) -> PathBuf {
}

fn output_testname(testfile: &Path) -> PathBuf {
PathBuf::new(testfile.file_stem().unwrap())
PathBuf::from(testfile.file_stem().unwrap())
}

fn output_base_name(config: &Config, testfile: &Path) -> PathBuf {
Expand Down
20 changes: 10 additions & 10 deletions src/doc/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -446,16 +446,16 @@ It gives us this error:
error: aborting due to previous error
```
It mentions that "captured outer variable in an `FnMut` closure".
Because we declared the closure as a moving closure, and it referred
to `numbers`, the closure will try to take ownership of the
vector. But the closure itself is created in a loop, and hence we will
actually create three closures, one for every iteration of the
loop. This means that all three of those closures would try to own
`numbers`, which is impossible -- `numbers` must have just one
owner. Rust detects this and gives us the error: we claim that
`numbers` has ownership, but our code tries to make three owners. This
may cause a safety problem, so Rust disallows it.
This is a little confusing because there are two closures here: the one passed
to `map`, and the one passed to `thread::scoped`. In this case, the closure for
`thread::scoped` is attempting to reference `numbers`, a `Vec<i32>`. This
closure is a `FnOnce` closure, as that’s what `thread::scoped` takes as an
argument. `FnOnce` closures take ownership of their environment. That’s fine,
but there’s one detail: because of `map`, we’re going to make three of these
closures. And since all three try to take ownership of `numbers`, that would be
a problem. That’s what it means by ‘cannot move out of captured outer
variable’: our `thread::scoped` closure wants to take ownership, and it can’t,
because the closure for `map` won’t let it.
What to do here? Rust has two types that helps us: `Arc<T>` and `Mutex<T>`.
*Arc* stands for "atomically reference counted". In other words, an Arc will
Expand Down
6 changes: 4 additions & 2 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -816,8 +816,7 @@ may optionally begin with any number of `attributes` that apply to the
containing module. Attributes on the anonymous crate module define important
metadata that influences the behavior of the compiler.

```{.rust}
# #![allow(unused_attribute)]
```no_run
// Crate name
#![crate_name = "projx"]
Expand Down Expand Up @@ -1020,6 +1019,7 @@ Use declarations support a number of convenient shortcuts:
An example of `use` declarations:

```
# #![feature(core)]
use std::iter::range_step;
use std::option::Option::{Some, None};
use std::collections::hash_map::{self, HashMap};
Expand Down Expand Up @@ -1080,6 +1080,7 @@ declarations.
An example of what will and will not work for `use` items:

```
# #![feature(core)]
# #![allow(unused_imports)]
use foo::core::iter; // good: foo is at the root of the crate
use foo::baz::foobaz; // good: foo is at the root of the crate
Expand Down Expand Up @@ -1781,6 +1782,7 @@ functions, with the exception that they may not have a body and are instead
terminated by a semicolon.

```
# #![feature(libc)]
extern crate libc;
use libc::{c_char, FILE};
Expand Down
69 changes: 36 additions & 33 deletions src/doc/trpl/compound-data-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ This pattern is very powerful, and we'll see it repeated more later.

There are also a few things you can do with a tuple as a whole, without
destructuring. You can assign one tuple into another, if they have the same
contained types and arity. Tuples have the same arity when they have the same
contained types and [arity]. Tuples have the same arity when they have the same
length.

```rust
Expand Down Expand Up @@ -196,8 +196,9 @@ Now, we have actual names, rather than positions. Good names are important,
and with a struct, we have actual names.

There _is_ one case when a tuple struct is very useful, though, and that's a
tuple struct with only one element. We call this a *newtype*, because it lets
you create a new type that's similar to another one:
tuple struct with only one element. We call this the *newtype* pattern, because
it allows you to create a new type, distinct from that of its contained value
and expressing its own semantic meaning:

```{rust}
struct Inches(i32);
Expand All @@ -216,7 +217,7 @@ destructuring `let`, as we discussed previously in 'tuples.' In this case, the

Finally, Rust has a "sum type", an *enum*. Enums are an incredibly useful
feature of Rust, and are used throughout the standard library. An `enum` is
a type which ties a set of alternates to a specific name. For example, below
a type which relates a set of alternates to a specific name. For example, below
we define `Character` to be either a `Digit` or something else. These
can be used via their fully scoped names: `Character::Other` (more about `::`
below).
Expand All @@ -228,8 +229,8 @@ enum Character {
}
```

An `enum` variant can be defined as most normal types. Below are some example
types which also would be allowed in an `enum`.
Most normal types are allowed as the variant components of an `enum`. Here are
some examples:

```rust
struct Empty;
Expand All @@ -239,15 +240,15 @@ struct Status { Health: i32, Mana: i32, Attack: i32, Defense: i32 }
struct HeightDatabase(Vec<i32>);
```

So you see that depending on the sub-datastructure, the `enum` variant, same as
a struct, may or may not hold data. That is, in `Character`, `Digit` is a name
tied to an `i32` where `Other` is just a name. However, the fact that they are
distinct makes this very useful.
You see that, depending on its type, an `enum` variant may or may not hold data.
In `Character`, for instance, `Digit` gives a meaningful name for an `i32`
value, where `Other` is only a name. However, the fact that they represent
distinct categories of `Character` is a very useful property.

As with structures, enums don't by default have access to operators such as
compare ( `==` and `!=`), binary operations (`*` and `+`), and order
(`<` and `>=`). As such, using the previous `Character` type, the
following code is invalid:
As with structures, the variants of an enum by default are not comparable with
equality operators (`==`, `!=`), have no ordering (`<`, `>=`, etc.), and do not
support other binary operations such as `*` and `+`. As such, the following code
is invalid for the example `Character` type:

```{rust,ignore}
// These assignments both succeed
Expand All @@ -265,9 +266,10 @@ let four_equals_ten = four == ten;
```

This may seem rather limiting, but it's a limitation which we can overcome.
There are two ways: by implementing equality ourselves, or by using the
[`match`][match] keyword. We don't know enough about Rust to implement equality
yet, but we can use the `Ordering` enum from the standard library, which does:
There are two ways: by implementing equality ourselves, or by pattern matching
variants with [`match`][match] expressions, which you'll learn in the next
chapter. We don't know enough about Rust to implement equality yet, but we can
use the `Ordering` enum from the standard library, which does:

```
enum Ordering {
Expand All @@ -277,9 +279,8 @@ enum Ordering {
}
```

Because we did not define `Ordering`, we must import it (from the std
library) with the `use` keyword. Here's an example of how `Ordering` is
used:
Because `Ordering` has already been defined for us, we will import it with the
`use` keyword. Here's an example of how it is used:

```{rust}
use std::cmp::Ordering;
Expand Down Expand Up @@ -313,17 +314,17 @@ the standard library if you need them.

Okay, let's talk about the actual code in the example. `cmp` is a function that
compares two things, and returns an `Ordering`. We return either
`Ordering::Less`, `Ordering::Greater`, or `Ordering::Equal`, depending on if
the two values are less, greater, or equal. Note that each variant of the
`enum` is namespaced under the `enum` itself: it's `Ordering::Greater` not
`Greater`.
`Ordering::Less`, `Ordering::Greater`, or `Ordering::Equal`, depending on
whether the first value is less than, greater than, or equal to the second. Note
that each variant of the `enum` is namespaced under the `enum` itself: it's
`Ordering::Greater`, not `Greater`.

The `ordering` variable has the type `Ordering`, and so contains one of the
three values. We then do a bunch of `if`/`else` comparisons to check which
one it is.

This `Ordering::Greater` notation is too long. Let's use `use` to import the
`enum` variants instead. This will avoid full scoping:
This `Ordering::Greater` notation is too long. Let's use another form of `use`
to import the `enum` variants instead. This will avoid full scoping:

```{rust}
use std::cmp::Ordering::{self, Equal, Less, Greater};
Expand All @@ -347,16 +348,18 @@ fn main() {
```

Importing variants is convenient and compact, but can also cause name conflicts,
so do this with caution. It's considered good style to rarely import variants
for this reason.
so do this with caution. For this reason, it's normally considered better style
to `use` an enum rather than its variants directly.

As you can see, `enum`s are quite a powerful tool for data representation, and are
even more useful when they're [generic][generics] across types. Before we
get to generics, though, let's talk about how to use them with pattern matching, a
tool that will let us deconstruct this sum type (the type theory term for enums)
in a very elegant way and avoid all these messy `if`/`else`s.
As you can see, `enum`s are quite a powerful tool for data representation, and
are even more useful when they're [generic][generics] across types. Before we
get to generics, though, let's talk about how to use enums with pattern
matching, a tool that will let us deconstruct sum types (the type theory term
for enums) like `Ordering` in a very elegant way that avoids all these messy
and brittle `if`/`else`s.


[arity]: ./glossary.html#arity
[match]: ./match.html
[game]: ./guessing-game.html#comparing-guesses
[generics]: ./generics.html
Loading