diff options
| author | varkor <github@varkor.com> | 2019-09-26 18:42:24 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2019-09-26 18:42:24 +0100 |
| commit | ff59620734fec2f87463b193c67f482285235256 (patch) | |
| tree | 0bee70320fab73488c8770d4b7f4bc8644e12608 /src | |
| parent | 1ae3c36800e422734a12f28d4e72617f0ad805c5 (diff) | |
| download | rust-ff59620734fec2f87463b193c67f482285235256.tar.gz rust-ff59620734fec2f87463b193c67f482285235256.zip | |
Rename `hair::PatternKind` to `hair::PatKind`
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_mir/build/block.rs | 2 | ||||
| -rw-r--r-- | src/librustc_mir/build/matches/mod.rs | 24 | ||||
| -rw-r--r-- | src/librustc_mir/build/matches/simplify.rs | 22 | ||||
| -rw-r--r-- | src/librustc_mir/build/matches/test.rs | 64 | ||||
| -rw-r--r-- | src/librustc_mir/build/mod.rs | 4 | ||||
| -rw-r--r-- | src/librustc_mir/hair/cx/block.rs | 2 | ||||
| -rw-r--r-- | src/librustc_mir/hair/mod.rs | 4 | ||||
| -rw-r--r-- | src/librustc_mir/hair/pattern/_match.rs | 96 | ||||
| -rw-r--r-- | src/librustc_mir/hair/pattern/check_match.rs | 24 | ||||
| -rw-r--r-- | src/librustc_mir/hair/pattern/mod.rs | 202 |
10 files changed, 222 insertions, 222 deletions
diff --git a/src/librustc_mir/build/block.rs b/src/librustc_mir/build/block.rs index 7ea08b15b44..7353ca9285d 100644 --- a/src/librustc_mir/build/block.rs +++ b/src/librustc_mir/build/block.rs @@ -98,7 +98,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { initializer, lint_level } => { - let ignores_expr_result = if let PatternKind::Wild = *pattern.kind { + let ignores_expr_result = if let PatKind::Wild = *pattern.kind { true } else { false diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 5f1bd3e9115..288c436ae8f 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -303,7 +303,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ) -> BlockAnd<()> { match *irrefutable_pat.kind { // Optimize the case of `let x = ...` to write directly into `x` - PatternKind::Binding { + PatKind::Binding { mode: BindingMode::ByValue, var, subpattern: None, @@ -336,9 +336,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // test works with uninitialized values in a rather // dubious way, so it may be that the test is kind of // broken. - PatternKind::AscribeUserType { + PatKind::AscribeUserType { subpattern: Pattern { - kind: box PatternKind::Binding { + kind: box PatKind::Binding { mode: BindingMode::ByValue, var, subpattern: None, @@ -571,7 +571,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ) { debug!("visit_bindings: pattern={:?} pattern_user_ty={:?}", pattern, pattern_user_ty); match *pattern.kind { - PatternKind::Binding { + PatKind::Binding { mutability, name, mode, @@ -586,12 +586,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - PatternKind::Array { + PatKind::Array { ref prefix, ref slice, ref suffix, } - | PatternKind::Slice { + | PatKind::Slice { ref prefix, ref slice, ref suffix, @@ -609,13 +609,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - PatternKind::Constant { .. } | PatternKind::Range { .. } | PatternKind::Wild => {} + PatKind::Constant { .. } | PatKind::Range { .. } | PatKind::Wild => {} - PatternKind::Deref { ref subpattern } => { + PatKind::Deref { ref subpattern } => { self.visit_bindings(subpattern, pattern_user_ty.deref(), f); } - PatternKind::AscribeUserType { + PatKind::AscribeUserType { ref subpattern, ascription: hair::pattern::Ascription { ref user_ty, @@ -644,7 +644,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.visit_bindings(subpattern, subpattern_user_ty, f) } - PatternKind::Leaf { ref subpatterns } => { + PatKind::Leaf { ref subpatterns } => { for subpattern in subpatterns { let subpattern_user_ty = pattern_user_ty.clone().leaf(subpattern.field); debug!("visit_bindings: subpattern_user_ty={:?}", subpattern_user_ty); @@ -652,14 +652,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - PatternKind::Variant { adt_def, substs: _, variant_index, ref subpatterns } => { + PatKind::Variant { adt_def, substs: _, variant_index, ref subpatterns } => { for subpattern in subpatterns { let subpattern_user_ty = pattern_user_ty.clone().variant( adt_def, variant_index, subpattern.field); self.visit_bindings(&subpattern.pattern, subpattern_user_ty, f); } } - PatternKind::Or { ref pats } => { + PatKind::Or { ref pats } => { for pat in pats { self.visit_bindings(&pat, pattern_user_ty.clone(), f); } diff --git a/src/librustc_mir/build/matches/simplify.rs b/src/librustc_mir/build/matches/simplify.rs index 224b1a2b4ef..38e23d3076b 100644 --- a/src/librustc_mir/build/matches/simplify.rs +++ b/src/librustc_mir/build/matches/simplify.rs @@ -57,7 +57,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { -> Result<(), MatchPair<'pat, 'tcx>> { let tcx = self.hir.tcx(); match *match_pair.pattern.kind { - PatternKind::AscribeUserType { + PatKind::AscribeUserType { ref subpattern, ascription: hair::pattern::Ascription { variance, @@ -79,12 +79,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { Ok(()) } - PatternKind::Wild => { + PatKind::Wild => { // nothing left to do Ok(()) } - PatternKind::Binding { name, mutability, mode, var, ty, ref subpattern } => { + PatKind::Binding { name, mutability, mode, var, ty, ref subpattern } => { candidate.bindings.push(Binding { name, mutability, @@ -103,12 +103,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { Ok(()) } - PatternKind::Constant { .. } => { + PatKind::Constant { .. } => { // FIXME normalize patterns when possible Err(match_pair) } - PatternKind::Range(PatternRange { lo, hi, end }) => { + PatKind::Range(PatternRange { lo, hi, end }) => { let (range, bias) = match lo.ty.kind { ty::Char => { (Some(('\u{0000}' as u128, '\u{10FFFF}' as u128, Size::from_bits(32))), 0) @@ -144,7 +144,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { Err(match_pair) } - PatternKind::Slice { ref prefix, ref slice, ref suffix } => { + PatKind::Slice { ref prefix, ref slice, ref suffix } => { if prefix.is_empty() && slice.is_some() && suffix.is_empty() { // irrefutable self.prefix_slice_suffix(&mut candidate.match_pairs, @@ -158,7 +158,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - PatternKind::Variant { adt_def, substs, variant_index, ref subpatterns } => { + PatKind::Variant { adt_def, substs, variant_index, ref subpatterns } => { let irrefutable = adt_def.variants.iter_enumerated().all(|(i, v)| { i == variant_index || { self.hir.tcx().features().exhaustive_patterns && @@ -174,7 +174,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - PatternKind::Array { ref prefix, ref slice, ref suffix } => { + PatKind::Array { ref prefix, ref slice, ref suffix } => { self.prefix_slice_suffix(&mut candidate.match_pairs, &match_pair.place, prefix, @@ -183,20 +183,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { Ok(()) } - PatternKind::Leaf { ref subpatterns } => { + PatKind::Leaf { ref subpatterns } => { // tuple struct, match subpats (if any) candidate.match_pairs .extend(self.field_match_pairs(match_pair.place, subpatterns)); Ok(()) } - PatternKind::Deref { ref subpattern } => { + PatKind::Deref { ref subpattern } => { let place = match_pair.place.deref(); candidate.match_pairs.push(MatchPair::new(place, subpattern)); Ok(()) } - PatternKind::Or { .. } => { + PatKind::Or { .. } => { Err(match_pair) } } diff --git a/src/librustc_mir/build/matches/test.rs b/src/librustc_mir/build/matches/test.rs index c6eb9a3916f..835f5e088a6 100644 --- a/src/librustc_mir/build/matches/test.rs +++ b/src/librustc_mir/build/matches/test.rs @@ -26,7 +26,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// It is a bug to call this with a simplifiable pattern. pub fn test<'pat>(&mut self, match_pair: &MatchPair<'pat, 'tcx>) -> Test<'tcx> { match *match_pair.pattern.kind { - PatternKind::Variant { ref adt_def, substs: _, variant_index: _, subpatterns: _ } => { + PatKind::Variant { ref adt_def, substs: _, variant_index: _, subpatterns: _ } => { Test { span: match_pair.pattern.span, kind: TestKind::Switch { @@ -36,7 +36,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - PatternKind::Constant { .. } if is_switch_ty(match_pair.pattern.ty) => { + PatKind::Constant { .. } if is_switch_ty(match_pair.pattern.ty) => { // For integers, we use a `SwitchInt` match, which allows // us to handle more cases. Test { @@ -52,7 +52,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - PatternKind::Constant { value } => { + PatKind::Constant { value } => { Test { span: match_pair.pattern.span, kind: TestKind::Eq { @@ -62,7 +62,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - PatternKind::Range(range) => { + PatKind::Range(range) => { assert_eq!(range.lo.ty, match_pair.pattern.ty); assert_eq!(range.hi.ty, match_pair.pattern.ty); Test { @@ -71,7 +71,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - PatternKind::Slice { ref prefix, ref slice, ref suffix } => { + PatKind::Slice { ref prefix, ref slice, ref suffix } => { let len = prefix.len() + suffix.len(); let op = if slice.is_some() { BinOp::Ge @@ -84,13 +84,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - PatternKind::AscribeUserType { .. } | - PatternKind::Array { .. } | - PatternKind::Wild | - PatternKind::Or { .. } | - PatternKind::Binding { .. } | - PatternKind::Leaf { .. } | - PatternKind::Deref { .. } => { + PatKind::AscribeUserType { .. } | + PatKind::Array { .. } | + PatKind::Wild | + PatKind::Or { .. } | + PatKind::Binding { .. } | + PatKind::Leaf { .. } | + PatKind::Deref { .. } => { self.error_simplifyable(match_pair) } } @@ -110,7 +110,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }; match *match_pair.pattern.kind { - PatternKind::Constant { value } => { + PatKind::Constant { value } => { indices.entry(value) .or_insert_with(|| { options.push(value.eval_bits( @@ -120,22 +120,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }); true } - PatternKind::Variant { .. } => { + PatKind::Variant { .. } => { panic!("you should have called add_variants_to_switch instead!"); } - PatternKind::Range(range) => { + PatKind::Range(range) => { // Check that none of the switch values are in the range. self.values_not_contained_in_range(range, indices) .unwrap_or(false) } - PatternKind::Slice { .. } | - PatternKind::Array { .. } | - PatternKind::Wild | - PatternKind::Or { .. } | - PatternKind::Binding { .. } | - PatternKind::AscribeUserType { .. } | - PatternKind::Leaf { .. } | - PatternKind::Deref { .. } => { + PatKind::Slice { .. } | + PatKind::Array { .. } | + PatKind::Wild | + PatKind::Or { .. } | + PatKind::Binding { .. } | + PatKind::AscribeUserType { .. } | + PatKind::Leaf { .. } | + PatKind::Deref { .. } => { // don't know how to add these patterns to a switch false } @@ -154,7 +154,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }; match *match_pair.pattern.kind { - PatternKind::Variant { adt_def: _ , variant_index, .. } => { + PatKind::Variant { adt_def: _ , variant_index, .. } => { // We have a pattern testing for variant `variant_index` // set the corresponding index to true variants.insert(variant_index); @@ -533,7 +533,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // If we are performing a variant switch, then this // informs variant patterns, but nothing else. (&TestKind::Switch { adt_def: tested_adt_def, .. }, - &PatternKind::Variant { adt_def, variant_index, ref subpatterns, .. }) => { + &PatKind::Variant { adt_def, variant_index, ref subpatterns, .. }) => { assert_eq!(adt_def, tested_adt_def); self.candidate_after_variant_switch(match_pair_index, adt_def, @@ -548,10 +548,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // If we are performing a switch over integers, then this informs integer // equality, but nothing else. // - // FIXME(#29623) we could use PatternKind::Range to rule + // FIXME(#29623) we could use PatKind::Range to rule // things out here, in some cases. (&TestKind::SwitchInt { switch_ty: _, options: _, ref indices }, - &PatternKind::Constant { ref value }) + &PatKind::Constant { ref value }) if is_switch_ty(match_pair.pattern.ty) => { let index = indices[value]; self.candidate_without_match_pair(match_pair_index, candidate); @@ -559,7 +559,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } (&TestKind::SwitchInt { switch_ty: _, ref options, ref indices }, - &PatternKind::Range(range)) => { + &PatKind::Range(range)) => { let not_contained = self .values_not_contained_in_range(range, indices) .unwrap_or(false); @@ -577,7 +577,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { (&TestKind::SwitchInt { .. }, _) => None, (&TestKind::Len { len: test_len, op: BinOp::Eq }, - &PatternKind::Slice { ref prefix, ref slice, ref suffix }) => { + &PatKind::Slice { ref prefix, ref slice, ref suffix }) => { let pat_len = (prefix.len() + suffix.len()) as u64; match (test_len.cmp(&pat_len), slice) { (Ordering::Equal, &None) => { @@ -610,7 +610,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } (&TestKind::Len { len: test_len, op: BinOp::Ge }, - &PatternKind::Slice { ref prefix, ref slice, ref suffix }) => { + &PatKind::Slice { ref prefix, ref slice, ref suffix }) => { // the test is `$actual_len >= test_len` let pat_len = (prefix.len() + suffix.len()) as u64; match (test_len.cmp(&pat_len), slice) { @@ -644,7 +644,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } (&TestKind::Range(test), - &PatternKind::Range(pat)) => { + &PatKind::Range(pat)) => { if test == pat { self.candidate_without_match_pair( match_pair_index, @@ -683,7 +683,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - (&TestKind::Range(range), &PatternKind::Constant { value }) => { + (&TestKind::Range(range), &PatKind::Constant { value }) => { if self.const_range_contains(range, value) == Some(false) { // `value` is not contained in the testing range, // so `value` can be matched only if this test fails. diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 6b7fee6effb..f1e045302ec 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -1,7 +1,7 @@ use crate::build; use crate::build::scope::DropKind; use crate::hair::cx::Cx; -use crate::hair::{LintLevel, BindingMode, PatternKind}; +use crate::hair::{LintLevel, BindingMode, PatKind}; use crate::transform::MirSource; use crate::util as mir_util; use rustc::hir; @@ -827,7 +827,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.set_correct_source_scope_for_arg(arg.hir_id, original_source_scope, span); match *pattern.kind { // Don't introduce extra copies for simple bindings - PatternKind::Binding { + PatKind::Binding { mutability, var, mode: BindingMode::ByValue, diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index 395f5b16fa4..33b7bd59769 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -81,7 +81,7 @@ fn mirror_stmts<'a, 'tcx>( pattern = Pattern { ty: pattern.ty, span: pattern.span, - kind: Box::new(PatternKind::AscribeUserType { + kind: Box::new(PatKind::AscribeUserType { ascription: hair::pattern::Ascription { user_ty: PatternTypeProjection::from_user_type(user_ty), user_ty_span: ty.span, diff --git a/src/librustc_mir/hair/mod.rs b/src/librustc_mir/hair/mod.rs index de293308f4c..8a76ad8ee7a 100644 --- a/src/librustc_mir/hair/mod.rs +++ b/src/librustc_mir/hair/mod.rs @@ -20,7 +20,7 @@ pub mod cx; mod constant; pub mod pattern; -pub use self::pattern::{BindingMode, Pattern, PatternKind, PatternRange, FieldPat}; +pub use self::pattern::{BindingMode, Pattern, PatKind, PatternRange, FieldPat}; pub(crate) use self::pattern::PatternTypeProjection; mod util; @@ -306,7 +306,7 @@ impl Arm<'tcx> { // correctly handle each case in which this method is used. pub fn top_pats_hack(&self) -> &[Pattern<'tcx>] { match &*self.pattern.kind { - PatternKind::Or { pats } => pats, + PatKind::Or { pats } => pats, _ => std::slice::from_ref(&self.pattern), } } diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index cd1515b20da..77a3b7ab031 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -163,7 +163,7 @@ use self::WitnessPreference::*; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::indexed_vec::Idx; -use super::{FieldPat, Pattern, PatternKind, PatternRange}; +use super::{FieldPat, Pattern, PatKind, PatternRange}; use super::{PatternFoldable, PatternFolder, compare_const_vals}; use rustc::hir::def_id::DefId; @@ -248,7 +248,7 @@ impl PatternFolder<'tcx> for LiteralExpander<'tcx> { match (&pat.ty.kind, &*pat.kind) { ( &ty::Ref(_, rty, _), - &PatternKind::Constant { value: Const { + &PatKind::Constant { value: Const { val, ty: ty::TyS { kind: ty::Ref(_, crty, _), .. }, } }, @@ -256,11 +256,11 @@ impl PatternFolder<'tcx> for LiteralExpander<'tcx> { Pattern { ty: pat.ty, span: pat.span, - kind: box PatternKind::Deref { + kind: box PatKind::Deref { subpattern: Pattern { ty: rty, span: pat.span, - kind: box PatternKind::Constant { value: self.tcx.mk_const(Const { + kind: box PatKind::Constant { value: self.tcx.mk_const(Const { val: self.fold_const_value_deref(*val, rty, crty), ty: rty, }) }, @@ -268,7 +268,7 @@ impl PatternFolder<'tcx> for LiteralExpander<'tcx> { } } } - (_, &PatternKind::Binding { subpattern: Some(ref s), .. }) => { + (_, &PatKind::Binding { subpattern: Some(ref s), .. }) => { s.fold_with(self) } _ => pat.super_fold_with(self) @@ -279,7 +279,7 @@ impl PatternFolder<'tcx> for LiteralExpander<'tcx> { impl<'tcx> Pattern<'tcx> { fn is_wildcard(&self) -> bool { match *self.kind { - PatternKind::Binding { subpattern: None, .. } | PatternKind::Wild => + PatKind::Binding { subpattern: None, .. } | PatKind::Wild => true, _ => false } @@ -397,7 +397,7 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> { fn is_non_exhaustive_variant<'p>(&self, pattern: &'p Pattern<'tcx>) -> bool { match *pattern.kind { - PatternKind::Variant { adt_def, variant_index, .. } => { + PatKind::Variant { adt_def, variant_index, .. } => { let ref variant = adt_def.variants[variant_index]; variant.is_field_list_non_exhaustive() } @@ -534,7 +534,7 @@ impl<'tcx> Witness<'tcx> { Pattern { ty, span: DUMMY_SP, - kind: box PatternKind::Wild, + kind: box PatKind::Wild, } })); self.apply_constructor(cx, ctor, ty) @@ -577,26 +577,26 @@ impl<'tcx> Witness<'tcx> { if let ty::Adt(adt, substs) = ty.kind { if adt.is_enum() { - PatternKind::Variant { + PatKind::Variant { adt_def: adt, substs, variant_index: ctor.variant_index_for_adt(cx, adt), subpatterns: pats } } else { - PatternKind::Leaf { subpatterns: pats } + PatKind::Leaf { subpatterns: pats } } } else { - PatternKind::Leaf { subpatterns: pats } + PatKind::Leaf { subpatterns: pats } } } ty::Ref(..) => { - PatternKind::Deref { subpattern: pats.nth(0).unwrap() } + PatKind::Deref { subpattern: pats.nth(0).unwrap() } } ty::Slice(_) | ty::Array(..) => { - PatternKind::Slice { + PatKind::Slice { prefix: pats.collect(), slice: None, suffix: vec![] @@ -605,13 +605,13 @@ impl<'tcx> Witness<'tcx> { _ => { match *ctor { - ConstantValue(value) => PatternKind::Constant { value }, - ConstantRange(lo, hi, ty, end) => PatternKind::Range(PatternRange { + ConstantValue(value) => PatKind::Constant { value }, + ConstantRange(lo, hi, ty, end) => PatKind::Range(PatternRange { lo: ty::Const::from_bits(cx.tcx, lo, ty::ParamEnv::empty().and(ty)), hi: ty::Const::from_bits(cx.tcx, hi, ty::ParamEnv::empty().and(ty)), end, }), - _ => PatternKind::Wild, + _ => PatKind::Wild, } } } @@ -783,7 +783,7 @@ where for row in patterns { match *row.kind { - PatternKind::Constant { value } => { + PatKind::Constant { value } => { // extract the length of an array/slice from a constant match (value.val, &value.ty.kind) { (_, ty::Array(_, n)) => max_fixed_len = cmp::max( @@ -797,11 +797,11 @@ where _ => {}, } } - PatternKind::Slice { ref prefix, slice: None, ref suffix } => { + PatKind::Slice { ref prefix, slice: None, ref suffix } => { let fixed_len = prefix.len() as u64 + suffix.len() as u64; max_fixed_len = cmp::max(max_fixed_len, fixed_len); } - PatternKind::Slice { ref prefix, slice: Some(_), ref suffix } => { + PatKind::Slice { ref prefix, slice: Some(_), ref suffix } => { max_prefix_len = cmp::max(max_prefix_len, prefix.len() as u64); max_suffix_len = cmp::max(max_suffix_len, suffix.len() as u64); } @@ -878,14 +878,14 @@ impl<'tcx> IntRange<'tcx> { ) -> Option<IntRange<'tcx>> { let range = loop { match pat.kind { - box PatternKind::Constant { value } => break ConstantValue(value), - box PatternKind::Range(PatternRange { lo, hi, end }) => break ConstantRange( + box PatKind::Constant { value } => break ConstantValue(value), + box PatKind::Range(PatternRange { lo, hi, end }) => break ConstantRange( lo.eval_bits(tcx, param_env, lo.ty), hi.eval_bits(tcx, param_env, hi.ty), lo.ty, end, ), - box PatternKind::AscribeUserType { ref subpattern, .. } => { + box PatKind::AscribeUserType { ref subpattern, .. } => { pat = subpattern; }, _ => return None, @@ -1058,7 +1058,7 @@ fn compute_missing_ctors<'tcx>( /// inputs that will match `v` but not any of the sets in `m`. /// /// All the patterns at each column of the `matrix ++ v` matrix must -/// have the same type, except that wildcard (PatternKind::Wild) patterns +/// have the same type, except that wildcard (PatKind::Wild) patterns /// with type `TyErr` are also allowed, even if the "type of the column" /// is not `TyErr`. That is used to represent private fields, as using their /// real type would assert that they are inhabited. @@ -1250,7 +1250,7 @@ pub fn is_useful<'p, 'a, 'tcx>( witness.0.push(Pattern { ty: pcx.ty, span: DUMMY_SP, - kind: box PatternKind::Wild, + kind: box PatKind::Wild, }); witness }).collect() @@ -1296,7 +1296,7 @@ fn is_useful_specialized<'p, 'a, 'tcx>( Pattern { ty, span: DUMMY_SP, - kind: box PatternKind::Wild, + kind: box PatKind::Wild, } }).collect(); let wild_patterns: Vec<_> = wild_patterns_owned.iter().collect(); @@ -1330,28 +1330,28 @@ fn pat_constructors<'tcx>(cx: &mut MatchCheckCtxt<'_, 'tcx>, -> Option<Vec<Constructor<'tcx>>> { match *pat.kind { - PatternKind::AscribeUserType { ref subpattern, .. } => + PatKind::AscribeUserType { ref subpattern, .. } => pat_constructors(cx, subpattern, pcx), - PatternKind::Binding { .. } | PatternKind::Wild => None, - PatternKind::Leaf { .. } | PatternKind::Deref { .. } => Some(vec![Single]), - PatternKind::Variant { adt_def, variant_index, .. } => { + PatKind::Binding { .. } | PatKind::Wild => None, + PatKind::Leaf { .. } | PatKind::Deref { .. } => Some(vec![Single]), + PatKind::Variant { adt_def, variant_index, .. } => { Some(vec![Variant(adt_def.variants[variant_index].def_id)]) } - PatternKind::Constant { value } => Some(vec![ConstantValue(value)]), - PatternKind::Range(PatternRange { lo, hi, end }) => + PatKind::Constant { value } => Some(vec![ConstantValue(value)]), + PatKind::Range(PatternRange { lo, hi, end }) => Some(vec![ConstantRange( lo.eval_bits(cx.tcx, cx.param_env, lo.ty), hi.eval_bits(cx.tcx, cx.param_env, hi.ty), lo.ty, end, )]), - PatternKind::Array { .. } => match pcx.ty.kind { + PatKind::Array { .. } => match pcx.ty.kind { ty::Array(_, length) => Some(vec![ Slice(length.eval_usize(cx.tcx, cx.param_env)) ]), _ => span_bug!(pat.span, "bad ty {:?} for array pattern", pcx.ty) }, - PatternKind::Slice { ref prefix, ref slice, ref suffix } => { + PatKind::Slice { ref prefix, ref slice, ref suffix } => { let pat_len = prefix.len() as u64 + suffix.len() as u64; if slice.is_some() { Some((pat_len..pcx.max_slice_length+1).map(Slice).collect()) @@ -1359,7 +1359,7 @@ fn pat_constructors<'tcx>(cx: &mut MatchCheckCtxt<'_, 'tcx>, Some(vec![Slice(pat_len)]) } } - PatternKind::Or { .. } => { + PatKind::Or { .. } => { bug!("support for or-patterns has not been fully implemented yet."); } } @@ -1481,7 +1481,7 @@ fn slice_pat_covered_by_const<'tcx>( data[data.len()-suffix.len()..].iter().zip(suffix)) { match pat.kind { - box PatternKind::Constant { value } => { + box PatKind::Constant { value } => { let b = value.eval_bits(tcx, param_env, pat.ty); assert_eq!(b as u8 as u128, b); if b as u8 != *ch { @@ -1657,8 +1657,8 @@ fn constructor_covered_by_range<'tcx>( pat: &Pattern<'tcx>, ) -> Result<bool, ErrorReported> { let (from, to, end, ty) = match pat.kind { - box PatternKind::Constant { value } => (value, value, RangeEnd::Included, value.ty), - box PatternKind::Range(PatternRange { lo, hi, end }) => (lo, hi, end, lo.ty), + box PatKind::Constant { value } => (value, value, RangeEnd::Included, value.ty), + box PatKind::Range(PatternRange { lo, hi, end }) => (lo, hi, end, lo.ty), _ => bug!("`constructor_covered_by_range` called with {:?}", pat), }; trace!("constructor_covered_by_range {:#?}, {:#?}, {:#?}, {}", ctor, from, to, ty); @@ -1745,30 +1745,30 @@ fn specialize<'p, 'a: 'p, 'tcx>( let pat = &r[0]; let head = match *pat.kind { - PatternKind::AscribeUserType { ref subpattern, .. } => { + PatKind::AscribeUserType { ref subpattern, .. } => { specialize(cx, ::std::slice::from_ref(&subpattern), constructor, wild_patterns) } - PatternKind::Binding { .. } | PatternKind::Wild => { + PatKind::Binding { .. } | PatKind::Wild => { Some(SmallVec::from_slice(wild_patterns)) } - PatternKind::Variant { adt_def, variant_index, ref subpatterns, .. } => { + PatKind::Variant { adt_def, variant_index, ref subpatterns, .. } => { let ref variant = adt_def.variants[variant_index]; Some(Variant(variant.def_id)) .filter(|variant_constructor| variant_constructor == constructor) .map(|_| patterns_for_variant(subpatterns, wild_patterns)) } - PatternKind::Leaf { ref subpatterns } => { + PatKind::Leaf { ref subpatterns } => { Some(patterns_for_variant(subpatterns, wild_patterns)) } - PatternKind::Deref { ref subpattern } => { + PatKind::Deref { ref subpattern } => { Some(smallvec![subpattern]) } - PatternKind::Constant { value } => { + PatKind::Constant { value } => { match *constructor { Slice(..) => { // we extract an `Option` for the pointer because slices of zero elements don't @@ -1830,7 +1830,7 @@ fn specialize<'p, 'a: 'p, 'tcx>( let pattern = Pattern { ty, span: pat.span, - kind: box PatternKind::Constant { value }, + kind: box PatKind::Constant { value }, }; Some(&*cx.pattern_arena.alloc(pattern)) }).collect() @@ -1847,15 +1847,15 @@ fn specialize<'p, 'a: 'p, 'tcx>( } } - PatternKind::Range { .. } => { + PatKind::Range { .. } => { // If the constructor is a: // Single value: add a row if the pattern contains the constructor. // Range: add a row if the constructor intersects the pattern. constructor_intersects_pattern(cx.tcx, cx.param_env, constructor, pat) } - PatternKind::Array { ref prefix, ref slice, ref suffix } | - PatternKind::Slice { ref prefix, ref slice, ref suffix } => { + PatKind::Array { ref prefix, ref slice, ref suffix } | + PatKind::Slice { ref prefix, ref slice, ref suffix } => { match *constructor { Slice(..) => { let pat_len = prefix.len() + suffix.len(); @@ -1888,7 +1888,7 @@ fn specialize<'p, 'a: 'p, 'tcx>( } } - PatternKind::Or { .. } => { + PatKind::Or { .. } => { bug!("support for or-patterns has not been fully implemented yet."); } }; diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 822c9318dc3..c4b7661dd23 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -2,7 +2,7 @@ use super::_match::{MatchCheckCtxt, Matrix, expand_pattern, is_useful}; use super::_match::Usefulness::*; use super::_match::WitnessPreference::*; -use super::{Pattern, PatternContext, PatternError, PatternKind}; +use super::{Pattern, PatternContext, PatternError, PatKind}; use rustc::middle::borrowck::SignalledError; use rustc::session::Session; @@ -14,7 +14,7 @@ use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc::hir::def::*; use rustc::hir::def_id::DefId; use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap}; -use rustc::hir::{self, Pat, PatKind}; +use rustc::hir::{self, Pat}; use smallvec::smallvec; use std::slice; @@ -271,7 +271,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> { origin, joined_patterns ); err.span_label(pat.span, match &pat.kind { - PatKind::Path(hir::QPath::Resolved(None, path)) + hir::PatKind::Path(hir::QPath::Resolved(None, path)) if path.segments.len() == 1 && path.segments[0].args.is_none() => { format!("interpreted as {} {} pattern, not new variable", path.res.article(), path.res.descr()) @@ -286,7 +286,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> { fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pat) { pat.walk(|p| { - if let PatKind::Binding(_, _, ident, None) = p.kind { + if let hir::PatKind::Binding(_, _, ident, None) = p.kind { if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) { if bm != ty::BindByValue(hir::MutImmutable) { // Nothing to check. @@ -322,10 +322,10 @@ fn check_for_bindings_named_same_as_variants(cx: &MatchVisitor<'_, '_>, pat: &Pa /// Checks for common cases of "catchall" patterns that may not be intended as such. fn pat_is_catchall(pat: &Pat) -> bool { match pat.kind { - PatKind::Binding(.., None) => true, - PatKind::Binding(.., Some(ref s)) => pat_is_catchall(s), - PatKind::Ref(ref s, _) => pat_is_catchall(s), - PatKind::Tuple(ref v, _) => v.iter().all(|p| { + hir::PatKind::Binding(.., None) => true, + hir::PatKind::Binding(.., Some(ref s)) => pat_is_catchall(s), + hir::PatKind::Ref(ref s, _) => pat_is_catchall(s), + hir::PatKind::Tuple(ref v, _) => v.iter().all(|p| { pat_is_catchall(&p) }), _ => false @@ -421,7 +421,7 @@ fn check_not_useful( ty: Ty<'tcx>, matrix: &Matrix<'_, 'tcx>, ) -> Result<(), Vec<Pattern<'tcx>>> { - let wild_pattern = Pattern { ty, span: DUMMY_SP, kind: box PatternKind::Wild }; + let wild_pattern = Pattern { ty, span: DUMMY_SP, kind: box PatKind::Wild }; match is_useful(cx, matrix, &[&wild_pattern], ConstructWitness) { NotUseful => Ok(()), // This is good, wildcard pattern isn't reachable. UsefulWithWitness(pats) => Err(if pats.is_empty() { @@ -506,7 +506,7 @@ fn maybe_point_at_variant(ty: Ty<'_>, patterns: &[Pattern<'_>]) -> Vec<Span> { // Don't point at variants that have already been covered due to other patterns to avoid // visual clutter. for pattern in patterns { - use PatternKind::{AscribeUserType, Deref, Variant, Or, Leaf}; + use PatKind::{AscribeUserType, Deref, Variant, Or, Leaf}; match &*pattern.kind { AscribeUserType { subpattern, .. } | Deref { subpattern } => { covered.extend(maybe_point_at_variant(ty, slice::from_ref(&subpattern))); @@ -568,7 +568,7 @@ fn check_legality_of_move_bindings(cx: &mut MatchVisitor<'_, '_>, has_guard: boo }; pat.walk(|p| { - if let PatKind::Binding(.., sub) = &p.kind { + if let hir::PatKind::Binding(.., sub) = &p.kind { if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) { if let ty::BindByValue(..) = bm { let pat_ty = cx.tables.node_type(p.hir_id); @@ -619,7 +619,7 @@ impl<'v> Visitor<'v> for AtBindingPatternVisitor<'_, '_, '_> { fn visit_pat(&mut self, pat: &Pat) { match pat.kind { - PatKind::Binding(.., ref subpat) => { + hir::PatKind::Binding(.., ref subpat) => { if !self.bindings_allowed { struct_span_err!(self.cx.tcx.sess, pat.span, E0303, "pattern bindings are not allowed after an `@`") diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 751876a90bd..cffcb5b796e 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -19,7 +19,7 @@ use rustc::ty::{self, Region, TyCtxt, AdtDef, Ty, UserType, DefIdTree}; use rustc::ty::{CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations}; use rustc::ty::subst::{SubstsRef, GenericArg}; use rustc::ty::layout::{VariantIdx, Size}; -use rustc::hir::{self, PatKind, RangeEnd}; +use rustc::hir::{self, RangeEnd}; use rustc::hir::def::{CtorOf, Res, DefKind, CtorKind}; use rustc::hir::pat_util::EnumerateAndAdjustIterator; use rustc::hir::ptr::P; @@ -57,7 +57,7 @@ pub struct FieldPat<'tcx> { pub struct Pattern<'tcx> { pub ty: Ty<'tcx>, pub span: Span, - pub kind: Box<PatternKind<'tcx>>, + pub kind: Box<PatKind<'tcx>>, } @@ -116,7 +116,7 @@ pub struct Ascription<'tcx> { } #[derive(Clone, Debug)] -pub enum PatternKind<'tcx> { +pub enum PatKind<'tcx> { Wild, AscribeUserType { @@ -205,10 +205,10 @@ impl<'tcx> fmt::Display for Pattern<'tcx> { let mut start_or_comma = || start_or_continue(", "); match *self.kind { - PatternKind::Wild => write!(f, "_"), - PatternKind::AscribeUserType { ref subpattern, .. } => + PatKind::Wild => write!(f, "_"), + PatKind::AscribeUserType { ref subpattern, .. } => write!(f, "{}: _", subpattern), - PatternKind::Binding { mutability, name, mode, ref subpattern, .. } => { + PatKind::Binding { mutability, name, mode, ref subpattern, .. } => { let is_mut = match mode { BindingMode::ByValue => mutability == Mutability::Mut, BindingMode::ByRef(bk) => { @@ -225,10 +225,10 @@ impl<'tcx> fmt::Display for Pattern<'tcx> { } Ok(()) } - PatternKind::Variant { ref subpatterns, .. } | - PatternKind::Leaf { ref subpatterns } => { + PatKind::Variant { ref subpatterns, .. } | + PatKind::Leaf { ref subpatterns } => { let variant = match *self.kind { - PatternKind::Variant { adt_def, variant_index, .. } => { + PatKind::Variant { adt_def, variant_index, .. } => { Some(&adt_def.variants[variant_index]) } _ => if let ty::Adt(adt, _) = self.ty.kind { @@ -252,7 +252,7 @@ impl<'tcx> fmt::Display for Pattern<'tcx> { let mut printed = 0; for p in subpatterns { - if let PatternKind::Wild = *p.pattern.kind { + if let PatKind::Wild = *p.pattern.kind { continue; } let name = variant.fields[p.field.index()].ident; @@ -294,7 +294,7 @@ impl<'tcx> fmt::Display for Pattern<'tcx> { Ok(()) } - PatternKind::Deref { ref subpattern } => { + PatKind::Deref { ref subpattern } => { match self.ty.kind { ty::Adt(def, _) if def.is_box() => write!(f, "box ")?, ty::Ref(_, _, mutbl) => { @@ -307,10 +307,10 @@ impl<'tcx> fmt::Display for Pattern<'tcx> { } write!(f, "{}", subpattern) } - PatternKind::Constant { value } => { + PatKind::Constant { value } => { write!(f, "{}", value) } - PatternKind::Range(PatternRange { lo, hi, end }) => { + PatKind::Range(PatternRange { lo, hi, end }) => { write!(f, "{}", lo)?; match end { RangeEnd::Included => write!(f, "..=")?, @@ -318,8 +318,8 @@ impl<'tcx> fmt::Display for Pattern<'tcx> { } write!(f, "{}", hi) } - PatternKind::Slice { ref prefix, ref slice, ref suffix } | - PatternKind::Array { ref prefix, ref slice, ref suffix } => { + PatKind::Slice { ref prefix, ref slice, ref suffix } | + PatKind::Array { ref prefix, ref slice, ref suffix } => { write!(f, "[")?; for p in prefix { write!(f, "{}{}", start_or_comma(), p)?; @@ -327,7 +327,7 @@ impl<'tcx> fmt::Display for Pattern<'tcx> { if let Some(ref slice) = *slice { write!(f, "{}", start_or_comma())?; match *slice.kind { - PatternKind::Wild => {} + PatKind::Wild => {} _ => write!(f, "{}", slice)? } write!(f, "..")?; @@ -337,7 +337,7 @@ impl<'tcx> fmt::Display for Pattern<'tcx> { } write!(f, "]") } - PatternKind::Or { ref pats } => { + PatKind::Or { ref pats } => { for pat in pats { write!(f, "{}{}", start_or_continue(" | "), pat)?; } @@ -412,7 +412,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { // `vec![&&Option<i32>, &Option<i32>]`. // // Applying the adjustments, we want to instead output `&&Some(n)` (as a HAIR pattern). So - // we wrap the unadjusted pattern in `PatternKind::Deref` repeatedly, consuming the + // we wrap the unadjusted pattern in `PatKind::Deref` repeatedly, consuming the // adjustments in *reverse order* (last-in-first-out, so that the last `Deref` inserted // gets the least-dereferenced type). let unadjusted_pat = self.lower_pattern_unadjusted(pat); @@ -427,7 +427,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { Pattern { span: pat.span, ty: ref_ty, - kind: Box::new(PatternKind::Deref { subpattern: pat }), + kind: Box::new(PatKind::Deref { subpattern: pat }), } }, ) @@ -436,9 +436,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { fn lower_range_expr( &mut self, expr: &'tcx hir::Expr, - ) -> (PatternKind<'tcx>, Option<Ascription<'tcx>>) { + ) -> (PatKind<'tcx>, Option<Ascription<'tcx>>) { match self.lower_lit(expr) { - PatternKind::AscribeUserType { + PatKind::AscribeUserType { ascription: lo_ascription, subpattern: Pattern { kind: box kind, .. }, } => (kind, Some(lo_ascription)), @@ -450,16 +450,16 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { let mut ty = self.tables.node_type(pat.hir_id); let kind = match pat.kind { - PatKind::Wild => PatternKind::Wild, + hir::PatKind::Wild => PatKind::Wild, - PatKind::Lit(ref value) => self.lower_lit(value), + hir::PatKind::Lit(ref value) => self.lower_lit(value), - PatKind::Range(ref lo_expr, ref hi_expr, end) => { + hir::PatKind::Range(ref lo_expr, ref hi_expr, end) => { let (lo, lo_ascription) = self.lower_range_expr(lo_expr); let (hi, hi_ascription) = self.lower_range_expr(hi_expr); let mut kind = match (lo, hi) { - (PatternKind::Constant { value: lo }, PatternKind::Constant { value: hi }) => { + (PatKind::Constant { value: lo }, PatKind::Constant { value: hi }) => { assert_eq!(lo.ty, ty); assert_eq!(hi.ty, ty); let cmp = compare_const_vals( @@ -471,7 +471,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { ); match (end, cmp) { (RangeEnd::Excluded, Some(Ordering::Less)) => - PatternKind::Range(PatternRange { lo, hi, end }), + PatKind::Range(PatternRange { lo, hi, end }), (RangeEnd::Excluded, _) => { span_err!( self.tcx.sess, @@ -479,13 +479,13 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { E0579, "lower range bound must be less than upper", ); - PatternKind::Wild + PatKind::Wild } (RangeEnd::Included, Some(Ordering::Equal)) => { - PatternKind::Constant { value: lo } + PatKind::Constant { value: lo } } (RangeEnd::Included, Some(Ordering::Less)) => { - PatternKind::Range(PatternRange { lo, hi, end }) + PatKind::Range(PatternRange { lo, hi, end }) } (RangeEnd::Included, _) => { let mut err = struct_span_err!( @@ -506,7 +506,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { to be less than or equal to the end of the range."); } err.emit(); - PatternKind::Wild + PatKind::Wild } } }, @@ -519,7 +519,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { ), ); - PatternKind::Wild + PatKind::Wild }, }; @@ -528,7 +528,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { // constants somewhere. Have them on the range pattern. for ascription in &[lo_ascription, hi_ascription] { if let Some(ascription) = ascription { - kind = PatternKind::AscribeUserType { + kind = PatKind::AscribeUserType { ascription: *ascription, subpattern: Pattern { span: pat.span, ty, kind: Box::new(kind), }, }; @@ -538,19 +538,19 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { kind } - PatKind::Path(ref qpath) => { + hir::PatKind::Path(ref qpath) => { return self.lower_path(qpath, pat.hir_id, pat.span); } - PatKind::Ref(ref subpattern, _) | - PatKind::Box(ref subpattern) => { - PatternKind::Deref { subpattern: self.lower_pattern(subpattern) } + hir::PatKind::Ref(ref subpattern, _) | + hir::PatKind::Box(ref subpattern) => { + PatKind::Deref { subpattern: self.lower_pattern(subpattern) } } - PatKind::Slice(ref prefix, ref slice, ref suffix) => { + hir::PatKind::Slice(ref prefix, ref slice, ref suffix) => { match ty.kind { ty::Ref(_, ty, _) => - PatternKind::Deref { + PatKind::Deref { subpattern: Pattern { ty, span: pat.span, @@ -562,7 +562,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { ty::Array(..) => self.slice_or_array_pattern(pat.span, ty, prefix, slice, suffix), ty::Error => { // Avoid ICE - return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) }; + return Pattern { span: pat.span, ty, kind: Box::new(PatKind::Wild) }; } _ => span_bug!( @@ -572,7 +572,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { } } - PatKind::Tuple(ref subpatterns, ddpos) => { + hir::PatKind::Tuple(ref subpatterns, ddpos) => { match ty.kind { ty::Tuple(ref tys) => { let subpatterns = @@ -584,20 +584,20 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { }) .collect(); - PatternKind::Leaf { subpatterns } + PatKind::Leaf { subpatterns } } ty::Error => { // Avoid ICE (#50577) - return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) }; + return Pattern { span: pat.span, ty, kind: Box::new(PatKind::Wild) }; } _ => span_bug!(pat.span, "unexpected type for tuple pattern: {:?}", ty), } } - PatKind::Binding(_, id, ident, ref sub) => { + hir::PatKind::Binding(_, id, ident, ref sub) => { let var_ty = self.tables.node_type(pat.hir_id); if let ty::Error = var_ty.kind { // Avoid ICE - return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) }; + return Pattern { span: pat.span, ty, kind: Box::new(PatKind::Wild) }; }; let bm = *self.tables.pat_binding_modes().get(pat.hir_id) .expect("missing binding mode"); @@ -624,7 +624,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { } } - PatternKind::Binding { + PatKind::Binding { mutability, mode, name: ident.name, @@ -634,12 +634,12 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { } } - PatKind::TupleStruct(ref qpath, ref subpatterns, ddpos) => { + hir::PatKind::TupleStruct(ref qpath, ref subpatterns, ddpos) => { let res = self.tables.qpath_res(qpath, pat.hir_id); let adt_def = match ty.kind { ty::Adt(adt_def, _) => adt_def, ty::Error => { // Avoid ICE (#50585) - return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) }; + return Pattern { span: pat.span, ty, kind: Box::new(PatKind::Wild) }; } _ => span_bug!(pat.span, "tuple struct pattern not applied to an ADT {:?}", @@ -659,7 +659,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { self.lower_variant_or_leaf(res, pat.hir_id, pat.span, ty, subpatterns) } - PatKind::Struct(ref qpath, ref fields, _) => { + hir::PatKind::Struct(ref qpath, ref fields, _) => { let res = self.tables.qpath_res(qpath, pat.hir_id); let subpatterns = fields.iter() @@ -675,8 +675,8 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { self.lower_variant_or_leaf(res, pat.hir_id, pat.span, ty, subpatterns) } - PatKind::Or(ref pats) => { - PatternKind::Or { + hir::PatKind::Or(ref pats) => { + PatKind::Or { pats: pats.iter().map(|p| self.lower_pattern(p)).collect(), } } @@ -715,8 +715,8 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { // dance because of intentional borrow-checker stupidity. let kind = *orig_slice.kind; match kind { - PatternKind::Slice { prefix, slice, mut suffix } | - PatternKind::Array { prefix, slice, mut suffix } => { + PatKind::Slice { prefix, slice, mut suffix } | + PatKind::Array { prefix, slice, mut suffix } => { let mut orig_prefix = orig_prefix; orig_prefix.extend(prefix); @@ -739,7 +739,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { prefix: &'tcx [P<hir::Pat>], slice: &'tcx Option<P<hir::Pat>>, suffix: &'tcx [P<hir::Pat>]) - -> PatternKind<'tcx> + -> PatKind<'tcx> { let prefix = self.lower_patterns(prefix); let slice = self.lower_opt_pattern(slice); @@ -750,14 +750,14 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { match ty.kind { ty::Slice(..) => { // matching a slice or fixed-length array - PatternKind::Slice { prefix: prefix, slice: slice, suffix: suffix } + PatKind::Slice { prefix: prefix, slice: slice, suffix: suffix } } ty::Array(_, len) => { // fixed-length array let len = len.eval_usize(self.tcx, self.param_env); assert!(len >= prefix.len() as u64 + suffix.len() as u64); - PatternKind::Array { prefix: prefix, slice: slice, suffix: suffix } + PatKind::Array { prefix: prefix, slice: slice, suffix: suffix } } _ => { @@ -773,7 +773,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { span: Span, ty: Ty<'tcx>, subpatterns: Vec<FieldPat<'tcx>>, - ) -> PatternKind<'tcx> { + ) -> PatKind<'tcx> { let res = match res { Res::Def(DefKind::Ctor(CtorOf::Variant, ..), variant_ctor_id) => { let variant_id = self.tcx.parent(variant_ctor_id).unwrap(); @@ -791,18 +791,18 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { ty::Adt(_, substs) | ty::FnDef(_, substs) => substs, ty::Error => { // Avoid ICE (#50585) - return PatternKind::Wild; + return PatKind::Wild; } _ => bug!("inappropriate type for def: {:?}", ty), }; - PatternKind::Variant { + PatKind::Variant { adt_def, substs, variant_index: adt_def.variant_index_with_id(variant_id), subpatterns, } } else { - PatternKind::Leaf { subpatterns } + PatKind::Leaf { subpatterns } } } @@ -813,18 +813,18 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { | Res::Def(DefKind::AssocTy, _) | Res::SelfTy(..) | Res::SelfCtor(..) => { - PatternKind::Leaf { subpatterns } + PatKind::Leaf { subpatterns } } _ => { self.errors.push(PatternError::NonConstPath(span)); - PatternKind::Wild + PatKind::Wild } }; if let Some(user_ty) = self.user_substs_applied_to_ty_of_hir_id(hir_id) { debug!("lower_variant_or_leaf: kind={:?} user_ty={:?} span={:?}", kind, user_ty, span); - kind = PatternKind::AscribeUserType { + kind = PatKind::AscribeUserType { subpattern: Pattern { span, ty, @@ -882,7 +882,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { Pattern { span, kind: Box::new( - PatternKind::AscribeUserType { + PatKind::AscribeUserType { subpattern: pattern, ascription: Ascription { /// Note that use `Contravariant` here. See the @@ -904,7 +904,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { span, "could not evaluate constant pattern", ); - PatternKind::Wild + PatKind::Wild } } }, @@ -914,7 +914,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { } else { PatternError::StaticInPattern(span) }); - PatternKind::Wild + PatKind::Wild }, } } @@ -932,7 +932,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { /// The special case for negation exists to allow things like `-128_i8` /// which would overflow if we tried to evaluate `128_i8` and then negate /// afterwards. - fn lower_lit(&mut self, expr: &'tcx hir::Expr) -> PatternKind<'tcx> { + fn lower_lit(&mut self, expr: &'tcx hir::Expr) -> PatKind<'tcx> { match expr.kind { hir::ExprKind::Lit(ref lit) => { let ty = self.tables.expr_ty(expr); @@ -946,9 +946,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { }, Err(LitToConstError::UnparseableFloat) => { self.errors.push(PatternError::FloatBug); - PatternKind::Wild + PatKind::Wild }, - Err(LitToConstError::Reported) => PatternKind::Wild, + Err(LitToConstError::Reported) => PatKind::Wild, } }, hir::ExprKind::Path(ref qpath) => *self.lower_path(qpath, expr.hir_id, expr.span).kind, @@ -968,9 +968,9 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { }, Err(LitToConstError::UnparseableFloat) => { self.errors.push(PatternError::FloatBug); - PatternKind::Wild + PatKind::Wild }, - Err(LitToConstError::Reported) => PatternKind::Wild, + Err(LitToConstError::Reported) => PatKind::Wild, } } _ => span_bug!(expr.span, "not a literal: {:?}", expr), @@ -1085,7 +1085,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { span, "floating-point types cannot be used in patterns", ); - PatternKind::Constant { + PatKind::Constant { value: cv, } } @@ -1093,7 +1093,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { // Matching on union fields is unsafe, we can't hide it in constants *saw_const_match_error = true; self.tcx.sess.span_err(span, "cannot use unions in constant patterns"); - PatternKind::Wild + PatKind::Wild } // keep old code until future-compat upgraded to errors. ty::Adt(adt_def, _) if !self.tcx.has_attr(adt_def.did, sym::structural_match) => { @@ -1106,13 +1106,13 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { ); *saw_const_match_error = true; self.tcx.sess.span_err(span, &msg); - PatternKind::Wild + PatKind::Wild } // keep old code until future-compat upgraded to errors. ty::Ref(_, ty::TyS { kind: ty::Adt(adt_def, _), .. }, _) if !self.tcx.has_attr(adt_def.did, sym::structural_match) => { // HACK(estebank): Side-step ICE #53708, but anything other than erroring here - // would be wrong. Returnging `PatternKind::Wild` is not technically correct. + // would be wrong. Returnging `PatKind::Wild` is not technically correct. let path = self.tcx.def_path_str(adt_def.did); let msg = format!( "to use a constant of type `{}` in a pattern, \ @@ -1122,7 +1122,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { ); *saw_const_match_error = true; self.tcx.sess.span_err(span, &msg); - PatternKind::Wild + PatKind::Wild } ty::Adt(adt_def, substs) if adt_def.is_enum() => { let variant_index = const_variant_index(self.tcx, self.param_env, cv); @@ -1130,7 +1130,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { adt_def.variants[variant_index].fields.len(), Some(variant_index), ); - PatternKind::Variant { + PatKind::Variant { adt_def, substs, variant_index, @@ -1139,17 +1139,17 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { } ty::Adt(adt_def, _) => { let struct_var = adt_def.non_enum_variant(); - PatternKind::Leaf { + PatKind::Leaf { subpatterns: adt_subpatterns(struct_var.fields.len(), None), } } ty::Tuple(fields) => { - PatternKind::Leaf { + PatKind::Leaf { subpatterns: adt_subpatterns(fields.len(), None), } } ty::Array(_, n) => { - PatternKind::Array { + PatKind::Array { prefix: (0..n.eval_usize(self.tcx, self.param_env)) .map(|i| adt_subpattern(i as usize, None)) .collect(), @@ -1158,7 +1158,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { } } _ => { - PatternKind::Constant { + PatKind::Constant { value: cv, } } @@ -1317,7 +1317,7 @@ pub trait PatternFolder<'tcx> : Sized { pattern.super_fold_with(self) } - fn fold_pattern_kind(&mut self, kind: &PatternKind<'tcx>) -> PatternKind<'tcx> { + fn fold_pattern_kind(&mut self, kind: &PatKind<'tcx>) -> PatKind<'tcx> { kind.super_fold_with(self) } } @@ -1384,22 +1384,22 @@ impl<'tcx> PatternFoldable<'tcx> for Pattern<'tcx> { } } -impl<'tcx> PatternFoldable<'tcx> for PatternKind<'tcx> { +impl<'tcx> PatternFoldable<'tcx> for PatKind<'tcx> { fn fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self { folder.fold_pattern_kind(self) } fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self { match *self { - PatternKind::Wild => PatternKind::Wild, - PatternKind::AscribeUserType { + PatKind::Wild => PatKind::Wild, + PatKind::AscribeUserType { ref subpattern, ascription: Ascription { variance, ref user_ty, user_ty_span, }, - } => PatternKind::AscribeUserType { + } => PatKind::AscribeUserType { subpattern: subpattern.fold_with(folder), ascription: Ascription { user_ty: user_ty.fold_with(folder), @@ -1407,14 +1407,14 @@ impl<'tcx> PatternFoldable<'tcx> for PatternKind<'tcx> { user_ty_span, }, }, - PatternKind::Binding { + PatKind::Binding { mutability, name, mode, var, ty, ref subpattern, - } => PatternKind::Binding { + } => PatKind::Binding { mutability: mutability.fold_with(folder), name: name.fold_with(folder), mode: mode.fold_with(folder), @@ -1422,52 +1422,52 @@ impl<'tcx> PatternFoldable<'tcx> for PatternKind<'tcx> { ty: ty.fold_with(folder), subpattern: subpattern.fold_with(folder), }, - PatternKind::Variant { + PatKind::Variant { adt_def, substs, variant_index, ref subpatterns, - } => PatternKind::Variant { + } => PatKind::Variant { adt_def: adt_def.fold_with(folder), substs: substs.fold_with(folder), variant_index, subpatterns: subpatterns.fold_with(folder) }, - PatternKind::Leaf { + PatKind::Leaf { ref subpatterns, - } => PatternKind::Leaf { + } => PatKind::Leaf { subpatterns: subpatterns.fold_with(folder), }, - PatternKind::Deref { + PatKind::Deref { ref subpattern, - } => PatternKind::Deref { + } => PatKind::Deref { subpattern: subpattern.fold_with(folder), }, - PatternKind::Constant { + PatKind::Constant { value - } => PatternKind::Constant { + } => PatKind::Constant { value, }, - PatternKind::Range(range) => PatternKind::Range(range), - PatternKind::Slice { + PatKind::Range(range) => PatKind::Range(range), + PatKind::Slice { ref prefix, ref slice, ref suffix, - } => PatternKind::Slice { + } => PatKind::Slice { prefix: prefix.fold_with(folder), slice: slice.fold_with(folder), suffix: suffix.fold_with(folder) }, - PatternKind::Array { + PatKind::Array { ref prefix, ref slice, ref suffix - } => PatternKind::Array { + } => PatKind::Array { prefix: prefix.fold_with(folder), slice: slice.fold_with(folder), suffix: suffix.fold_with(folder) }, - PatternKind::Or { ref pats } => PatternKind::Or { pats: pats.fold_with(folder) }, + PatKind::Or { ref pats } => PatKind::Or { pats: pats.fold_with(folder) }, } } } |
