Skip to content

Commit 3f428cc

Browse files
Update diagnostics.rs
1 parent 264d365 commit 3f428cc

File tree

1 file changed

+57
-43
lines changed

1 file changed

+57
-43
lines changed

src/librustc/diagnostics.rs

+57-43
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,12 @@ enum Method {
278278
279279
you would match it using:
280280
281+
```
281282
match m {
282283
Method::GET => ...
283284
Method::POST => ...
284285
}
286+
```
285287
286288
If you don't qualify the names, the code will bind new variables named "GET" and
287289
"POST" instead. This behavior is likely not what you want, so rustc warns when
@@ -290,8 +292,10 @@ that happens.
290292
Qualified names are good practice, and most code works well with them. But if
291293
you prefer them unqualified, you can import the variants into scope:
292294
293-
use Method::*;
294-
enum Method { GET, POST }
295+
```
296+
use Method::*;
297+
enum Method { GET, POST }
298+
```
295299
"##,
296300

297301
E0267: r##"
@@ -311,7 +315,9 @@ E0296: r##"
311315
This error indicates that the given recursion limit could not be parsed. Ensure
312316
that the value provided is a positive integer between quotes, like so:
313317
314-
#![recursion_limit="1000"]
318+
```
319+
#![recursion_limit="1000"]
320+
```
315321
"##,
316322

317323
E0297: r##"
@@ -320,25 +326,27 @@ that a name will be extracted in all cases. Instead of pattern matching the
320326
loop variable, consider using a `match` or `if let` inside the loop body. For
321327
instance:
322328
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 => ...
334340
}
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+
...
341347
}
348+
}
349+
```
342350
"##,
343351

344352
E0301: r##"
@@ -348,11 +356,13 @@ on which the match depends in such a way, that the match would not be
348356
exhaustive. For instance, the following would not match any arm if mutable
349357
borrows were allowed:
350358
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+
```
356366
"##,
357367

358368
E0302: r##"
@@ -362,32 +372,36 @@ on which the match depends in such a way, that the match would not be
362372
exhaustive. For instance, the following would not match any arm if assignments
363373
were allowed:
364374
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+
```
370382
"##,
371383

372384
E0303: r##"
373385
In certain cases it is possible for sub-bindings to violate memory safety.
374386
Updates to the borrow checker in a future version of Rust may remove this
375387
restriction, but for now patterns must be rewritten without sub-bindings.
376388
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+
...
390401
}
402+
None => ...
403+
}
404+
```
391405
392406
The `op_string_ref` binding has type &Option<&String> in both cases.
393407

0 commit comments

Comments
 (0)