Fix style nits
Fix style nits discovered in reading code.
This commit is contained in:
parent
684b09ba7f
commit
f8b6449f80
16 changed files with 64 additions and 48 deletions
|
@ -150,9 +150,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pats_all<'b, I: Iterator<Item=&'b P<hir::Pat>>>(&mut self,
|
fn pats_all<'b, I: Iterator<Item=&'b P<hir::Pat>>>(
|
||||||
pats: I,
|
&mut self,
|
||||||
pred: CFGIndex) -> CFGIndex {
|
pats: I,
|
||||||
|
pred: CFGIndex
|
||||||
|
) -> CFGIndex {
|
||||||
//! Handles case where all of the patterns must match.
|
//! Handles case where all of the patterns must match.
|
||||||
pats.fold(pred, |pred, pat| self.pat(&pat, pred))
|
pats.fold(pred, |pred, pat| self.pat(&pat, pred))
|
||||||
}
|
}
|
||||||
|
|
|
@ -948,14 +948,19 @@ pub enum PatKind {
|
||||||
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
|
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
|
||||||
/// `0 <= position <= subpats.len()`
|
/// `0 <= position <= subpats.len()`
|
||||||
Tuple(HirVec<P<Pat>>, Option<usize>),
|
Tuple(HirVec<P<Pat>>, Option<usize>),
|
||||||
|
|
||||||
/// A `box` pattern.
|
/// A `box` pattern.
|
||||||
Box(P<Pat>),
|
Box(P<Pat>),
|
||||||
|
|
||||||
/// A reference pattern (e.g., `&mut (a, b)`).
|
/// A reference pattern (e.g., `&mut (a, b)`).
|
||||||
Ref(P<Pat>, Mutability),
|
Ref(P<Pat>, Mutability),
|
||||||
|
|
||||||
/// A literal.
|
/// A literal.
|
||||||
Lit(P<Expr>),
|
Lit(P<Expr>),
|
||||||
|
|
||||||
/// A range pattern (e.g., `1...2` or `1..2`).
|
/// A range pattern (e.g., `1...2` or `1..2`).
|
||||||
Range(P<Expr>, P<Expr>, RangeEnd),
|
Range(P<Expr>, P<Expr>, RangeEnd),
|
||||||
|
|
||||||
/// `[a, b, ..i, y, z]` is represented as:
|
/// `[a, b, ..i, y, z]` is represented as:
|
||||||
/// `PatKind::Slice(box [a, b], Some(i), box [y, z])`.
|
/// `PatKind::Slice(box [a, b], Some(i), box [y, z])`.
|
||||||
Slice(HirVec<P<Pat>>, Option<P<Pat>>, HirVec<P<Pat>>),
|
Slice(HirVec<P<Pat>>, Option<P<Pat>>, HirVec<P<Pat>>),
|
||||||
|
|
|
@ -1311,12 +1311,12 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||||
Def::Err => {
|
Def::Err => {
|
||||||
debug!("access to unresolvable pattern {:?}", pat);
|
debug!("access to unresolvable pattern {:?}", pat);
|
||||||
return Err(())
|
return Err(())
|
||||||
},
|
}
|
||||||
Def::Variant(variant_did) |
|
Def::Variant(variant_did) |
|
||||||
Def::VariantCtor(variant_did, ..) => {
|
Def::VariantCtor(variant_did, ..) => {
|
||||||
self.cat_downcast_if_needed(pat, cmt, variant_did)
|
self.cat_downcast_if_needed(pat, cmt, variant_did)
|
||||||
},
|
}
|
||||||
_ => cmt
|
_ => cmt,
|
||||||
};
|
};
|
||||||
|
|
||||||
for fp in field_pats {
|
for fp in field_pats {
|
||||||
|
@ -1347,7 +1347,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PatKind::Box(ref subpat) | PatKind::Ref(ref subpat, _) => {
|
PatKind::Box(ref subpat) | PatKind::Ref(ref subpat, _) => {
|
||||||
// box p1, &p1, &mut p1. we can ignore the mutability of
|
// box p1, &p1, &mut p1. we can ignore the mutability of
|
||||||
// PatKind::Ref since that information is already contained
|
// PatKind::Ref since that information is already contained
|
||||||
// in the type.
|
// in the type.
|
||||||
|
|
|
@ -1167,13 +1167,13 @@ pub type Region<'tcx> = &'tcx RegionKind;
|
||||||
/// [rustc guide]: https://rust-lang.github.io/rustc-guide/traits/hrtb.html
|
/// [rustc guide]: https://rust-lang.github.io/rustc-guide/traits/hrtb.html
|
||||||
#[derive(Clone, PartialEq, Eq, Hash, Copy, RustcEncodable, RustcDecodable, PartialOrd, Ord)]
|
#[derive(Clone, PartialEq, Eq, Hash, Copy, RustcEncodable, RustcDecodable, PartialOrd, Ord)]
|
||||||
pub enum RegionKind {
|
pub enum RegionKind {
|
||||||
// Region bound in a type or fn declaration which will be
|
/// Region bound in a type or fn declaration which will be
|
||||||
// substituted 'early' -- that is, at the same time when type
|
/// substituted 'early' -- that is, at the same time when type
|
||||||
// parameters are substituted.
|
/// parameters are substituted.
|
||||||
ReEarlyBound(EarlyBoundRegion),
|
ReEarlyBound(EarlyBoundRegion),
|
||||||
|
|
||||||
// Region bound in a function scope, which will be substituted when the
|
/// Region bound in a function scope, which will be substituted when the
|
||||||
// function is called.
|
/// function is called.
|
||||||
ReLateBound(DebruijnIndex, BoundRegion),
|
ReLateBound(DebruijnIndex, BoundRegion),
|
||||||
|
|
||||||
/// When checking a function body, the types of all arguments and so forth
|
/// When checking a function body, the types of all arguments and so forth
|
||||||
|
|
|
@ -192,8 +192,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
|
||||||
"size_of_val" => {
|
"size_of_val" => {
|
||||||
let tp_ty = substs.type_at(0);
|
let tp_ty = substs.type_at(0);
|
||||||
if let OperandValue::Pair(_, meta) = args[0].val {
|
if let OperandValue::Pair(_, meta) = args[0].val {
|
||||||
let (llsize, _) =
|
let (llsize, _) = glue::size_and_align_of_dst(self, tp_ty, Some(meta));
|
||||||
glue::size_and_align_of_dst(self, tp_ty, Some(meta));
|
|
||||||
llsize
|
llsize
|
||||||
} else {
|
} else {
|
||||||
self.const_usize(self.size_of(tp_ty).bytes())
|
self.const_usize(self.size_of(tp_ty).bytes())
|
||||||
|
@ -206,8 +205,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
|
||||||
"min_align_of_val" => {
|
"min_align_of_val" => {
|
||||||
let tp_ty = substs.type_at(0);
|
let tp_ty = substs.type_at(0);
|
||||||
if let OperandValue::Pair(_, meta) = args[0].val {
|
if let OperandValue::Pair(_, meta) = args[0].val {
|
||||||
let (_, llalign) =
|
let (_, llalign) = glue::size_and_align_of_dst(self, tp_ty, Some(meta));
|
||||||
glue::size_and_align_of_dst(self, tp_ty, Some(meta));
|
|
||||||
llalign
|
llalign
|
||||||
} else {
|
} else {
|
||||||
self.const_usize(self.align_of(tp_ty).bytes())
|
self.const_usize(self.align_of(tp_ty).bytes())
|
||||||
|
|
|
@ -82,7 +82,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||||
|
|
||||||
fn type_i16(&self) -> &'ll Type {
|
fn type_i16(&self) -> &'ll Type {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
||||||
llvm::LLVMInt16TypeInContext(self.llcx)
|
llvm::LLVMInt16TypeInContext(self.llcx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -338,6 +338,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
self.schedule_drop_for_binding(var, irrefutable_pat.span, OutsideGuard);
|
self.schedule_drop_for_binding(var, irrefutable_pat.span, OutsideGuard);
|
||||||
block.unit()
|
block.unit()
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
let place = unpack!(block = self.as_place(block, initializer));
|
let place = unpack!(block = self.as_place(block, initializer));
|
||||||
self.place_into_pattern(block, irrefutable_pat, &place, true)
|
self.place_into_pattern(block, irrefutable_pat, &place, true)
|
||||||
|
@ -534,6 +535,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
self.visit_bindings(subpattern, pattern_user_ty, f);
|
self.visit_bindings(subpattern, pattern_user_ty, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PatternKind::Array {
|
PatternKind::Array {
|
||||||
ref prefix,
|
ref prefix,
|
||||||
ref slice,
|
ref slice,
|
||||||
|
@ -556,10 +558,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
self.visit_bindings(subpattern, pattern_user_ty.clone().index(), f);
|
self.visit_bindings(subpattern, pattern_user_ty.clone().index(), f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PatternKind::Constant { .. } | PatternKind::Range { .. } | PatternKind::Wild => {}
|
PatternKind::Constant { .. } | PatternKind::Range { .. } | PatternKind::Wild => {}
|
||||||
|
|
||||||
PatternKind::Deref { ref subpattern } => {
|
PatternKind::Deref { ref subpattern } => {
|
||||||
self.visit_bindings(subpattern, pattern_user_ty.deref(), f);
|
self.visit_bindings(subpattern, pattern_user_ty.deref(), f);
|
||||||
}
|
}
|
||||||
|
|
||||||
PatternKind::AscribeUserType {
|
PatternKind::AscribeUserType {
|
||||||
ref subpattern,
|
ref subpattern,
|
||||||
ascription: hair::pattern::Ascription {
|
ascription: hair::pattern::Ascription {
|
||||||
|
|
|
@ -45,10 +45,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tries to simplify `match_pair`, returning true if
|
/// Tries to simplify `match_pair`, returning `Ok(())` if
|
||||||
/// successful. If successful, new match pairs and bindings will
|
/// successful. If successful, new match pairs and bindings will
|
||||||
/// have been pushed into the candidate. If no simplification is
|
/// have been pushed into the candidate. If no simplification is
|
||||||
/// possible, Err is returned and no changes are made to
|
/// possible, `Err` is returned and no changes are made to
|
||||||
/// candidate.
|
/// candidate.
|
||||||
fn simplify_match_pair<'pat>(&mut self,
|
fn simplify_match_pair<'pat>(&mut self,
|
||||||
match_pair: MatchPair<'pat, 'tcx>,
|
match_pair: MatchPair<'pat, 'tcx>,
|
||||||
|
@ -174,7 +174,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
} else {
|
} else {
|
||||||
Err(match_pair)
|
Err(match_pair)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
PatternKind::Array { ref prefix, ref slice, ref suffix } => {
|
PatternKind::Array { ref prefix, ref slice, ref suffix } => {
|
||||||
self.prefix_slice_suffix(&mut candidate.match_pairs,
|
self.prefix_slice_suffix(&mut candidate.match_pairs,
|
||||||
|
|
|
@ -35,10 +35,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PatternKind::Constant { .. }
|
PatternKind::Constant { .. } if is_switch_ty(match_pair.pattern.ty) => {
|
||||||
if is_switch_ty(match_pair.pattern.ty) => {
|
// For integers, we use a `SwitchInt` match, which allows
|
||||||
// for integers, we use a SwitchInt match, which allows
|
// us to handle more cases.
|
||||||
// us to handle more cases
|
|
||||||
Test {
|
Test {
|
||||||
span: match_pair.pattern.span,
|
span: match_pair.pattern.span,
|
||||||
kind: TestKind::SwitchInt {
|
kind: TestKind::SwitchInt {
|
||||||
|
@ -253,12 +252,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
TestKind::Eq { value, mut ty } => {
|
TestKind::Eq { value, mut ty } => {
|
||||||
let val = Operand::Copy(place.clone());
|
let val = Operand::Copy(place.clone());
|
||||||
let mut expect = self.literal_operand(test.span, ty, value);
|
let mut expect = self.literal_operand(test.span, ty, value);
|
||||||
// Use PartialEq::eq instead of BinOp::Eq
|
// Use `PartialEq::eq` instead of `BinOp::Eq`
|
||||||
// (the binop can only handle primitives)
|
// (the binop can only handle primitives)
|
||||||
let fail = self.cfg.start_new_block();
|
let fail = self.cfg.start_new_block();
|
||||||
if !ty.is_scalar() {
|
if !ty.is_scalar() {
|
||||||
// If we're using b"..." as a pattern, we need to insert an
|
// If we're using `b"..."` as a pattern, we need to insert an
|
||||||
// unsizing coercion, as the byte string has the type &[u8; N].
|
// unsizing coercion, as the byte string has the type `&[u8; N]`.
|
||||||
//
|
//
|
||||||
// We want to do this even when the scrutinee is a reference to an
|
// We want to do this even when the scrutinee is a reference to an
|
||||||
// array, so we can call `<[u8]>::eq` rather than having to find an
|
// array, so we can call `<[u8]>::eq` rather than having to find an
|
||||||
|
@ -503,6 +502,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
resulting_candidates[variant_index.as_usize()].push(new_candidate);
|
resulting_candidates[variant_index.as_usize()].push(new_candidate);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
(&TestKind::Switch { .. }, _) => false,
|
(&TestKind::Switch { .. }, _) => false,
|
||||||
|
|
||||||
// If we are performing a switch over integers, then this informs integer
|
// If we are performing a switch over integers, then this informs integer
|
||||||
|
@ -539,7 +539,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
|
|
||||||
(&TestKind::SwitchInt { .. }, _) => false,
|
(&TestKind::SwitchInt { .. }, _) => false,
|
||||||
|
|
||||||
|
|
||||||
(&TestKind::Len { len: test_len, op: BinOp::Eq },
|
(&TestKind::Len { len: test_len, op: BinOp::Eq },
|
||||||
&PatternKind::Slice { ref prefix, ref slice, ref suffix }) => {
|
&PatternKind::Slice { ref prefix, ref slice, ref suffix }) => {
|
||||||
let pat_len = (prefix.len() + suffix.len()) as u64;
|
let pat_len = (prefix.len() + suffix.len()) as u64;
|
||||||
|
|
|
@ -13,7 +13,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||||
subpatterns.iter()
|
subpatterns.iter()
|
||||||
.map(|fieldpat| {
|
.map(|fieldpat| {
|
||||||
let place = place.clone().field(fieldpat.field,
|
let place = place.clone().field(fieldpat.field,
|
||||||
fieldpat.pattern.ty);
|
fieldpat.pattern.ty);
|
||||||
MatchPair::new(place, &fieldpat.pattern)
|
MatchPair::new(place, &fieldpat.pattern)
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
|
|
|
@ -634,8 +634,8 @@ impl<'tcx> Witness<'tcx> {
|
||||||
/// but is instead bounded by the maximum fixed length of slice patterns in
|
/// but is instead bounded by the maximum fixed length of slice patterns in
|
||||||
/// the column of patterns being analyzed.
|
/// the column of patterns being analyzed.
|
||||||
///
|
///
|
||||||
/// We make sure to omit constructors that are statically impossible. eg for
|
/// We make sure to omit constructors that are statically impossible. E.g., for
|
||||||
/// Option<!> we do not include Some(_) in the returned list of constructors.
|
/// `Option<!>`, we do not include `Some(_)` in the returned list of constructors.
|
||||||
fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
||||||
pcx: PatternContext<'tcx>)
|
pcx: PatternContext<'tcx>)
|
||||||
-> Vec<Constructor<'tcx>>
|
-> Vec<Constructor<'tcx>>
|
||||||
|
@ -1347,7 +1347,7 @@ fn pat_constructors<'tcx>(cx: &mut MatchCheckCtxt<'_, 'tcx>,
|
||||||
/// This computes the arity of a constructor. The arity of a constructor
|
/// This computes the arity of a constructor. The arity of a constructor
|
||||||
/// is how many subpattern patterns of that constructor should be expanded to.
|
/// is how many subpattern patterns of that constructor should be expanded to.
|
||||||
///
|
///
|
||||||
/// For instance, a tuple pattern (_, 42, Some([])) has the arity of 3.
|
/// For instance, a tuple pattern `(_, 42, Some([]))` has the arity of 3.
|
||||||
/// A struct pattern's arity is the number of fields it contains, etc.
|
/// A struct pattern's arity is the number of fields it contains, etc.
|
||||||
fn constructor_arity(cx: &MatchCheckCtxt<'a, 'tcx>, ctor: &Constructor<'tcx>, ty: Ty<'tcx>) -> u64 {
|
fn constructor_arity(cx: &MatchCheckCtxt<'a, 'tcx>, ctor: &Constructor<'tcx>, ty: Ty<'tcx>) -> u64 {
|
||||||
debug!("constructor_arity({:#?}, {:?})", ctor, ty);
|
debug!("constructor_arity({:#?}, {:?})", ctor, ty);
|
||||||
|
@ -1357,7 +1357,7 @@ fn constructor_arity(cx: &MatchCheckCtxt<'a, 'tcx>, ctor: &Constructor<'tcx>, ty
|
||||||
Slice(length) => length,
|
Slice(length) => length,
|
||||||
ConstantValue(_) => 0,
|
ConstantValue(_) => 0,
|
||||||
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty)
|
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty)
|
||||||
},
|
}
|
||||||
ty::Ref(..) => 1,
|
ty::Ref(..) => 1,
|
||||||
ty::Adt(adt, _) => {
|
ty::Adt(adt, _) => {
|
||||||
adt.variants[ctor.variant_index_for_adt(cx, adt)].fields.len() as u64
|
adt.variants[ctor.variant_index_for_adt(cx, adt)].fields.len() as u64
|
||||||
|
@ -1381,7 +1381,7 @@ fn constructor_sub_pattern_tys<'a, 'tcx: 'a>(cx: &MatchCheckCtxt<'a, 'tcx>,
|
||||||
Slice(length) => (0..length).map(|_| ty).collect(),
|
Slice(length) => (0..length).map(|_| ty).collect(),
|
||||||
ConstantValue(_) => vec![],
|
ConstantValue(_) => vec![],
|
||||||
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty)
|
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty)
|
||||||
},
|
}
|
||||||
ty::Ref(_, rty, _) => vec![rty],
|
ty::Ref(_, rty, _) => vec![rty],
|
||||||
ty::Adt(adt, substs) => {
|
ty::Adt(adt, substs) => {
|
||||||
if adt.is_box() {
|
if adt.is_box() {
|
||||||
|
|
|
@ -375,7 +375,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
||||||
},
|
},
|
||||||
_ => bug!(),
|
_ => bug!(),
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
|
||||||
hir::MatchSource::ForLoopDesugar |
|
hir::MatchSource::ForLoopDesugar |
|
||||||
hir::MatchSource::Normal => {
|
hir::MatchSource::Normal => {
|
||||||
|
@ -391,7 +391,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
||||||
err.span_label(catchall, "matches any value");
|
err.span_label(catchall, "matches any value");
|
||||||
}
|
}
|
||||||
err.emit();
|
err.emit();
|
||||||
},
|
}
|
||||||
|
|
||||||
// Unreachable patterns in try expressions occur when one of the arms
|
// Unreachable patterns in try expressions occur when one of the arms
|
||||||
// are an uninhabited type. Which is OK.
|
// are an uninhabited type. Which is OK.
|
||||||
|
@ -436,7 +436,7 @@ fn check_exhaustive<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
||||||
let (tail, head) = witnesses.split_last().unwrap();
|
let (tail, head) = witnesses.split_last().unwrap();
|
||||||
let head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
|
let head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
|
||||||
format!("`{}` and `{}`", head.join("`, `"), tail)
|
format!("`{}` and `{}`", head.join("`, `"), tail)
|
||||||
},
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let (head, tail) = witnesses.split_at(LIMIT);
|
let (head, tail) = witnesses.split_at(LIMIT);
|
||||||
let head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
|
let head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
|
||||||
|
@ -446,7 +446,7 @@ fn check_exhaustive<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
||||||
|
|
||||||
let label_text = match witnesses.len() {
|
let label_text = match witnesses.len() {
|
||||||
1 => format!("pattern {} not covered", joined_patterns),
|
1 => format!("pattern {} not covered", joined_patterns),
|
||||||
_ => format!("patterns {} not covered", joined_patterns)
|
_ => format!("patterns {} not covered", joined_patterns),
|
||||||
};
|
};
|
||||||
create_e0004(cx.tcx.sess, sp,
|
create_e0004(cx.tcx.sess, sp,
|
||||||
format!("non-exhaustive patterns: {} not covered",
|
format!("non-exhaustive patterns: {} not covered",
|
||||||
|
@ -456,7 +456,7 @@ fn check_exhaustive<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
||||||
}
|
}
|
||||||
NotUseful => {
|
NotUseful => {
|
||||||
// This is good, wildcard pattern isn't reachable
|
// This is good, wildcard pattern isn't reachable
|
||||||
},
|
}
|
||||||
_ => bug!()
|
_ => bug!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -965,7 +965,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||||
PatternKind::Constant {
|
PatternKind::Constant {
|
||||||
value: cv,
|
value: cv,
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
ty::Adt(adt_def, _) if adt_def.is_union() => {
|
ty::Adt(adt_def, _) if adt_def.is_union() => {
|
||||||
// Matching on union fields is unsafe, we can't hide it in constants
|
// Matching on union fields is unsafe, we can't hide it in constants
|
||||||
self.tcx.sess.span_err(span, "cannot use unions in constant patterns");
|
self.tcx.sess.span_err(span, "cannot use unions in constant patterns");
|
||||||
|
@ -978,7 +978,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||||
self.tcx.item_path_str(adt_def.did));
|
self.tcx.item_path_str(adt_def.did));
|
||||||
self.tcx.sess.span_err(span, &msg);
|
self.tcx.sess.span_err(span, &msg);
|
||||||
PatternKind::Wild
|
PatternKind::Wild
|
||||||
},
|
}
|
||||||
ty::Adt(adt_def, substs) if adt_def.is_enum() => {
|
ty::Adt(adt_def, substs) if adt_def.is_enum() => {
|
||||||
let variant_index = const_variant_index(
|
let variant_index = const_variant_index(
|
||||||
self.tcx, self.param_env, cv
|
self.tcx, self.param_env, cv
|
||||||
|
@ -993,7 +993,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||||
variant_index,
|
variant_index,
|
||||||
subpatterns,
|
subpatterns,
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
ty::Adt(adt_def, _) => {
|
ty::Adt(adt_def, _) => {
|
||||||
let struct_var = adt_def.non_enum_variant();
|
let struct_var = adt_def.non_enum_variant();
|
||||||
PatternKind::Leaf {
|
PatternKind::Leaf {
|
||||||
|
@ -1018,7 +1018,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||||
PatternKind::Constant {
|
PatternKind::Constant {
|
||||||
value: cv,
|
value: cv,
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Pattern {
|
Pattern {
|
||||||
|
@ -1252,19 +1252,19 @@ pub fn compare_const_vals<'a, 'gcx, 'tcx>(
|
||||||
let l = ::rustc_apfloat::ieee::Single::from_bits(a);
|
let l = ::rustc_apfloat::ieee::Single::from_bits(a);
|
||||||
let r = ::rustc_apfloat::ieee::Single::from_bits(b);
|
let r = ::rustc_apfloat::ieee::Single::from_bits(b);
|
||||||
l.partial_cmp(&r)
|
l.partial_cmp(&r)
|
||||||
},
|
}
|
||||||
ty::Float(ast::FloatTy::F64) => {
|
ty::Float(ast::FloatTy::F64) => {
|
||||||
let l = ::rustc_apfloat::ieee::Double::from_bits(a);
|
let l = ::rustc_apfloat::ieee::Double::from_bits(a);
|
||||||
let r = ::rustc_apfloat::ieee::Double::from_bits(b);
|
let r = ::rustc_apfloat::ieee::Double::from_bits(b);
|
||||||
l.partial_cmp(&r)
|
l.partial_cmp(&r)
|
||||||
},
|
}
|
||||||
ty::Int(_) => {
|
ty::Int(_) => {
|
||||||
let layout = tcx.layout_of(ty).ok()?;
|
let layout = tcx.layout_of(ty).ok()?;
|
||||||
assert!(layout.abi.is_signed());
|
assert!(layout.abi.is_signed());
|
||||||
let a = sign_extend(a, layout.size);
|
let a = sign_extend(a, layout.size);
|
||||||
let b = sign_extend(b, layout.size);
|
let b = sign_extend(b, layout.size);
|
||||||
Some((a as i128).cmp(&(b as i128)))
|
Some((a as i128).cmp(&(b as i128)))
|
||||||
},
|
}
|
||||||
_ => Some(a.cmp(&b)),
|
_ => Some(a.cmp(&b)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -640,19 +640,26 @@ pub enum PatKind {
|
||||||
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
|
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
|
||||||
/// `0 <= position <= subpats.len()`.
|
/// `0 <= position <= subpats.len()`.
|
||||||
Tuple(Vec<P<Pat>>, Option<usize>),
|
Tuple(Vec<P<Pat>>, Option<usize>),
|
||||||
|
|
||||||
/// A `box` pattern.
|
/// A `box` pattern.
|
||||||
Box(P<Pat>),
|
Box(P<Pat>),
|
||||||
|
|
||||||
/// A reference pattern (e.g., `&mut (a, b)`).
|
/// A reference pattern (e.g., `&mut (a, b)`).
|
||||||
Ref(P<Pat>, Mutability),
|
Ref(P<Pat>, Mutability),
|
||||||
|
|
||||||
/// A literal.
|
/// A literal.
|
||||||
Lit(P<Expr>),
|
Lit(P<Expr>),
|
||||||
|
|
||||||
/// A range pattern (e.g., `1...2`, `1..=2` or `1..2`).
|
/// A range pattern (e.g., `1...2`, `1..=2` or `1..2`).
|
||||||
Range(P<Expr>, P<Expr>, Spanned<RangeEnd>),
|
Range(P<Expr>, P<Expr>, Spanned<RangeEnd>),
|
||||||
|
|
||||||
/// `[a, b, ..i, y, z]` is represented as:
|
/// `[a, b, ..i, y, z]` is represented as:
|
||||||
/// `PatKind::Slice(box [a, b], Some(i), box [y, z])`
|
/// `PatKind::Slice(box [a, b], Some(i), box [y, z])`
|
||||||
Slice(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
|
Slice(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
|
||||||
|
|
||||||
/// Parentheses in patterns used for grouping (i.e., `(PAT)`).
|
/// Parentheses in patterns used for grouping (i.e., `(PAT)`).
|
||||||
Paren(P<Pat>),
|
Paren(P<Pat>),
|
||||||
|
|
||||||
/// A macro pattern; pre-expansion.
|
/// A macro pattern; pre-expansion.
|
||||||
Mac(Mac),
|
Mac(Mac),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1037,7 +1037,7 @@ pub fn noop_visit_pat<T: MutVisitor>(pat: &mut P<Pat>, vis: &mut T) {
|
||||||
vis.visit_expr(e1);
|
vis.visit_expr(e1);
|
||||||
vis.visit_expr(e2);
|
vis.visit_expr(e2);
|
||||||
vis.visit_span(span);
|
vis.visit_span(span);
|
||||||
},
|
}
|
||||||
PatKind::Slice(before, slice, after) => {
|
PatKind::Slice(before, slice, after) => {
|
||||||
visit_vec(before, |pat| vis.visit_pat(pat));
|
visit_vec(before, |pat| vis.visit_pat(pat));
|
||||||
visit_opt(slice, |slice| vis.visit_pat(slice));
|
visit_opt(slice, |slice| vis.visit_pat(slice));
|
||||||
|
|
|
@ -4173,7 +4173,8 @@ impl<'a> Parser<'a> {
|
||||||
err.emit();
|
err.emit();
|
||||||
self.bump();
|
self.bump();
|
||||||
} else if self.eat(&token::BinOp(token::Or)) {
|
} else if self.eat(&token::BinOp(token::Or)) {
|
||||||
// No op.
|
// This is a No-op. Continue the loop to parse the next
|
||||||
|
// pattern.
|
||||||
} else {
|
} else {
|
||||||
return Ok(pats);
|
return Ok(pats);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue