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

A few small updates. #221

Merged
merged 4 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rust-2018/data-types/inclusive-ranges.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Since well before Rust 1.0, you’ve been able to create exclusive ranges with
`..` like this:

```
```rust
for i in 1..3 {
println!("i: {}", i);
}
Expand Down
12 changes: 7 additions & 5 deletions src/rust-2018/edition-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ the 2018 edition compared to the 2015 edition.
- [Anonymous trait function parameters] are not allowed.
- [Trait function parameters] may use any irrefutable pattern when the
function has a body.
- [`dyn`] is a [strict keyword], in 2015 it is a [weak keyword].
- `async`, `await`, and `try` are [reserved keywords].
- The following lints are now deny by default:
- Keyword changes:
- [`dyn`] is a [strict keyword][strict], in 2015 it is a [weak keyword].
- `async` and `await` are [strict keywords][strict].
- `try` is a [reserved keyword].
- The following lints are now a hard error that you cannot silence:
- [tyvar_behind_raw_pointer]

## Cargo
Expand All @@ -28,7 +30,7 @@ the 2018 edition compared to the 2015 edition.
[Path changes]: module-system/path-clarity.md
[Trait function parameters]: https://doc.rust-lang.org/stable/reference/items/traits.html#parameter-patterns
[`dyn`]: trait-system/dyn-trait-for-trait-objects.md
[reserved keywords]: https://doc.rust-lang.org/reference/keywords.html#reserved-keywords
[strict keyword]: https://doc.rust-lang.org/reference/keywords.html#strict-keywords
[reserved keyword]: https://doc.rust-lang.org/reference/keywords.html#reserved-keywords
[strict]: https://doc.rust-lang.org/reference/keywords.html#strict-keywords
[tyvar_behind_raw_pointer]: https://github.com/rust-lang/rust/issues/46906
[weak keyword]: https://doc.rust-lang.org/reference/keywords.html#weak-keywords
54 changes: 34 additions & 20 deletions src/rust-2018/module-system/path-clarity.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,40 @@ keep doing what you were doing there as well.
#### An exception

There's one exception to this rule, and that's the "sysroot" crates. These are the
crates distributed with Rust itself. We'd eventually like to remove the requirement
for `extern crate` for them as well, but it hasn't shipped yet.

You'll need to use `extern crate` for:

* `proc_macro`

Additionally, you would need to use it for:

* `core`
* `std`

However, `extern crate std;` is already implicit, and with `#![no_std]`,
`extern crate core;` is already implicit. You'll only need these in highly
specialized situations.

Finally, on nightly, you'll need it for crates like:

* `alloc`
* `test`
crates distributed with Rust itself.

Usually these are only needed in very specialized situations. Starting in
1.41, `rustc` accepts the `--extern=CRATE_NAME` flag which automatically adds
the given crate name in a way similar to `extern crate`. Build tools may use
this to inject sysroot crates into the crate's prelude. Cargo does not have a
general way to express this, though it uses it for `proc_macro` crates.

Some examples of needing to explicitly import sysroot crates are:

* [`std`]: Usually this is not neccesary, because `std` is automatically
imported unless the crate is marked with [`#![no_std]`][no_std].
* [`core`]: Usually this is not necessary, because `core` is automatically
imported, unless the crate is marked with [`#![no_core]`][no_core]. For
example, some of the internal crates used by the standard library itself
need this.
* [`proc_macro`]: This is automatically imported by Cargo if it is a
proc-macro crate starting in 1.42. `extern crate proc_macro;` would be
needed if you want to support older releases, or if using another build tool
that does not pass the appropriate `--extern` flags to `rustc`.
* [`alloc`]: Items in the `alloc` crate are usually accessed via re-exports in
the `std` crate. If you are working with a `no_std` crate that supports
allocation, then you may need to explicitly import `alloc`.
* [`test`]: This is only available on the [nightly channel], and is usually
only used for the unstable benchmark support.

[`alloc`]: ../../../alloc/index.html
[`core`]: ../../../core/index.html
[`proc_macro`]: ../../../proc_macro/index.html
[`std`]: ../../../std/index.html
[`test`]: ../../../test/index.html
[nightly channel]: ../../../book/appendix-07-nightly-rust.html
[no_core]: https://github.com/rust-lang/rust/issues/29639
[no_std]: ../../../reference/crates-and-source-files.html#preludes-and-no_std

#### Macros

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

```
```rust
/// ```compile_fail
/// let x = 5;
/// x += 2; // shouldn't compile!
Expand Down
28 changes: 14 additions & 14 deletions src/rust-next/const-fn.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Expanded in many releases, see each aspect below for more details.

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

```
```rust
const fn five() -> i32 {
5
}
Expand Down Expand Up @@ -34,7 +34,7 @@ that it is becoming more `const` over time.

You can do arithmetic on integer literals:

```
```rust
const fn foo() -> i32 {
5 + 6
}
Expand All @@ -46,7 +46,7 @@ const fn foo() -> i32 {

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

```
```rust
const fn mask(val: u8) -> u8 {
let mask = 0x0f;

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

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

```
```rust
struct Point {
x: i32,
y: i32,
Expand Down Expand Up @@ -92,7 +92,7 @@ const fn foo() {
You can call `const fn` from a `const fn`:


```
```rust
const fn foo() -> i32 {
5
}
Expand All @@ -108,7 +108,7 @@ const fn bar() -> i32 {

You can index into an array or slice:

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

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

You can access parts of a struct or tuple:

```
```rust
struct Point {
x: i32,
y: i32,
Expand All @@ -147,7 +147,7 @@ const fn foo() {

You can read from a constant:

```
```rust
const FOO: i32 = 5;

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

You can create and de-reference references:

```
```rust
const fn foo(r: &i32) {
*r;

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

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

```
```rust
const fn foo() {
let x: usize = 5;

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

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

```
```rust
const fn foo((x, y): (u8, u8)) {
// ...
}
Expand All @@ -206,7 +206,7 @@ place that uses irrefutable patterns.

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

```
```rust
const fn foo() {
let x = 5;
let mut y = 10;
Expand All @@ -219,7 +219,7 @@ const fn foo() {

You can use assignment and assignment operators:

```
```rust
const fn foo() {
let mut x = 5;
x = 10;
Expand All @@ -232,7 +232,7 @@ const fn foo() {

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

```
```rust
const unsafe fn foo() -> i32 { 5 }

const fn bar() -> i32 {
Expand Down