about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-10-14 17:33:30 +0000
committerbors <bors@rust-lang.org>2019-10-14 17:33:30 +0000
commit8fae2dd3c1bfed13bdd6c0cfd4170dd1363f25f7 (patch)
tree5191a1ef86462ec213300758e44a6ee6f25fdd55 /src
parentc40d7db6ed04ce0a2f8ce5b0e057615850d69f48 (diff)
parentcc622608db7318b1c0fe3ccd541558436c7c6c4c (diff)
downloadrust-8fae2dd3c1bfed13bdd6c0cfd4170dd1363f25f7.tar.gz
rust-8fae2dd3c1bfed13bdd6c0cfd4170dd1363f25f7.zip
Auto merge of #4560 - rust-lang:must-use-pure, r=phansch
new lints around`#[must_use]`

changelog: Add `must_use_candidate` lint,  add `must-use-unit` lint, add `double_must_use` lint

The first one checks if an public function or method has no mutable argument and mutates no non-local data and lints if it has no `#[must_use]` attribute. It will skip inner functions, because those are usually highly local and the attribute doesn't have as much benefit there.

The second lints `#[must_use]` attributes on functions and methods that return unit. Those attributes are likely a remnant from a refactoring that removed the return value.

The last one lints for `#[must_use]` attributrs without text on functions that return a type which is already marked `#[must_use]`. This has no auto-suggestion, because while it would be easy to do, there may be value in writing a detailed text for the attribute instead.

This fixes #4526
Diffstat (limited to 'src')
-rw-r--r--src/lintlist/mod.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs
index 28f212fb2b2..66ee41402ea 100644
--- a/src/lintlist/mod.rs
+++ b/src/lintlist/mod.rs
@@ -6,7 +6,7 @@ pub use lint::Lint;
 pub use lint::LINT_LEVELS;
 
 // begin lint list, do not remove this comment, it’s used in `update_lints`
-pub const ALL_LINTS: [Lint; 321] = [
+pub const ALL_LINTS: [Lint; 324] = [
     Lint {
         name: "absurd_extreme_comparisons",
         group: "correctness",
@@ -351,6 +351,13 @@ pub const ALL_LINTS: [Lint; 321] = [
         module: "double_comparison",
     },
     Lint {
+        name: "double_must_use",
+        group: "style",
+        desc: "`#[must_use]` attribute on a `#[must_use]`-returning function / method",
+        deprecation: None,
+        module: "functions",
+    },
+    Lint {
         name: "double_neg",
         group: "style",
         desc: "`--x`, which is a double negation of `x` and not a pre-decrement as in C/C++",
@@ -1156,6 +1163,20 @@ pub const ALL_LINTS: [Lint; 321] = [
         module: "inherent_impl",
     },
     Lint {
+        name: "must_use_candidate",
+        group: "pedantic",
+        desc: "function or method that could take a `#[must_use]` attribute",
+        deprecation: None,
+        module: "functions",
+    },
+    Lint {
+        name: "must_use_unit",
+        group: "style",
+        desc: "`#[must_use]` attribute on a unit-returning function / method",
+        deprecation: None,
+        module: "functions",
+    },
+    Lint {
         name: "mut_from_ref",
         group: "correctness",
         desc: "fns that create mutable refs from immutable ref args",