Skip to content

Commit 845f4af

Browse files
committed
new lint for missing #[must_use] on pure fns
1 parent ca9e4ad commit 845f4af

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

+694
-76
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,7 @@ Released 2018-09-13
11161116
[`ptr_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
11171117
[`ptr_offset_with_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_offset_with_cast
11181118
[`pub_enum_variant_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_enum_variant_names
1119+
[`pure_without_must_use`]: https://rust-lang.github.io/rust-clippy/master/index.html#pure_without_must_use
11191120
[`question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
11201121
[`range_minus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_minus_one
11211122
[`range_plus_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#range_plus_one

README.md

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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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),

0 commit comments

Comments
 (0)