File tree 2 files changed +12
-7
lines changed
doc/unstable-book/src/language-features
2 files changed +12
-7
lines changed Original file line number Diff line number Diff line change @@ -6,18 +6,23 @@ The tracking issue for this feature is: [#44495]
6
6
7
7
------------------------
8
8
9
- This feature changes the way that the irrefutable pattern is handled
10
- in the ` if let ` and ` while let ` forms. The old way was to always error
11
- but now with a tag the error-by-default lint can be switched off.
9
+ This feature changes the way that "irrefutable patterns" are handled
10
+ in the ` if let ` and ` while let ` forms. An * irrefutable pattern* is one
11
+ that cannot fail to match -- for example, the ` _ ` pattern matches any
12
+ value, and hence it is "irrefutable". Without this feature, using an
13
+ irrefutable pattern in an ` if let ` gives a hard error (since often
14
+ this indicates programmer error). But when the feature is enabled, the
15
+ error becomes a lint (since in some cases irrefutable patterns are
16
+ expected). This means you can use ` #[allow] ` to silence the lint:
12
17
13
18
``` rust
14
19
#![feature(irrefutable_let_patterns)]
15
20
21
+ #[allow(irrefutable_let_patterns)]
16
22
fn main () {
17
- #[allow(irrefutable_let_patterns)]
23
+ // These two examples used to be errors, but now they
24
+ // trigger a lint (that is allowed):
18
25
if let _ = 5 {}
19
-
20
- #[allow(irrefutable_let_patterns)]
21
26
while let _ = 5 {}
22
27
}
23
28
```
Original file line number Diff line number Diff line change @@ -2597,7 +2597,7 @@ impl<'a> Parser<'a> {
2597
2597
attrs. extend :: < Vec < _ > > ( expr. attrs . into ( ) ) ;
2598
2598
expr. attrs = attrs;
2599
2599
match expr. node {
2600
- ExprKind :: If ( ..) => {
2600
+ ExprKind :: If ( ..) | ExprKind :: IfLet ( .. ) => {
2601
2601
if !expr. attrs . is_empty ( ) {
2602
2602
// Just point to the first attribute in there...
2603
2603
let span = expr. attrs [ 0 ] . span ;
You can’t perform that action at this time.
0 commit comments