Skip to content

Commit 49e898c

Browse files
committed
Normalize Book headings to only level 2+
Doc headings in The Book sometimes started from level 1 (#), sometimes from level 2 (##). Normalize to always be 2nd level and deeper only. (Issue rust-lang#20826.)
1 parent a09b139 commit 49e898c

10 files changed

+104
-104
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fit them together. It's also important to have a well-defined interface, so
66
that some of your functionality is private, and some is public. To facilitate
77
these kinds of things, Rust has a module system.
88

9-
# Basic terminology: Crates and Modules
9+
## Basic terminology: Crates and Modules
1010

1111
Rust has two distinct terms that relate to the module system: *crate* and
1212
*module*. A crate is synonymous with a *library* or *package* in other
@@ -70,7 +70,7 @@ $ tree .
7070
`src/lib.rs` is our crate root, corresponding to the `phrases` in our diagram
7171
above.
7272

73-
# Defining Modules
73+
## Defining Modules
7474

7575
To define each of our modules, we use the `mod` keyword. Let's make our
7676
`src/lib.rs` look like this:
@@ -124,7 +124,7 @@ deps libphrases-a7448e02a0468eaa.rlib native
124124
`libphrase-hash.rlib` is the compiled crate. Before we see how to use this
125125
crate from another crate, let's break it up into multiple files.
126126

127-
# Multiple file crates
127+
## Multiple file crates
128128

129129
If each crate were just one file, these files would get very large. It's often
130130
easier to split up crates into multiple files, and Rust supports this in two
@@ -261,7 +261,7 @@ fn goodbye() -> String {
261261
Now that we have our some functionality in our crate, let's try to use it from
262262
another crate.
263263

264-
# Importing External Crates
264+
## Importing External Crates
265265

266266
We have a library crate. Let's make an executable crate that imports and uses
267267
our library.
@@ -314,7 +314,7 @@ note: in expansion of format_args!
314314
By default, everything is private in Rust. Let's talk about this in some more
315315
depth.
316316
317-
# Exporting a Public Interface
317+
## Exporting a Public Interface
318318
319319
Rust allows you to precisely control which aspects of your interface are
320320
public, and so private is the default. To make things public, you use the `pub`
@@ -396,7 +396,7 @@ Now that our functions are public, we can use them. Great! However, typing out
396396
another keyword for importing names into the current scope, so that you can
397397
refer to them with shorter names. Let's talk about `use`.
398398
399-
# Importing Modules with `use`
399+
## Importing Modules with `use`
400400
401401
Rust has a `use` keyword, which allows us to import names into our local scope.
402402
Let's change our `src/main.rs` to look like this:
@@ -477,7 +477,7 @@ use phrases::english::{greetings, farewells};
477477
478478
These two declarations are equivalent, but the second is a lot less typing.
479479
480-
## Re-exporting with `pub use`
480+
### Re-exporting with `pub use`
481481
482482
You don't just use `use` to shorten identifiers. You can also use it inside of your crate
483483
to re-export a function inside another module. This allows you to present an external

src/doc/trpl/error-handling.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ There are two main kinds of errors that can occur in your programs: failures,
1313
and panics. Let's talk about the difference between the two, and then discuss
1414
how to handle each. Then, we'll discuss upgrading failures to panics.
1515

16-
# Failure vs. Panic
16+
## Failure vs. Panic
1717

1818
Rust uses two terms to differentiate between two forms of error: failure, and
1919
panic. A *failure* is an error that can be recovered from in some way. A
@@ -116,7 +116,7 @@ We shouldn't ever hit the `_` case, so we use the `unreachable!()` macro to
116116
indicate this. `unreachable!()` gives a different kind of error than `Result`.
117117
Rust calls these sorts of errors *panics*.
118118

119-
# Handling errors with `Option` and `Result`
119+
## Handling errors with `Option` and `Result`
120120

121121
The simplest way to indicate that a function may fail is to use the `Option<T>`
122122
type. Remember our `from_str()` example? Here's its type signature:
@@ -178,7 +178,7 @@ match version {
178178
This function makes use of an enum, `ParseError`, to enumerate the various
179179
errors that can occur.
180180

181-
# Non-recoverable errors with `panic!`
181+
## Non-recoverable errors with `panic!`
182182

183183
In the case of an error that is unexpected and not recoverable, the `panic!`
184184
macro will induce a panic. This will crash the current task, and give an error:
@@ -197,7 +197,7 @@ when you run it.
197197

198198
Because these kinds of situations are relatively rare, use panics sparingly.
199199

200-
# Upgrading failures to panics
200+
## Upgrading failures to panics
201201

202202
In certain circumstances, even though a function may fail, we may want to treat
203203
it as a panic instead. For example, `io::stdin().read_line()` returns an

src/doc/trpl/ffi.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% The Rust Foreign Function Interface Guide
22

3-
# Introduction
3+
## Introduction
44

55
This guide will use the [snappy](https://github.com/google/snappy)
66
compression/decompression library as an introduction to writing bindings for
@@ -68,7 +68,7 @@ extern {
6868
# fn main() {}
6969
~~~~
7070

71-
# Creating a safe interface
71+
## Creating a safe interface
7272

7373
The raw C API needs to be wrapped to provide memory safety and make use of higher-level concepts
7474
like vectors. A library can choose to expose only the safe, high-level interface and hide the unsafe
@@ -164,7 +164,7 @@ pub fn uncompress(src: &[u8]) -> Option<Vec<u8>> {
164164
For reference, the examples used here are also available as an [library on
165165
GitHub](https://github.com/thestinger/rust-snappy).
166166

167-
# Stack management
167+
## Stack management
168168

169169
Rust tasks by default run on a *large stack*. This is actually implemented as a
170170
reserving a large segment of the address space and then lazily mapping in pages
@@ -187,13 +187,13 @@ interoperate. If, however, it is determined that a larger stack is necessary,
187187
there are appropriate functions in the task spawning API to control the size of
188188
the stack of the task which is spawned.
189189

190-
# Destructors
190+
## Destructors
191191

192192
Foreign libraries often hand off ownership of resources to the calling code.
193193
When this occurs, we must use Rust's destructors to provide safety and guarantee
194194
the release of these resources (especially in the case of panic).
195195

196-
# Callbacks from C code to Rust functions
196+
## Callbacks from C code to Rust functions
197197

198198
Some external libraries require the usage of callbacks to report back their
199199
current state or intermediate data to the caller.
@@ -247,7 +247,7 @@ In this example Rust's `main()` will call `trigger_callback()` in C,
247247
which would, in turn, call back to `callback()` in Rust.
248248
249249
250-
## Targeting callbacks to Rust objects
250+
### Targeting callbacks to Rust objects
251251
252252
The former example showed how a global function can be called from C code.
253253
However it is often desired that the callback is targeted to a special
@@ -314,7 +314,7 @@ void trigger_callback() {
314314
}
315315
~~~~
316316
317-
## Asynchronous callbacks
317+
### Asynchronous callbacks
318318
319319
In the previously given examples the callbacks are invoked as a direct reaction
320320
to a function call to the external C library.
@@ -338,7 +338,7 @@ This can be achieved by unregistering the callback in the object's
338338
destructor and designing the library in a way that guarantees that no
339339
callback will be performed after deregistration.
340340
341-
# Linking
341+
## Linking
342342
343343
The `link` attribute on `extern` blocks provides the basic building block for
344344
instructing rustc how it will link to native libraries. There are two accepted
@@ -385,7 +385,7 @@ A few examples of how this model can be used are:
385385
386386
On OSX, frameworks behave with the same semantics as a dynamic library.
387387
388-
## The `link_args` attribute
388+
### The `link_args` attribute
389389
390390
There is one other way to tell rustc how to customize linking, and that is via
391391
the `link_args` attribute. This attribute is applied to `extern` blocks and
@@ -410,7 +410,7 @@ meaning.
410410
It is highly recommended to *not* use this attribute, and rather use the more
411411
formal `#[link(...)]` attribute on `extern` blocks instead.
412412
413-
# Unsafe blocks
413+
## Unsafe blocks
414414
415415
Some operations, like dereferencing unsafe pointers or calling functions that have been marked
416416
unsafe are only allowed inside unsafe blocks. Unsafe blocks isolate unsafety and are a promise to
@@ -425,7 +425,7 @@ unsafe fn kaboom(ptr: *const int) -> int { *ptr }
425425
426426
This function can only be called from an `unsafe` block or another `unsafe` function.
427427
428-
# Accessing foreign globals
428+
## Accessing foreign globals
429429
430430
Foreign APIs often export a global variable which could do something like track
431431
global state. In order to access these variables, you declare them in `extern`
@@ -468,7 +468,7 @@ fn main() {
468468
}
469469
~~~
470470
471-
# Foreign calling conventions
471+
## Foreign calling conventions
472472
473473
Most foreign code exposes a C ABI, and Rust uses the platform's C calling convention by default when
474474
calling foreign functions. Some foreign functions, most notably the Windows API, use other calling
@@ -507,7 +507,7 @@ however, windows uses the `C` calling convention, so `C` would be used. This
507507
means that in our previous example, we could have used `extern "system" { ... }`
508508
to define a block for all windows systems, not just x86 ones.
509509
510-
# Interoperability with foreign code
510+
## Interoperability with foreign code
511511
512512
Rust guarantees that the layout of a `struct` is compatible with the platform's
513513
representation in C only if the `#[repr(C)]` attribute is applied to it.
@@ -532,7 +532,7 @@ The standard library includes type aliases and function definitions for the C
532532
standard library in the `libc` module, and Rust links against `libc` and `libm`
533533
by default.
534534
535-
# The "nullable pointer optimization"
535+
## The "nullable pointer optimization"
536536
537537
Certain types are defined to not be `null`. This includes references (`&T`,
538538
`&mut T`), boxes (`Box<T>`), and function pointers (`extern "abi" fn()`).

src/doc/trpl/macros.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
% The Rust Macros Guide
22

3-
# Introduction
3+
## Introduction
44

55
Functions are the primary tool that programmers can use to build abstractions.
66
Sometimes, however, programmers want to abstract over compile-time syntax
@@ -64,7 +64,7 @@ Macros are defined in pattern-matching style: in the above example, the text
6464
macro. The text on the right-hand side of the `=>`, beginning with `match
6565
$inp`, is the *macro transcription syntax*: what the macro expands to.
6666

67-
# Invocation syntax
67+
## Invocation syntax
6868

6969
The macro invocation syntax specifies the syntax for the arguments to the
7070
macro. It appears on the left-hand side of the `=>` in a macro definition. It
@@ -97,7 +97,7 @@ rules of tokenization apply,
9797
So `($x:ident -> (($e:expr)))`, though excessively fancy, would designate a macro
9898
that could be invoked like: `my_macro!(i->(( 2+2 )))`.
9999

100-
## Invocation location
100+
### Invocation location
101101

102102
A macro invocation may take the place of (and therefore expand to) an
103103
expression, item, statement, or pattern. The Rust parser will parse the macro
@@ -112,7 +112,7 @@ location). Although this behavior sounds excessively dynamic, it is known to
112112
be useful under some circumstances.
113113

114114

115-
# Transcription syntax
115+
## Transcription syntax
116116

117117
The right-hand side of the `=>` follows the same rules as the left-hand side,
118118
except that a `$` need only be followed by the name of the syntactic fragment
@@ -132,15 +132,15 @@ are permitted in expression, statement, and item locations. However, nothing
132132
else about the code is examined or executed by the macro system; execution
133133
still has to wait until run-time.
134134

135-
## Interpolation location
135+
### Interpolation location
136136

137137
The interpolation `$argument_name` may appear in any location consistent with
138138
its fragment specifier (i.e., if it is specified as `ident`, it may be used
139139
anywhere an identifier is permitted).
140140

141-
# Multiplicity
141+
## Multiplicity
142142

143-
## Invocation
143+
### Invocation
144144

145145
Going back to the motivating example, recall that `early_return` expanded into
146146
a `match` that would `return` if the `match`'s scrutinee matched the
@@ -179,7 +179,7 @@ early_return!(input_2, [T::SpecialB]);
179179
# fn main() {}
180180
~~~~
181181

182-
### Transcription
182+
#### Transcription
183183

184184
As the above example demonstrates, `$(...)*` is also valid on the right-hand
185185
side of a macro definition. The behavior of `*` in transcription,
@@ -191,7 +191,7 @@ of repetitions for all of the `$name`s it contains in lockstep, and (2) each
191191
`$name` must be under at least as many `$(...)*`s as it was matched against.
192192
If it is under more, it'll be repeated, as appropriate.
193193

194-
## Parsing limitations
194+
### Parsing limitations
195195

196196

197197
For technical reasons, there are two limitations to the treatment of syntax
@@ -210,9 +210,9 @@ parsing `e`. Changing the invocation syntax to require a distinctive token in
210210
front can solve the problem. In the above example, `$(T $t:ty)* E $e:exp`
211211
solves the problem.
212212

213-
# Macro argument pattern matching
213+
## Macro argument pattern matching
214214

215-
## Motivation
215+
### Motivation
216216

217217
Now consider code like the following:
218218

@@ -295,7 +295,7 @@ pattern we want is clear:
295295
However, it's not possible to directly expand to nested match statements. But
296296
there is a solution.
297297

298-
## The recursive approach to macro writing
298+
### The recursive approach to macro writing
299299

300300
A macro may accept multiple different input grammars. The first one to
301301
successfully match the actual argument to a macro invocation is the one that
@@ -408,7 +408,7 @@ position (in particular, not as an argument to yet another macro invocation),
408408
the expander will then proceed to evaluate `m2!()` (along with any other macro
409409
invocations `m1!(m2!())` produced).
410410

411-
# Hygiene
411+
## Hygiene
412412

413413
To prevent clashes, rust implements
414414
[hygienic macros](http://en.wikipedia.org/wiki/Hygienic_macro).
@@ -438,7 +438,7 @@ fn main() {
438438
The two `'x` names did not clash, which would have caused the loop
439439
to print "I am never printed" and to run forever.
440440

441-
# Scoping and macro import/export
441+
## Scoping and macro import/export
442442

443443
Macros are expanded at an early stage in compilation, before name resolution.
444444
One downside is that scoping works differently for macros, compared to other
@@ -513,7 +513,7 @@ be imported.
513513
The Rust Reference has a [listing of macro-related
514514
attributes](../reference.html#macro--and-plugin-related-attributes).
515515

516-
# The variable `$crate`
516+
## The variable `$crate`
517517

518518
A further difficulty occurs when a macro is used in multiple crates. Say that
519519
`mylib` defines
@@ -560,7 +560,7 @@ To keep this system simple and correct, `#[macro_use] extern crate ...` may
560560
only appear at the root of your crate, not inside `mod`. This ensures that
561561
`$crate` is a single identifier.
562562

563-
# A final note
563+
## A final note
564564

565565
Macros, as currently implemented, are not for the faint of heart. Even
566566
ordinary syntax errors can be more difficult to debug when they occur inside a

0 commit comments

Comments
 (0)