Skip to content

Commit 94aafe1

Browse files
author
Alexander Regueiro
committed
Various cosmetic improvements.
1 parent 32ee306 commit 94aafe1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+400
-370
lines changed

clippy_dev/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub struct FileChange {
189189
pub new_lines: String,
190190
}
191191

192-
/// Replace a region in a file delimited by two lines matching regexes.
192+
/// Replaces a region in a file delimited by two lines matching regexes.
193193
///
194194
/// `path` is the relative path to the file on which you want to perform the replacement.
195195
///
@@ -223,7 +223,7 @@ where
223223
file_change
224224
}
225225

226-
/// Replace a region in a text delimited by two lines matching regexes.
226+
/// Replaces a region in a text delimited by two lines matching regexes.
227227
///
228228
/// * `text` is the input text on which you want to perform the replacement
229229
/// * `start` is a `&str` that describes the delimiter line before the region you want to replace.

clippy_lints/src/approx_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, mod
104104
}
105105
}
106106

107-
/// Returns false if the number of significant figures in `value` are
107+
/// Returns `false` if the number of significant figures in `value` are
108108
/// less than `min_digits`; otherwise, returns true if `value` is equal
109109
/// to `constant`, rounded to the number of digits present in `value`.
110110
fn is_approx_const(constant: f64, value: &str, min_digits: usize) -> bool {

clippy_lints/src/assertions_on_constants.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
use if_chain::if_chain;
2+
use rustc::hir::{Expr, ExprKind};
3+
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4+
use rustc::{declare_tool_lint, lint_array};
5+
16
use crate::consts::{constant, Constant};
2-
use crate::rustc::hir::{Expr, ExprKind};
3-
use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
4-
use crate::rustc::{declare_tool_lint, lint_array};
57
use crate::syntax::ast::LitKind;
68
use crate::utils::{in_macro, is_direct_expn_of, span_help_and_lint};
7-
use if_chain::if_chain;
89

9-
/// **What it does:** Check to call assert!(true/false)
10+
/// **What it does:** Checks for `assert!(true)` and `assert!(false)` calls.
1011
///
1112
/// **Why is this bad?** Will be optimized out by the compiler or should probably be replaced by a
1213
/// panic!() or unreachable!()
@@ -25,7 +26,8 @@ use if_chain::if_chain;
2526
declare_clippy_lint! {
2627
pub ASSERTIONS_ON_CONSTANTS,
2728
style,
28-
"assert!(true/false) will be optimized out by the compiler/should probably be replaced by a panic!() or unreachable!()"
29+
"`assert!(true)` / `assert!(false)` will be optimized out by the compiler, \
30+
and should probably be replaced by a `panic!()` or `unreachable!()`"
2931
}
3032

3133
pub struct AssertionsOnConstants;

clippy_lints/src/assign_ops.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
use crate::utils::{get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, SpanlessEq};
2-
use crate::utils::{higher, sugg};
31
use if_chain::if_chain;
2+
use rustc_errors::Applicability;
43
use rustc::hir;
54
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
65
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
76
use rustc::{declare_tool_lint, lint_array};
8-
use rustc_errors::Applicability;
97
use syntax::ast;
108

9+
use crate::utils::{get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, SpanlessEq};
10+
use crate::utils::{higher, sugg};
11+
1112
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
1213
/// patterns.
1314
///
@@ -34,7 +35,7 @@ declare_clippy_lint! {
3435
/// op= b`.
3536
///
3637
/// **Known problems:** Clippy cannot know for sure if `a op= a op b` should have
37-
/// been `a = a op a op b` or `a = a op b`/`a op= b`. Therefore it suggests both.
38+
/// been `a = a op a op b` or `a = a op b`/`a op= b`. Therefore, it suggests both.
3839
/// If `a op= a op b` is really the correct behaviour it should be
3940
/// written as `a = a op a op b` as it's less confusing.
4041
///

clippy_lints/src/bit_mask.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ declare_clippy_lint! {
7070
declare_clippy_lint! {
7171
pub INEFFECTIVE_BIT_MASK,
7272
correctness,
73-
"expressions where a bit mask will be rendered useless by a comparison, e.g. `(x | 1) > 2`"
73+
"expressions where a bit mask will be rendered useless by a comparison, e.g., `(x | 1) > 2`"
7474
}
7575

7676
/// **What it does:** Checks for bit masks that can be replaced by a call

clippy_lints/src/block_in_if_condition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc::{declare_tool_lint, lint_array};
2020
declare_clippy_lint! {
2121
pub BLOCK_IN_IF_CONDITION_EXPR,
2222
style,
23-
"braces that can be eliminated in conditions, e.g. `if { true } ...`"
23+
"braces that can be eliminated in conditions, e.g., `if { true } ...`"
2424
}
2525

2626
/// **What it does:** Checks for `if` conditions that use blocks containing
@@ -39,7 +39,7 @@ declare_clippy_lint! {
3939
declare_clippy_lint! {
4040
pub BLOCK_IN_IF_CONDITION_STMT,
4141
style,
42-
"complex blocks in conditions, e.g. `if { let x = true; x } ...`"
42+
"complex blocks in conditions, e.g., `if { let x = true; x } ...`"
4343
}
4444

4545
#[derive(Copy, Clone)]

clippy_lints/src/collapsible_if.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use rustc_errors::Applicability;
6868
declare_clippy_lint! {
6969
pub COLLAPSIBLE_IF,
7070
style,
71-
"`if`s that can be collapsed (e.g. `if x { if y { ... } }` and `else { if x { ... } }`)"
71+
"`if`s that can be collapsed (e.g., `if x { if y { ... } }` and `else { if x { ... } }`)"
7272
}
7373

7474
#[derive(Copy, Clone)]

clippy_lints/src/consts.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ use syntax_pos::symbol::Symbol;
2121
/// A `LitKind`-like enum to fold constant `Expr`s into.
2222
#[derive(Debug, Clone)]
2323
pub enum Constant {
24-
/// a String "abc"
24+
/// A `String` (e.g., "abc").
2525
Str(String),
26-
/// a Binary String b"abc"
26+
/// A binary string (e.g., `b"abc"`).
2727
Binary(Lrc<Vec<u8>>),
28-
/// a single char 'a'
28+
/// A single `char` (e.g., `'a'`).
2929
Char(char),
30-
/// an integer's bit representation
30+
/// An integer's bit representation.
3131
Int(u128),
32-
/// an f32
32+
/// An `f32`.
3333
F32(f32),
34-
/// an f64
34+
/// An `f64`
3535
F64(f64),
36-
/// true or false
36+
/// A `bool` (i.e., `true` or `false`).
3737
Bool(bool),
38-
/// an array of constants
38+
/// An array of constants
3939
Vec(Vec<Constant>),
40-
/// also an array, but with only one constant, repeated N times
40+
/// Also an array, but with only one constant, repeated `N` times.
4141
Repeat(Box<Constant>, u64),
42-
/// a tuple of constants
42+
/// A tuple of constants.
4343
Tuple(Vec<Constant>),
44-
/// a literal with syntax error
44+
/// A literal with a syntax error.
4545
Err(Symbol),
4646
}
4747

clippy_lints/src/copies.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ fn lint_match_arms(cx: &LateContext<'_, '_>, expr: &Expr) {
239239
}
240240
}
241241

242-
/// Return the list of condition expressions and the list of blocks in a
242+
/// Returns the list of condition expressions and the list of blocks in a
243243
/// sequence of `if/else`.
244-
/// Eg. would return `([a, b], [c, d, e])` for the expression
244+
/// E.g., this returns `([a, b], [c, d, e])` for the expression
245245
/// `if a { c } else if b { d } else { e }`.
246246
fn if_sequence(mut expr: &Expr) -> (SmallVec<[&Expr; 1]>, SmallVec<[&Block; 1]>) {
247247
let mut conds = SmallVec::new();
@@ -272,7 +272,7 @@ fn if_sequence(mut expr: &Expr) -> (SmallVec<[&Expr; 1]>, SmallVec<[&Block; 1]>)
272272
(conds, blocks)
273273
}
274274

275-
/// Return the list of bindings in a pattern.
275+
/// Returns the list of bindings in a pattern.
276276
fn bindings<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, pat: &Pat) -> FxHashMap<LocalInternedString, Ty<'tcx>> {
277277
fn bindings_impl<'a, 'tcx>(
278278
cx: &LateContext<'a, 'tcx>,

clippy_lints/src/deprecated_lints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ declare_deprecated_lint! {
9090
/// counterparts, so this lint may suggest a change in behavior or the code may not compile.
9191
declare_deprecated_lint! {
9292
pub ASSIGN_OPS,
93-
"using compound assignment operators (e.g. `+=`) is harmless"
93+
"using compound assignment operators (e.g., `+=`) is harmless"
9494
}
9595

9696
/// **What it does:** Nothing. This lint has been deprecated.

clippy_lints/src/doc.rs

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

259259
fn check_word(cx: &EarlyContext<'_>, word: &str, span: Span) {
260-
/// Checks if a string is camel-case, ie. contains at least two uppercase
261-
/// letter (`Clippy` is
260+
/// Checks if a string is camel-case, i.e., contains at least two uppercase
261+
/// letters (`Clippy` is
262262
/// ok) and one lower-case letter (`NASA` is ok). Plural are also excluded
263263
/// (`IDs` is ok).
264264
fn is_camel_case(s: &str) -> bool {

clippy_lints/src/else_if_without_else.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::utils::span_help_and_lint;
99
/// **What it does:** Checks for usage of if expressions with an `else if` branch,
1010
/// but without a final `else` branch.
1111
///
12-
/// **Why is this bad?** Some coding guidelines require this (e.g. MISRA-C:2004 Rule 14.10).
12+
/// **Why is this bad?** Some coding guidelines require this (e.g., MISRA-C:2004 Rule 14.10).
1313
///
1414
/// **Known problems:** None.
1515
///

clippy_lints/src/eq_op.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_errors::Applicability;
2424
declare_clippy_lint! {
2525
pub EQ_OP,
2626
correctness,
27-
"equal operands on both sides of a comparison or bitwise combination (e.g. `x == x`)"
27+
"equal operands on both sides of a comparison or bitwise combination (e.g., `x == x`)"
2828
}
2929

3030
/// **What it does:** Checks for arguments to `==` which have their address

clippy_lints/src/erasing_op.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
55
use rustc::{declare_tool_lint, lint_array};
66
use syntax::source_map::Span;
77

8-
/// **What it does:** Checks for erasing operations, e.g. `x * 0`.
8+
/// **What it does:** Checks for erasing operations, e.g., `x * 0`.
99
///
1010
/// **Why is this bad?** The whole expression can be replaced by zero.
1111
/// This is most likely not the intended outcome and should probably be
@@ -22,7 +22,7 @@ use syntax::source_map::Span;
2222
declare_clippy_lint! {
2323
pub ERASING_OP,
2424
correctness,
25-
"using erasing operations, e.g. `x * 0` or `y & 0`"
25+
"using erasing operations, e.g., `x * 0` or `y & 0`"
2626
}
2727

2828
#[derive(Copy, Clone)]

clippy_lints/src/escape.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
6868
_: Span,
6969
node_id: NodeId,
7070
) {
71-
// If the method is an impl for a trait, don't warn
71+
// If the method is an impl for a trait, don't warn.
7272
let parent_id = cx.tcx.hir().get_parent(node_id);
7373
let parent_node = cx.tcx.hir().find(parent_id);
7474

@@ -103,7 +103,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
103103
fn consume(&mut self, _: NodeId, _: Span, cmt: &cmt_<'tcx>, mode: ConsumeMode) {
104104
if let Categorization::Local(lid) = cmt.cat {
105105
if let Move(DirectRefMove) = mode {
106-
// moved out or in. clearly can't be localized
106+
// Moved out or in. Clearly can't be localized.
107107
self.set.remove(&lid);
108108
}
109109
}
@@ -159,20 +159,20 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
159159
) {
160160
if let Categorization::Local(lid) = cmt.cat {
161161
match loan_cause {
162-
// x.foo()
163-
// Used without autodereffing (i.e. x.clone())
162+
// `x.foo()`
163+
// Used without autoderef-ing (i.e., `x.clone()`).
164164
LoanCause::AutoRef |
165165

166-
// &x
167-
// foo(&x) where no extra autoreffing is happening
166+
// `&x`
167+
// `foo(&x)` where no extra autoref-ing is happening.
168168
LoanCause::AddrOf |
169169

170-
// `match x` can move
170+
// `match x` can move.
171171
LoanCause::MatchDiscriminant => {
172172
self.set.remove(&lid);
173173
}
174174

175-
// do nothing for matches, etc. These can't escape
175+
// Do nothing for matches, etc. These can't escape.
176176
_ => {}
177177
}
178178
}
@@ -183,8 +183,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
183183

184184
impl<'a, 'tcx> EscapeDelegate<'a, 'tcx> {
185185
fn is_large_box(&self, ty: Ty<'tcx>) -> bool {
186-
// Large types need to be boxed to avoid stack
187-
// overflows.
186+
// Large types need to be boxed to avoid stack overflows.
188187
if ty.is_box() {
189188
self.cx.layout_of(ty.boxed_ty()).ok().map_or(0, |l| l.size.bytes()) > self.too_large_for_stack
190189
} else {

clippy_lints/src/eta_reduction.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ pub struct EtaPass;
1818
/// **Known problems:** If creating the closure inside the closure has a side-
1919
/// effect then moving the closure creation out will change when that side-
2020
/// effect runs.
21-
/// See https://github.com/rust-lang/rust-clippy/issues/1439 for more
22-
/// details.
21+
/// See rust-lang/rust-clippy#1439 for more details.
2322
///
2423
/// **Example:**
2524
/// ```rust
@@ -30,7 +29,7 @@ pub struct EtaPass;
3029
declare_clippy_lint! {
3130
pub REDUNDANT_CLOSURE,
3231
style,
33-
"redundant closures, i.e. `|a| foo(a)` (which can be written as just `foo`)"
32+
"redundant closures, i.e., `|a| foo(a)` (which can be written as just `foo`)"
3433
}
3534

3635
impl LintPass for EtaPass {

clippy_lints/src/eval_order_dependence.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt) -> St
286286
/// A visitor that looks for reads from a variable.
287287
struct ReadVisitor<'a, 'tcx: 'a> {
288288
cx: &'a LateContext<'a, 'tcx>,
289-
/// The id of the variable we're looking for.
289+
/// The ID of the variable we're looking for.
290290
var: ast::NodeId,
291291
/// The expressions where the write to the variable occurred (for reporting
292292
/// in the lint).
@@ -351,7 +351,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
351351
}
352352
}
353353

354-
/// Returns true if `expr` is the LHS of an assignment, like `expr = ...`.
354+
/// Returns `true` if `expr` is the LHS of an assignment, like `expr = ...`.
355355
fn is_in_assignment_position(cx: &LateContext<'_, '_>, expr: &Expr) -> bool {
356356
if let Some(parent) = get_parent_expr(cx, expr) {
357357
if let ExprKind::Assign(ref lhs, _) = parent.node {

clippy_lints/src/identity_op.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc::ty;
66
use rustc::{declare_tool_lint, lint_array};
77
use syntax::source_map::Span;
88

9-
/// **What it does:** Checks for identity operations, e.g. `x + 0`.
9+
/// **What it does:** Checks for identity operations, e.g., `x + 0`.
1010
///
1111
/// **Why is this bad?** This code can be removed without changing the
1212
/// meaning. So it just obscures what's going on. Delete it mercilessly.
@@ -20,7 +20,7 @@ use syntax::source_map::Span;
2020
declare_clippy_lint! {
2121
pub IDENTITY_OP,
2222
complexity,
23-
"using identity operations, e.g. `x + 0` or `y / 1`"
23+
"using identity operations, e.g., `x + 0` or `y / 1`"
2424
}
2525

2626
#[derive(Copy, Clone)]

clippy_lints/src/indexing_slicing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
102102
if let ExprKind::Index(ref array, ref index) = &expr.node {
103103
let ty = cx.tables.expr_ty(array);
104104
if let Some(range) = higher::range(cx, index) {
105-
// Ranged indexes, i.e. &x[n..m], &x[n..], &x[..n] and &x[..]
105+
// Ranged indexes, i.e., &x[n..m], &x[n..], &x[..n] and &x[..]
106106
if let ty::Array(_, s) = ty.sty {
107107
let size: u128 = s.assert_usize(cx.tcx).unwrap().into();
108108

@@ -148,7 +148,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
148148

149149
utils::span_help_and_lint(cx, INDEXING_SLICING, expr.span, "slicing may panic.", help_msg);
150150
} else {
151-
// Catchall non-range index, i.e. [n] or [n << m]
151+
// Catchall non-range index, i.e., [n] or [n << m]
152152
if let ty::Array(..) = ty.sty {
153153
// Index is a constant uint.
154154
if let Some(..) = constant(cx, cx.tables, index) {

clippy_lints/src/infinite_iter.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc::{declare_tool_lint, lint_array};
66
/// **What it does:** Checks for iteration that is guaranteed to be infinite.
77
///
88
/// **Why is this bad?** While there may be places where this is acceptable
9-
/// (e.g. in event streams), in most cases this is simply an error.
9+
/// (e.g., in event streams), in most cases this is simply an error.
1010
///
1111
/// **Known problems:** None.
1212
///
@@ -23,7 +23,7 @@ declare_clippy_lint! {
2323
/// **What it does:** Checks for iteration that may be infinite.
2424
///
2525
/// **Why is this bad?** While there may be places where this is acceptable
26-
/// (e.g. in event streams), in most cases this is simply an error.
26+
/// (e.g., in event streams), in most cases this is simply an error.
2727
///
2828
/// **Known problems:** The code may have a condition to stop iteration, but
2929
/// this lint is not clever enough to analyze it.
@@ -120,8 +120,8 @@ use self::Heuristic::{All, Always, Any, First};
120120
/// a slice of (method name, number of args, heuristic, bounds) tuples
121121
/// that will be used to determine whether the method in question
122122
/// returns an infinite or possibly infinite iterator. The finiteness
123-
/// is an upper bound, e.g. some methods can return a possibly
124-
/// infinite iterator at worst, e.g. `take_while`.
123+
/// is an upper bound, e.g., some methods can return a possibly
124+
/// infinite iterator at worst, e.g., `take_while`.
125125
static HEURISTICS: &[(&str, usize, Heuristic, Finiteness)] = &[
126126
("zip", 2, All, Infinite),
127127
("chain", 2, Any, Infinite),

0 commit comments

Comments
 (0)