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

Clippy demands you violate ownership to satisfy assigning_clones #12757

Open
workingjubilee opened this issue May 3, 2024 · 3 comments · May be fixed by #12756
Open

Clippy demands you violate ownership to satisfy assigning_clones #12757

workingjubilee opened this issue May 3, 2024 · 3 comments · May be fixed by #12756
Labels
C-bug Category: Clippy is not doing the correct thing I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied

Comments

@workingjubilee
Copy link
Contributor

Summary

I believe this isn't checking to see if it's in any kind of looping structure which makes this kind of lint extremely fallible:

   Checking pgrx-sql-entity-graph v0.12.0-alpha.1 (/home/jubilee/tcdi/pgrx/pgrx-sql-entity-graph)
warning: failed to automatically apply fixes suggested by rustc to crate `pgrx_sql_entity_graph`

after fixes were automatically applied the compiler reported errors within these files:

  * pgrx-sql-entity-graph/src/pg_extern/returning.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust-clippy/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error[E0502]: cannot borrow `segments` as mutable because it is also borrowed as immutable
   --> pgrx-sql-entity-graph/src/pg_extern/returning.rs:120:29
    |
107 |                         if let Some(segment) = segments.filter_last_ident("Option") {
    |                                                -------- immutable borrow occurs here
...
120 |                             segments.clone_from(&this_path.path.segments); // recurse deeper
    |                             ^^^^^^^^^----------^^^^^^^^^^^^^^^^^^^^^^^^^^
    |                             |        |
    |                             |        immutable borrow later used by call
    |                             mutable borrow occurs here

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0502`.
Original diagnostics will follow.

warning: assigning the result of `Clone::clone()` may be inefficient
   --> pgrx-sql-entity-graph/src/pg_extern/returning.rs:120:29
    |
120 | ...                   segments = this_path.path.segments.clone(); // recurse deeper
    |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `segments.clone_from(&this_path.path.segments)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones
    = note: `#[warn(clippy::assigning_clones)]` on by default

warning: `pgrx-sql-entity-graph` (lib test) generated 1 warning (run `cargo clippy --fix --lib -p pgrx-sql-entity-graph --tests` to apply 1 suggestion)
warning: failed to automatically apply fixes suggested by rustc to crate `pgrx_sql_entity_graph`

after fixes were automatically applied the compiler reported errors within these files:

  * pgrx-sql-entity-graph/src/pg_extern/returning.rs

This likely indicates a bug in either rustc or cargo itself,
and we would appreciate a bug report! You're likely to see
a number of compiler warnings after this message which cargo
attempted to fix but failed. If you could open an issue at
https://github.com/rust-lang/rust-clippy/issues
quoting the full output of this command we'd be very appreciative!
Note that you may be able to make some more progress in the near-term
fixing code with the `--broken-code` flag

The following errors were reported:
error[E0502]: cannot borrow `segments` as mutable because it is also borrowed as immutable
   --> pgrx-sql-entity-graph/src/pg_extern/returning.rs:120:29
    |
107 |                         if let Some(segment) = segments.filter_last_ident("Option") {
    |                                                -------- immutable borrow occurs here
...
120 |                             segments.clone_from(&this_path.path.segments); // recurse deeper
    |                             ^^^^^^^^^----------^^^^^^^^^^^^^^^^^^^^^^^^^^
    |                             |        |
    |                             |        immutable borrow later used by call
    |                             mutable borrow occurs here

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0502`.
Original diagnostics will follow.

warning: `pgrx-sql-entity-graph` (lib) generated 1 warning (1 duplicate)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.20s

Reproducer

The source is here:

https://github.com/pgcentralfoundation/pgrx/blob/beb79011a377bb96c34fcc50ae2d652aa1419eb5/pgrx-sql-entity-graph/src/pg_extern/returning.rs#L107-L120

Version

rustc 1.78.0 (9b00956e5 2024-04-29)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2

Additional Labels

@rustbot label: +I-suggestion-causes-error

@workingjubilee workingjubilee added the C-bug Category: Clippy is not doing the correct thing label May 3, 2024
@rustbot rustbot added the I-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied label May 3, 2024
@workingjubilee
Copy link
Contributor Author

May duplicate #12756

@y21
Copy link
Member

y21 commented May 3, 2024

May duplicate #12756

Looks like that fixes it indeed. I ran a clippy build with those changes on the pgrx-sql-entity-graph crate and it no longer shows that warning.

@workingjubilee
Copy link
Contributor Author

thanks!

m4tx added a commit to riichi/chombot that referenced this issue May 6, 2024
The remaining error will be fixed after rust-lang/rust-clippy#12757 is
merged.
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-suggestion-causes-error Issue: The suggestions provided by this Lint cause an ICE/error when applied
Projects
None yet
3 participants