Skip to content

Commit 2560a7a

Browse files
authored
Merge pull request #141 from taku-a11y/patch-1
Update codes and errors in Chapter 3.3 and 4.2
2 parents 4e41af6 + b7bd22e commit 2560a7a

File tree

2 files changed

+61
-21
lines changed

2 files changed

+61
-21
lines changed

src/ch03-03-how-functions-work.md

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,38 @@ When you run this program, the error you’ll get looks like this:
337337
```text
338338
$ cargo run
339339
Compiling functions v0.1.0 (file:///projects/functions)
340+
error[E0658]: `let` expressions in this position are experimental
341+
--> src/main.rs:2:14
342+
|
343+
2 | let x = (let y = 6);
344+
| ^^^^^^^^^
345+
|
346+
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
347+
340348
error: expected expression, found statement (`let`)
341349
(エラー: 式を予期しましたが、文が見つかりました (`let`))
342350
--> src/main.rs:2:14
343351
|
344352
2 | let x = (let y = 6);
345-
| ^^^
353+
| ^^^^^^^^^
346354
|
347355
= note: variable declaration using `let` is a statement
348356
(注釈: `let`を使う変数宣言は、文です)
357+
358+
warning: unnecessary parentheses around assigned value
359+
--> src/main.rs:2:13
360+
|
361+
2 | let x = (let y = 6);
362+
| ^^^^^^^^^^^ help: remove these parentheses
363+
|
364+
= note: `#[warn(unused_parens)]` on by default
365+
366+
error: aborting due to 2 previous errors; 1 warning emitted
367+
368+
For more information about this error, try `rustc --explain E0658`.
369+
error: could not compile `functions`
370+
371+
To learn more, run the command again with --verbose.
349372
```
350373

351374
<!--
@@ -563,20 +586,26 @@ Running this code produces an error, as follows:
563586
このコードを実行すると、以下のようにエラーが出ます:
564587

565588
```text
589+
$ cargo run
590+
Compiling functions v0.1.0 (file:///projects/functions)
566591
error[E0308]: mismatched types
567592
(型が合いません)
568-
--> src/main.rs:7:28
569-
|
570-
7 | fn plus_one(x: i32) -> i32 {
571-
| ____________________________^
572-
8 | | x + 1;
573-
| | - help: consider removing this semicolon
574-
9 | | }
575-
| |_^ expected i32, found ()
576-
| (i32を予期したのに、()型が見つかりました)
593+
594+
--> src/main.rs:7:24
577595
|
578-
= note: expected type `i32`
579-
found type `()`
596+
7 | fn plus_one(x: i32) -> i32 {
597+
| -------- ^^^ expected `i32`, found `()`
598+
| |
599+
| implicitly returns `()` as its body has no tail or `return` expression
600+
8 | x + 1;
601+
| - help: consider removing this semicolon
602+
603+
error: aborting due to previous error
604+
605+
For more information about this error, try `rustc --explain E0308`.
606+
error: could not compile `functions`
607+
608+
To learn more, run the command again with --verbose.
580609
```
581610

582611
<!--

src/ch04-02-references-and-borrowing.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,12 @@ fail:
265265
<span class="filename">ファイル名: src/main.rs</span>
266266

267267
```rust,ignore
268-
let mut s = String::from("hello");
268+
let mut s = String::from("hello");
269269
270-
let r1 = &mut s;
271-
let r2 = &mut s;
270+
let r1 = &mut s;
271+
let r2 = &mut s;
272+
273+
println!("{}, {}", r1, r2);
272274
```
273275

274276
<!--
@@ -278,19 +280,28 @@ Here’s the error:
278280
これがエラーです:
279281

280282
```text
283+
$ cargo run
284+
Compiling ownership v0.1.0 (file:///projects/ownership)
281285
error[E0499]: cannot borrow `s` as mutable more than once at a time
282286
(エラー: 一度に`s`を可変として2回以上借用することはできません)
283-
--> borrow_twice.rs:5:19
287+
--> src/main.rs:5:14
284288
|
285289
4 | let r1 = &mut s;
286-
| - first mutable borrow occurs here
290+
| ------ first mutable borrow occurs here
287291
| (最初の可変な参照はここ)
288292
5 | let r2 = &mut s;
289-
| ^ second mutable borrow occurs here
293+
| ^^^^^^ second mutable borrow occurs here
290294
| (二つ目の可変な参照はここ)
291-
6 | }
292-
| - first borrow ends here
293-
| (最初の借用はここで終わり)
295+
6 |
296+
7 | println!("{}, {}", r1, r2);
297+
| -- first borrow later used here
298+
299+
error: aborting due to previous error
300+
301+
For more information about this error, try `rustc --explain E0499`.
302+
error: could not compile `ownership`
303+
304+
To learn more, run the command again with --verbose.
294305
```
295306

296307
<!--

0 commit comments

Comments
 (0)