Skip to content

Commit 7bc9b7a

Browse files
authored
Merge pull request #221 from ehuss/small-updates
A few small updates.
2 parents 23077a5 + 36e8884 commit 7bc9b7a

File tree

5 files changed

+57
-41
lines changed

5 files changed

+57
-41
lines changed

src/rust-2018/data-types/inclusive-ranges.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Since well before Rust 1.0, you’ve been able to create exclusive ranges with
66
`..` like this:
77

8-
```
8+
```rust
99
for i in 1..3 {
1010
println!("i: {}", i);
1111
}

src/rust-2018/edition-changes.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ the 2018 edition compared to the 2015 edition.
1111
- [Anonymous trait function parameters] are not allowed.
1212
- [Trait function parameters] may use any irrefutable pattern when the
1313
function has a body.
14-
- [`dyn`] is a [strict keyword], in 2015 it is a [weak keyword].
15-
- `async`, `await`, and `try` are [reserved keywords].
16-
- The following lints are now deny by default:
14+
- Keyword changes:
15+
- [`dyn`] is a [strict keyword][strict], in 2015 it is a [weak keyword].
16+
- `async` and `await` are [strict keywords][strict].
17+
- `try` is a [reserved keyword].
18+
- The following lints are now a hard error that you cannot silence:
1719
- [tyvar_behind_raw_pointer]
1820

1921
## Cargo
@@ -28,7 +30,7 @@ the 2018 edition compared to the 2015 edition.
2830
[Path changes]: module-system/path-clarity.md
2931
[Trait function parameters]: https://doc.rust-lang.org/stable/reference/items/traits.html#parameter-patterns
3032
[`dyn`]: trait-system/dyn-trait-for-trait-objects.md
31-
[reserved keywords]: https://doc.rust-lang.org/reference/keywords.html#reserved-keywords
32-
[strict keyword]: https://doc.rust-lang.org/reference/keywords.html#strict-keywords
33+
[reserved keyword]: https://doc.rust-lang.org/reference/keywords.html#reserved-keywords
34+
[strict]: https://doc.rust-lang.org/reference/keywords.html#strict-keywords
3335
[tyvar_behind_raw_pointer]: https://github.com/rust-lang/rust/issues/46906
3436
[weak keyword]: https://doc.rust-lang.org/reference/keywords.html#weak-keywords

src/rust-2018/module-system/path-clarity.md

+34-20
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,40 @@ keep doing what you were doing there as well.
6565
#### An exception
6666

6767
There's one exception to this rule, and that's the "sysroot" crates. These are the
68-
crates distributed with Rust itself. We'd eventually like to remove the requirement
69-
for `extern crate` for them as well, but it hasn't shipped yet.
70-
71-
You'll need to use `extern crate` for:
72-
73-
* `proc_macro`
74-
75-
Additionally, you would need to use it for:
76-
77-
* `core`
78-
* `std`
79-
80-
However, `extern crate std;` is already implicit, and with `#![no_std]`,
81-
`extern crate core;` is already implicit. You'll only need these in highly
82-
specialized situations.
83-
84-
Finally, on nightly, you'll need it for crates like:
85-
86-
* `alloc`
87-
* `test`
68+
crates distributed with Rust itself.
69+
70+
Usually these are only needed in very specialized situations. Starting in
71+
1.41, `rustc` accepts the `--extern=CRATE_NAME` flag which automatically adds
72+
the given crate name in a way similar to `extern crate`. Build tools may use
73+
this to inject sysroot crates into the crate's prelude. Cargo does not have a
74+
general way to express this, though it uses it for `proc_macro` crates.
75+
76+
Some examples of needing to explicitly import sysroot crates are:
77+
78+
* [`std`]: Usually this is not neccesary, because `std` is automatically
79+
imported unless the crate is marked with [`#![no_std]`][no_std].
80+
* [`core`]: Usually this is not necessary, because `core` is automatically
81+
imported, unless the crate is marked with [`#![no_core]`][no_core]. For
82+
example, some of the internal crates used by the standard library itself
83+
need this.
84+
* [`proc_macro`]: This is automatically imported by Cargo if it is a
85+
proc-macro crate starting in 1.42. `extern crate proc_macro;` would be
86+
needed if you want to support older releases, or if using another build tool
87+
that does not pass the appropriate `--extern` flags to `rustc`.
88+
* [`alloc`]: Items in the `alloc` crate are usually accessed via re-exports in
89+
the `std` crate. If you are working with a `no_std` crate that supports
90+
allocation, then you may need to explicitly import `alloc`.
91+
* [`test`]: This is only available on the [nightly channel], and is usually
92+
only used for the unstable benchmark support.
93+
94+
[`alloc`]: ../../../alloc/index.html
95+
[`core`]: ../../../core/index.html
96+
[`proc_macro`]: ../../../proc_macro/index.html
97+
[`std`]: ../../../std/index.html
98+
[`test`]: ../../../test/index.html
99+
[nightly channel]: ../../../book/appendix-07-nightly-rust.html
100+
[no_core]: https://github.com/rust-lang/rust/issues/29639
101+
[no_std]: ../../../reference/crates-and-source-files.html#preludes-and-no_std
88102

89103
#### Macros
90104

src/rust-2018/rustdoc/documentation-tests-can-now-compile-fail.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
You can now create `compile-fail` tests in Rustdoc, like this:
66

7-
```
7+
```rust
88
/// ```compile_fail
99
/// let x = 5;
1010
/// x += 2; // shouldn't compile!

src/rust-next/const-fn.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Expanded in many releases, see each aspect below for more details.
66

77
A `const fn` allows you to execute code in a "const context." For example:
88

9-
```
9+
```rust
1010
const fn five() -> i32 {
1111
5
1212
}
@@ -34,7 +34,7 @@ that it is becoming more `const` over time.
3434

3535
You can do arithmetic on integer literals:
3636

37-
```
37+
```rust
3838
const fn foo() -> i32 {
3939
5 + 6
4040
}
@@ -46,7 +46,7 @@ const fn foo() -> i32 {
4646

4747
You can use boolean operators other than `&&` and `||`, because they short-circut evaluation:
4848

49-
```
49+
```rust
5050
const fn mask(val: u8) -> u8 {
5151
let mask = 0x0f;
5252

@@ -60,7 +60,7 @@ const fn mask(val: u8) -> u8 {
6060

6161
You can create arrays, structs, enums, and tuples:
6262

63-
```
63+
```rust
6464
struct Point {
6565
x: i32,
6666
y: i32,
@@ -92,7 +92,7 @@ const fn foo() {
9292
You can call `const fn` from a `const fn`:
9393

9494

95-
```
95+
```rust
9696
const fn foo() -> i32 {
9797
5
9898
}
@@ -108,7 +108,7 @@ const fn bar() -> i32 {
108108

109109
You can index into an array or slice:
110110

111-
```
111+
```rust
112112
const fn foo() -> i32 {
113113
let array = [1, 2, 3];
114114

@@ -122,7 +122,7 @@ const fn foo() -> i32 {
122122

123123
You can access parts of a struct or tuple:
124124

125-
```
125+
```rust
126126
struct Point {
127127
x: i32,
128128
y: i32,
@@ -147,7 +147,7 @@ const fn foo() {
147147

148148
You can read from a constant:
149149

150-
```
150+
```rust
151151
const FOO: i32 = 5;
152152

153153
const fn foo() -> i32 {
@@ -163,7 +163,7 @@ Note that this is *only* `const`, not `static`.
163163

164164
You can create and de-reference references:
165165

166-
```
166+
```rust
167167
const fn foo(r: &i32) {
168168
*r;
169169

@@ -177,7 +177,7 @@ const fn foo(r: &i32) {
177177

178178
You may cast things, except for raw pointers may not be casted to an integer:
179179

180-
```
180+
```rust
181181
const fn foo() {
182182
let x: usize = 5;
183183

@@ -191,7 +191,7 @@ const fn foo() {
191191

192192
You can use irrefutable patterns that destructure values. For example:
193193

194-
```
194+
```rust
195195
const fn foo((x, y): (u8, u8)) {
196196
// ...
197197
}
@@ -206,7 +206,7 @@ place that uses irrefutable patterns.
206206

207207
You can use both mutable and immutable `let` bindings:
208208

209-
```
209+
```rust
210210
const fn foo() {
211211
let x = 5;
212212
let mut y = 10;
@@ -219,7 +219,7 @@ const fn foo() {
219219

220220
You can use assignment and assignment operators:
221221

222-
```
222+
```rust
223223
const fn foo() {
224224
let mut x = 5;
225225
x = 10;
@@ -232,7 +232,7 @@ const fn foo() {
232232

233233
You can call an `unsafe fn` inside a `const fn`:
234234

235-
```
235+
```rust
236236
const unsafe fn foo() -> i32 { 5 }
237237

238238
const fn bar() -> i32 {

0 commit comments

Comments
 (0)