Skip to content
Permalink
Browse files

Rename `hair::PatternKind` to `hair::PatKind`

  • Loading branch information...
varkor committed Sep 26, 2019
1 parent 1ae3c36 commit ff59620734fec2f87463b193c67f482285235256
@@ -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
@@ -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,22 +644,22 @@ 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);
self.visit_bindings(&subpattern.pattern, subpattern_user_ty, f);
}
}

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);
}
@@ -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)
}
}
@@ -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,18 +548,18 @@ 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);
Some(index)
}

(&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.
@@ -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,
@@ -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,

0 comments on commit ff59620

Please sign in to comment.
You can’t perform that action at this time.