|
13 | 13 | //! testing a value against a constant. |
14 | 14 |
|
15 | 15 | use crate::build::expr::as_place::PlaceBuilder; |
16 | | -use crate::build::matches::{Ascription, Binding, Candidate, MatchPair}; |
| 16 | +use crate::build::matches::{Ascription, Binding, Candidate, MatchPair, TestCase}; |
17 | 17 | use crate::build::Builder; |
18 | 18 | use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; |
19 | 19 | use rustc_middle::thir::{self, *}; |
@@ -128,14 +128,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { |
128 | 128 | ascriptions: &mut Vec<Ascription<'tcx>>, |
129 | 129 | match_pairs: &mut Vec<MatchPair<'pat, 'tcx>>, |
130 | 130 | ) -> Result<(), MatchPair<'pat, 'tcx>> { |
| 131 | + // Collect bindings and ascriptions. |
131 | 132 | match match_pair.pattern.kind { |
132 | | - PatKind::Leaf { .. } |
133 | | - | PatKind::Deref { .. } |
134 | | - | PatKind::Array { .. } |
135 | | - | PatKind::Never |
136 | | - | PatKind::Wild |
137 | | - | PatKind::Error(_) => {} |
138 | | - |
139 | 133 | PatKind::AscribeUserType { |
140 | 134 | ascription: thir::Ascription { ref annotation, variance }, |
141 | 135 | .. |
@@ -203,47 +197,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { |
203 | 197 | } |
204 | 198 | } |
205 | 199 |
|
206 | | - PatKind::Constant { .. } => { |
207 | | - // FIXME normalize patterns when possible |
208 | | - return Err(match_pair); |
209 | | - } |
210 | | - |
211 | | - PatKind::Range(ref range) => { |
212 | | - if range.is_full_range(self.tcx) != Some(true) { |
213 | | - return Err(match_pair); |
214 | | - } |
215 | | - } |
216 | | - |
217 | | - PatKind::Slice { ref prefix, ref slice, ref suffix } => { |
218 | | - if !(prefix.is_empty() && slice.is_some() && suffix.is_empty()) { |
219 | | - self.simplify_match_pairs(&mut match_pair.subpairs, bindings, ascriptions); |
220 | | - return Err(match_pair); |
221 | | - } |
222 | | - } |
223 | | - |
224 | | - PatKind::Variant { adt_def, args, variant_index, subpatterns: _ } => { |
225 | | - let irrefutable = adt_def.variants().iter_enumerated().all(|(i, v)| { |
226 | | - i == variant_index || { |
227 | | - (self.tcx.features().exhaustive_patterns |
228 | | - || self.tcx.features().min_exhaustive_patterns) |
229 | | - && !v |
230 | | - .inhabited_predicate(self.tcx, adt_def) |
231 | | - .instantiate(self.tcx, args) |
232 | | - .apply_ignore_module(self.tcx, self.param_env) |
233 | | - } |
234 | | - }) && (adt_def.did().is_local() |
235 | | - || !adt_def.is_variant_list_non_exhaustive()); |
236 | | - if !irrefutable { |
237 | | - self.simplify_match_pairs(&mut match_pair.subpairs, bindings, ascriptions); |
238 | | - return Err(match_pair); |
239 | | - } |
240 | | - } |
241 | | - |
242 | | - PatKind::Or { .. } => return Err(match_pair), |
| 200 | + _ => {} |
243 | 201 | } |
244 | 202 |
|
245 | | - // Simplifiable pattern; we replace it with its subpairs. |
246 | | - match_pairs.append(&mut match_pair.subpairs); |
247 | | - Ok(()) |
| 203 | + if let TestCase::Irrefutable = match_pair.test_case { |
| 204 | + // Simplifiable pattern; we replace it with its subpairs. |
| 205 | + match_pairs.append(&mut match_pair.subpairs); |
| 206 | + Ok(()) |
| 207 | + } else { |
| 208 | + // Unsimplifiable pattern; we recursively simplify its subpairs. |
| 209 | + self.simplify_match_pairs(&mut match_pair.subpairs, bindings, ascriptions); |
| 210 | + Err(match_pair) |
| 211 | + } |
248 | 212 | } |
249 | 213 | } |
0 commit comments