diff options
| author | bors <bors@rust-lang.org> | 2019-10-14 17:33:30 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-10-14 17:33:30 +0000 |
| commit | 8fae2dd3c1bfed13bdd6c0cfd4170dd1363f25f7 (patch) | |
| tree | 5191a1ef86462ec213300758e44a6ee6f25fdd55 /clippy_dev/src | |
| parent | c40d7db6ed04ce0a2f8ce5b0e057615850d69f48 (diff) | |
| parent | cc622608db7318b1c0fe3ccd541558436c7c6c4c (diff) | |
| download | rust-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 'clippy_dev/src')
| -rw-r--r-- | clippy_dev/src/lib.rs | 7 | ||||
| -rw-r--r-- | clippy_dev/src/stderr_length_check.rs | 1 |
2 files changed, 8 insertions, 0 deletions
diff --git a/clippy_dev/src/lib.rs b/clippy_dev/src/lib.rs index 7df7109c75f..84b2814a7ce 100644 --- a/clippy_dev/src/lib.rs +++ b/clippy_dev/src/lib.rs @@ -42,6 +42,7 @@ pub struct Lint { } impl Lint { + #[must_use] pub fn new(name: &str, group: &str, desc: &str, deprecation: Option<&str>, module: &str) -> Self { Self { name: name.to_lowercase(), @@ -58,6 +59,7 @@ impl Lint { } /// Returns the lints in a `HashMap`, grouped by the different lint groups + #[must_use] pub fn by_lint_group(lints: &[Self]) -> HashMap<String, Vec<Self>> { lints .iter() @@ -65,12 +67,14 @@ impl Lint { .into_group_map() } + #[must_use] pub fn is_internal(&self) -> bool { self.group.starts_with("internal") } } /// Generates the Vec items for `register_lint_group` calls in `clippy_lints/src/lib.rs`. +#[must_use] pub fn gen_lint_group_list(lints: Vec<Lint>) -> Vec<String> { lints .into_iter() @@ -86,6 +90,7 @@ pub fn gen_lint_group_list(lints: Vec<Lint>) -> Vec<String> { } /// Generates the `pub mod module_name` list in `clippy_lints/src/lib.rs`. +#[must_use] pub fn gen_modules_list(lints: Vec<Lint>) -> Vec<String> { lints .into_iter() @@ -103,6 +108,7 @@ pub fn gen_modules_list(lints: Vec<Lint>) -> Vec<String> { } /// Generates the list of lint links at the bottom of the README +#[must_use] pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> { let mut lint_list_sorted: Vec<Lint> = lints; 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> { } /// Generates the `register_removed` code in `./clippy_lints/src/lib.rs`. +#[must_use] pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> { lints .iter() diff --git a/clippy_dev/src/stderr_length_check.rs b/clippy_dev/src/stderr_length_check.rs index 3049c45ddc8..2d7d119f3ff 100644 --- a/clippy_dev/src/stderr_length_check.rs +++ b/clippy_dev/src/stderr_length_check.rs @@ -42,6 +42,7 @@ fn stderr_files() -> impl Iterator<Item = walkdir::DirEntry> { .filter(|f| f.path().extension() == Some(OsStr::new("stderr"))) } +#[must_use] fn count_linenumbers(filepath: &str) -> usize { if let Ok(mut file) = File::open(filepath) { let mut content = String::new(); |
