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

Fix /some/ new clippy warnings #757

Merged
merged 11 commits into from
Sep 23, 2022
Merged

Fix /some/ new clippy warnings #757

merged 11 commits into from
Sep 23, 2022

Conversation

psychon
Copy link
Owner

@psychon psychon commented Sep 22, 2022

Okay, enough CI ping-pong for today. This is as far as I want to go for now. Good night.

Example:

error: deref which would be done by auto-deref
   --> x11rb/src/rust_connection/stream.rs:168:35
    |
168 |                 return self.write(&**buf, fds);
    |                                   ^^^^^^ help: try this: `buf`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref

Signed-off-by: Uli Schlachter <psychon@znc.in>
Example warning:

error: the borrowed expression implements the required traits
  --> x11rb/examples/integration_test_util/util.rs:41:83
   |
41 |             if let Err(err) = conn.send_event(false, window, EventMask::NO_EVENT, &event) {
   |                                                                                   ^^^^^^ help: change this to: `event`
   |
   = note: `-D clippy::needless-borrow` implied by `-D warnings`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

Signed-off-by: Uli Schlachter <psychon@znc.in>
error: deref which would be done by auto-deref
  --> x11rb/tests/parsing_tests.rs:86:47
   |
86 |     let (setup, remaining) = Setup::try_parse(&*setup)?;
   |                                               ^^^^^^^ help: try this: `&setup`
   |
   = note: `-D clippy::explicit-auto-deref` implied by `-D warnings`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref

Signed-off-by: Uli Schlachter <psychon@znc.in>
error: deref which would be done by auto-deref
  --> x11rb/src/utils.rs:76:13
   |
76 |             &**self
   |             ^^^^^^^ help: try this: `self`
   |
   = note: `-D clippy::explicit-auto-deref` implied by `-D warnings`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref

Signed-off-by: Uli Schlachter <psychon@znc.in>
@codecov
Copy link

codecov bot commented Sep 22, 2022

Codecov Report

Base: 13.54% // Head: 13.54% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (b3a1437) compared to base (03ad826).
Patch coverage: 90.38% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #757   +/-   ##
=======================================
  Coverage   13.54%   13.54%           
=======================================
  Files         141      141           
  Lines      119917   119909    -8     
=======================================
+ Hits        16240    16243    +3     
+ Misses     103677   103666   -11     
Flag Coverage Δ
tests 13.54% <90.38%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
x11rb/src/image.rs 65.44% <0.00%> (+0.99%) ⬆️
x11rb/src/utils.rs 0.00% <0.00%> (ø)
x11rb/src/wrapper.rs 0.00% <0.00%> (ø)
x11rb/src/xcb_ffi/mod.rs 23.78% <0.00%> (-0.16%) ⬇️
x11rb/src/connection.rs 53.79% <33.33%> (ø)
generator/src/generator/namespace/switch.rs 80.66% <80.00%> (ø)
generator/src/generator/namespace/mod.rs 98.21% <100.00%> (ø)
generator/src/generator/namespace/request.rs 96.25% <100.00%> (ø)
...erator/src/generator/namespace/resource_wrapper.rs 96.41% <100.00%> (ø)
generator/src/generator/namespace/serialize.rs 83.44% <100.00%> (ø)
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Example:

error: deref which would be done by auto-deref
    --> generator/src/generator/namespace/mod.rs:1468:29
     |
1468 | ...                   &*case.fields.borrow(),
     |                       ^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&case.fields.borrow()`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref

Signed-off-by: Uli Schlachter <psychon@znc.in>
error: the borrowed expression implements the required traits
   --> x11rb/src/cursor/find_cursor.rs:262:36
    |
262 |                     theme_dir.push(&home);
    |                                    ^^^^^ help: change this to: `home`
    |
    = note: `-D clippy::needless-borrow` implied by `-D warnings`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

error: this `to_owned` call clones the std::borrow::Cow<[u8]> itself and does not cause the std::borrow::Cow<[u8]> contents to become owned
   --> x11rb/src/image.rs:525:19
    |
525 |             data: self.data.to_owned(),
    |                   ^^^^^^^^^^^^^^^^^^^^ help: consider using, depending on intent: `self.data.clone()` or `self.data.into_owned()`
    |
    = note: `-D clippy::suspicious-to-owned` implied by `-D warnings`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_to_owned

error: deref which would be done by auto-deref
   --> x11rb-protocol/src/resource_manager/parser.rs:298:38
    |
298 |             let result = parse_query(*data);
    |                                      ^^^^^ help: try this: `data`
    |
    = note: `-D clippy::explicit-auto-deref` implied by `-D warnings`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref

error: deref which would be done by auto-deref
   --> x11rb-protocol/src/resource_manager/parser.rs:313:38
    |
313 |             let result = parse_query(*data);
    |                                      ^^^^^ help: try this: `data`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref

error: deref which would be done by auto-deref
   --> x11rb-protocol/src/resource_manager/parser.rs:561:31
    |
561 |             match parse_entry(*data) {
    |                               ^^^^^ help: try this: `data`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#explicit_auto_deref

Signed-off-by: Uli Schlachter <psychon@znc.in>
ToOwned is automatically implemented for everything that implements
Clone and our hand-written implementation of ToOwned does nothing else
than we would get from this blanket implementation. Thus, let the
compiler simply derive this.

Signed-off-by: Uli Schlachter <psychon@znc.in>
error: boolean to int conversion using if
   --> x11rb/src/xcb_ffi/mod.rs:206:21
    |
206 |             isvoid: if has_reply { 0 } else { 1 },
    |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with from: `u8::from(!has_reply)`
    |
    = note: `-D clippy::bool-to-int-with-if` implied by `-D warnings`
    = note: `!has_reply as u8` or `(!has_reply).into()` can also be valid options
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bool_to_int_with_if

Signed-off-by: Uli Schlachter <psychon@znc.in>
error: the borrowed expression implements the required traits
  --> x11rb/tests/resource_manager.rs:42:32
   |
42 |             fs::create_dir_all(&parent).unwrap();
   |                                ^^^^^^^ help: change this to: `parent`
   |
   = note: `-D clippy::needless-borrow` implied by `-D warnings`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

Signed-off-by: Uli Schlachter <psychon@znc.in>
@psychon
Copy link
Owner Author

psychon commented Sep 23, 2022

This PR now adds something more than just "mechanically apply clippy suggestions": 71fd6c7 makes x11rb::image::Image derive Clone. This then causes

error[E0119]: conflicting implementations of trait `std::borrow::ToOwned` for type `image::Image<'_>`
   --> x11rb/src/image.rs:513:1
    |
513 | impl<'a> ToOwned for Image<'a> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: conflicting implementation in crate `alloc`:
            - impl<T> std::borrow::ToOwned for T
              where T: std::clone::Clone;

Oh, hey, a blanket implementation! Let's just use that.

(Note: This is actually a behaviour change because previously to_owned() would copy the underlying data. However, it was not possible to express this in the type system and thus the borrow checker still kept the original borrow. The new code now actually does exactly that, which I think should be fine.)

once_cell v1.15 switched to the 2021 edition and thus requires at least
Rust 1.56 to build. This commit increases our MSRV accordingly.

Fixes: #756
Signed-off-by: Uli Schlachter <psychon@znc.in>
@psychon
Copy link
Owner Author

psychon commented Sep 23, 2022

....aaaand this now also bumps the MSRV to 1.56 to fix #756

I am not quite sure why these only showed up after the MSRV was
increased, but whatever...

Example:

error: the borrowed expression implements the required traits
  --> x11rb/src/wrapper.rs:50:28
   |
50 |             data_u8.extend(&item.to_ne_bytes());
   |                            ^^^^^^^^^^^^^^^^^^^ help: change this to: `item.to_ne_bytes()`
   |
   = note: `-D clippy::needless-borrow` implied by `-D warnings`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

Signed-off-by: Uli Schlachter <psychon@znc.in>
@psychon
Copy link
Owner Author

psychon commented Sep 23, 2022

@notgull Could you approve this?

@mergify mergify bot merged commit 43e7520 into master Sep 23, 2022
@mergify mergify bot deleted the fix-clippy-complaints branch September 23, 2022 16:02
@psychon
Copy link
Owner Author

psychon commented Sep 23, 2022

Thanks!

I'll now take a look at the VecDeque binary search thing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants