Skip to content

Commit 1cdac4a

Browse files
committed
Auto merge of #3767 - alexreg:cosmetic-2, r=flip1995
Various cosmetic improvements Related to the larger effort of rust-lang/rust#58036.
2 parents 016d92d + 72aeaa8 commit 1cdac4a

Some content is hidden

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

80 files changed

+636
-605
lines changed

clippy_dev/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub struct FileChange {
191191
pub new_lines: String,
192192
}
193193

194-
/// Replace a region in a file delimited by two lines matching regexes.
194+
/// Replaces a region in a file delimited by two lines matching regexes.
195195
///
196196
/// `path` is the relative path to the file on which you want to perform the replacement.
197197
///
@@ -225,7 +225,7 @@ where
225225
file_change
226226
}
227227

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

clippy_lints/src/approx_const.rs

+1-1
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

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
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

910
declare_clippy_lint! {
10-
/// **What it does:** Check to call assert!(true/false)
11+
/// **What it does:** Checks for `assert!(true)` and `assert!(false)` calls.
1112
///
1213
/// **Why is this bad?** Will be optimized out by the compiler or should probably be replaced by a
1314
/// panic!() or unreachable!()
1415
///
1516
/// **Known problems:** None
1617
///
1718
/// **Example:**
18-
/// ```no_run
19-
/// assert!(false);
19+
/// ```rust,ignore
20+
/// assert!(false)
2021
/// // or
21-
/// assert!(true);
22+
/// assert!(true)
2223
/// // or
2324
/// const B: bool = false;
24-
/// assert!(B);
25+
/// assert!(B)
2526
/// ```
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, and should probably be replaced by a `panic!()` or `unreachable!()`"
2930
}
3031

3132
pub struct AssertionsOnConstants;

clippy_lints/src/assign_ops.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
use crate::utils::{
2-
get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method, SpanlessEq,
3-
};
4-
use crate::utils::{higher, sugg};
51
use if_chain::if_chain;
62
use rustc::hir;
73
use rustc::hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
84
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
95
use rustc::{declare_tool_lint, lint_array};
106
use rustc_errors::Applicability;
117

8+
use crate::utils::{
9+
get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method, SpanlessEq,
10+
};
11+
use crate::utils::{higher, sugg};
12+
1213
declare_clippy_lint! {
1314
/// **What it does:** Checks for `a = a op b` or `a = b commutative_op a`
1415
/// patterns.
@@ -19,9 +20,10 @@ declare_clippy_lint! {
1920
/// implementations that differ from the regular `Op` impl.
2021
///
2122
/// **Example:**
22-
/// ```ignore
23+
/// ```rust
2324
/// let mut a = 5;
24-
/// ...
25+
/// let b = 0;
26+
/// // ...
2527
/// a = a + b;
2628
/// ```
2729
pub ASSIGN_OP_PATTERN,
@@ -36,12 +38,12 @@ declare_clippy_lint! {
3638
/// op= b`.
3739
///
3840
/// **Known problems:** Clippy cannot know for sure if `a op= a op b` should have
39-
/// been `a = a op a op b` or `a = a op b`/`a op= b`. Therefore it suggests both.
41+
/// been `a = a op a op b` or `a = a op b`/`a op= b`. Therefore, it suggests both.
4042
/// If `a op= a op b` is really the correct behaviour it should be
4143
/// written as `a = a op a op b` as it's less confusing.
4244
///
4345
/// **Example:**
44-
/// ```ignore
46+
/// ```rust
4547
/// let mut a = 5;
4648
/// ...
4749
/// a += a + b;

clippy_lints/src/bit_mask.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ declare_clippy_lint! {
7070
/// ```
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
declare_clippy_lint! {

clippy_lints/src/block_in_if_condition.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ declare_clippy_lint! {
2020
/// ```
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
declare_clippy_lint! {
@@ -39,7 +39,7 @@ declare_clippy_lint! {
3939
/// ```
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ declare_clippy_lint! {
6868
/// ```
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

+22-20
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+
/// `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 syntax error.
4545
Err(Symbol),
4646
}
4747

@@ -53,23 +53,24 @@ impl PartialEq for Constant {
5353
(&Constant::Char(l), &Constant::Char(r)) => l == r,
5454
(&Constant::Int(l), &Constant::Int(r)) => l == r,
5555
(&Constant::F64(l), &Constant::F64(r)) => {
56-
// we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
57-
// `Fw32 == Fw64` so don’t compare them
58-
// to_bits is required to catch non-matching 0.0, -0.0, and NaNs
56+
// We want `Fw32 == FwAny` and `FwAny == Fw64`, and by transitivity we must have
57+
// `Fw32 == Fw64`, so don’t compare them.
58+
// `to_bits` is required to catch non-matching 0.0, -0.0, and NaNs.
5959
l.to_bits() == r.to_bits()
6060
},
6161
(&Constant::F32(l), &Constant::F32(r)) => {
62-
// we want `Fw32 == FwAny` and `FwAny == Fw64`, by transitivity we must have
63-
// `Fw32 == Fw64` so don’t compare them
64-
// to_bits is required to catch non-matching 0.0, -0.0, and NaNs
62+
// We want `Fw32 == FwAny` and `FwAny == Fw64`, and by transitivity we must have
63+
// `Fw32 == Fw64`, so don’t compare them.
64+
// `to_bits` is required to catch non-matching 0.0, -0.0, and NaNs.
6565
f64::from(l).to_bits() == f64::from(r).to_bits()
6666
},
6767
(&Constant::Bool(l), &Constant::Bool(r)) => l == r,
6868
(&Constant::Vec(ref l), &Constant::Vec(ref r)) | (&Constant::Tuple(ref l), &Constant::Tuple(ref r)) => {
6969
l == r
7070
},
7171
(&Constant::Repeat(ref lv, ref ls), &Constant::Repeat(ref rv, ref rs)) => ls == rs && lv == rv,
72-
_ => false, // TODO: Are there inter-type equalities?
72+
// TODO: are there inter-type equalities?
73+
_ => false,
7374
}
7475
}
7576
}
@@ -142,12 +143,13 @@ impl Constant {
142143
x => x,
143144
}
144145
},
145-
_ => None, // TODO: Are there any useful inter-type orderings?
146+
// TODO: are there any useful inter-type orderings?
147+
_ => None,
146148
}
147149
}
148150
}
149151

150-
/// parse a `LitKind` to a `Constant`
152+
/// Parses a `LitKind` to a `Constant`.
151153
pub fn lit_to_constant<'tcx>(lit: &LitKind, ty: Ty<'tcx>) -> Constant {
152154
use syntax::ast::*;
153155

clippy_lints/src/copies.rs

+3-3
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

+1-1
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

+3-4
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,9 @@ 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
262-
/// ok) and one lower-case letter (`NASA` is ok). Plural are also excluded
263-
/// (`IDs` is ok).
260+
/// Checks if a string is camel-case, i.e., contains at least two uppercase
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/else_if_without_else.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! lint on if expressions with an else if, but without a final else branch
1+
//! Lint on if expressions with an else if, but without a final else branch.
22
33
use rustc::lint::{in_external_macro, EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass};
44
use rustc::{declare_tool_lint, lint_array};
@@ -10,7 +10,7 @@ declare_clippy_lint! {
1010
/// **What it does:** Checks for usage of if expressions with an `else if` branch,
1111
/// but without a final `else` branch.
1212
///
13-
/// **Why is this bad?** Some coding guidelines require this (e.g. MISRA-C:2004 Rule 14.10).
13+
/// **Why is this bad?** Some coding guidelines require this (e.g., MISRA-C:2004 Rule 14.10).
1414
///
1515
/// **Known problems:** None.
1616
///
@@ -31,7 +31,7 @@ declare_clippy_lint! {
3131
/// } else if x.is_negative() {
3232
/// b();
3333
/// } else {
34-
/// // we don't care about zero
34+
/// // We don't care about zero.
3535
/// }
3636
/// ```
3737
pub ELSE_IF_WITHOUT_ELSE,

clippy_lints/src/eq_op.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ declare_clippy_lint! {
2424
/// ```
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
declare_clippy_lint! {

clippy_lints/src/erasing_op.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
use crate::consts::{constant_simple, Constant};
2-
use crate::utils::{in_macro, span_lint};
31
use rustc::hir::*;
42
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
53
use rustc::{declare_tool_lint, lint_array};
64
use syntax::source_map::Span;
75

6+
use crate::consts::{constant_simple, Constant};
7+
use crate::utils::{in_macro, span_lint};
8+
89
declare_clippy_lint! {
9-
/// **What it does:** Checks for erasing operations, e.g. `x * 0`.
10+
/// **What it does:** Checks for erasing operations, e.g., `x * 0`.
1011
///
1112
/// **Why is this bad?** The whole expression can be replaced by zero.
1213
/// This is most likely not the intended outcome and should probably be
@@ -15,14 +16,15 @@ declare_clippy_lint! {
1516
/// **Known problems:** None.
1617
///
1718
/// **Example:**
18-
/// ```ignore
19+
/// ```rust
20+
/// let x = 1;
1921
/// 0 / x;
2022
/// 0 * x;
21-
/// x & 0
23+
/// x & 0;
2224
/// ```
2325
pub ERASING_OP,
2426
correctness,
25-
"using erasing operations, e.g. `x * 0` or `y & 0`"
27+
"using erasing operations, e.g., `x * 0` or `y & 0`"
2628
}
2729

2830
#[derive(Copy, Clone)]

0 commit comments

Comments
 (0)