Skip to content

Commit 4c34693

Browse files
committed
or-patterns: fix problems in typeck.
1 parent 89bbef3 commit 4c34693

File tree

1 file changed

+15
-6
lines changed
  • src/librustc_typeck/check

1 file changed

+15
-6
lines changed

src/librustc_typeck/check/pat.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9797
self.check_pat_struct(pat, qpath, fields, *etc, expected, def_bm, discrim_span)
9898
}
9999
PatKind::Or(pats) => {
100-
let expected_ty = self.structurally_resolved_type(pat.span, expected);
101100
for pat in pats {
102101
self.check_pat(pat, expected, def_bm, discrim_span);
103102
}
104-
expected_ty
103+
expected
105104
}
106105
PatKind::Tuple(elements, ddpos) => {
107106
self.check_pat_tuple(pat.span, elements, *ddpos, expected, def_bm, discrim_span)
@@ -208,7 +207,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
208207
match pat.node {
209208
PatKind::Struct(..) |
210209
PatKind::TupleStruct(..) |
211-
PatKind::Or(_) |
212210
PatKind::Tuple(..) |
213211
PatKind::Box(_) |
214212
PatKind::Range(..) |
@@ -226,6 +224,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
226224
_ => true,
227225
}
228226
}
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(_) |
229239
PatKind::Wild |
230240
PatKind::Binding(..) |
231241
PatKind::Ref(..) => false,
@@ -426,12 +436,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
426436
// If the binding is like `ref x | ref const x | ref mut x`
427437
// then `x` is assigned a value of type `&M T` where M is the
428438
// mutability and T is the expected type.
429-
let region_ty = self.new_ref_ty(pat.span, mutbl, expected);
430-
439+
//
431440
// `x` is assigned a value of type `&M T`, hence `&M T <: typeof(x)`
432441
// is required. However, we use equality, which is stronger.
433442
// See (note_1) for an explanation.
434-
region_ty
443+
self.new_ref_ty(pat.span, mutbl, expected)
435444
}
436445
// Otherwise, the type of x is the expected type `T`.
437446
ty::BindByValue(_) => {

0 commit comments

Comments
 (0)