File tree Expand file tree Collapse file tree 2 files changed +12
-7
lines changed
doc/unstable-book/src/language-features Expand file tree Collapse file tree 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]
66
77------------------------
88
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:
1217
1318``` rust
1419#![feature(irrefutable_let_patterns)]
1520
21+ #[allow(irrefutable_let_patterns)]
1622fn main () {
17- #[allow(irrefutable_let_patterns)]
23+ // These two examples used to be errors, but now they
24+ // trigger a lint (that is allowed):
1825 if let _ = 5 {}
19-
20- #[allow(irrefutable_let_patterns)]
2126 while let _ = 5 {}
2227}
2328```
Original file line number Diff line number Diff line change @@ -2597,7 +2597,7 @@ impl<'a> Parser<'a> {
25972597 attrs. extend :: < Vec < _ > > ( expr. attrs . into ( ) ) ;
25982598 expr. attrs = attrs;
25992599 match expr. node {
2600- ExprKind :: If ( ..) => {
2600+ ExprKind :: If ( ..) | ExprKind :: IfLet ( .. ) => {
26012601 if !expr. attrs . is_empty ( ) {
26022602 // Just point to the first attribute in there...
26032603 let span = expr. attrs [ 0 ] . span ;
You can’t perform that action at this time.
0 commit comments