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

Nightly&beta clippy auto-fixes cause errors #12467

Closed
ilyagr opened this issue Mar 12, 2024 · 4 comments
Closed

Nightly&beta clippy auto-fixes cause errors #12467

ilyagr opened this issue Mar 12, 2024 · 4 comments
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@ilyagr
Copy link

ilyagr commented Mar 12, 2024

Summary

Running cargo clippy --workspace --fix on the commit https://github.com/martinvonz/jj/tree/6fd15dc7e52bd0479812cde66a4908c69ae1ff8d resulted in a broken build.

The error messages asked me to submit a bug report, and here it is :)

Full output of the command:

$ cargo clippy --workspace --fix
    Checking futures-channel v0.3.30
    Checking openssl-sys v0.9.101
   Compiling jj-lib-proc-macros v0.15.1 (/Users/ilyagr/dev/jj/lib/proc-macros)
    Checking indexmap v2.2.5
   Compiling jj-cli v0.15.1 (/Users/ilyagr/dev/jj/cli)
    Checking futures-util v0.3.30
    Checking toml_edit v0.19.15
    Checking petgraph v0.6.4
    Checking libssh2-sys v0.3.0
    Checking libgit2-sys v0.16.2+1.7.2
    Checking git2 v0.18.2
    Checking prost-build v0.12.3
    Checking gen-protos v0.15.1 (/Users/ilyagr/dev/jj/lib/gen-protos)
    Checking futures-executor v0.3.30
    Checking futures v0.3.30
    Checking watchman_client v0.8.0
    Checking jj-lib v0.15.1 (/Users/ilyagr/dev/jj/lib)
warning: failed to automatically apply fixes suggested by rustc to crate `jj_lib`

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

  * lib/src/stacked_table.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 `maybe_other_ancestor` as mutable because it is also borrowed as immutable
   --> lib/src/stacked_table.rs:237:17
    |
234 | ...et other_ancestor = maybe_other_ancestor.as_ref().unwrap();
    |                        -------------------- immutable borrow occurs here
...
237 | ...   maybe_other_ancestor.clone_from(&other_ancestor.parent_fil...
    |       ^^^^^^^^^^^^^^^^^^^^^----------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |       |                    |
    |       |                    immutable borrow later used by call
    |       mutable borrow occurs here

error[E0502]: cannot borrow `maybe_other_ancestor` as mutable because it is also borrowed as immutable
   --> lib/src/stacked_table.rs:246:17
    |
234 | ...et other_ancestor = maybe_other_ancestor.as_ref().unwrap();
    |                        -------------------- immutable borrow occurs here
...
246 | ...   maybe_other_ancestor.clone_from(&other_ancestor.parent_fil...
    |       ^^^^^^^^^^^^^^^^^^^^^----------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |       |                    |
    |       |                    immutable borrow later used by call
    |       mutable borrow occurs here

error[E0502]: cannot borrow `maybe_own_ancestor` as mutable because it is also borrowed as immutable
   --> lib/src/stacked_table.rs:248:17
    |
240 | ...et own_ancestor = maybe_own_ancestor.as_ref().unwrap();
    |                      ------------------ immutable borrow occurs here
...
248 | ...   maybe_own_ancestor.clone_from(&own_ancestor.parent_fil...
    |       ^^^^^^^^^^^^^^^^^^^----------^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |       |                  |
    |       |                  immutable borrow later used by call
    |       mutable borrow occurs here

error[E0382]: use of moved value
   --> lib/src/stacked_table.rs:291:22
    |
291 |                 Some(parent_file) => {
    |                      ^^^^^^^^^^^ value moved here, in previous iteration of loop
    |
    = note: move occurs because value has type `std::sync::Arc<stacked_table::ReadonlyTable>`, which does not implement the `Copy` trait
help: borrow this binding in the pattern to avoid moving the value
    |
291 |                 Some(ref parent_file) => {
    |                      +++

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0382, E0502.
For more information about an error, try `rustc --explain E0382`.
Original diagnostics will follow.

warning: struct `SyncRegion` is never constructed
   --> lib/src/files.rs:164:8
    |
164 | struct SyncRegion {
    |        ^^^^^^^^^^
    |
    = note: `#[warn(dead_code)]` on by default

warning: assigning the result of `Clone::clone()` may be inefficient
  --> lib/src/commit_builder.rs:79:13
   |
79 | ...   commit.author.name = commit.committer.name.clone...
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `commit.author.name.clone_from(&commit.committer.name)`
   |
   = 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: assigning the result of `Clone::clone()` may be inefficient
  --> lib/src/commit_builder.rs:84:13
   |
84 | ...   commit.author.email = commit.committer.email.clone...
   |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `commit.author.email.clone_from(&commit.committer.email)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones

warning: assigning the result of `Clone::clone()` may be inefficient
   --> lib/src/local_backend.rs:327:5
    |
327 |     proto.description = commit.description.clone();
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `proto.description.clone_from(&commit.description)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones

warning: assigning the result of `Clone::clone()` may be inefficient
   --> lib/src/local_working_copy.rs:629:9
    |
629 | ...   proto.file_states = self.file_states.data.clone...
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `proto.file_states.clone_from(&self.file_states.data)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones

warning: assigning the result of `Clone::clone()` may be inefficient
   --> lib/src/local_working_copy.rs:637:9
    |
637 | ...   proto.watchman_clock = self.watchman_clock.clone...
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `proto.watchman_clock.clone_from(&self.watchman_clock)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones

warning: empty doc comment
  --> lib/src/revset.rs:75:10
   |
75 | #[derive(Parser)]
   |          ^^^^^^
   |
   = help: consider removing or filling it
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_docs
   = note: `#[warn(clippy::empty_docs)]` on by default
   = note: this warning originates in the derive macro `Parser` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: assigning the result of `Clone::clone()` may be inefficient
   --> lib/src/stacked_table.rs:237:17
    |
237 | ...   maybe_other_ancestor = other_ancestor.parent_file.clone...
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `maybe_other_ancestor.clone_from(&other_ancestor.parent_file)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones

warning: assigning the result of `Clone::clone()` may be inefficient
   --> lib/src/stacked_table.rs:246:17
    |
246 | ...   maybe_other_ancestor = other_ancestor.parent_file.clone...
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `maybe_other_ancestor.clone_from(&other_ancestor.parent_file)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones

warning: assigning the result of `Clone::clone()` may be inefficient
   --> lib/src/stacked_table.rs:248:17
    |
248 | ...   maybe_own_ancestor = own_ancestor.parent_file.clone...
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `maybe_own_ancestor.clone_from(&own_ancestor.parent_file)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones

warning: assigning the result of `Clone::clone()` may be inefficient
   --> lib/src/stacked_table.rs:300:21
    |
300 | ...   maybe_parent_file = parent_file.parent_file.clone...
    |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `maybe_parent_file.clone_from(&parent_file.parent_file)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones

warning: `jj-lib` (lib) generated 11 warnings (run `cargo clippy --fix --lib -p jj-lib` to apply 9 suggestions)
    Checking testutils v0.15.1 (/Users/ilyagr/dev/jj/lib/testutils)
warning: failed to automatically apply fixes suggested by rustc to crate `jj_cli`

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

  * cli/src/ui.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 `buf` as mutable because it is also borrowed as immutable
   --> cli/src/ui.rs:431:32
    |
430 | ...f let Some(trimmed) = buf.strip_suffix('\n') {
    |                          --- immutable borrow occurs here
431 | ...   trimmed.clone_into(&mut buf);
    |               ---------- ^^^^^^^^ mutable borrow occurs here
    |               |
    |               immutable borrow later used by call

error: aborting due to 1 previous error

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

warning: empty doc comment
  --> cli/src/template_parser.rs:27:10
   |
27 | #[derive(Parser)]
   |          ^^^^^^
   |
   = help: consider removing or filling it
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_docs
   = note: `#[warn(clippy::empty_docs)]` on by default
   = note: this warning originates in the derive macro `Parser` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: assigning the result of `ToOwned::to_owned()` may be inefficient
   --> cli/src/ui.rs:431:13
    |
431 |             buf = trimmed.to_owned();
    |             ^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `trimmed.clone_into(&mut buf)`
    |
    = 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: `jj-cli` (lib) generated 2 warnings (run `cargo clippy --fix --lib -p jj-cli` to apply 1 suggestion)
warning: failed to automatically apply fixes suggested by rustc to crate `jj_lib`

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

  * lib/src/stacked_table.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 `maybe_other_ancestor` as mutable because it is also borrowed as immutable
   --> lib/src/stacked_table.rs:237:17
    |
234 | ...et other_ancestor = maybe_other_ancestor.as_ref().unwrap();
    |                        -------------------- immutable borrow occurs here
...
237 | ...   maybe_other_ancestor.clone_from(&other_ancestor.parent_fil...
    |       ^^^^^^^^^^^^^^^^^^^^^----------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |       |                    |
    |       |                    immutable borrow later used by call
    |       mutable borrow occurs here

error[E0502]: cannot borrow `maybe_other_ancestor` as mutable because it is also borrowed as immutable
   --> lib/src/stacked_table.rs:246:17
    |
234 | ...et other_ancestor = maybe_other_ancestor.as_ref().unwrap();
    |                        -------------------- immutable borrow occurs here
...
246 | ...   maybe_other_ancestor.clone_from(&other_ancestor.parent_fil...
    |       ^^^^^^^^^^^^^^^^^^^^^----------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |       |                    |
    |       |                    immutable borrow later used by call
    |       mutable borrow occurs here

error[E0502]: cannot borrow `maybe_own_ancestor` as mutable because it is also borrowed as immutable
   --> lib/src/stacked_table.rs:248:17
    |
240 | ...et own_ancestor = maybe_own_ancestor.as_ref().unwrap();
    |                      ------------------ immutable borrow occurs here
...
248 | ...   maybe_own_ancestor.clone_from(&own_ancestor.parent_fil...
    |       ^^^^^^^^^^^^^^^^^^^----------^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |       |                  |
    |       |                  immutable borrow later used by call
    |       mutable borrow occurs here

error[E0382]: use of moved value
   --> lib/src/stacked_table.rs:291:22
    |
291 |                 Some(parent_file) => {
    |                      ^^^^^^^^^^^ value moved here, in previous iteration of loop
    |
    = note: move occurs because value has type `std::sync::Arc<stacked_table::ReadonlyTable>`, which does not implement the `Copy` trait
help: borrow this binding in the pattern to avoid moving the value
    |
291 |                 Some(ref parent_file) => {
    |                      +++

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0382, E0502.
For more information about an error, try `rustc --explain E0382`.
Original diagnostics will follow.

warning: `jj-lib` (lib test) generated 11 warnings (11 duplicates)
warning: failed to automatically apply fixes suggested by rustc to crate `jj_cli`

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

  * cli/src/template_builder.rs
  * cli/src/ui.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:
warning: the item `TemplateAliasesMap` is imported redundantly
    --> cli/src/template_builder.rs:1150:9
     |
1147 |     use super::*;
     |         -------- the item `TemplateAliasesMap` is already imported here
...
1150 |     use crate::template_parser::TemplateAliasesMap;
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: `#[warn(unused_imports)]` on by default

error[E0502]: cannot borrow `buf` as mutable because it is also borrowed as immutable
   --> cli/src/ui.rs:431:32
    |
430 | ...f let Some(trimmed) = buf.strip_suffix('\n') {
    |                          --- immutable borrow occurs here
431 | ...   trimmed.clone_into(&mut buf);
    |               ---------- ^^^^^^^^ mutable borrow occurs here
    |               |
    |               immutable borrow later used by call

error: aborting due to 1 previous error; 1 warning emitted

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

warning: the item `TemplateAliasesMap` is imported redundantly
    --> cli/src/template_builder.rs:1150:9
     |
1147 |     use super::*;
     |         -------- the item `TemplateAliasesMap` is already imported here
...
1150 |     use crate::template_parser::TemplateAliasesMap;
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: `#[warn(unused_imports)]` on by default

warning: `jj-cli` (lib test) generated 3 warnings (2 duplicates)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 30.70s

I'm guessing the curlprits may be the clippy::assigning_clones warnings, since I haven't seen them before seeing this problem, but this might be wrong.

When running cargo build, I get two of the warnings, but the build is successful and tests run successfully. The warnings that I get even on build (and that therefore can likely be safely ignored above) are the dead_code on SyncRegion and unused_imports on TemplateAliasesMap.

Reproducer

See above

Version

binary: rustc
commit-hash: 4a0cc881dcc4d800f10672747f61a94377ff6662
commit-date: 2024-03-11
host: aarch64-apple-darwin
release: 1.78.0-nightly
LLVM version: 18.1.0

Additional Labels

No response

@ilyagr ilyagr added the C-bug Category: Clippy is not doing the correct thing label Mar 12, 2024
@ilyagr ilyagr changed the title Clippy auto-fixes cause errors Nightly clippy auto-fixes cause errors Mar 12, 2024
@y21
Copy link
Member

y21 commented Mar 12, 2024

Likely a duplicate of #12460 and/or #12444.

@ilyagr
Copy link
Author

ilyagr commented Mar 19, 2024

I'm now getting this problem in the beta release. :(

rustc 1.78.0-beta.1 (efd9d2df1 2024-03-18)
binary: rustc
commit-hash: efd9d2df12b5e17fac0b4d0fb89f612ecd79f259
commit-date: 2024-03-18
host: aarch64-apple-darwin
release: 1.78.0-beta.1
LLVM version: 18.1.2

ilyagr added a commit to ilyagr/jj that referenced this issue Mar 19, 2024
There are still some warnings from (seemingly) clippy bugs. Quoting
myself from Discord:

> PSA: the latest beta cargo clippy (from Rust 1.78) has some problems
> that affect jj: rust-lang/rust-clippy#12467
> and rust-lang/rust-clippy#12377.  You could
> disable clippy::assigning_clones and clippy::empty_docs as a workaround.
> VS Code can disable them in rust-analyzer, you can also use
> https://github.com/ericseppanen/cargo-cranky (you can put Cranky.toml in
> the per-user gitignore).
@ilyagr ilyagr changed the title Nightly clippy auto-fixes cause errors Nightly&beta clippy auto-fixes cause errors Mar 20, 2024
ilyagr added a commit to jj-vcs/jj that referenced this issue Mar 20, 2024
There are still some warnings from (seemingly) clippy bugs. Quoting
myself from Discord:

> PSA: the latest beta cargo clippy (from Rust 1.78) has some problems
> that affect jj: rust-lang/rust-clippy#12467
> and rust-lang/rust-clippy#12377.  You could
> disable clippy::assigning_clones and clippy::empty_docs as a workaround.
> VS Code can disable them in rust-analyzer, you can also use
> https://github.com/ericseppanen/cargo-cranky (you can put Cranky.toml in
> the per-user gitignore).
@Kobzol
Copy link
Contributor

Kobzol commented Jun 21, 2024

This should have been fixed by #12756.

@ilyagr
Copy link
Author

ilyagr commented Jun 22, 2024

This seems to be fixed in the current nightly, best as I can tell.

@ilyagr ilyagr closed this as completed Jun 22, 2024
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
Projects
None yet
Development

No branches or pull requests

3 participants