Skip to content

Commit

Permalink
Fix style nits
Browse files Browse the repository at this point in the history
Fix style nits discovered in reading code.
  • Loading branch information
dlrobertson committed Feb 18, 2019
1 parent 684b09b commit f8b6449
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 48 deletions.
8 changes: 5 additions & 3 deletions src/librustc/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,14 +948,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>>),
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_codegen_llvm/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand Down
1 change: 0 additions & 1 deletion src/librustc_codegen_llvm/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {

fn type_i16(&self) -> &'ll Type {
unsafe {

llvm::LLVMInt16TypeInContext(self.llcx)
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_mir/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/build/matches/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 7 additions & 8 deletions src/librustc_mir/build/matches/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/matches/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_mir/hair/pattern/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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() {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_mir/hair/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
},
_ => bug!(),
}
},
}

hir::MatchSource::ForLoopDesugar |
hir::MatchSource::Normal => {
Expand All @@ -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.
Expand Down Expand Up @@ -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();
Expand All @@ -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",
Expand All @@ -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!()
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_mir/hair/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -1018,7 +1018,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
PatternKind::Constant {
value: cv,
}
},
}
};

Pattern {
Expand Down Expand Up @@ -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)),
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading

0 comments on commit f8b6449

Please sign in to comment.