@@ -62,11 +62,13 @@ macro_rules! panic {
62
62
/// # Custom Messages
63
63
///
64
64
/// This macro has a second form, where a custom panic message can
65
- /// be provided with or without arguments for formatting.
65
+ /// be provided with or without arguments for formatting. See [`std::fmt`]
66
+ /// for syntax for this form.
66
67
///
67
68
/// [`panic!`]: macro.panic.html
68
69
/// [`debug_assert!`]: macro.debug_assert.html
69
- /// [testing]: ../book/first-edition/testing.html
70
+ /// [testing]: ../book/second-edition/ch11-01-writing-tests.html#checking-results-with-the-assert-macro
71
+ /// [`std::fmt`]: ../std/fmt/index.html
70
72
///
71
73
/// # Examples
72
74
///
@@ -252,13 +254,15 @@ macro_rules! debug_assert {
252
254
/// On panic, this macro will print the values of the expressions with their
253
255
/// debug representations.
254
256
///
255
- /// Unlike `assert_eq!`, `debug_assert_eq!` statements are only enabled in non
257
+ /// Unlike [ `assert_eq!`] , `debug_assert_eq!` statements are only enabled in non
256
258
/// optimized builds by default. An optimized build will omit all
257
259
/// `debug_assert_eq!` statements unless `-C debug-assertions` is passed to the
258
260
/// compiler. This makes `debug_assert_eq!` useful for checks that are too
259
261
/// expensive to be present in a release build but may be helpful during
260
262
/// development.
261
263
///
264
+ /// [`assert_eq!`]: ../std/macro.assert_eq.html
265
+ ///
262
266
/// # Examples
263
267
///
264
268
/// ```
@@ -277,13 +281,15 @@ macro_rules! debug_assert_eq {
277
281
/// On panic, this macro will print the values of the expressions with their
278
282
/// debug representations.
279
283
///
280
- /// Unlike `assert_ne!`, `debug_assert_ne!` statements are only enabled in non
284
+ /// Unlike [ `assert_ne!`] , `debug_assert_ne!` statements are only enabled in non
281
285
/// optimized builds by default. An optimized build will omit all
282
286
/// `debug_assert_ne!` statements unless `-C debug-assertions` is passed to the
283
287
/// compiler. This makes `debug_assert_ne!` useful for checks that are too
284
288
/// expensive to be present in a release build but may be helpful during
285
289
/// development.
286
290
///
291
+ /// [`assert_ne!`]: ../std/macro.assert_ne.html
292
+ ///
287
293
/// # Examples
288
294
///
289
295
/// ```
@@ -300,10 +306,9 @@ macro_rules! debug_assert_ne {
300
306
/// Helper macro for reducing boilerplate code for matching `Result` together
301
307
/// with converting downstream errors.
302
308
///
303
- /// Prefer using `?` syntax to `try!`. `?` is built in to the language and is
304
- /// more succinct than `try!`. It is the standard method for error propagation.
309
+ /// The `?` operator was added to replace `try!` and should be used instead.
305
310
///
306
- /// `try!` matches the given `Result`. In case of the `Ok` variant, the
311
+ /// `try!` matches the given [ `Result`] . In case of the `Ok` variant, the
307
312
/// expression has the value of the wrapped value.
308
313
///
309
314
/// In case of the `Err` variant, it retrieves the inner error. `try!` then
@@ -312,7 +317,9 @@ macro_rules! debug_assert_ne {
312
317
/// error is then immediately returned.
313
318
///
314
319
/// Because of the early return, `try!` can only be used in functions that
315
- /// return `Result`.
320
+ /// return [`Result`].
321
+ ///
322
+ /// [`Result`]: ../std/result/enum.Result.html
316
323
///
317
324
/// # Examples
318
325
///
@@ -331,20 +338,26 @@ macro_rules! debug_assert_ne {
331
338
/// }
332
339
/// }
333
340
///
341
+ /// // The prefered method of quick returning Errors
342
+ /// fn write_to_file_question() -> Result<(), MyError> {
343
+ /// let mut file = File::create("my_best_friends.txt")?;
344
+ /// Ok(())
345
+ /// }
346
+ ///
347
+ /// // The previous method of quick returning Errors
334
348
/// fn write_to_file_using_try() -> Result<(), MyError> {
335
349
/// let mut file = try!(File::create("my_best_friends.txt"));
336
350
/// try!(file.write_all(b"This is a list of my best friends."));
337
- /// println!("I wrote to the file");
338
351
/// Ok(())
339
352
/// }
353
+ ///
340
354
/// // This is equivalent to:
341
355
/// fn write_to_file_using_match() -> Result<(), MyError> {
342
356
/// let mut file = try!(File::create("my_best_friends.txt"));
343
357
/// match file.write_all(b"This is a list of my best friends.") {
344
358
/// Ok(v) => v,
345
359
/// Err(e) => return Err(From::from(e)),
346
360
/// }
347
- /// println!("I wrote to the file");
348
361
/// Ok(())
349
362
/// }
350
363
/// ```
@@ -365,7 +378,7 @@ macro_rules! try {
365
378
/// formatted according to the specified format string and the result will be passed to the writer.
366
379
/// The writer may be any value with a `write_fmt` method; generally this comes from an
367
380
/// implementation of either the [`std::fmt::Write`] or the [`std::io::Write`] trait. The macro
368
- /// returns whatever the ' write_fmt' method returns; commonly a [`std::fmt::Result`], or an
381
+ /// returns whatever the ` write_fmt` method returns; commonly a [`std::fmt::Result`], or an
369
382
/// [`io::Result`].
370
383
///
371
384
/// See [`std::fmt`] for more information on the format string syntax.
@@ -470,10 +483,20 @@ macro_rules! writeln {
470
483
/// * Loops that dynamically terminate.
471
484
/// * Iterators that dynamically terminate.
472
485
///
486
+ /// If the determination that the code is unreachable proves incorrect, the
487
+ /// program immediately terminates with a [`panic!`]. The function [`unreachable`],
488
+ /// which belongs to the [`std::intrinsics`] module, informs the compilier to
489
+ /// optimize the code out of the release version entirely.
490
+ ///
491
+ /// [`panic!`]: ../std/macro.panic.html
492
+ /// [`unreachable`]: ../std/intrinsics/fn.unreachable.html
493
+ /// [`std::intrinsics`]: ../std/intrinsics/index.html
494
+ ///
473
495
/// # Panics
474
496
///
475
- /// This will always [panic!](macro.panic.html)
497
+ /// This will always [` panic!`]
476
498
///
499
+ /// [`panic!`]: ../std/macro.panic.html
477
500
/// # Examples
478
501
///
479
502
/// Match arms:
@@ -516,13 +539,18 @@ macro_rules! unreachable {
516
539
} ) ;
517
540
}
518
541
519
- /// A standardized placeholder for marking unfinished code. It panics with the
520
- /// message `"not yet implemented"` when executed.
542
+ /// A standardized placeholder for marking unfinished code.
543
+ ///
544
+ /// It panics with the message `"not yet implemented"` when executed.
521
545
///
522
546
/// This can be useful if you are prototyping and are just looking to have your
523
547
/// code typecheck, or if you're implementing a trait that requires multiple
524
548
/// methods, and you're only planning on using one of them.
525
549
///
550
+ /// # Panics
551
+ ///
552
+ /// This macro always panics.
553
+ ///
526
554
/// # Examples
527
555
///
528
556
/// Here's an example of some in-progress code. We have a trait `Foo`:
0 commit comments