Skip to content

Commit f8b6449

Browse files
committed
Fix style nits
Fix style nits discovered in reading code.
1 parent 684b09b commit f8b6449

File tree

16 files changed

+64
-48
lines changed

16 files changed

+64
-48
lines changed

src/librustc/cfg/construct.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
150150
}
151151
}
152152

153-
fn pats_all<'b, I: Iterator<Item=&'b P<hir::Pat>>>(&mut self,
154-
pats: I,
155-
pred: CFGIndex) -> CFGIndex {
153+
fn pats_all<'b, I: Iterator<Item=&'b P<hir::Pat>>>(
154+
&mut self,
155+
pats: I,
156+
pred: CFGIndex
157+
) -> CFGIndex {
156158
//! Handles case where all of the patterns must match.
157159
pats.fold(pred, |pred, pat| self.pat(&pat, pred))
158160
}

src/librustc/hir/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -948,14 +948,19 @@ pub enum PatKind {
948948
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
949949
/// `0 <= position <= subpats.len()`
950950
Tuple(HirVec<P<Pat>>, Option<usize>),
951+
951952
/// A `box` pattern.
952953
Box(P<Pat>),
954+
953955
/// A reference pattern (e.g., `&mut (a, b)`).
954956
Ref(P<Pat>, Mutability),
957+
955958
/// A literal.
956959
Lit(P<Expr>),
960+
957961
/// A range pattern (e.g., `1...2` or `1..2`).
958962
Range(P<Expr>, P<Expr>, RangeEnd),
963+
959964
/// `[a, b, ..i, y, z]` is represented as:
960965
/// `PatKind::Slice(box [a, b], Some(i), box [y, z])`.
961966
Slice(HirVec<P<Pat>>, Option<P<Pat>>, HirVec<P<Pat>>),

src/librustc/middle/mem_categorization.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1311,12 +1311,12 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
13111311
Def::Err => {
13121312
debug!("access to unresolvable pattern {:?}", pat);
13131313
return Err(())
1314-
},
1314+
}
13151315
Def::Variant(variant_did) |
13161316
Def::VariantCtor(variant_did, ..) => {
13171317
self.cat_downcast_if_needed(pat, cmt, variant_did)
1318-
},
1319-
_ => cmt
1318+
}
1319+
_ => cmt,
13201320
};
13211321

13221322
for fp in field_pats {
@@ -1347,7 +1347,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
13471347
}
13481348
}
13491349

1350-
PatKind::Box(ref subpat) | PatKind::Ref(ref subpat, _) => {
1350+
PatKind::Box(ref subpat) | PatKind::Ref(ref subpat, _) => {
13511351
// box p1, &p1, &mut p1. we can ignore the mutability of
13521352
// PatKind::Ref since that information is already contained
13531353
// in the type.

src/librustc/ty/sty.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1167,13 +1167,13 @@ pub type Region<'tcx> = &'tcx RegionKind;
11671167
/// [rustc guide]: https://rust-lang.github.io/rustc-guide/traits/hrtb.html
11681168
#[derive(Clone, PartialEq, Eq, Hash, Copy, RustcEncodable, RustcDecodable, PartialOrd, Ord)]
11691169
pub enum RegionKind {
1170-
// Region bound in a type or fn declaration which will be
1171-
// substituted 'early' -- that is, at the same time when type
1172-
// parameters are substituted.
1170+
/// Region bound in a type or fn declaration which will be
1171+
/// substituted 'early' -- that is, at the same time when type
1172+
/// parameters are substituted.
11731173
ReEarlyBound(EarlyBoundRegion),
11741174

1175-
// Region bound in a function scope, which will be substituted when the
1176-
// function is called.
1175+
/// Region bound in a function scope, which will be substituted when the
1176+
/// function is called.
11771177
ReLateBound(DebruijnIndex, BoundRegion),
11781178

11791179
/// When checking a function body, the types of all arguments and so forth

src/librustc_codegen_llvm/intrinsic.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
192192
"size_of_val" => {
193193
let tp_ty = substs.type_at(0);
194194
if let OperandValue::Pair(_, meta) = args[0].val {
195-
let (llsize, _) =
196-
glue::size_and_align_of_dst(self, tp_ty, Some(meta));
195+
let (llsize, _) = glue::size_and_align_of_dst(self, tp_ty, Some(meta));
197196
llsize
198197
} else {
199198
self.const_usize(self.size_of(tp_ty).bytes())
@@ -206,8 +205,7 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
206205
"min_align_of_val" => {
207206
let tp_ty = substs.type_at(0);
208207
if let OperandValue::Pair(_, meta) = args[0].val {
209-
let (_, llalign) =
210-
glue::size_and_align_of_dst(self, tp_ty, Some(meta));
208+
let (_, llalign) = glue::size_and_align_of_dst(self, tp_ty, Some(meta));
211209
llalign
212210
} else {
213211
self.const_usize(self.align_of(tp_ty).bytes())

src/librustc_codegen_llvm/type_.rs

-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ impl BaseTypeMethods<'tcx> for CodegenCx<'ll, 'tcx> {
8282

8383
fn type_i16(&self) -> &'ll Type {
8484
unsafe {
85-
8685
llvm::LLVMInt16TypeInContext(self.llcx)
8786
}
8887
}

src/librustc_mir/build/matches/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
338338
self.schedule_drop_for_binding(var, irrefutable_pat.span, OutsideGuard);
339339
block.unit()
340340
}
341+
341342
_ => {
342343
let place = unpack!(block = self.as_place(block, initializer));
343344
self.place_into_pattern(block, irrefutable_pat, &place, true)
@@ -534,6 +535,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
534535
self.visit_bindings(subpattern, pattern_user_ty, f);
535536
}
536537
}
538+
537539
PatternKind::Array {
538540
ref prefix,
539541
ref slice,
@@ -556,10 +558,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
556558
self.visit_bindings(subpattern, pattern_user_ty.clone().index(), f);
557559
}
558560
}
561+
559562
PatternKind::Constant { .. } | PatternKind::Range { .. } | PatternKind::Wild => {}
563+
560564
PatternKind::Deref { ref subpattern } => {
561565
self.visit_bindings(subpattern, pattern_user_ty.deref(), f);
562566
}
567+
563568
PatternKind::AscribeUserType {
564569
ref subpattern,
565570
ascription: hair::pattern::Ascription {

src/librustc_mir/build/matches/simplify.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
4545
}
4646
}
4747

48-
/// Tries to simplify `match_pair`, returning true if
48+
/// Tries to simplify `match_pair`, returning `Ok(())` if
4949
/// successful. If successful, new match pairs and bindings will
5050
/// have been pushed into the candidate. If no simplification is
51-
/// possible, Err is returned and no changes are made to
51+
/// possible, `Err` is returned and no changes are made to
5252
/// candidate.
5353
fn simplify_match_pair<'pat>(&mut self,
5454
match_pair: MatchPair<'pat, 'tcx>,
@@ -174,7 +174,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
174174
} else {
175175
Err(match_pair)
176176
}
177-
},
177+
}
178178

179179
PatternKind::Array { ref prefix, ref slice, ref suffix } => {
180180
self.prefix_slice_suffix(&mut candidate.match_pairs,

src/librustc_mir/build/matches/test.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
3535
}
3636
}
3737

38-
PatternKind::Constant { .. }
39-
if is_switch_ty(match_pair.pattern.ty) => {
40-
// for integers, we use a SwitchInt match, which allows
41-
// us to handle more cases
38+
PatternKind::Constant { .. } if is_switch_ty(match_pair.pattern.ty) => {
39+
// For integers, we use a `SwitchInt` match, which allows
40+
// us to handle more cases.
4241
Test {
4342
span: match_pair.pattern.span,
4443
kind: TestKind::SwitchInt {
@@ -253,12 +252,12 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
253252
TestKind::Eq { value, mut ty } => {
254253
let val = Operand::Copy(place.clone());
255254
let mut expect = self.literal_operand(test.span, ty, value);
256-
// Use PartialEq::eq instead of BinOp::Eq
255+
// Use `PartialEq::eq` instead of `BinOp::Eq`
257256
// (the binop can only handle primitives)
258257
let fail = self.cfg.start_new_block();
259258
if !ty.is_scalar() {
260-
// If we're using b"..." as a pattern, we need to insert an
261-
// unsizing coercion, as the byte string has the type &[u8; N].
259+
// If we're using `b"..."` as a pattern, we need to insert an
260+
// unsizing coercion, as the byte string has the type `&[u8; N]`.
262261
//
263262
// We want to do this even when the scrutinee is a reference to an
264263
// 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> {
503502
resulting_candidates[variant_index.as_usize()].push(new_candidate);
504503
true
505504
}
505+
506506
(&TestKind::Switch { .. }, _) => false,
507507

508508
// If we are performing a switch over integers, then this informs integer
@@ -539,7 +539,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
539539

540540
(&TestKind::SwitchInt { .. }, _) => false,
541541

542-
543542
(&TestKind::Len { len: test_len, op: BinOp::Eq },
544543
&PatternKind::Slice { ref prefix, ref slice, ref suffix }) => {
545544
let pat_len = (prefix.len() + suffix.len()) as u64;

src/librustc_mir/build/matches/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
1313
subpatterns.iter()
1414
.map(|fieldpat| {
1515
let place = place.clone().field(fieldpat.field,
16-
fieldpat.pattern.ty);
16+
fieldpat.pattern.ty);
1717
MatchPair::new(place, &fieldpat.pattern)
1818
})
1919
.collect()

src/librustc_mir/hair/pattern/_match.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,8 @@ impl<'tcx> Witness<'tcx> {
634634
/// but is instead bounded by the maximum fixed length of slice patterns in
635635
/// the column of patterns being analyzed.
636636
///
637-
/// We make sure to omit constructors that are statically impossible. eg for
638-
/// Option<!> we do not include Some(_) in the returned list of constructors.
637+
/// We make sure to omit constructors that are statically impossible. E.g., for
638+
/// `Option<!>`, we do not include `Some(_)` in the returned list of constructors.
639639
fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
640640
pcx: PatternContext<'tcx>)
641641
-> Vec<Constructor<'tcx>>
@@ -1347,7 +1347,7 @@ fn pat_constructors<'tcx>(cx: &mut MatchCheckCtxt<'_, 'tcx>,
13471347
/// This computes the arity of a constructor. The arity of a constructor
13481348
/// is how many subpattern patterns of that constructor should be expanded to.
13491349
///
1350-
/// For instance, a tuple pattern (_, 42, Some([])) has the arity of 3.
1350+
/// For instance, a tuple pattern `(_, 42, Some([]))` has the arity of 3.
13511351
/// A struct pattern's arity is the number of fields it contains, etc.
13521352
fn constructor_arity(cx: &MatchCheckCtxt<'a, 'tcx>, ctor: &Constructor<'tcx>, ty: Ty<'tcx>) -> u64 {
13531353
debug!("constructor_arity({:#?}, {:?})", ctor, ty);
@@ -1357,7 +1357,7 @@ fn constructor_arity(cx: &MatchCheckCtxt<'a, 'tcx>, ctor: &Constructor<'tcx>, ty
13571357
Slice(length) => length,
13581358
ConstantValue(_) => 0,
13591359
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty)
1360-
},
1360+
}
13611361
ty::Ref(..) => 1,
13621362
ty::Adt(adt, _) => {
13631363
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>,
13811381
Slice(length) => (0..length).map(|_| ty).collect(),
13821382
ConstantValue(_) => vec![],
13831383
_ => bug!("bad slice pattern {:?} {:?}", ctor, ty)
1384-
},
1384+
}
13851385
ty::Ref(_, rty, _) => vec![rty],
13861386
ty::Adt(adt, substs) => {
13871387
if adt.is_box() {

src/librustc_mir/hair/pattern/check_match.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
375375
},
376376
_ => bug!(),
377377
}
378-
},
378+
}
379379

380380
hir::MatchSource::ForLoopDesugar |
381381
hir::MatchSource::Normal => {
@@ -391,7 +391,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
391391
err.span_label(catchall, "matches any value");
392392
}
393393
err.emit();
394-
},
394+
}
395395

396396
// Unreachable patterns in try expressions occur when one of the arms
397397
// are an uninhabited type. Which is OK.
@@ -436,7 +436,7 @@ fn check_exhaustive<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
436436
let (tail, head) = witnesses.split_last().unwrap();
437437
let head: Vec<_> = head.iter().map(|w| w.to_string()).collect();
438438
format!("`{}` and `{}`", head.join("`, `"), tail)
439-
},
439+
}
440440
_ => {
441441
let (head, tail) = witnesses.split_at(LIMIT);
442442
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>,
446446

447447
let label_text = match witnesses.len() {
448448
1 => format!("pattern {} not covered", joined_patterns),
449-
_ => format!("patterns {} not covered", joined_patterns)
449+
_ => format!("patterns {} not covered", joined_patterns),
450450
};
451451
create_e0004(cx.tcx.sess, sp,
452452
format!("non-exhaustive patterns: {} not covered",
@@ -456,7 +456,7 @@ fn check_exhaustive<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
456456
}
457457
NotUseful => {
458458
// This is good, wildcard pattern isn't reachable
459-
},
459+
}
460460
_ => bug!()
461461
}
462462
}

src/librustc_mir/hair/pattern/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
965965
PatternKind::Constant {
966966
value: cv,
967967
}
968-
},
968+
}
969969
ty::Adt(adt_def, _) if adt_def.is_union() => {
970970
// Matching on union fields is unsafe, we can't hide it in constants
971971
self.tcx.sess.span_err(span, "cannot use unions in constant patterns");
@@ -978,7 +978,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
978978
self.tcx.item_path_str(adt_def.did));
979979
self.tcx.sess.span_err(span, &msg);
980980
PatternKind::Wild
981-
},
981+
}
982982
ty::Adt(adt_def, substs) if adt_def.is_enum() => {
983983
let variant_index = const_variant_index(
984984
self.tcx, self.param_env, cv
@@ -993,7 +993,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
993993
variant_index,
994994
subpatterns,
995995
}
996-
},
996+
}
997997
ty::Adt(adt_def, _) => {
998998
let struct_var = adt_def.non_enum_variant();
999999
PatternKind::Leaf {
@@ -1018,7 +1018,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> {
10181018
PatternKind::Constant {
10191019
value: cv,
10201020
}
1021-
},
1021+
}
10221022
};
10231023

10241024
Pattern {
@@ -1252,19 +1252,19 @@ pub fn compare_const_vals<'a, 'gcx, 'tcx>(
12521252
let l = ::rustc_apfloat::ieee::Single::from_bits(a);
12531253
let r = ::rustc_apfloat::ieee::Single::from_bits(b);
12541254
l.partial_cmp(&r)
1255-
},
1255+
}
12561256
ty::Float(ast::FloatTy::F64) => {
12571257
let l = ::rustc_apfloat::ieee::Double::from_bits(a);
12581258
let r = ::rustc_apfloat::ieee::Double::from_bits(b);
12591259
l.partial_cmp(&r)
1260-
},
1260+
}
12611261
ty::Int(_) => {
12621262
let layout = tcx.layout_of(ty).ok()?;
12631263
assert!(layout.abi.is_signed());
12641264
let a = sign_extend(a, layout.size);
12651265
let b = sign_extend(b, layout.size);
12661266
Some((a as i128).cmp(&(b as i128)))
1267-
},
1267+
}
12681268
_ => Some(a.cmp(&b)),
12691269
}
12701270
}

src/libsyntax/ast.rs

+7
Original file line numberDiff line numberDiff line change
@@ -640,19 +640,26 @@ pub enum PatKind {
640640
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
641641
/// `0 <= position <= subpats.len()`.
642642
Tuple(Vec<P<Pat>>, Option<usize>),
643+
643644
/// A `box` pattern.
644645
Box(P<Pat>),
646+
645647
/// A reference pattern (e.g., `&mut (a, b)`).
646648
Ref(P<Pat>, Mutability),
649+
647650
/// A literal.
648651
Lit(P<Expr>),
652+
649653
/// A range pattern (e.g., `1...2`, `1..=2` or `1..2`).
650654
Range(P<Expr>, P<Expr>, Spanned<RangeEnd>),
655+
651656
/// `[a, b, ..i, y, z]` is represented as:
652657
/// `PatKind::Slice(box [a, b], Some(i), box [y, z])`
653658
Slice(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
659+
654660
/// Parentheses in patterns used for grouping (i.e., `(PAT)`).
655661
Paren(P<Pat>),
662+
656663
/// A macro pattern; pre-expansion.
657664
Mac(Mac),
658665
}

src/libsyntax/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ pub fn noop_visit_pat<T: MutVisitor>(pat: &mut P<Pat>, vis: &mut T) {
10371037
vis.visit_expr(e1);
10381038
vis.visit_expr(e2);
10391039
vis.visit_span(span);
1040-
},
1040+
}
10411041
PatKind::Slice(before, slice, after) => {
10421042
visit_vec(before, |pat| vis.visit_pat(pat));
10431043
visit_opt(slice, |slice| vis.visit_pat(slice));

0 commit comments

Comments
 (0)