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 fails on Surf #6958

Closed
Fishrock123 opened this issue Mar 23, 2021 · 1 comment · Fixed by #6980
Closed

len_without_is_empty fails on Surf #6958

Fishrock123 opened this issue Mar 23, 2021 · 1 comment · 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

@Fishrock123
Copy link
Contributor

Fishrock123 commented Mar 23, 2021

Lint name:

I tried this code:

    pub fn len(&self) -> Option<usize> {
        self.req.len()
    }

    pub fn is_empty(&self) -> Option<bool> {
        self.req.is_empty()
    }

https://github.com/http-rs/surf/blob/fb228d8536b041f26f53f7b6eaa3ff56238d9f2c/src/request.rs#L272-L286

I expected to see this happen:

No warning. We implement a is_empty() but since the request body is a stream (AsyncRead), we may not know the length for e.g. chunked request bodies. The natural API for expressing that is Option<>.

Instead, this happened:

https://github.com/http-rs/surf/pull/294/checks?check_run_id=2177417044

warning: struct `Request` has a public `len` method, but the `is_empty` method has an unexpected signature
   --> src/request.rs:278:5
    |
278 |     pub fn len(&self) -> Option<usize> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(clippy::len_without_is_empty)]` on by default
note: `is_empty` defined here
   --> src/request.rs:284:5
    |
284 |     pub fn is_empty(&self) -> Option<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

error: struct `Request` has a public `len` method, but the `is_empty` method has an unexpected signature
   --> src/request.rs:278:5
    |
278 |     pub fn len(&self) -> Option<usize> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: the lint level is defined here
   --> src/lib.rs:78:24
    |
78  | #![cfg_attr(test, deny(warnings))]
    |                        ^^^^^^^^
    = note: `#[deny(clippy::len_without_is_empty)]` implied by `#[deny(warnings)]`
note: `is_empty` defined here
   --> src/request.rs:284:5
    |
284 |     pub fn is_empty(&self) -> Option<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 (f5d8117 2021-03-16)
  • rustc -Vv:
rustc 1.52.0-nightly (f5d8117c3 2021-03-16)
binary: rustc
commit-hash: f5d8117c338a788bd24abec733fd143dfceb25a0
commit-date: 2021-03-16
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 12.0.0
@Fishrock123 Fishrock123 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 23, 2021
@llogiq
Copy link
Contributor

llogiq commented Mar 25, 2021

So I guess the lint should at least check if len(&self) returns usize and not fire otherwise.

@bors bors closed this as completed in dcee00d Mar 27, 2021
Fishrock123 added a commit to Fishrock123/surf that referenced this issue Jun 9, 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.

2 participants