Skip to content

len_without_is_empty fails on Surf #6958

@Fishrock123

Description

@Fishrock123

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 

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions