Skip to content

Commit 04e0125

Browse files
committed
Auto merge of #23981 - chastell:book_crates-and-modules_io_sync, r=Manishearth
This syncs the _Crates and Modules_ chapter of the book with current output: * the runs are supposed to be in the project’s directory, * `rustc` has slightly different error messages (and things like macro line:col numbers), * Cargo now compiles things into `target/debug`.
2 parents 6971727 + d97325c commit 04e0125

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

src/doc/trpl/crates-and-modules.md

+29-27
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ Cargo will build this crate as a library:
111111
```bash
112112
$ cargo build
113113
Compiling phrases v0.0.1 (file:///home/you/projects/phrases)
114-
$ ls target
115-
deps libphrases-a7448e02a0468eaa.rlib native
114+
$ ls target/debug
115+
build deps examples libphrases-a7448e02a0468eaa.rlib native
116116
```
117117

118118
`libphrase-hash.rlib` is the compiled crate. Before we see how to use this
@@ -163,9 +163,12 @@ $ tree .
163163
│   │   └── mod.rs
164164
│   └── lib.rs
165165
└── target
166-
├── deps
167-
├── libphrases-a7448e02a0468eaa.rlib
168-
└── native
166+
└── debug
167+
├── build
168+
├── deps
169+
├── examples
170+
├── libphrases-a7448e02a0468eaa.rlib
171+
└── native
169172
```
170173

171174
`src/lib.rs` is our crate root, and looks like this:
@@ -214,8 +217,6 @@ fn goodbye() -> String {
214217
Put this in `src/japanese/greetings.rs`:
215218

216219
```rust
217-
// in src/japanese/greetings.rs
218-
219220
fn hello() -> String {
220221
"こんにちは".to_string()
221222
}
@@ -275,14 +276,15 @@ this:
275276
```bash
276277
$ cargo build
277278
Compiling phrases v0.0.1 (file:///home/you/projects/phrases)
278-
/home/you/projects/phrases/src/main.rs:4:38: 4:72 error: function `hello` is private
279-
/home/you/projects/phrases/src/main.rs:4 println!("Hello in English: {}", phrases::english::greetings::hello());
280-
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
279+
src/main.rs:4:38: 4:72 error: function `hello` is private
280+
src/main.rs:4 println!("Hello in English: {}", phrases::english::greetings::hello());
281+
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
281282
note: in expansion of format_args!
282-
<std macros>:2:23: 2:77 note: expansion site
283-
<std macros>:1:1: 3:2 note: in expansion of println!
284-
/home/you/projects/phrases/src/main.rs:4:5: 4:76 note: expansion site
285-
283+
<std macros>:2:25: 2:58 note: expansion site
284+
<std macros>:1:1: 2:62 note: in expansion of print!
285+
<std macros>:3:1: 3:54 note: expansion site
286+
<std macros>:1:1: 3:58 note: in expansion of println!
287+
phrases/src/main.rs:4:5: 4:76 note: expansion site
286288
```
287289
288290
By default, everything is private in Rust. Let's talk about this in some more
@@ -340,15 +342,15 @@ functions:
340342
```bash
341343
$ cargo run
342344
Compiling phrases v0.0.1 (file:///home/you/projects/phrases)
343-
/home/you/projects/phrases/src/japanese/greetings.rs:1:1: 3:2 warning: code is never used: `hello`, #[warn(dead_code)] on by default
344-
/home/you/projects/phrases/src/japanese/greetings.rs:1 fn hello() -> String {
345-
/home/you/projects/phrases/src/japanese/greetings.rs:2 "こんにちは".to_string()
346-
/home/you/projects/phrases/src/japanese/greetings.rs:3 }
347-
/home/you/projects/phrases/src/japanese/farewells.rs:1:1: 3:2 warning: code is never used: `goodbye`, #[warn(dead_code)] on by default
348-
/home/you/projects/phrases/src/japanese/farewells.rs:1 fn goodbye() -> String {
349-
/home/you/projects/phrases/src/japanese/farewells.rs:2 "さようなら".to_string()
350-
/home/you/projects/phrases/src/japanese/farewells.rs:3 }
351-
Running `target/phrases`
345+
src/japanese/greetings.rs:1:1: 3:2 warning: function is never used: `hello`, #[warn(dead_code)] on by default
346+
src/japanese/greetings.rs:1 fn hello() -> String {
347+
src/japanese/greetings.rs:2 "こんにちは".to_string()
348+
src/japanese/greetings.rs:3 }
349+
src/japanese/farewells.rs:1:1: 3:2 warning: function is never used: `goodbye`, #[warn(dead_code)] on by default
350+
src/japanese/farewells.rs:1 fn goodbye() -> String {
351+
src/japanese/farewells.rs:2 "さようなら".to_string()
352+
src/japanese/farewells.rs:3 }
353+
Running `target/debug/phrases`
352354
Hello in English: Hello!
353355
Goodbye in English: Goodbye.
354356
```
@@ -414,9 +416,9 @@ Rust will give us a compile-time error:
414416
415417
```text
416418
Compiling phrases v0.0.1 (file:///home/you/projects/phrases)
417-
/home/you/projects/phrases/src/main.rs:4:5: 4:40 error: a value named `hello` has already been imported in this module
418-
/home/you/projects/phrases/src/main.rs:4 use phrases::japanese::greetings::hello;
419-
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
419+
src/main.rs:4:5: 4:40 error: a value named `hello` has already been imported in this module [E0252]
420+
src/main.rs:4 use phrases::japanese::greetings::hello;
421+
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
420422
error: aborting due to previous error
421423
Could not compile `phrases`.
422424
```
@@ -523,7 +525,7 @@ This will build and run:
523525
```bash
524526
$ cargo run
525527
Compiling phrases v0.0.1 (file:///home/you/projects/phrases)
526-
Running `target/phrases`
528+
Running `target/debug/phrases`
527529
Hello in English: Hello!
528530
Goodbye in English: Goodbye.
529531
Hello in Japanese: こんにちは

0 commit comments

Comments
 (0)