@@ -97,11 +97,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
97
97
self . check_pat_struct ( pat, qpath, fields, * etc, expected, def_bm, discrim_span)
98
98
}
99
99
PatKind :: Or ( pats) => {
100
- let expected_ty = self . structurally_resolved_type ( pat. span , expected) ;
101
100
for pat in pats {
102
101
self . check_pat ( pat, expected, def_bm, discrim_span) ;
103
102
}
104
- expected_ty
103
+ expected
105
104
}
106
105
PatKind :: Tuple ( elements, ddpos) => {
107
106
self . check_pat_tuple ( pat. span , elements, * ddpos, expected, def_bm, discrim_span)
@@ -208,7 +207,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
208
207
match pat. node {
209
208
PatKind :: Struct ( ..) |
210
209
PatKind :: TupleStruct ( ..) |
211
- PatKind :: Or ( _) |
212
210
PatKind :: Tuple ( ..) |
213
211
PatKind :: Box ( _) |
214
212
PatKind :: Range ( ..) |
@@ -226,6 +224,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
226
224
_ => true ,
227
225
}
228
226
}
227
+ // FIXME(or_patterns; Centril | dlrobertson): To keep things compiling
228
+ // for or-patterns at the top level, we need to make `p_0 | ... | p_n`
229
+ // a "non reference pattern". For example the following currently compiles:
230
+ // ```
231
+ // match &1 {
232
+ // e @ &(1...2) | e @ &(3...4) => {}
233
+ // _ => {}
234
+ // }
235
+ // ```
236
+ //
237
+ // We should consider whether we should do something special in nested or-patterns.
238
+ PatKind :: Or ( _) |
229
239
PatKind :: Wild |
230
240
PatKind :: Binding ( ..) |
231
241
PatKind :: Ref ( ..) => false ,
@@ -426,12 +436,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
426
436
// If the binding is like `ref x | ref const x | ref mut x`
427
437
// then `x` is assigned a value of type `&M T` where M is the
428
438
// mutability and T is the expected type.
429
- let region_ty = self . new_ref_ty ( pat. span , mutbl, expected) ;
430
-
439
+ //
431
440
// `x` is assigned a value of type `&M T`, hence `&M T <: typeof(x)`
432
441
// is required. However, we use equality, which is stronger.
433
442
// See (note_1) for an explanation.
434
- region_ty
443
+ self . new_ref_ty ( pat . span , mutbl , expected )
435
444
}
436
445
// Otherwise, the type of x is the expected type `T`.
437
446
ty:: BindByValue ( _) => {
0 commit comments