Skip to content

Commit de7681b

Browse files
Merge branch 'master' into issue-4078
2 parents 7211ea0 + 8fae2dd commit de7681b

Some content is hidden

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

70 files changed

+983
-162
lines changed

.github/PULL_REQUEST_TEMPLATE renamed to .github/PULL_REQUEST_TEMPLATE.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<!--
21
Thank you for making Clippy better!
32

43
We're collecting our changelog from pull request descriptions.
@@ -25,6 +24,8 @@ checked during review or continuous integration.
2524
Note that you can skip the above if you are just opening a WIP PR in
2625
order to get feedback.
2726

28-
Delete this line and everything above before opening your PR -->
27+
Delete this line and everything above before opening your PR.
28+
29+
---
2930

3031
changelog: none

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,7 @@ Released 2018-09-13
976976
[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
977977
[`doc_markdown`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown
978978
[`double_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_comparisons
979+
[`double_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_must_use
979980
[`double_neg`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_neg
980981
[`double_parens`]: https://rust-lang.github.io/rust-clippy/master/index.html#double_parens
981982
[`drop_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#drop_bounds
@@ -1095,6 +1096,8 @@ Released 2018-09-13
10951096
[`modulo_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#modulo_one
10961097
[`multiple_crate_versions`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_crate_versions
10971098
[`multiple_inherent_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_inherent_impl
1099+
[`must_use_candidate`]: https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate
1100+
[`must_use_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#must_use_unit
10981101
[`mut_from_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_from_ref
10991102
[`mut_mut`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_mut
11001103
[`mut_range_bound`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_range_bound

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ You can use [rustup-toolchain-install-master][rtim] to do that:
147147

148148
```bash
149149
cargo install rustup-toolchain-install-master
150-
rustup-toolchain-install-master -n master --force
150+
rustup-toolchain-install-master --force -n master
151151
rustup override set master
152152
cargo test
153153
```

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util"}
4646

4747
[dev-dependencies]
4848
cargo_metadata = "0.8.0"
49-
compiletest_rs = { version = "0.3.23", features = ["tmp"] }
49+
compiletest_rs = { version = "0.3.24", features = ["tmp"] }
5050
lazy_static = "1.0"
5151
clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }
5252
serde = { version = "1.0", features = ["derive"] }

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
88

9-
[There are 322 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 324 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1010

1111
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1212

appveyor.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ install:
1717
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
1818
- rustup-init.exe -y --default-host %TARGET% --default-toolchain nightly
1919
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
20-
- git ls-remote https://github.com/rust-lang/rust.git master | awk '{print $1}' >rustc-hash.txt
21-
- set /p RUSTC_HASH=<rustc-hash.txt
2220
- del rust-toolchain
23-
- cargo install rustup-toolchain-install-master --debug || echo "rustup-toolchain-install-master already installed"
24-
- rustup-toolchain-install-master %RUSTC_HASH% -f -n master
21+
- cargo install --git https://github.com/kennytm/rustup-toolchain-install-master --debug || echo "rustup-toolchain-install-master already installed"
22+
- rustup-toolchain-install-master -f -n master
2523
- rustup component add rustfmt --toolchain nightly & exit 0 # Format test handles missing rustfmt
2624
- rustup default master
2725
- set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin

clippy_dev/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub struct Lint {
4242
}
4343

4444
impl Lint {
45+
#[must_use]
4546
pub fn new(name: &str, group: &str, desc: &str, deprecation: Option<&str>, module: &str) -> Self {
4647
Self {
4748
name: name.to_lowercase(),
@@ -58,19 +59,22 @@ impl Lint {
5859
}
5960

6061
/// Returns the lints in a `HashMap`, grouped by the different lint groups
62+
#[must_use]
6163
pub fn by_lint_group(lints: &[Self]) -> HashMap<String, Vec<Self>> {
6264
lints
6365
.iter()
6466
.map(|lint| (lint.group.to_string(), lint.clone()))
6567
.into_group_map()
6668
}
6769

70+
#[must_use]
6871
pub fn is_internal(&self) -> bool {
6972
self.group.starts_with("internal")
7073
}
7174
}
7275

7376
/// Generates the Vec items for `register_lint_group` calls in `clippy_lints/src/lib.rs`.
77+
#[must_use]
7478
pub fn gen_lint_group_list(lints: Vec<Lint>) -> Vec<String> {
7579
lints
7680
.into_iter()
@@ -86,6 +90,7 @@ pub fn gen_lint_group_list(lints: Vec<Lint>) -> Vec<String> {
8690
}
8791

8892
/// Generates the `pub mod module_name` list in `clippy_lints/src/lib.rs`.
93+
#[must_use]
8994
pub fn gen_modules_list(lints: Vec<Lint>) -> Vec<String> {
9095
lints
9196
.into_iter()
@@ -103,6 +108,7 @@ pub fn gen_modules_list(lints: Vec<Lint>) -> Vec<String> {
103108
}
104109

105110
/// Generates the list of lint links at the bottom of the README
111+
#[must_use]
106112
pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
107113
let mut lint_list_sorted: Vec<Lint> = lints;
108114
lint_list_sorted.sort_by_key(|l| l.name.clone());
@@ -119,6 +125,7 @@ pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
119125
}
120126

121127
/// Generates the `register_removed` code in `./clippy_lints/src/lib.rs`.
128+
#[must_use]
122129
pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> {
123130
lints
124131
.iter()

clippy_dev/src/stderr_length_check.rs

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ fn stderr_files() -> impl Iterator<Item = walkdir::DirEntry> {
4242
.filter(|f| f.path().extension() == Some(OsStr::new("stderr")))
4343
}
4444

45+
#[must_use]
4546
fn count_linenumbers(filepath: &str) -> usize {
4647
if let Ok(mut file) = File::open(filepath) {
4748
let mut content = String::new();

clippy_lints/src/approx_const.rs

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ fn check_known_consts(cx: &LateContext<'_, '_>, e: &Expr, s: symbol::Symbol, mod
9393
/// Returns `false` if the number of significant figures in `value` are
9494
/// less than `min_digits`; otherwise, returns true if `value` is equal
9595
/// to `constant`, rounded to the number of digits present in `value`.
96+
#[must_use]
9697
fn is_approx_const(constant: f64, value: &str, min_digits: usize) -> bool {
9798
if value.len() <= min_digits {
9899
false

clippy_lints/src/assertions_on_constants.rs

+1-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::consts::{constant, Constant};
22
use crate::utils::paths;
3-
use crate::utils::{is_direct_expn_of, is_expn_of, match_def_path, snippet_opt, span_help_and_lint};
3+
use crate::utils::{is_direct_expn_of, is_expn_of, match_function_call, snippet_opt, span_help_and_lint};
44
use if_chain::if_chain;
55
use rustc::hir::*;
66
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -145,23 +145,3 @@ fn match_assert_with_message<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx E
145145
}
146146
None
147147
}
148-
149-
/// Matches a function call with the given path and returns the arguments.
150-
///
151-
/// Usage:
152-
///
153-
/// ```rust,ignore
154-
/// if let Some(args) = match_function_call(cx, begin_panic_call, &paths::BEGIN_PANIC);
155-
/// ```
156-
fn match_function_call<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, path: &[&str]) -> Option<&'a [Expr]> {
157-
if_chain! {
158-
if let ExprKind::Call(ref fun, ref args) = expr.kind;
159-
if let ExprKind::Path(ref qpath) = fun.kind;
160-
if let Some(fun_def_id) = cx.tables.qpath_res(qpath, fun.hir_id).opt_def_id();
161-
if match_def_path(cx, fun_def_id, path);
162-
then {
163-
return Some(&args)
164-
}
165-
};
166-
None
167-
}

clippy_lints/src/assign_ops.rs

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ fn lint_misrefactored_assign_op(
229229
);
230230
}
231231

232+
#[must_use]
232233
fn is_commutative(op: hir::BinOpKind) -> bool {
233234
use rustc::hir::BinOpKind::*;
234235
match op {

clippy_lints/src/bit_mask.rs

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub struct BitMask {
100100
}
101101

102102
impl BitMask {
103+
#[must_use]
103104
pub fn new(verbose_bit_mask_threshold: u64) -> Self {
104105
Self {
105106
verbose_bit_mask_threshold,
@@ -150,6 +151,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
150151
}
151152
}
152153

154+
#[must_use]
153155
fn invert_cmp(cmp: BinOpKind) -> BinOpKind {
154156
match cmp {
155157
BinOpKind::Eq => BinOpKind::Eq,

clippy_lints/src/checked_conversions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ impl<'a> Conversion<'a> {
160160

161161
impl ConversionType {
162162
/// Creates a conversion type if the type is allowed & conversion is valid
163+
#[must_use]
163164
fn try_new(from: &str, to: &str) -> Option<Self> {
164165
if UINTS.contains(&from) {
165166
Some(Self::FromUnsigned)

clippy_lints/src/cognitive_complexity.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub struct CognitiveComplexity {
2929
}
3030

3131
impl CognitiveComplexity {
32+
#[must_use]
3233
pub fn new(limit: u64) -> Self {
3334
Self {
3435
limit: LimitStack::new(limit),

clippy_lints/src/doc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for DocMarkdown {
191191
/// need to keep track of
192192
/// the spans but this function is inspired from the later.
193193
#[allow(clippy::cast_possible_truncation)]
194+
#[must_use]
194195
pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(usize, Span)>) {
195196
// one-line comments lose their prefix
196197
const ONELINERS: &[&str] = &["///!", "///", "//!", "//"];

clippy_lints/src/enum_variants.rs

+4
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ pub struct EnumVariantNames {
107107
}
108108

109109
impl EnumVariantNames {
110+
#[must_use]
110111
pub fn new(threshold: u64) -> Self {
111112
Self {
112113
modules: Vec::new(),
@@ -123,13 +124,15 @@ impl_lint_pass!(EnumVariantNames => [
123124
]);
124125

125126
/// Returns the number of chars that match from the start
127+
#[must_use]
126128
fn partial_match(pre: &str, name: &str) -> usize {
127129
let mut name_iter = name.chars();
128130
let _ = name_iter.next_back(); // make sure the name is never fully matched
129131
pre.chars().zip(name_iter).take_while(|&(l, r)| l == r).count()
130132
}
131133

132134
/// Returns the number of chars that match from the end
135+
#[must_use]
133136
fn partial_rmatch(post: &str, name: &str) -> usize {
134137
let mut name_iter = name.chars();
135138
let _ = name_iter.next(); // make sure the name is never fully matched
@@ -211,6 +214,7 @@ fn check_variant(
211214
);
212215
}
213216

217+
#[must_use]
214218
fn to_camel_case(item_name: &str) -> String {
215219
let mut s = String::new();
216220
let mut up = true;

clippy_lints/src/excessive_precision.rs

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
6262

6363
impl ExcessivePrecision {
6464
// None if nothing to lint, Some(suggestion) if lint necessary
65+
#[must_use]
6566
fn check(self, sym: Symbol, fty: FloatTy) -> Option<String> {
6667
let max = max_digits(fty);
6768
let sym_str = sym.as_str();
@@ -97,6 +98,7 @@ impl ExcessivePrecision {
9798
/// Should we exclude the float because it has a `.0` or `.` suffix
9899
/// Ex `1_000_000_000.0`
99100
/// Ex `1_000_000_000.`
101+
#[must_use]
100102
fn dot_zero_exclusion(s: &str) -> bool {
101103
s.split('.').nth(1).map_or(false, |after_dec| {
102104
let mut decpart = after_dec.chars().take_while(|c| *c != 'e' || *c != 'E');
@@ -109,6 +111,7 @@ fn dot_zero_exclusion(s: &str) -> bool {
109111
})
110112
}
111113

114+
#[must_use]
112115
fn max_digits(fty: FloatTy) -> u32 {
113116
match fty {
114117
FloatTy::F32 => f32::DIGITS,
@@ -117,6 +120,7 @@ fn max_digits(fty: FloatTy) -> u32 {
117120
}
118121

119122
/// Counts the digits excluding leading zeros
123+
#[must_use]
120124
fn count_digits(s: &str) -> usize {
121125
// Note that s does not contain the f32/64 suffix, and underscores have been stripped
122126
s.chars()
@@ -138,6 +142,7 @@ enum FloatFormat {
138142
Normal,
139143
}
140144
impl FloatFormat {
145+
#[must_use]
141146
fn new(s: &str) -> Self {
142147
s.chars()
143148
.find_map(|x| match x {

clippy_lints/src/explicit_write.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::{is_expn_of, match_def_path, paths, resolve_node, span_lint, span_lint_and_sugg};
1+
use crate::utils::{is_expn_of, match_function_call, paths, span_lint, span_lint_and_sugg};
22
use if_chain::if_chain;
33
use rustc::hir::*;
44
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
@@ -41,12 +41,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitWrite {
4141
if write_fun.ident.name == sym!(write_fmt);
4242
// match calls to std::io::stdout() / std::io::stderr ()
4343
if write_args.len() > 0;
44-
if let ExprKind::Call(ref dest_fun, _) = write_args[0].kind;
45-
if let ExprKind::Path(ref qpath) = dest_fun.kind;
46-
if let Some(dest_fun_id) = resolve_node(cx, qpath, dest_fun.hir_id).opt_def_id();
47-
if let Some(dest_name) = if match_def_path(cx, dest_fun_id, &paths::STDOUT) {
44+
if let Some(dest_name) = if match_function_call(cx, &write_args[0], &paths::STDOUT).is_some() {
4845
Some("stdout")
49-
} else if match_def_path(cx, dest_fun_id, &paths::STDERR) {
46+
} else if match_function_call(cx, &write_args[0], &paths::STDERR).is_some() {
5047
Some("stderr")
5148
} else {
5249
None

clippy_lints/src/format.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::utils::paths;
22
use crate::utils::{
3-
is_expn_of, last_path_segment, match_def_path, match_type, resolve_node, snippet, span_lint_and_then, walk_ptrs_ty,
3+
is_expn_of, last_path_segment, match_def_path, match_function_call, match_type, snippet, span_lint_and_then,
4+
walk_ptrs_ty,
45
};
56
use if_chain::if_chain;
67
use rustc::hir::*;
@@ -70,19 +71,16 @@ fn span_useless_format<T: LintContext>(cx: &T, span: Span, help: &str, mut sugg:
7071
});
7172
}
7273

73-
fn on_argumentv1_new<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, arms: &'a [Arm]) -> Option<String> {
74+
fn on_argumentv1_new<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, arms: &'tcx [Arm]) -> Option<String> {
7475
if_chain! {
7576
if let ExprKind::AddrOf(_, ref format_args) = expr.kind;
7677
if let ExprKind::Array(ref elems) = arms[0].body.kind;
7778
if elems.len() == 1;
78-
if let ExprKind::Call(ref fun, ref args) = elems[0].kind;
79-
if let ExprKind::Path(ref qpath) = fun.kind;
80-
if let Some(did) = resolve_node(cx, qpath, fun.hir_id).opt_def_id();
81-
if match_def_path(cx, did, &paths::FMT_ARGUMENTV1_NEW);
79+
if let Some(args) = match_function_call(cx, &elems[0], &paths::FMT_ARGUMENTV1_NEW);
8280
// matches `core::fmt::Display::fmt`
8381
if args.len() == 2;
8482
if let ExprKind::Path(ref qpath) = args[1].kind;
85-
if let Some(did) = resolve_node(cx, qpath, args[1].hir_id).opt_def_id();
83+
if let Some(did) = cx.tables.qpath_res(qpath, args[1].hir_id).opt_def_id();
8684
if match_def_path(cx, did, &paths::DISPLAY_FMT_METHOD);
8785
// check `(arg0,)` in match block
8886
if let PatKind::Tuple(ref pats, None) = arms[0].pat.kind;
@@ -114,11 +112,8 @@ fn on_argumentv1_new<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, arm
114112

115113
fn on_new_v1<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<String> {
116114
if_chain! {
117-
if let ExprKind::Call(ref fun, ref args) = expr.kind;
115+
if let Some(args) = match_function_call(cx, expr, &paths::FMT_ARGUMENTS_NEW_V1);
118116
if args.len() == 2;
119-
if let ExprKind::Path(ref qpath) = fun.kind;
120-
if let Some(did) = resolve_node(cx, qpath, fun.hir_id).opt_def_id();
121-
if match_def_path(cx, did, &paths::FMT_ARGUMENTS_NEW_V1);
122117
// Argument 1 in `new_v1()`
123118
if let ExprKind::AddrOf(_, ref arr) = args[0].kind;
124119
if let ExprKind::Array(ref pieces) = arr.kind;
@@ -144,11 +139,8 @@ fn on_new_v1<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<S
144139

145140
fn on_new_v1_fmt<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) -> Option<String> {
146141
if_chain! {
147-
if let ExprKind::Call(ref fun, ref args) = expr.kind;
142+
if let Some(args) = match_function_call(cx, expr, &paths::FMT_ARGUMENTS_NEW_V1_FORMATTED);
148143
if args.len() == 3;
149-
if let ExprKind::Path(ref qpath) = fun.kind;
150-
if let Some(did) = resolve_node(cx, qpath, fun.hir_id).opt_def_id();
151-
if match_def_path(cx, did, &paths::FMT_ARGUMENTS_NEW_V1_FORMATTED);
152144
if check_unformatted(&args[2]);
153145
// Argument 1 in `new_v1_formatted()`
154146
if let ExprKind::AddrOf(_, ref arr) = args[0].kind;

clippy_lints/src/formatting.rs

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ fn check_else(cx: &EarlyContext<'_>, expr: &Expr) {
235235
}
236236
}
237237

238+
#[must_use]
238239
fn has_unary_equivalent(bin_op: BinOpKind) -> bool {
239240
// &, *, -
240241
bin_op == BinOpKind::And || bin_op == BinOpKind::Mul || bin_op == BinOpKind::Sub

0 commit comments

Comments
 (0)