Skip to content

Commit 134fac1

Browse files
committed
new lint for missing #[must_use] on pure fns
1 parent c23b375 commit 134fac1

Some content is hidden

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

56 files changed

+767
-78
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,7 @@ Released 2018-09-13
10651065
[`modulo_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#modulo_one
10661066
[`multiple_crate_versions`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_crate_versions
10671067
[`multiple_inherent_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_inherent_impl
1068+
[`must_use_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#must_use_unit
10681069
[`mut_from_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_from_ref
10691070
[`mut_mut`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_mut
10701071
[`mut_range_bound`]: https://rust-lang.github.io/rust-clippy/master/index.html#mut_range_bound
@@ -1116,6 +1117,7 @@ Released 2018-09-13
11161117
[`ptr_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
11171118
[`ptr_offset_with_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_offset_with_cast
11181119
[`pub_enum_variant_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_enum_variant_names
1120+
[`pure_without_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#pure_without_must_use
11191121
[`question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
11201122
[`range_minus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_minus_one
11211123
[`range_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one

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 316 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 318 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

clippy_dev/src/fmt.rs

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ fn exec(
134134
Ok(success)
135135
}
136136

137+
#[must_use]
137138
fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
138139
let mut args = vec!["+nightly", "fmt", "--all"];
139140
if context.check {
@@ -145,6 +146,7 @@ fn cargo_fmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
145146
Ok(success)
146147
}
147148

149+
#[must_use]
148150
fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
149151
let program = "rustfmt";
150152
let dir = std::env::current_dir()?;
@@ -168,6 +170,7 @@ fn rustfmt_test(context: &FmtContext) -> Result<(), CliError> {
168170
}
169171
}
170172

173+
#[must_use]
171174
fn rustfmt(context: &FmtContext, path: &Path) -> Result<bool, CliError> {
172175
let mut args = vec!["+nightly".as_ref(), path.as_os_str()];
173176
if context.check {

clippy_dev/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> {
137137
}
138138

139139
/// Gathers all files in `src/clippy_lints` and gathers all lints inside
140+
#[must_use]
140141
pub fn gather_all() -> impl Iterator<Item = Lint> {
141142
lint_files().flat_map(|f| gather_from_file(&f))
142143
}
@@ -161,6 +162,7 @@ fn gather_from_file(dir_entry: &walkdir::DirEntry) -> impl Iterator<Item = Lint>
161162
parse_contents(&content, filename)
162163
}
163164

165+
#[must_use]
164166
fn parse_contents(content: &str, filename: &str) -> impl Iterator<Item = Lint> {
165167
let lints = DEC_CLIPPY_LINT_RE
166168
.captures_iter(content)
@@ -173,6 +175,7 @@ fn parse_contents(content: &str, filename: &str) -> impl Iterator<Item = Lint> {
173175
}
174176

175177
/// Collects all .rs files in the `clippy_lints/src` directory
178+
#[must_use]
176179
fn lint_files() -> impl Iterator<Item = walkdir::DirEntry> {
177180
// We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
178181
// Otherwise we would not collect all the lints, for example in `clippy_lints/src/methods/`.

clippy_dev/src/stderr_length_check.rs

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ fn exceeding_stderr_files(files: impl Iterator<Item = walkdir::DirEntry>) -> imp
3434
})
3535
}
3636

37+
#[must_use]
3738
fn stderr_files() -> impl Iterator<Item = walkdir::DirEntry> {
3839
// We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
3940
WalkDir::new("../tests/ui")
@@ -42,6 +43,7 @@ fn stderr_files() -> impl Iterator<Item = walkdir::DirEntry> {
4243
.filter(|f| f.path().extension() == Some(OsStr::new("stderr")))
4344
}
4445

46+
#[must_use]
4547
fn count_linenumbers(filepath: &str) -> usize {
4648
if let Ok(mut file) = File::open(filepath) {
4749
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/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
@@ -112,6 +112,7 @@ impl EarlyLintPass for DocMarkdown {
112112
/// need to keep track of
113113
/// the spans but this function is inspired from the later.
114114
#[allow(clippy::cast_possible_truncation)]
115+
#[must_use]
115116
pub fn strip_doc_comment_decoration(comment: &str, span: Span) -> (String, Vec<(usize, Span)>) {
116117
// one-line comments lose their prefix
117118
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/formatting.rs

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ fn check_else(cx: &EarlyContext<'_>, expr: &Expr) {
172172
}
173173
}
174174

175+
#[must_use]
175176
fn has_unary_equivalent(bin_op: BinOpKind) -> bool {
176177
// &, *, -
177178
bin_op == BinOpKind::And || bin_op == BinOpKind::Mul || bin_op == BinOpKind::Sub

0 commit comments

Comments
 (0)