@@ -278,10 +278,12 @@ enum Method {
278
278
279
279
you would match it using:
280
280
281
+ ```
281
282
match m {
282
283
Method::GET => ...
283
284
Method::POST => ...
284
285
}
286
+ ```
285
287
286
288
If you don't qualify the names, the code will bind new variables named "GET" and
287
289
"POST" instead. This behavior is likely not what you want, so rustc warns when
@@ -290,8 +292,10 @@ that happens.
290
292
Qualified names are good practice, and most code works well with them. But if
291
293
you prefer them unqualified, you can import the variants into scope:
292
294
293
- use Method::*;
294
- enum Method { GET, POST }
295
+ ```
296
+ use Method::*;
297
+ enum Method { GET, POST }
298
+ ```
295
299
"## ,
296
300
297
301
E0267 : r##"
@@ -311,7 +315,9 @@ E0296: r##"
311
315
This error indicates that the given recursion limit could not be parsed. Ensure
312
316
that the value provided is a positive integer between quotes, like so:
313
317
314
- #![recursion_limit="1000"]
318
+ ```
319
+ #![recursion_limit="1000"]
320
+ ```
315
321
"## ,
316
322
317
323
E0297 : r##"
@@ -320,25 +326,27 @@ that a name will be extracted in all cases. Instead of pattern matching the
320
326
loop variable, consider using a `match` or `if let` inside the loop body. For
321
327
instance:
322
328
323
- // This fails because `None` is not covered.
324
- for Some(x) in xs {
325
- ...
326
- }
327
-
328
- // Match inside the loop instead:
329
- for item in xs {
330
- match item {
331
- Some(x) => ...
332
- None => ...
333
- }
329
+ ```
330
+ // This fails because `None` is not covered.
331
+ for Some(x) in xs {
332
+ ...
333
+ }
334
+
335
+ // Match inside the loop instead:
336
+ for item in xs {
337
+ match item {
338
+ Some(x) => ...
339
+ None => ...
334
340
}
335
-
336
- // Or use `if let`:
337
- for item in xs {
338
- if let Some(x) = item {
339
- ...
340
- }
341
+ }
342
+
343
+ // Or use `if let`:
344
+ for item in xs {
345
+ if let Some(x) = item {
346
+ ...
341
347
}
348
+ }
349
+ ```
342
350
"## ,
343
351
344
352
E0301 : r##"
@@ -348,11 +356,13 @@ on which the match depends in such a way, that the match would not be
348
356
exhaustive. For instance, the following would not match any arm if mutable
349
357
borrows were allowed:
350
358
351
- match Some(()) {
352
- None => { },
353
- option if option.take().is_none() => { /* impossible, option is `Some` */ },
354
- Some(_) => { } // When the previous match failed, the option became `None`.
355
- }
359
+ ```
360
+ match Some(()) {
361
+ None => { },
362
+ option if option.take().is_none() => { /* impossible, option is `Some` */ },
363
+ Some(_) => { } // When the previous match failed, the option became `None`.
364
+ }
365
+ ```
356
366
"## ,
357
367
358
368
E0302 : r##"
@@ -362,32 +372,36 @@ on which the match depends in such a way, that the match would not be
362
372
exhaustive. For instance, the following would not match any arm if assignments
363
373
were allowed:
364
374
365
- match Some(()) {
366
- None => { },
367
- option if { option = None; false } { },
368
- Some(_) => { } // When the previous match failed, the option became `None`.
369
- }
375
+ ```
376
+ match Some(()) {
377
+ None => { },
378
+ option if { option = None; false } { },
379
+ Some(_) => { } // When the previous match failed, the option became `None`.
380
+ }
381
+ ```
370
382
"## ,
371
383
372
384
E0303 : r##"
373
385
In certain cases it is possible for sub-bindings to violate memory safety.
374
386
Updates to the borrow checker in a future version of Rust may remove this
375
387
restriction, but for now patterns must be rewritten without sub-bindings.
376
388
377
- // Code like this...
378
- match Some(5) {
379
- ref op_num @ Some(num) => ...
380
- None => ...
381
- }
382
-
383
- // After.
384
- match Some("hi".to_string()) {
385
- Some(ref s) => {
386
- let op_string_ref = &Some(&s);
387
- ...
388
- }
389
- None => ...
389
+ ```
390
+ // Code like this...
391
+ match Some(5) {
392
+ ref op_num @ Some(num) => ...
393
+ None => ...
394
+ }
395
+
396
+ // After.
397
+ match Some("hi".to_string()) {
398
+ Some(ref s) => {
399
+ let op_string_ref = &Some(&s);
400
+ ...
390
401
}
402
+ None => ...
403
+ }
404
+ ```
391
405
392
406
The `op_string_ref` binding has type &Option<&String> in both cases.
393
407
0 commit comments