Skip to content

Commit e06aec8

Browse files
authored
Merge branch 'master' into patch-1
2 parents b767364 + 6af3f81 commit e06aec8

File tree

8 files changed

+18
-15
lines changed

8 files changed

+18
-15
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Please see the [CONTRIBUTING.md] file for more details.
3535

3636
## Translations to other languages
3737

38+
* [Bulgarian](https://github.com/kberov/rust-by-example-bg)
3839
* [Chinese](https://github.com/rust-lang-cn/rust-by-example-cn)
3940
* [Japanese](https://github.com/rust-lang-ja/rust-by-example-ja)
4041
* [French](https://github.com/Songbird0/FR_RBE)

src/error/option_unwrap/question_mark.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ function is being executed and return `None`.
88
```rust,editable
99
fn next_birthday(current_age: Option<u8>) -> Option<String> {
1010
// If `current_age` is `None`, this returns `None`.
11-
// If `current_age` is `Some`, the inner `u8` gets assigned to `next_age`
11+
// If `current_age` is `Some`, the inner `u8` value + 1
12+
// gets assigned to `next_age`
1213
let next_age: u8 = current_age? + 1;
1314
Some(format!("Next year I will be {}", next_age))
1415
}

src/fn/closures.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn main() {
2626
// TODO: uncomment the line above and see the compiler error. The compiler
2727
// suggests that we define a closure instead.
2828
29-
// Closures are anonymous, here we are binding them to references
29+
// Closures are anonymous, here we are binding them to references.
3030
// Annotation is identical to function annotation but is optional
3131
// as are the `{}` wrapping the body. These nameless functions
3232
// are assigned to appropriately named variables.

src/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Now let's begin!
2121

2222
- [Types](types.md) - Learn about changing and defining types.
2323

24-
- [Conversion](conversion.md)
24+
- [Conversion](conversion.md) - Convert between different types, such as strings, integers, and floats.
2525

26-
- [Expressions](expression.md)
26+
- [Expressions](expression.md) - Learn about Expressions & how to use them.
2727

2828
- [Flow of Control](flow_control.md) - `if`/`else`, `for`, and others.
2929

@@ -43,7 +43,7 @@ Now let's begin!
4343

4444
- [Traits](trait.md) - A trait is a collection of methods defined for an unknown type: `Self`
4545

46-
- [Macros](macros.md)
46+
- [Macros](macros.md) - Macros are a way of writing code that writes other code, which is known as metaprogramming.
4747

4848
- [Error handling](error.md) - Learn Rust way of handling failures.
4949

@@ -53,9 +53,9 @@ Now let's begin!
5353

5454
- [Testing](testing.md) - All sorts of testing in Rust.
5555

56-
- [Unsafe Operations](unsafe.md)
56+
- [Unsafe Operations](unsafe.md) - Learn about entering a block of unsafe operations.
5757

58-
- [Compatibility](compatibility.md)
58+
- [Compatibility](compatibility.md) - Handling Rust's evolution and potential compatibility issues.
5959

6060
- [Meta](meta.md) - Documentation, Benchmarking.
6161

src/std/hash/alt_key_types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Any type that implements the `Eq` and `Hash` traits can be a key in `HashMap`.
44
This includes:
55

6-
* `bool` (though not very useful since there is only two possible keys)
6+
* `bool` (though not very useful since there are only two possible keys)
77
* `int`, `uint`, and all variations thereof
88
* `String` and `&str` (protip: you can have a `HashMap` keyed by `String`
99
and call `.get()` with an `&str`)

src/std_misc/file/read_lines.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn main() {
6262
}
6363
}
6464
65-
// The output is wrapped in a Result to allow matching on errors
65+
// The output is wrapped in a Result to allow matching on errors.
6666
// Returns an Iterator to the Reader of the lines of the file.
6767
fn read_lines<P>(filename: P) -> io::Result<io::Lines<io::BufReader<File>>>
6868
where P: AsRef<Path>, {

src/std_misc/threads/testcase_mapreduce.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::thread;
3030
fn main() {
3131
3232
// This is our data to process.
33-
// We will calculate the sum of all digits via a threaded map-reduce algorithm.
33+
// We will calculate the sum of all digits via a threaded map-reduce algorithm.
3434
// Each whitespace separated chunk will be handled in a different thread.
3535
//
3636
// TODO: see what happens to the output if you insert spaces!

src/unsafe/asm.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ can be written at any time, and can therefore not share its location with any ot
139139
However, to guarantee optimal performance it is important to use as few registers as possible,
140140
so they won't have to be saved and reloaded around the inline assembly block.
141141
To achieve this Rust provides a `lateout` specifier. This can be used on any output that is
142-
written only after all inputs have been consumed.
143-
There is also a `inlateout` variant of this specifier.
142+
written only after all inputs have been consumed. There is also an `inlateout` variant of this
143+
specifier.
144144

145145
Here is an example where `inlateout` *cannot* be used in `release` mode or other optimized cases:
146146

@@ -163,11 +163,12 @@ unsafe {
163163
assert_eq!(a, 12);
164164
# }
165165
```
166-
The above could work well in unoptimized cases (`Debug` mode), but if you want optimized performance (`release` mode or other optimized cases), it could not work.
167166

168-
That is because in optimized cases, the compiler is free to allocate the same register for inputs `b` and `c` since it knows they have the same value. However it must allocate a separate register for `a` since it uses `inout` and not `inlateout`. If `inlateout` was used, then `a` and `c` could be allocated to the same register, in which case the first instruction to overwrite the value of `c` and cause the assembly code to produce the wrong result.
167+
In unoptimized cases (e.g. `Debug` mode), replacing `inout(reg) a` with `inlateout(reg) a` in the above example can continue to give the expected result. However, with `release` mode or other optimized cases, using `inlateout(reg) a` can instead lead to the final value `a = 16`, causing the assertion to fail.
169168

170-
However the following example can use `inlateout` since the output is only modified after all input registers have been read:
169+
This is because in optimized cases, the compiler is free to allocate the same register for inputs `b` and `c` since it knows that they have the same value. Furthermore, when `inlateout` is used, `a` and `c` could be allocated to the same register, in which case the first `add` instruction would overwrite the initial load from variable `c`. This is in contrast to how using `inout(reg) a` ensures a separate register is allocated for `a`.
170+
171+
However, the following example can use `inlateout` since the output is only modified after all input registers have been read:
171172

172173
```rust
173174
# #[cfg(target_arch = "x86_64")] {

0 commit comments

Comments
 (0)