Skip to content

Commit d2b8532

Browse files
author
Alexander Regueiro
committed
Addressed points raised in review.
1 parent d43966a commit d2b8532

File tree

13 files changed

+44
-48
lines changed

13 files changed

+44
-48
lines changed

clippy_lints/src/assertions_on_constants.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ declare_clippy_lint! {
2626
/// ```
2727
pub ASSERTIONS_ON_CONSTANTS,
2828
style,
29-
"`assert!(true)` / `assert!(false)` will be optimized out by the compiler, \
30-
and should probably be replaced by a `panic!()` or `unreachable!()`"
29+
"`assert!(true)` / `assert!(false)` will be optimized out by the compiler, and should probably be replaced by a `panic!()` or `unreachable!()`"
3130
}
3231

3332
pub struct AssertionsOnConstants;

clippy_lints/src/doc.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,8 @@ fn check_text(cx: &EarlyContext<'_>, valid_idents: &FxHashSet<String>, text: &st
258258

259259
fn check_word(cx: &EarlyContext<'_>, word: &str, span: Span) {
260260
/// Checks if a string is camel-case, i.e., contains at least two uppercase
261-
/// letters (`Clippy` is
262-
/// ok) and one lower-case letter (`NASA` is ok). Plural are also excluded
263-
/// (`IDs` is ok).
261+
/// letters (`Clippy` is ok) and one lower-case letter (`NASA` is ok).
262+
/// Plurals are also excluded (`IDs` is ok).
264263
fn is_camel_case(s: &str) -> bool {
265264
if s.starts_with(|c: char| c.is_digit(10)) {
266265
return false;

clippy_lints/src/lifetimes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ declare_clippy_lint! {
2020
/// them leads to more readable code.
2121
///
2222
/// **Known problems:** Potential false negatives: we bail out if the function
23-
/// has a where-clause where lifetimes are mentioned.
23+
/// has a `where` clause where lifetimes are mentioned.
2424
///
2525
/// **Example:**
2626
/// ```rust
@@ -385,7 +385,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
385385
}
386386
}
387387

388-
/// Are any lifetimes mentioned in the where-clause? If yes, we don't try to
388+
/// Are any lifetimes mentioned in the `where` clause? If so, we don't try to
389389
/// reason about elision.
390390
fn has_where_lifetimes<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, where_clause: &'tcx WhereClause) -> bool {
391391
for predicate in &where_clause.predicates {

clippy_lints/src/loops.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,7 @@ fn check_for_loop_arg(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr, expr: &Ex
14131413
}
14141414
}
14151415

1416-
/// Checks for `for` loops over `Option`s and `Results`
1416+
/// Checks for `for` loops over `Option`s and `Result`s.
14171417
fn check_arg_type(cx: &LateContext<'_, '_>, pat: &Pat, arg: &Expr) {
14181418
let ty = cx.tables.expr_ty(arg);
14191419
if match_type(cx, ty, &paths::OPTION) {
@@ -1673,7 +1673,7 @@ fn check_for_mutation(
16731673
delegate.mutation_span()
16741674
}
16751675

1676-
/// Returns `true` if the pattern is a `PatWild` or an ident prefixed with `'_'`.
1676+
/// Returns `true` if the pattern is a `PatWild` or an ident prefixed with `_`.
16771677
fn pat_is_wild<'tcx>(pat: &'tcx PatKind, body: &'tcx Expr) -> bool {
16781678
match *pat {
16791679
PatKind::Wild => true,
@@ -2336,7 +2336,7 @@ fn path_name(e: &Expr) -> Option<Name> {
23362336

23372337
fn check_infinite_loop<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, cond: &'tcx Expr, expr: &'tcx Expr) {
23382338
if constant(cx, cx.tables, cond).is_some() {
2339-
// A pure constant condition (e.g., while false) is not linted.
2339+
// A pure constant condition (e.g., `while false`) is not linted.
23402340
return;
23412341
}
23422342

clippy_lints/src/matches.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ fn check_single_match_opt_like(
322322
ty: Ty<'_>,
323323
els: Option<&Expr>,
324324
) {
325-
// list of candidate Enums we know will never get any more members
325+
// list of candidate `Enum`s we know will never get any more members
326326
let candidates = &[
327327
(&paths::COW, "Borrowed"),
328328
(&paths::COW, "Cow::Borrowed"),
@@ -335,7 +335,7 @@ fn check_single_match_opt_like(
335335

336336
let path = match arms[1].pats[0].node {
337337
PatKind::TupleStruct(ref path, ref inner, _) => {
338-
// contains any non wildcard patterns? e.g., Err(err)
338+
// Contains any non wildcard patterns (e.g., `Err(err)`)?
339339
if !inner.iter().all(is_wild) {
340340
return;
341341
}
@@ -354,7 +354,7 @@ fn check_single_match_opt_like(
354354
}
355355

356356
fn check_match_bool(cx: &LateContext<'_, '_>, ex: &Expr, arms: &[Arm], expr: &Expr) {
357-
// type of expression == bool
357+
// Type of expression is `bool`.
358358
if cx.tables.expr_ty(ex).sty == ty::Bool {
359359
span_lint_and_then(
360360
cx,

clippy_lints/src/misc.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,7 @@ fn is_used(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
592592
}
593593

594594
/// Tests whether an expression is in a macro expansion (e.g., something
595-
/// generated by
596-
/// `#[derive(...)`] or the like).
595+
/// generated by `#[derive(...)]` or the like).
597596
fn in_attributes_expansion(expr: &Expr) -> bool {
598597
expr.span
599598
.ctxt()

clippy_lints/src/question_mark.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Pass {
5252
///
5353
/// ```ignore
5454
/// if option.is_none() {
55-
/// return `None`;
55+
/// return None;
5656
/// }
5757
/// ```
5858
///

clippy_lints/src/slow_vector_initialization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ struct VectorInitializationVisitor<'a, 'tcx: 'a> {
197197
/// Contains the information.
198198
vec_alloc: VecAllocation<'tcx>,
199199

200-
/// Contains, the slow initialization expression, if one was found.
200+
/// Contains the slow initialization expression, if one was found.
201201
slow_expression: Option<InitializationType<'tcx>>,
202202

203203
/// `true` if the initialization of the vector has been found on the visited block.

clippy_lints/src/utils/camel_case.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
/// Returns the index of the character after the first camel-case component of
2-
/// `s`.
1+
/// Returns the index of the character after the first camel-case component of `s`.
32
pub fn until(s: &str) -> usize {
43
let mut iter = s.char_indices();
54
if let Some((_, first)) = iter.next() {

clippy_lints/src/utils/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,15 @@ pub fn get_def_path(tcx: TyCtxt<'_, '_, '_>, def_id: DefId) -> Vec<&'static str>
147147
.collect()
148148
}
149149

150-
/// Checks if type is struct, enum or union type with given def path.
150+
/// Checks if type is struct, enum or union type with the given def path.
151151
pub fn match_type(cx: &LateContext<'_, '_>, ty: Ty<'_>, path: &[&str]) -> bool {
152152
match ty.sty {
153153
ty::Adt(adt, _) => match_def_path(cx.tcx, adt.did, path),
154154
_ => false,
155155
}
156156
}
157157

158-
/// Checks if the method call given in `expr` belongs to given trait.
158+
/// Checks if the method call given in `expr` belongs to the given trait.
159159
pub fn match_trait_method(cx: &LateContext<'_, '_>, expr: &Expr, path: &[&str]) -> bool {
160160
let method_call = cx.tables.type_dependent_defs()[expr.hir_id];
161161
let trt_id = cx.tcx.trait_of_item(method_call.def_id());
@@ -434,7 +434,7 @@ pub fn get_item_name(cx: &LateContext<'_, '_>, expr: &Expr) -> Option<Name> {
434434
}
435435
}
436436

437-
/// Gets the name of a `Pat`, if any
437+
/// Gets the name of a `Pat`, if any.
438438
pub fn get_pat_name(pat: &Pat) -> Option<Name> {
439439
match pat.node {
440440
PatKind::Binding(.., ref spname, _) => Some(spname.name),
@@ -614,7 +614,7 @@ fn trim_multiline_inner(s: Cow<'_, str>, ignore_first: bool, ch: char) -> Cow<'_
614614
}
615615
}
616616

617-
/// Gets a parent expressions if any – this is useful to constrain a lint.
617+
/// Gets the parent expression, if any –- this is useful to constrain a lint.
618618
pub fn get_parent_expr<'c>(cx: &'c LateContext<'_, '_>, e: &Expr) -> Option<&'c Expr> {
619619
let map = &cx.tcx.hir();
620620
let hir_id = e.hir_id;
@@ -727,7 +727,7 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
727727
}
728728
}
729729

730-
/// Returns the pre-expansion span if is this directly comes from an expansion
730+
/// Returns the pre-expansion span if the span directly comes from an expansion
731731
/// of the macro `name`.
732732
/// The difference with `is_expn_of` is that in
733733
/// ```rust,ignore
@@ -749,7 +749,7 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
749749
}
750750
}
751751

752-
/// Convenience function to get the return type of a function
752+
/// Convenience function to get the return type of a function.
753753
pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: hir::HirId) -> Ty<'tcx> {
754754
let fn_def_id = cx.tcx.hir().local_def_id_from_hir_id(fn_item);
755755
let ret_ty = cx.tcx.fn_sig(fn_def_id).output();
@@ -759,9 +759,9 @@ pub fn return_ty<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, fn_item: hir::HirId) -> T
759759
/// Checks if two types are the same.
760760
///
761761
/// This discards any lifetime annotations, too.
762-
// FIXME: this works correctly for lifetimes bounds (`for <'a> Foo<'a>` == `for
763-
// <'b> Foo<'b>` but
764-
// not for type parameters.
762+
//
763+
// FIXME: this works correctly for lifetimes bounds (`for <'a> Foo<'a>` ==
764+
// `for <'b> Foo<'b>`, but not for type parameters).
765765
pub fn same_tys<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
766766
let a = cx.tcx.erase_late_bound_regions(&Binder::bind(a));
767767
let b = cx.tcx.erase_late_bound_regions(&Binder::bind(b));
@@ -871,8 +871,8 @@ pub fn iter_input_pats<'tcx>(decl: &FnDecl, body: &'tcx Body) -> impl Iterator<I
871871
(0..decl.inputs.len()).map(move |i| &body.arguments[i])
872872
}
873873

874-
/// Checks if a given expression is a match expression
875-
/// expanded from `?` operator or `try` macro.
874+
/// Checks if a given expression is a match expression expanded from the `?`
875+
/// operator or the `try` macro.
876876
pub fn is_try<'a>(cx: &'_ LateContext<'_, '_>, expr: &'a Expr) -> Option<&'a Expr> {
877877
fn is_ok(cx: &'_ LateContext<'_, '_>, arm: &Arm) -> bool {
878878
if_chain! {

clippy_lints/src/utils/sugg.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,12 @@ impl<'a> Sugg<'a> {
241241
}
242242

243243
/// Adds parenthesis to any expression that might need them. Suitable to the
244-
/// `self` argument of
245-
/// a method call (e.g., to build `bar.foo()` or `(1 + 2).foo()`).
244+
/// `self` argument of a method call
245+
/// (e.g., to build `bar.foo()` or `(1 + 2).foo()`).
246246
pub fn maybe_par(self) -> Self {
247247
match self {
248248
Sugg::NonParen(..) => self,
249-
// (x) and (x).y() both don't need additional parens
249+
// `(x)` and `(x).y()` both don't need additional parens.
250250
Sugg::MaybeParen(sugg) => {
251251
if sugg.starts_with('(') && sugg.ends_with(')') {
252252
Sugg::MaybeParen(sugg)
@@ -282,7 +282,7 @@ impl<'a> std::ops::Not for Sugg<'a> {
282282

283283
/// Helper type to display either `foo` or `(foo)`.
284284
struct ParenHelper<T> {
285-
/// Whether parenthesis are needed.
285+
/// `true` if parentheses are needed.
286286
paren: bool,
287287
/// The main thing to display.
288288
wrapped: T,
@@ -320,22 +320,22 @@ pub fn make_unop(op: &str, expr: Sugg<'_>) -> Sugg<'static> {
320320
/// often confusing so
321321
/// parenthesis will always be added for a mix of these.
322322
pub fn make_assoc(op: AssocOp, lhs: &Sugg<'_>, rhs: &Sugg<'_>) -> Sugg<'static> {
323-
/// Whether the operator is a shift operator `<<` or `>>`.
323+
/// Returns `true` if the operator is a shift operator `<<` or `>>`.
324324
fn is_shift(op: &AssocOp) -> bool {
325325
matches!(*op, AssocOp::ShiftLeft | AssocOp::ShiftRight)
326326
}
327327

328-
/// Whether the operator is a arithmetic operator (`+`, `-`, `*`, `/`, `%`).
328+
/// Returns `true` if the operator is a arithmetic operator
329+
/// (i.e., `+`, `-`, `*`, `/`, `%`).
329330
fn is_arith(op: &AssocOp) -> bool {
330331
matches!(
331332
*op,
332333
AssocOp::Add | AssocOp::Subtract | AssocOp::Multiply | AssocOp::Divide | AssocOp::Modulus
333334
)
334335
}
335336

336-
/// Whether the operator `op` needs parenthesis with the operator `other`
337-
/// in the direction
338-
/// `dir`.
337+
/// Returns `true` if the operator `op` needs parenthesis with the operator
338+
/// `other` in the direction `dir`.
339339
fn needs_paren(op: &AssocOp, other: &AssocOp, dir: Associativity) -> bool {
340340
other.precedence() < op.precedence()
341341
|| (other.precedence() == op.precedence()
@@ -414,9 +414,8 @@ enum Associativity {
414414
}
415415

416416
/// Returns the associativity/fixity of an operator. The difference with
417-
/// `AssocOp::fixity` is that
418-
/// an operator can be both left and right associative (such as `+`:
419-
/// `a + b + c == (a + b) + c == a + (b + c)`.
417+
/// `AssocOp::fixity` is that an operator can be both left and right associative
418+
/// (such as `+`: `a + b + c == (a + b) + c == a + (b + c)`.
420419
///
421420
/// Chained `as` and explicit `:` type coercion never need inner parenthesis so
422421
/// they are considered

tests/ui/block_in_if_condition.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ fn predicate<F: FnOnce(T) -> bool, T>(pfn: F, val: T) -> bool {
4848
fn pred_test() {
4949
let v = 3;
5050
let sky = "blue";
51-
// this is a sneaky case, where the block isn't directly in the condition, but is actually
52-
, andadd some extra
53-
// expressions to make sure linter isn't confused by them.
51+
// This is a sneaky case, where the block isn't directly in the condition,
52+
// but is actually nside a closure that the condition is using.
53+
// The same principle applies -- add some extra expressions to make sure
54+
// linter isn't confused by them.
5455
if v == 3
5556
&& sky == "blue"
5657
&& predicate(

tests/ui/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
struct Foo(pub String);
77

88
macro_rules! foo {
9-
($($t:tt)*) => (Foo(format!($($t)*)))
9+
($($t:tt)*) => (Foo(format!($($t)*)))
1010
}
1111

1212
fn main() {
@@ -49,8 +49,8 @@ fn main() {
4949
foo!("should not warn");
5050

5151
// Precision on string means slicing without panicking on size.
52-
format!("{:.1}", "foo"); // could be `"foo"[..1]`
53-
format!("{:.10}", "foo"); // could not be `"foo"[..10]`
52+
format!("{:.1}", "foo"); // Could be `"foo"[..1]`
53+
format!("{:.10}", "foo"); // Could not be `"foo"[..10]`
5454
format!("{:.prec$}", "foo", prec = 1);
5555
format!("{:.prec$}", "foo", prec = 10);
5656

0 commit comments

Comments
 (0)