Skip to content

Commit 064a677

Browse files
committed
Auto merge of #24637 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #24516, #24537, #24571, #24577, #24625, #24627, #24628, #24629, #24630, #24632 - Failed merges:
2 parents f46c4e1 + fb57ba0 commit 064a677

21 files changed

+687
-672
lines changed

mk/tests.mk

+10-8
Original file line numberDiff line numberDiff line change
@@ -753,20 +753,22 @@ PRETTY_DEPS_pretty-rpass-full = $(RPASS_FULL_TESTS)
753753
PRETTY_DEPS_pretty-rfail = $(RFAIL_TESTS)
754754
PRETTY_DEPS_pretty-bench = $(BENCH_TESTS)
755755
PRETTY_DEPS_pretty-pretty = $(PRETTY_TESTS)
756-
# The stage- and host-specific dependencies are for e.g. macro_crate_test which pulls in
757-
# external crates.
758-
PRETTY_DEPS$(1)_H_$(3)_pretty-rpass =
759-
PRETTY_DEPS$(1)_H_$(3)_pretty-rpass-full = $$(HLIB$(1)_H_$(3))/stamp.syntax $$(HLIB$(1)_H_$(3))/stamp.rustc
760-
PRETTY_DEPS$(1)_H_$(3)_pretty-rfail =
761-
PRETTY_DEPS$(1)_H_$(3)_pretty-bench =
762-
PRETTY_DEPS$(1)_H_$(3)_pretty-pretty =
763756
PRETTY_DIRNAME_pretty-rpass = run-pass
764757
PRETTY_DIRNAME_pretty-rpass-valgrind = run-pass-valgrind
765758
PRETTY_DIRNAME_pretty-rpass-full = run-pass-fulldeps
766759
PRETTY_DIRNAME_pretty-rfail = run-fail
767760
PRETTY_DIRNAME_pretty-bench = bench
768761
PRETTY_DIRNAME_pretty-pretty = pretty
769762

763+
define DEF_PRETTY_FULLDEPS
764+
PRETTY_DEPS$(1)_T_$(2)_H_$(3)_pretty-rpass-full = $$(CSREQ$(1)_T_$(2)_H_$(3))
765+
endef
766+
767+
$(foreach host,$(CFG_HOST), \
768+
$(foreach target,$(CFG_TARGET), \
769+
$(foreach stage,$(STAGES), \
770+
$(eval $(call DEF_PRETTY_FULLDEPS,$(stage),$(target),$(host))))))
771+
770772
define DEF_RUN_PRETTY_TEST
771773

772774
PRETTY_ARGS$(1)-T-$(2)-H-$(3)-$(4) := \
@@ -780,7 +782,7 @@ check-stage$(1)-T-$(2)-H-$(3)-$(4)-exec: $$(call TEST_OK_FILE,$(1),$(2),$(3),$(4
780782
$$(call TEST_OK_FILE,$(1),$(2),$(3),$(4)): \
781783
$$(TEST_SREQ$(1)_T_$(2)_H_$(3)) \
782784
$$(PRETTY_DEPS_$(4)) \
783-
$$(PRETTY_DEPS$(1)_H_$(3)_$(4))
785+
$$(PRETTY_DEPS$(1)_T_$(2)_H_$(3)_$(4))
784786
@$$(call E, run pretty-rpass [$(2)]: $$<)
785787
$$(Q)touch $$@.start_time
786788
$$(Q)$$(call CFG_RUN_CTEST_$(2),$(1),$$<,$(3)) \

src/doc/reference.md

+22-115
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,7 @@ Use declarations support a number of convenient shortcuts:
973973

974974
An example of `use` declarations:
975975

976-
```
977-
# #![feature(core)]
976+
```rust
978977
use std::option::Option::{Some, None};
979978
use std::collections::hash_map::{self, HashMap};
980979

@@ -1031,16 +1030,17 @@ declarations.
10311030
An example of what will and will not work for `use` items:
10321031

10331032
```
1034-
# #![feature(core)]
10351033
# #![allow(unused_imports)]
1036-
use foo::core::iter; // good: foo is at the root of the crate
10371034
use foo::baz::foobaz; // good: foo is at the root of the crate
10381035
10391036
mod foo {
1040-
extern crate core;
10411037
1042-
use foo::core::iter; // good: foo is at crate root
1043-
// use core::iter; // bad: core is not at the crate root
1038+
mod example {
1039+
pub mod iter {}
1040+
}
1041+
1042+
use foo::example::iter; // good: foo is at crate root
1043+
// use example::iter; // bad: core is not at the crate root
10441044
use self::baz::foobaz; // good: self refers to module 'foo'
10451045
use foo::bar::foobar; // good: foo is at crate root
10461046
@@ -1368,17 +1368,14 @@ a = Animal::Cat;
13681368

13691369
Enumeration constructors can have either named or unnamed fields:
13701370

1371-
```
1372-
# #![feature(struct_variant)]
1373-
# fn main() {
1371+
```rust
13741372
enum Animal {
13751373
Dog (String, f64),
13761374
Cat { name: String, weight: f64 }
13771375
}
13781376

13791377
let mut a: Animal = Animal::Dog("Cocoa".to_string(), 37.2);
13801378
a = Animal::Cat { name: "Spotty".to_string(), weight: 2.7 };
1381-
# }
13821379
```
13831380

13841381
In this example, `Cat` is a _struct-like enum variant_,
@@ -1718,17 +1715,6 @@ Functions within external blocks are declared in the same way as other Rust
17181715
functions, with the exception that they may not have a body and are instead
17191716
terminated by a semicolon.
17201717

1721-
```
1722-
# #![feature(libc)]
1723-
extern crate libc;
1724-
use libc::{c_char, FILE};
1725-
1726-
extern {
1727-
fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE;
1728-
}
1729-
# fn main() {}
1730-
```
1731-
17321718
Functions within external blocks may be called by Rust code, just like
17331719
functions defined in Rust. The Rust compiler automatically translates between
17341720
the Rust ABI and the foreign ABI.
@@ -1739,7 +1725,7 @@ By default external blocks assume that the library they are calling uses the
17391725
standard C "cdecl" ABI. Other ABIs may be specified using an `abi` string, as
17401726
shown here:
17411727

1742-
```{.ignore}
1728+
```ignore
17431729
// Interface to the Windows API
17441730
extern "stdcall" { }
17451731
```
@@ -3231,55 +3217,7 @@ expression.
32313217

32323218
In a pattern whose head expression has an `enum` type, a placeholder (`_`)
32333219
stands for a *single* data field, whereas a wildcard `..` stands for *all* the
3234-
fields of a particular variant. For example:
3235-
3236-
```
3237-
#![feature(box_patterns)]
3238-
#![feature(box_syntax)]
3239-
enum List<X> { Nil, Cons(X, Box<List<X>>) }
3240-
3241-
fn main() {
3242-
let x: List<i32> = List::Cons(10, box List::Cons(11, box List::Nil));
3243-
3244-
match x {
3245-
List::Cons(_, box List::Nil) => panic!("singleton list"),
3246-
List::Cons(..) => return,
3247-
List::Nil => panic!("empty list")
3248-
}
3249-
}
3250-
```
3251-
3252-
The first pattern matches lists constructed by applying `Cons` to any head
3253-
value, and a tail value of `box Nil`. The second pattern matches _any_ list
3254-
constructed with `Cons`, ignoring the values of its arguments. The difference
3255-
between `_` and `..` is that the pattern `C(_)` is only type-correct if `C` has
3256-
exactly one argument, while the pattern `C(..)` is type-correct for any enum
3257-
variant `C`, regardless of how many arguments `C` has.
3258-
3259-
Used inside an array pattern, `..` stands for any number of elements, when the
3260-
`advanced_slice_patterns` feature gate is turned on. This wildcard can be used
3261-
at most once for a given array, which implies that it cannot be used to
3262-
specifically match elements that are at an unknown distance from both ends of a
3263-
array, like `[.., 42, ..]`. If preceded by a variable name, it will bind the
3264-
corresponding slice to the variable. Example:
3265-
3266-
```
3267-
# #![feature(advanced_slice_patterns, slice_patterns)]
3268-
fn is_symmetric(list: &[u32]) -> bool {
3269-
match list {
3270-
[] | [_] => true,
3271-
[x, inside.., y] if x == y => is_symmetric(inside),
3272-
_ => false
3273-
}
3274-
}
3275-
3276-
fn main() {
3277-
let sym = &[0, 1, 4, 2, 4, 1, 0];
3278-
let not_sym = &[0, 1, 7, 2, 4, 1, 0];
3279-
assert!(is_symmetric(sym));
3280-
assert!(!is_symmetric(not_sym));
3281-
}
3282-
```
3220+
fields of a particular variant.
32833221

32843222
A `match` behaves differently depending on whether or not the head expression
32853223
is an [lvalue or an rvalue](#lvalues,-rvalues-and-temporaries). If the head
@@ -3298,30 +3236,15 @@ the inside of the match.
32983236
An example of a `match` expression:
32993237

33003238
```
3301-
#![feature(box_patterns)]
3302-
#![feature(box_syntax)]
3303-
# fn process_pair(a: i32, b: i32) { }
3304-
# fn process_ten() { }
3305-
3306-
enum List<X> { Nil, Cons(X, Box<List<X>>) }
3307-
3308-
fn main() {
3309-
let x: List<i32> = List::Cons(10, box List::Cons(11, box List::Nil));
3239+
let x = 1;
33103240
3311-
match x {
3312-
List::Cons(a, box List::Cons(b, _)) => {
3313-
process_pair(a, b);
3314-
}
3315-
List::Cons(10, _) => {
3316-
process_ten();
3317-
}
3318-
List::Nil => {
3319-
return;
3320-
}
3321-
_ => {
3322-
panic!();
3323-
}
3324-
}
3241+
match x {
3242+
1 => println!("one"),
3243+
2 => println!("two"),
3244+
3 => println!("three"),
3245+
4 => println!("four"),
3246+
5 => println!("five"),
3247+
_ => println!("something else"),
33253248
}
33263249
```
33273250

@@ -3334,28 +3257,12 @@ Subpatterns can also be bound to variables by the use of the syntax `variable @
33343257
subpattern`. For example:
33353258

33363259
```
3337-
#![feature(box_patterns)]
3338-
#![feature(box_syntax)]
3339-
3340-
enum List { Nil, Cons(u32, Box<List>) }
3260+
let x = 1;
33413261
3342-
fn is_sorted(list: &List) -> bool {
3343-
match *list {
3344-
List::Nil | List::Cons(_, box List::Nil) => true,
3345-
List::Cons(x, ref r @ box List::Cons(_, _)) => {
3346-
match *r {
3347-
box List::Cons(y, _) => (x <= y) && is_sorted(&**r),
3348-
_ => panic!()
3349-
}
3350-
}
3351-
}
3352-
}
3353-
3354-
fn main() {
3355-
let a = List::Cons(6, box List::Cons(7, box List::Cons(42, box List::Nil)));
3356-
assert!(is_sorted(&a));
3262+
match x {
3263+
e @ 1 ... 5 => println!("got a range element {}", e),
3264+
_ => println!("anything"),
33573265
}
3358-
33593266
```
33603267

33613268
Patterns can also dereference pointers by using the `&`, `&mut` and `box`

src/doc/trpl/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn main() {
165165

166166
Rust has [move semantics][move] by default, so if we want to make a copy of some
167167
data, we call the `clone()` method. In this example, `y` is no longer a reference
168-
to the vector stored in `x`, but a copy of its first element, `"hello"`. Now
168+
to the vector stored in `x`, but a copy of its first element, `"Hello"`. Now
169169
that we don’t have a reference, our `push()` works just fine.
170170

171171
[move]: move-semantics.html

src/doc/trpl/SUMMARY.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* [Concurrency](concurrency.md)
1515
* [Error Handling](error-handling.md)
1616
* [FFI](ffi.md)
17-
* [Deref coercions](deref-coercions.md)
1817
* [Syntax and Semantics](syntax-and-semantics.md)
1918
* [Variable Bindings](variable-bindings.md)
2019
* [Functions](functions.md)
@@ -30,15 +29,15 @@
3029
* [Move semantics](move-semantics.md)
3130
* [Enums](enums.md)
3231
* [Match](match.md)
33-
* [Patterns](patterns.md)
3432
* [Structs](structs.md)
33+
* [Patterns](patterns.md)
3534
* [Method Syntax](method-syntax.md)
36-
* [Drop](drop.md)
3735
* [Vectors](vectors.md)
3836
* [Strings](strings.md)
37+
* [Generics](generics.md)
3938
* [Traits](traits.md)
4039
* [Operators and Overloading](operators-and-overloading.md)
41-
* [Generics](generics.md)
40+
* [Drop](drop.md)
4241
* [if let](if-let.md)
4342
* [Trait Objects](trait-objects.md)
4443
* [Closures](closures.md)
@@ -53,6 +52,7 @@
5352
* [Casting between types](casting-between-types.md)
5453
* [Associated Types](associated-types.md)
5554
* [Unsized Types](unsized-types.md)
55+
* [Deref coercions](deref-coercions.md)
5656
* [Macros](macros.md)
5757
* [`unsafe` Code](unsafe-code.md)
5858
* [Nightly Rust](nightly-rust.md)

src/doc/trpl/casting-between-types.md

+87-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,89 @@
11
% Casting Between Types
22

3-
Coming Soon
3+
Rust, with its focus on safety, provides two different ways of casting
4+
different types between each other. The first, `as`, is for safe casts.
5+
In contrast, `transmute` allows for arbitrary casting, and is one of the
6+
most dangerous features of Rust!
7+
8+
# `as`
9+
10+
The `as` keyword does basic casting:
11+
12+
```rust
13+
let x: i32 = 5;
14+
15+
let y = x as i64;
16+
```
17+
18+
It only allows certain kinds of casting, however:
19+
20+
```rust,ignore
21+
let a = [0u8, 0u8, 0u8, 0u8];
22+
23+
let b = a as u32; // four eights makes 32
24+
```
25+
26+
This errors with:
27+
28+
```text
29+
error: non-scalar cast: `[u8; 4]` as `u32`
30+
let b = a as u32; // four eights makes 32
31+
^~~~~~~~
32+
```
33+
34+
It’s a ‘non-scalar cast’ because we have multiple values here: the four
35+
elements of the array. These kinds of casts are very dangerous, because they
36+
make assumptions about the way that multiple underlying strucutres are
37+
implemented. For this, we need something more dangerous.
38+
39+
# `transmute`
40+
41+
The `transmute` function is provided by a [compiler intrinsic][intrinsics], and
42+
what it does is very simple, but very scary. It tells Rust to treat a value of
43+
one type as though it were another type. It does this regardless of the
44+
typechecking system, and just completely trusts you.
45+
46+
[intrinsic]: intrinsics.html
47+
48+
In our previous example, we know that an array of four `u8`s represents a `u32`
49+
properly, and so we want to do the cast. Using `transmute` instead of `as`,
50+
Rust lets us:
51+
52+
```rust
53+
use std::mem;
54+
55+
unsafe {
56+
let a = [0u8, 0u8, 0u8, 0u8];
57+
58+
let b = mem::transmute::<[u8; 4], u32>(a);
59+
}
60+
```
61+
62+
We have to wrap the operation in an `unsafe` block, but this will compile
63+
successfully. Technically, only the `mem::transmute` call itself needs to be in
64+
the block, but it's nice in this case to enclose everything related, so you
65+
know where to look. In this case, the details about `a` are also important, and
66+
so they're in the block. You'll see code in either style, sometimes the context
67+
is too far away, and wrapping all of the code in `unsafe` isn't a great idea.
68+
69+
While `transmute` does very little checking, it will at least make sure that
70+
the types are the same size. This errors:
71+
72+
```rust,ignore
73+
use std::mem;
74+
75+
unsafe {
76+
let a = [0u8, 0u8, 0u8, 0u8];
77+
78+
let b = mem::transmute::<[u8; 4], u64>(a);
79+
}
80+
```
81+
82+
with:
83+
84+
```text
85+
error: transmute called on types with different sizes: [u8; 4] (32 bits) to u64
86+
(64 bits)
87+
```
88+
89+
Other than that, you're on your own!

0 commit comments

Comments
 (0)