Skip to content

Commit b613ef5

Browse files
committed
Rollup merge of rust-lang#25580 - killercup:trpl/unify-code-blocks, r=steveklabnik
This adds strictly more information to the source files and reduces the need for customized tooling to render the book. (While this should not change the output of _rustbook_, it is very useful when rendering the sources with external tools like Pandoc.) This only adds the language marker to "first level" code blocks (and not to code blocks in comments inside of code examples). r? @steveklabnik
2 parents cc50fd6 + f3adea5 commit b613ef5

25 files changed

+107
-106
lines changed

src/doc/trpl/benchmark-tests.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Rust supports benchmark tests, which can test the performance of your
44
code. Let's make our `src/lib.rs` look like this (comments elided):
55

6-
```{rust,ignore}
6+
```rust,ignore
77
#![feature(test)]
88
99
extern crate test;
@@ -77,7 +77,7 @@ the benchmark is no longer benchmarking what one expects. For example, the
7777
compiler might recognize that some calculation has no external effects and
7878
remove it entirely.
7979

80-
```{rust,ignore}
80+
```rust,ignore
8181
#![feature(test)]
8282
8383
extern crate test;

src/doc/trpl/borrow-and-asref.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ kind of borrowed value. This is especially true of references and slices: you
5151
can have both an `&T` or a `&mut T`. If we wanted to accept both of these types,
5252
`Borrow` is up for it:
5353

54-
```
54+
```rust
5555
use std::borrow::Borrow;
5656
use std::fmt::Display;
5757

src/doc/trpl/box-syntax-and-patterns.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Also it is not possible in stable Rust to destructure a `Box` in a match
55
pattern. The unstable `box` keyword can be used to both create and destructure
66
a `Box`. An example usage would be:
77

8-
```
8+
```rust
99
#![feature(box_syntax, box_patterns)]
1010

1111
fn main() {
@@ -34,7 +34,7 @@ because the syntax may still change in the future.
3434
In many languages with pointers, you'd return a pointer from a function
3535
so as to avoid copying a large data structure. For example:
3636

37-
```{rust}
37+
```rust
3838
struct BigStruct {
3939
one: i32,
4040
two: i32,

src/doc/trpl/concurrency.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ place!
5959
Rust's standard library provides a library for threads, which allow you to
6060
run Rust code in parallel. Here's a basic example of using `std::thread`:
6161

62-
```
62+
```rust
6363
use std::thread;
6464

6565
fn main() {
@@ -73,7 +73,7 @@ The `thread::spawn()` method accepts a closure, which is executed in a
7373
new thread. It returns a handle to the thread, that can be used to
7474
wait for the child thread to finish and extract its result:
7575

76-
```
76+
```rust
7777
use std::thread;
7878

7979
fn main() {
@@ -189,7 +189,7 @@ guard across thread boundaries, which gives us our error.
189189

190190
We can use `Arc<T>` to fix this. Here's the working version:
191191

192-
```
192+
```rust
193193
use std::sync::{Arc, Mutex};
194194
use std::thread;
195195

@@ -248,7 +248,7 @@ threads with each other. Let's talk about one of them: channels.
248248
Here's a version of our code that uses channels for synchronization, rather
249249
than waiting for a specific time:
250250

251-
```
251+
```rust
252252
use std::sync::{Arc, Mutex};
253253
use std::thread;
254254
use std::sync::mpsc;
@@ -281,7 +281,7 @@ a simple `()` down the channel, and then wait for ten of them to come back.
281281
While this channel is just sending a generic signal, we can send any data that
282282
is `Send` over the channel!
283283

284-
```
284+
```rust
285285
use std::thread;
286286
use std::sync::mpsc;
287287

@@ -311,7 +311,7 @@ the answer, and then it `send()`s us the answer over the channel.
311311
A `panic!` will crash the currently executing thread. You can use Rust's
312312
threads as a simple isolation mechanism:
313313

314-
```
314+
```rust
315315
use std::thread;
316316

317317
let result = thread::spawn(move || {

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ above.
7575
To define each of our modules, we use the `mod` keyword. Let’s make our
7676
`src/lib.rs` look like this:
7777

78-
```
78+
```rust
7979
mod english {
8080
mod greetings {
8181
}
@@ -126,15 +126,15 @@ ways.
126126

127127
Instead of declaring a module like this:
128128

129-
```{rust,ignore}
129+
```rust,ignore
130130
mod english {
131131
// contents of our module go here
132132
}
133133
```
134134

135135
We can instead declare our module like this:
136136

137-
```{rust,ignore}
137+
```rust,ignore
138138
mod english;
139139
```
140140

@@ -173,7 +173,7 @@ $ tree .
173173

174174
`src/lib.rs` is our crate root, and looks like this:
175175

176-
```{rust,ignore}
176+
```rust,ignore
177177
mod english;
178178
mod japanese;
179179
```
@@ -184,7 +184,7 @@ on our preference. In this case, because our modules have sub-modules, we’ve
184184
chosen the second. Both `src/english/mod.rs` and `src/japanese/mod.rs` look
185185
like this:
186186

187-
```{rust,ignore}
187+
```rust,ignore
188188
mod greetings;
189189
mod farewells;
190190
```
@@ -297,7 +297,7 @@ public, and so private is the default. To make things public, you use the `pub`
297297
keyword. Let’s focus on the `english` module first, so let’s reduce our `src/main.rs`
298298
to just this:
299299
300-
```{rust,ignore}
300+
```rust,ignore
301301
extern crate phrases;
302302

303303
fn main() {
@@ -308,29 +308,29 @@ fn main() {
308308
309309
In our `src/lib.rs`, let’s add `pub` to the `english` module declaration:
310310
311-
```{rust,ignore}
311+
```rust,ignore
312312
pub mod english;
313313
mod japanese;
314314
```
315315
316316
And in our `src/english/mod.rs`, let’s make both `pub`:
317317
318-
```{rust,ignore}
318+
```rust,ignore
319319
pub mod greetings;
320320
pub mod farewells;
321321
```
322322
323323
In our `src/english/greetings.rs`, let’s add `pub` to our `fn` declaration:
324324
325-
```{rust,ignore}
325+
```rust,ignore
326326
pub fn hello() -> String {
327327
"Hello!".to_string()
328328
}
329329
```
330330
331331
And also in `src/english/farewells.rs`:
332332
333-
```{rust,ignore}
333+
```rust,ignore
334334
pub fn goodbye() -> String {
335335
"Goodbye.".to_string()
336336
}
@@ -365,7 +365,7 @@ refer to them with shorter names. Let’s talk about `use`.
365365
Rust has a `use` keyword, which allows us to import names into our local scope.
366366
Let’s change our `src/main.rs` to look like this:
367367
368-
```{rust,ignore}
368+
```rust,ignore
369369
extern crate phrases;
370370

371371
use phrases::english::greetings;
@@ -382,7 +382,7 @@ the functions by a much shorter name. By convention, when importing functions, i
382382
considered best practice to import the module, rather than the function directly. In
383383
other words, you _can_ do this:
384384
385-
```{rust,ignore}
385+
```rust,ignore
386386
extern crate phrases;
387387

388388
use phrases::english::greetings::hello;
@@ -400,7 +400,7 @@ becomes a problem. If we have conflicting names, Rust will give a compilation
400400
error. For example, if we made the `japanese` functions public, and tried to do
401401
this:
402402
403-
```{rust,ignore}
403+
```rust,ignore
404404
extern crate phrases;
405405
406406
use phrases::english::greetings::hello;
@@ -426,14 +426,14 @@ Could not compile `phrases`.
426426
If we’re importing multiple names from the same module, we don’t have to type it out
427427
twice. Instead of this:
428428
429-
```{rust,ignore}
429+
```rust,ignore
430430
use phrases::english::greetings;
431431
use phrases::english::farewells;
432432
```
433433
434434
We can use this shortcut:
435435
436-
```{rust,ignore}
436+
```rust,ignore
437437
use phrases::english::{greetings, farewells};
438438
```
439439
@@ -445,7 +445,7 @@ interface that may not directly map to your internal code organization.
445445
446446
Let’s look at an example. Modify your `src/main.rs` to read like this:
447447
448-
```{rust,ignore}
448+
```rust,ignore
449449
extern crate phrases;
450450
451451
use phrases::english::{greetings,farewells};
@@ -462,30 +462,30 @@ fn main() {
462462
463463
Then, modify your `src/lib.rs` to make the `japanese` mod public:
464464
465-
```{rust,ignore}
465+
```rust,ignore
466466
pub mod english;
467467
pub mod japanese;
468468
```
469469
470470
Next, make the two functions public, first in `src/japanese/greetings.rs`:
471471
472-
```{rust,ignore}
472+
```rust,ignore
473473
pub fn hello() -> String {
474474
"こんにちは".to_string()
475475
}
476476
```
477477
478478
And then in `src/japanese/farewells.rs`:
479479
480-
```{rust,ignore}
480+
```rust,ignore
481481
pub fn goodbye() -> String {
482482
"さようなら".to_string()
483483
}
484484
```
485485
486486
Finally, modify your `src/japanese/mod.rs` to read like this:
487487
488-
```{rust,ignore}
488+
```rust,ignore
489489
pub use self::greetings::hello;
490490
pub use self::farewells::goodbye;
491491

0 commit comments

Comments
 (0)