Skip to content

Commit 675f795

Browse files
committed
update original
1 parent a462e87 commit 675f795

16 files changed

Lines changed: 726 additions & 559 deletions

File tree

rustbook-en/listings/ch13-functional-features/listing-13-19/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ fn main() {
1111
process::exit(1);
1212
});
1313

14-
1514
if let Err(e) = run(config) {
1615
eprintln!("Application error: {e}");
1716
process::exit(1);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
There's no Rust code in here; just us Cargo.tomls.

rustbook-en/listings/ch19-patterns-and-matching/listing-19-29/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ fn main() {
77
let msg = Message::Hello { id: 5 };
88

99
match msg {
10-
Message::Hello {
11-
id: id @ 3..=7,
12-
} => println!("Found an id in range: {id}"),
10+
Message::Hello { id: id @ 3..=7 } => {
11+
println!("Found an id in range: {id}")
12+
}
1313
Message::Hello { id: 10..=12 } => {
1414
println!("Found an id in another range")
1515
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
$ cargo +nightly miri run
2+
Compiling unsafe-example v0.1.0 (file:///projects/unsafe-example)
3+
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.01s
4+
Running `file:///home/.rustup/toolchains/nightly/bin/cargo-miri runner target/miri/debug/unsafe-example`
5+
warning: integer-to-pointer cast
6+
--> src/main.rs:5:13
7+
|
8+
5 | let r = address as *mut i32;
9+
| ^^^^^^^^^^^^^^^^^^^ integer-to-pointer cast
10+
|
11+
= help: this program is using integer-to-pointer casts or (equivalently) `ptr::with_exposed_provenance`, which means that Miri might miss pointer bugs in this program
12+
= help: see https://doc.rust-lang.org/nightly/std/ptr/fn.with_exposed_provenance.html for more details on that operation
13+
= help: to ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead
14+
= help: you can then set `MIRIFLAGS=-Zmiri-strict-provenance` to ensure you are not relying on `with_exposed_provenance` semantics
15+
= help: alternatively, `MIRIFLAGS=-Zmiri-permissive-provenance` disables this warning
16+
= note: BACKTRACE:
17+
= note: inside `main` at src/main.rs:5:13: 5:32
18+
19+
error: Undefined Behavior: pointer not dereferenceable: pointer must be dereferenceable for 40000 bytes, but got 0x1234[noalloc] which is a dangling pointer (it has no provenance)
20+
--> src/main.rs:7:35
21+
|
22+
7 | let values: &[i32] = unsafe { slice::from_raw_parts_mut(r, 10000) };
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here
24+
|
25+
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
26+
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
27+
= note: BACKTRACE:
28+
= note: inside `main` at src/main.rs:7:35: 7:70
29+
30+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
31+
32+
error: aborting due to 1 previous error; 1 warning emitted
33+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
static HELLO_WORLD: &str = "Hello, world!";
22

33
fn main() {
4-
println!("name is: {HELLO_WORLD}");
4+
println!("value is: {HELLO_WORLD}");
55
}

rustbook-en/listings/ch20-advanced-features/listing-20-11/output.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

rustbook-en/listings/ch20-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ pub fn hello_macro_derive(input: TokenStream) -> TokenStream {
1313

1414
fn impl_hello_macro(ast: &syn::DeriveInput) -> TokenStream {
1515
let name = &ast.ident;
16-
let gen = quote! {
16+
let generated = quote! {
1717
impl HelloMacro for #name {
1818
fn hello_macro() {
1919
println!("Hello, Macro! My name is {}!", stringify!(#name));
2020
}
2121
}
2222
};
23-
gen.into()
23+
generated.into()
2424
}

rustbook-en/nostarch/chapter20.md

Lines changed: 427 additions & 303 deletions
Large diffs are not rendered by default.
1.19 KB
Binary file not shown.

rustbook-en/src/ch20-00-advanced-features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Advanced Features
22

33
By now, you’ve learned the most commonly used parts of the Rust programming
4-
language. Before we do one more project in Chapter 21, we’ll look at a few
4+
language. Before we do one more project, in Chapter 21, we’ll look at a few
55
aspects of the language you might run into every once in a while, but may not
66
use every day. You can use this chapter as a reference for when you encounter
77
any unknowns. The features covered here are useful in very specific situations.

0 commit comments

Comments
 (0)