From: Dan Robertson Date: Mon, 18 Feb 2019 18:34:42 +0000 (+0000) Subject: Fix style nits X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=f8b6449f80b75c8d42b1ebbe4c1fb6d4bfec7ace;p=rust.git Fix style nits Fix style nits discovered in reading code. --- diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index f7ffbe8c658..9eeae6eeb5f 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -150,9 +150,11 @@ fn pat(&mut self, pat: &hir::Pat, pred: CFGIndex) -> CFGIndex { } } - fn pats_all<'b, I: Iterator>>(&mut self, - pats: I, - pred: CFGIndex) -> CFGIndex { + fn pats_all<'b, I: Iterator>>( + &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)) } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index d774359fa79..74630bdf9fb 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -948,14 +948,19 @@ pub enum PatKind { /// If the `..` pattern fragment is present, then `Option` denotes its position. /// `0 <= position <= subpats.len()` Tuple(HirVec>, Option), + /// A `box` pattern. Box(P), + /// A reference pattern (e.g., `&mut (a, b)`). Ref(P, Mutability), + /// A literal. Lit(P), + /// A range pattern (e.g., `1...2` or `1..2`). Range(P, P, RangeEnd), + /// `[a, b, ..i, y, z]` is represented as: /// `PatKind::Slice(box [a, b], Some(i), box [y, z])`. Slice(HirVec>, Option>, HirVec>), diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index 231dcc9bfd2..c0596665d75 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -1311,12 +1311,12 @@ fn cat_pattern_(&self, mut cmt: cmt<'tcx>, pat: &hir::Pat, op: &mut F) -> McR 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 @@ fn cat_pattern_(&self, mut cmt: cmt<'tcx>, pat: &hir::Pat, op: &mut F) -> McR } } - 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. diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 66efd2aea15..350bc450263 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -1167,13 +1167,13 @@ pub struct DebruijnIndex { /// [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 diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index 58b466dbe6f..8b4742b4b37 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -192,8 +192,7 @@ fn codegen_intrinsic_call( "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 @@ fn codegen_intrinsic_call( "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()) diff --git a/src/librustc_codegen_llvm/type_.rs b/src/librustc_codegen_llvm/type_.rs index 958e00506d6..ce0a7a287f0 100644 --- a/src/librustc_codegen_llvm/type_.rs +++ b/src/librustc_codegen_llvm/type_.rs @@ -82,7 +82,6 @@ fn type_i8(&self) -> &'ll Type { fn type_i16(&self) -> &'ll Type { unsafe { - llvm::LLVMInt16TypeInContext(self.llcx) } } diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 28d2a397f3e..96d2c903459 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -338,6 +338,7 @@ pub(super) fn expr_into_pattern( 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 @@ pub(super) fn visit_bindings( self.visit_bindings(subpattern, pattern_user_ty, f); } } + PatternKind::Array { ref prefix, ref slice, @@ -556,10 +558,13 @@ pub(super) fn visit_bindings( 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 { diff --git a/src/librustc_mir/build/matches/simplify.rs b/src/librustc_mir/build/matches/simplify.rs index b8e38e40b63..01f8cbfbe8e 100644 --- a/src/librustc_mir/build/matches/simplify.rs +++ b/src/librustc_mir/build/matches/simplify.rs @@ -45,10 +45,10 @@ pub fn simplify_candidate<'pat>(&mut self, } } - /// 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 @@ fn simplify_match_pair<'pat>(&mut self, } else { Err(match_pair) } - }, + } PatternKind::Array { ref prefix, ref slice, ref suffix } => { self.prefix_slice_suffix(&mut candidate.match_pairs, diff --git a/src/librustc_mir/build/matches/test.rs b/src/librustc_mir/build/matches/test.rs index 75189777aa3..a41d3895d6d 100644 --- a/src/librustc_mir/build/matches/test.rs +++ b/src/librustc_mir/build/matches/test.rs @@ -35,10 +35,9 @@ pub fn test<'pat>(&mut self, match_pair: &MatchPair<'pat, 'tcx>) -> Test<'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 @@ pub fn perform_test(&mut self, 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 @@ pub fn sort_candidate<'pat>(&mut self, 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 @@ pub fn sort_candidate<'pat>(&mut self, (&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; diff --git a/src/librustc_mir/build/matches/util.rs b/src/librustc_mir/build/matches/util.rs index ed12c1b3bc9..b583b184a41 100644 --- a/src/librustc_mir/build/matches/util.rs +++ b/src/librustc_mir/build/matches/util.rs @@ -13,7 +13,7 @@ pub fn field_match_pairs<'pat>(&mut self, subpatterns.iter() .map(|fieldpat| { let place = place.clone().field(fieldpat.field, - fieldpat.pattern.ty); + fieldpat.pattern.ty); MatchPair::new(place, &fieldpat.pattern) }) .collect() diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 1c7e1aa4d71..6910fb7e988 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -634,8 +634,8 @@ fn apply_constructor<'a>( /// 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> @@ -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() { diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 8c2ab6437f9..7c44d1bf2c9 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -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!() } } diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 2012086ea66..4d571f4f782 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -965,7 +965,7 @@ fn const_to_pat( 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 @@ fn const_to_pat( 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 @@ fn const_to_pat( variant_index, subpatterns, } - }, + } ty::Adt(adt_def, _) => { let struct_var = adt_def.non_enum_variant(); PatternKind::Leaf { @@ -1018,7 +1018,7 @@ fn const_to_pat( 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)), } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index ab62dd2bc9b..9c4945d74db 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -640,19 +640,26 @@ pub enum PatKind { /// If the `..` pattern fragment is present, then `Option` denotes its position. /// `0 <= position <= subpats.len()`. Tuple(Vec>, Option), + /// A `box` pattern. Box(P), + /// A reference pattern (e.g., `&mut (a, b)`). Ref(P, Mutability), + /// A literal. Lit(P), + /// A range pattern (e.g., `1...2`, `1..=2` or `1..2`). Range(P, P, Spanned), + /// `[a, b, ..i, y, z]` is represented as: /// `PatKind::Slice(box [a, b], Some(i), box [y, z])` Slice(Vec>, Option>, Vec>), + /// Parentheses in patterns used for grouping (i.e., `(PAT)`). Paren(P), + /// A macro pattern; pre-expansion. Mac(Mac), } diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index 1e5eb0992bd..fd7003d30a1 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -1037,7 +1037,7 @@ pub fn noop_visit_pat(pat: &mut P, 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)); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index e22047938e5..b1fb38d8eaf 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4173,7 +4173,8 @@ fn parse_pats(&mut self) -> PResult<'a, Vec>> { 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); }