File tree 2 files changed +42
-1
lines changed
2 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,6 @@ language: rust
2
2
rust :
3
3
- beta
4
4
- stable
5
- - 1.7 .0
5
+ - 1.11 .0
6
6
script :
7
7
- cargo test
Original file line number Diff line number Diff line change 99
99
//! }
100
100
//! ```
101
101
//!
102
+ //! ## Type ascription
103
+ //!
104
+ //! ```rust,ignore
105
+ //! let mut x = some_generic_computation();
106
+ //! if_chain! {
107
+ //! if x > 7;
108
+ //! let y: u32 = another_generic_computation();
109
+ //! then { x += y }
110
+ //! else { x += 1 }
111
+ //! }
112
+ //! ```
113
+ //!
114
+ //! becomes
115
+ //!
116
+ //! ```rust,ignore
117
+ //! let mut x = some_generic_computation();
118
+ //! if x > 7 {
119
+ //! let y: u32 = another_generic_computation();
120
+ //! x += y
121
+ //! } else {
122
+ //! x += 1
123
+ //! }
124
+ //! ```
125
+ //!
102
126
//! ## Multiple patterns
103
127
//!
104
128
//! ```rust,ignore
@@ -152,6 +176,10 @@ macro_rules! __if_chain {
152
176
$( $pat) |+ => __if_chain! { @expand $other $( $tt) + }
153
177
}
154
178
} ;
179
+ ( @expand $other: block let $ident: ident: $ty: ty = $expr: expr; $( $tt: tt) +) => {
180
+ let $ident: $ty = $expr;
181
+ __if_chain! { @expand $other $( $tt) + }
182
+ } ;
155
183
( @expand $other: block if let $( $pat: pat) |+ = $expr: expr; $( $tt: tt) +) => {
156
184
match $expr {
157
185
$( $pat) |+ => __if_chain! { @expand $other $( $tt) + } ,
@@ -236,4 +264,17 @@ mod tests {
236
264
else { panic!( ) ; }
237
265
}
238
266
}
267
+
268
+ #[ test]
269
+ fn let_type_annotation_patterns ( ) {
270
+ let mut x = 1 ;
271
+ if_chain ! {
272
+ if x > 0 ;
273
+ let y: u32 = 2 ;
274
+
275
+ then { x += y; }
276
+ else { x += 1 ; }
277
+ } ;
278
+ assert_eq ! ( x, 3 ) ;
279
+ }
239
280
}
You can’t perform that action at this time.
0 commit comments