]> git.lizzy.rs Git - rust.git/commitdiff
Fix style nits
authorDan Robertson <dan@dlrobertson.com>
Mon, 18 Feb 2019 18:34:42 +0000 (18:34 +0000)
committerDan Robertson <dan@dlrobertson.com>
Mon, 18 Feb 2019 22:22:19 +0000 (22:22 +0000)
Fix style nits discovered in reading code.

16 files changed:
src/librustc/cfg/construct.rs
src/librustc/hir/mod.rs
src/librustc/middle/mem_categorization.rs
src/librustc/ty/sty.rs
src/librustc_codegen_llvm/intrinsic.rs
src/librustc_codegen_llvm/type_.rs
src/librustc_mir/build/matches/mod.rs
src/librustc_mir/build/matches/simplify.rs
src/librustc_mir/build/matches/test.rs
src/librustc_mir/build/matches/util.rs
src/librustc_mir/hair/pattern/_match.rs
src/librustc_mir/hair/pattern/check_match.rs
src/librustc_mir/hair/pattern/mod.rs
src/libsyntax/ast.rs
src/libsyntax/mut_visit.rs
src/libsyntax/parse/parser.rs

index f7ffbe8c65833af10c0a040c39df216296a7cd42..9eeae6eeb5f34819f73d44f8c79b0771ab296632 100644 (file)
@@ -150,9 +150,11 @@ fn pat(&mut self, pat: &hir::Pat, pred: CFGIndex) -> CFGIndex {
         }
     }
 
-    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))
     }
index d774359fa79ec2fb8f9b242cab2416ddd6d79943..74630bdf9fb4f6cfa9c581b1d43333c512a6b916 100644 (file)
@@ -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>>),
index 231dcc9bfd272af8d1db2709639b5ceb4e89529a..c0596665d75ad38b32945072ae10826fbf092119 100644 (file)
@@ -1311,12 +1311,12 @@ fn cat_pattern_<F>(&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_<F>(&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.
index 66efd2aea155a7f704bf76287f15587a6dc5b47a..350bc450263226b96d20c35b1ff71f994ec951da 100644 (file)
@@ -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
index 58b466dbe6faabb381e36227d6279e941339ee1a..8b4742b4b372e3a1218e06cda495fdf1451284bf 100644 (file)
@@ -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())
index 958e00506d62a266f192d23eed05cc83328062fb..ce0a7a287f050e4234dbcb1a15c83f74672df04b 100644 (file)
@@ -82,7 +82,6 @@ fn type_i8(&self) -> &'ll Type {
 
     fn type_i16(&self) -> &'ll Type {
         unsafe {
-
             llvm::LLVMInt16TypeInContext(self.llcx)
         }
     }
index 28d2a397f3ed61bc9b15811e7b5f34210612d97a..96d2c90345933d7487bb101f5e95286dec6fdd35 100644 (file)
@@ -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 {
index b8e38e40b63474f479024aa3cc7e650a85c117c7..01f8cbfbe8e2b2a4d727647966bf8ed412ed73ba 100644 (file)
@@ -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,
index 75189777aa31113f9c2322ea55e4c0051e277f78..a41d3895d6d3cfcace3d167745f430ca6461f159 100644 (file)
@@ -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;
index ed12c1b3bc9c1de1461b3c657a97eef8eebfc24d..b583b184a4103146286e5d81a7e53d5cf9d55a5f 100644 (file)
@@ -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()
index 1c7e1aa4d71e0a5bdca22031e3bd56ee9ff16055..6910fb7e988bb268ddf27f964bc94d352bff948c 100644 (file)
@@ -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<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() {
index 8c2ab6437f9a29d1a554eb368c5dea4a6f3a11af..7c44d1bf2c9369d2dd5cca0df6d4bd19de32bead 100644 (file)
@@ -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!()
     }
 }
index 2012086ea664937584234cc38ad07eec82418467..4d571f4f78296124d665a00d3818c5244e38d0c2 100644 (file)
@@ -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)),
         }
     }
index ab62dd2bc9b0165fd4abb2161c20268c7bc68ffd..9c4945d74dbfef9e82e07bffd3d04441f413d151 100644 (file)
@@ -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),
 }
index 1e5eb0992bd1bbbe4377faed0b97629a08c3711a..fd7003d30a1dc5c0613936305ba5e5282733bd41 100644 (file)
@@ -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));
index e22047938e51821d564878b9c781ffa5941ba5b7..b1fb38d8eafb4e4404dd4f32ab8706444b10694f 100644 (file)
@@ -4173,7 +4173,8 @@ fn parse_pats(&mut self) -> PResult<'a, Vec<P<Pat>>> {
                 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);
             }