Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

len_without_is_empty : warning: struct Lru has a public len method, but the is_empty method has an unexpected signature #6972

Closed
rohitjoshi opened this issue Mar 25, 2021 · 0 comments · Fixed by #6980
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@rohitjoshi
Copy link

Lint name: len_without_is_empty

I tried this code:

 #[inline(always)]
    pub async fn is_empty(&self) -> bool {
        self.len().await > 0
    }

    #[inline(always)]
    pub async fn len(&self) -> usize {
        self.cache.lock().await.len()
    }

I expected to see this happen: It should not generate warning

Instead, this happened: *
warning: struct Lru has a public len method, but the is_empty method has an unexpected signature
--> xxx-async/src/cache/lru_cache.rs:175:5
|
175 | pub async fn len(&self) -> usize {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(clippy::len_without_is_empty)] on by default
note: is_empty defined here
--> xxx-async/src/cache/lru_cache.rs:170:5
|
170 | pub async fn is_empty(&self) -> bool {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: expected signature: (&self) -> bool
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty
*

Meta

  • cargo clippy -V: clippy 0.1.52 (07e0e2e 2021-03-24))
  • rustc -Vv:

rustc 1.53.0-nightly (07e0e2e 2021-03-24)
binary: rustc
commit-hash: 07e0e2e
commit-date: 2021-03-24
host: x86_64-apple-darwin
release: 1.53.0-nightly
LLVM version: 12.0.0

@rohitjoshi rohitjoshi added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Mar 25, 2021
@bors bors closed this as completed in dcee00d Mar 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant