mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-12 15:04:03 +00:00
Rollup merge of #58562 - dlrobertson:fix_nits, r=alexreg
Fix style nits Fix style nits discovered in reading code. r? @alexreg
This commit is contained in:
commit
6e991011dc
@ -150,9 +150,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn pats_all<'b, I: Iterator<Item=&'b P<hir::Pat>>>(&mut self,
|
||||
pats: I,
|
||||
pred: CFGIndex) -> CFGIndex {
|
||||
fn pats_all<'b, I: Iterator<Item=&'b P<hir::Pat>>>(
|
||||
&mut self,
|
||||
pats: I,
|
||||
pred: CFGIndex
|
||||
) -> CFGIndex {
|
||||
//! Handles case where all of the patterns must match.
|
||||
pats.fold(pred, |pred, pat| self.pat(&pat, pred))
|
||||
}
|
||||
|
@ -964,14 +964,19 @@ pub enum PatKind {
|
||||
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
|
||||
/// `0 <= position <= subpats.len()`
|
||||
Tuple(HirVec<P<Pat>>, Option<usize>),
|
||||
|
||||
/// A `box` pattern.
|
||||
Box(P<Pat>),
|
||||
|
||||
/// A reference pattern (e.g., `&mut (a, b)`).
|
||||
Ref(P<Pat>, Mutability),
|
||||
|
||||
/// A literal.
|
||||
Lit(P<Expr>),
|
||||
|
||||
/// A range pattern (e.g., `1...2` or `1..2`).
|
||||
Range(P<Expr>, P<Expr>, RangeEnd),
|
||||
|
||||
/// `[a, b, ..i, y, z]` is represented as:
|
||||
/// `PatKind::Slice(box [a, b], Some(i), box [y, z])`.
|
||||
Slice(HirVec<P<Pat>>, Option<P<Pat>>, HirVec<P<Pat>>),
|
||||
|
@ -1311,12 +1311,12 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
|
||||
Def::Err => {
|
||||
debug!("access to unresolvable pattern {:?}", pat);
|
||||
return Err(())
|
||||
},
|
||||
}
|
||||
Def::Variant(variant_did) |
|
||||
Def::VariantCtor(variant_did, ..) => {
|
||||
self.cat_downcast_if_needed(pat, cmt, variant_did)
|
||||
},
|
||||
_ => cmt
|
||||
}
|
||||
_ => cmt,
|
||||
};
|
||||
|
||||
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
|
||||
// PatKind::Ref since that information is already contained
|
||||
// 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
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Copy, RustcEncodable, RustcDecodable, PartialOrd, Ord)]
|
||||
pub enum RegionKind {
|
||||
// Region bound in a type or fn declaration which will be
|
||||
// substituted 'early' -- that is, at the same time when type
|
||||
// parameters are substituted.
|
||||
/// Region bound in a type or fn declaration which will be
|
||||
/// substituted 'early' -- that is, at the same time when type
|
||||
/// parameters are substituted.
|
||||
ReEarlyBound(EarlyBoundRegion),
|
||||
|
||||
// Region bound in a function scope, which will be substituted when the
|
||||
// function is called.
|
||||
/// Region bound in a function scope, which will be substituted when the
|
||||
/// function is called.
|
||||
ReLateBound(DebruijnIndex, BoundRegion),
|
||||
|
||||
/// 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" => {
|
||||
let tp_ty = substs.type_at(0);
|
||||
if let OperandValue::Pair(_, meta) = args[0].val {
|
||||
let (llsize, _) =
|
||||
glue::size_and_align_of_dst(self, tp_ty, Some(meta));
|
||||
let (llsize, _) = glue::size_and_align_of_dst(self, tp_ty, Some(meta));
|
||||
llsize
|
||||
} else {
|
||||
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" => {
|
||||
let tp_ty = substs.type_at(0);
|
||||
if let OperandValue::Pair(_, meta) = args[0].val {
|
||||
let (_, llalign) =
|
||||
glue::size_and_align_of_dst(self, tp_ty, Some(meta));
|
||||
let (_, llalign) = glue::size_and_align_of_dst(self, tp_ty, Some(meta));
|
||||
llalign
|
||||
} else {
|
||||
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 {
|
||||
unsafe {
|
||||
|
||||
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);
|
||||
block.unit()
|
||||
}
|
||||
|
||||
_ => {
|
||||
let place = unpack!(block = self.as_place(block, initializer));
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
PatternKind::Array {
|
||||
ref prefix,
|
||||
ref slice,
|
||||
@ -556,10 +558,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||
self.visit_bindings(subpattern, pattern_user_ty.clone().index(), f);
|
||||
}
|
||||
}
|
||||
|
||||
PatternKind::Constant { .. } | PatternKind::Range { .. } | PatternKind::Wild => {}
|
||||
|
||||
PatternKind::Deref { ref subpattern } => {
|
||||
self.visit_bindings(subpattern, pattern_user_ty.deref(), f);
|
||||
}
|
||||
|
||||
PatternKind::AscribeUserType {
|
||||
ref subpattern,
|
||||
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
|
||||
/// 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.
|
||||
fn simplify_match_pair<'pat>(&mut self,
|
||||
match_pair: MatchPair<'pat, 'tcx>,
|
||||
@ -174,7 +174,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||
} else {
|
||||
Err(match_pair)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
PatternKind::Array { ref prefix, ref slice, ref suffix } => {
|
||||
self.prefix_slice_suffix(&mut candidate.match_pairs,
|
||||
|
@ -35,10 +35,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
PatternKind::Constant { .. }
|
||||
if is_switch_ty(match_pair.pattern.ty) => {
|
||||
// for integers, we use a SwitchInt match, which allows
|
||||
// us to handle more cases
|
||||
PatternKind::Constant { .. } if is_switch_ty(match_pair.pattern.ty) => {
|
||||
// For integers, we use a `SwitchInt` match, which allows
|
||||
// us to handle more cases.
|
||||
Test {
|
||||
span: match_pair.pattern.span,
|
||||
kind: TestKind::SwitchInt {
|
||||
@ -253,12 +252,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||
TestKind::Eq { value, mut ty } => {
|
||||
let val = Operand::Copy(place.clone());
|
||||
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)
|
||||
let fail = self.cfg.start_new_block();
|
||||
if !ty.is_scalar() {
|
||||
// If we're using b"..." as a pattern, we need to insert an
|
||||
// unsizing coercion, as the byte string has the type &[u8; N].
|
||||
// If we're using `b"..."` as a pattern, we need to insert an
|
||||
// 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
|
||||
// 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);
|
||||
true
|
||||
}
|
||||
|
||||
(&TestKind::Switch { .. }, _) => false,
|
||||
|
||||
// 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::Len { len: test_len, op: BinOp::Eq },
|
||||
&PatternKind::Slice { ref prefix, ref slice, ref suffix }) => {
|
||||
let pat_len = (prefix.len() + suffix.len()) as u64;
|
||||
|
@ -13,7 +13,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
||||
subpatterns.iter()
|
||||
.map(|fieldpat| {
|
||||
let place = place.clone().field(fieldpat.field,
|
||||
fieldpat.pattern.ty);
|
||||
fieldpat.pattern.ty);
|
||||
MatchPair::new(place, &fieldpat.pattern)
|
||||
})
|
||||
.collect()
|
||||
|
@ -634,8 +634,8 @@ impl<'tcx> Witness<'tcx> {
|
||||
/// but is instead bounded by the maximum fixed length of slice patterns in
|
||||
/// the column of patterns being analyzed.
|
||||
///
|
||||
/// We make sure to omit constructors that are statically impossible. eg for
|
||||
/// Option<!> we do not include Some(_) in the returned list of constructors.
|
||||
/// 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.
|
||||
fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
||||
pcx: PatternContext<'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
|
||||
/// 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.
|
||||
fn constructor_arity(cx: &MatchCheckCtxt<'a, 'tcx>, ctor: &Constructor<'tcx>, ty: Ty<'tcx>) -> u64 {
|
||||
debug!("constructor_arity({:#?}, {:?})", ctor, ty);
|
||||
@ -1357,7 +1357,7 @@ fn constructor_arity(cx: &MatchCheckCtxt<'a, 'tcx>, ctor: &Constructor<'tcx>, ty
|
||||
Slice(length) => length,
|
||||
ConstantValue(_) => 0,
|
||||
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty)
|
||||
},
|
||||
}
|
||||
ty::Ref(..) => 1,
|
||||
ty::Adt(adt, _) => {
|
||||
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(),
|
||||
ConstantValue(_) => vec![],
|
||||
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty)
|
||||
},
|
||||
}
|
||||
ty::Ref(_, rty, _) => vec![rty],
|
||||
ty::Adt(adt, substs) => {
|
||||
if adt.is_box() {
|
||||
|
@ -375,7 +375,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
||||
},
|
||||
_ => bug!(),
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
hir::MatchSource::ForLoopDesugar |
|
||||
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.emit();
|
||||
},
|
||||
}
|
||||
|
||||
// Unreachable patterns in try expressions occur when one of the arms
|
||||
// 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 head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
|
||||
format!("`{}` and `{}`", head.join("`, `"), tail)
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
let (head, tail) = witnesses.split_at(LIMIT);
|
||||
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() {
|
||||
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,
|
||||
format!("non-exhaustive patterns: {} not covered",
|
||||
@ -456,7 +456,7 @@ fn check_exhaustive<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
|
||||
}
|
||||
NotUseful => {
|
||||
// This is good, wildcard pattern isn't reachable
|
||||
},
|
||||
}
|
||||
_ => bug!()
|
||||
}
|
||||
}
|
||||
|
@ -965,7 +965,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||
PatternKind::Constant {
|
||||
value: cv,
|
||||
}
|
||||
},
|
||||
}
|
||||
ty::Adt(adt_def, _) if adt_def.is_union() => {
|
||||
// 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");
|
||||
@ -978,7 +978,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||
self.tcx.item_path_str(adt_def.did));
|
||||
self.tcx.sess.span_err(span, &msg);
|
||||
PatternKind::Wild
|
||||
},
|
||||
}
|
||||
ty::Adt(adt_def, substs) if adt_def.is_enum() => {
|
||||
let variant_index = const_variant_index(
|
||||
self.tcx, self.param_env, cv
|
||||
@ -993,7 +993,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||
variant_index,
|
||||
subpatterns,
|
||||
}
|
||||
},
|
||||
}
|
||||
ty::Adt(adt_def, _) => {
|
||||
let struct_var = adt_def.non_enum_variant();
|
||||
PatternKind::Leaf {
|
||||
@ -1018,7 +1018,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
|
||||
PatternKind::Constant {
|
||||
value: cv,
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
Pattern {
|
||||
@ -1252,19 +1252,19 @@ pub fn compare_const_vals<'a, 'gcx, 'tcx>(
|
||||
let l = ::rustc_apfloat::ieee::Single::from_bits(a);
|
||||
let r = ::rustc_apfloat::ieee::Single::from_bits(b);
|
||||
l.partial_cmp(&r)
|
||||
},
|
||||
}
|
||||
ty::Float(ast::FloatTy::F64) => {
|
||||
let l = ::rustc_apfloat::ieee::Double::from_bits(a);
|
||||
let r = ::rustc_apfloat::ieee::Double::from_bits(b);
|
||||
l.partial_cmp(&r)
|
||||
},
|
||||
}
|
||||
ty::Int(_) => {
|
||||
let layout = tcx.layout_of(ty).ok()?;
|
||||
assert!(layout.abi.is_signed());
|
||||
let a = sign_extend(a, layout.size);
|
||||
let b = sign_extend(b, layout.size);
|
||||
Some((a as i128).cmp(&(b as i128)))
|
||||
},
|
||||
}
|
||||
_ => Some(a.cmp(&b)),
|
||||
}
|
||||
}
|
||||
|
@ -640,19 +640,26 @@ pub enum PatKind {
|
||||
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
|
||||
/// `0 <= position <= subpats.len()`.
|
||||
Tuple(Vec<P<Pat>>, Option<usize>),
|
||||
|
||||
/// A `box` pattern.
|
||||
Box(P<Pat>),
|
||||
|
||||
/// A reference pattern (e.g., `&mut (a, b)`).
|
||||
Ref(P<Pat>, Mutability),
|
||||
|
||||
/// A literal.
|
||||
Lit(P<Expr>),
|
||||
|
||||
/// A range pattern (e.g., `1...2`, `1..=2` or `1..2`).
|
||||
Range(P<Expr>, P<Expr>, Spanned<RangeEnd>),
|
||||
|
||||
/// `[a, b, ..i, y, z]` is represented as:
|
||||
/// `PatKind::Slice(box [a, b], Some(i), box [y, z])`
|
||||
Slice(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
|
||||
|
||||
/// Parentheses in patterns used for grouping (i.e., `(PAT)`).
|
||||
Paren(P<Pat>),
|
||||
|
||||
/// A macro pattern; pre-expansion.
|
||||
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(e2);
|
||||
vis.visit_span(span);
|
||||
},
|
||||
}
|
||||
PatKind::Slice(before, slice, after) => {
|
||||
visit_vec(before, |pat| vis.visit_pat(pat));
|
||||
visit_opt(slice, |slice| vis.visit_pat(slice));
|
||||
|
@ -4173,7 +4173,8 @@ impl<'a> Parser<'a> {
|
||||
err.emit();
|
||||
self.bump();
|
||||
} else if self.eat(&token::BinOp(token::Or)) {
|
||||
// No op.
|
||||
// This is a No-op. Continue the loop to parse the next
|
||||
// pattern.
|
||||
} else {
|
||||
return Ok(pats);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user