From cc622608db7318b1c0fe3ccd541558436c7c6c4c Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Wed, 18 Sep 2019 08:37:41 +0200 Subject: new lints around `#[must_use]` fns `must_use_unit` lints unit-returning functions with a `#[must_use]` attribute, suggesting to remove it. `double_must_use` lints functions with a plain `#[must_use]` attribute, but which return a type which is already `#[must_use]`, so the attribute has no benefit. `must_use_candidate` is a pedantic lint that lints functions and methods that return some non-unit type that is not already `#[must_use]` and suggests to add the annotation. --- clippy_dev/src/lib.rs | 7 +++++++ clippy_dev/src/stderr_length_check.rs | 1 + 2 files changed, 8 insertions(+) (limited to 'clippy_dev') 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> { 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) -> Vec { lints .into_iter() @@ -86,6 +90,7 @@ pub fn gen_lint_group_list(lints: Vec) -> Vec { } /// Generates the `pub mod module_name` list in `clippy_lints/src/lib.rs`. +#[must_use] pub fn gen_modules_list(lints: Vec) -> Vec { lints .into_iter() @@ -103,6 +108,7 @@ pub fn gen_modules_list(lints: Vec) -> Vec { } /// Generates the list of lint links at the bottom of the README +#[must_use] pub fn gen_changelog_lint_list(lints: Vec) -> Vec { let mut lint_list_sorted: Vec = lints; lint_list_sorted.sort_by_key(|l| l.name.clone()); @@ -119,6 +125,7 @@ pub fn gen_changelog_lint_list(lints: Vec) -> Vec { } /// Generates the `register_removed` code in `./clippy_lints/src/lib.rs`. +#[must_use] pub fn gen_deprecated(lints: &[Lint]) -> Vec { 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 { .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(); -- cgit 1.4.1-3-g733a5