rust-lang / rust-lang/rust-clippy

Compiler error after running cargo clippy --fix

Open
#9,926 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug S-triage
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Configurations checked:

  • clippy 0.1.66 (42325c52 2022-11-11), cargo 1.67.0-nightly (9286a1beb 2022-11-04) (via cargo +nightly clippy --fix)
  • clippy 0.1.65 (897e3755 2022-11-02), cargo 1.65.0 (4bc8f24d3 2022-10-20)

If you clone the repo with the initial commit:

https://github.com/typesanitizer/pichpich/tree/b971066734479f1bae779a0fa481fdc0d2b4e458

Then running cargo clippy --fix gives an error: (there are other warnings from clippy too but not showing those here)

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

  * src/lib.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/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[E0277]: a value of type `std::vec::Vec<AppErrorNewtype>` cannot be built from an iterator over elements of type `std::boxed::Box<AppErrorNewtype>`
    --> src/lib.rs:30:24
     |
30   |               unrelated: errors
     |  ________________________^
31   | |                 .into_iter()
32   | |                 .map(|e| Box::new(AppErrorNewtype(e)))
     | |______________________________________________________^ value of type `std::vec::Vec<AppErrorNewtype>` cannot be built from `std::iter::Iterator<Item=std::boxed::Box<AppErrorNewtype>>`
33   |                   .collect(),
     |                    ------- required by a bound introduced by this call
     |
     = help: the trait `std::iter::FromIterator<std::boxed::Box<AppErrorNewtype>>` is not implemented for `std::vec::Vec<AppErrorNewtype>`
     = help: the trait `std::iter::FromIterator<T>` is implemented for `std::vec::Vec<T>`
note: required by a bound in `std::iter::Iterator::collect`
    --> /Users/varun/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:1832:19
     |
1832 |     fn collect<B: FromIterator<Self::Item>>(self) -> B
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `std::iter::Iterator::collect`

error[E0599]: the method `as_ref` exists for reference `&AppErrorNewtype`, but its trait bounds were not satisfied
   --> src/lib.rs:57:45
    |
57  |             self.unrelated.iter().map(|b| b.as_ref() as &dyn Diagnostic),
    |                                             ^^^^^^ method cannot be called on `&AppErrorNewtype` due to unsatisfied trait bounds
...
79  | pub struct AppErrorNewtype(pub AppError);
    | -------------------------- doesn't satisfy `AppErrorNewtype: std::convert::AsRef<_>`
    |
    = note: the following trait bounds were not satisfied:
            `AppErrorNewtype: std::convert::AsRef<_>`
            which is required by `&AppErrorNewtype: std::convert::AsRef<_>`
note: the following trait must be implemented
   --> /Users/varun/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/convert/mod.rs:218:1
    |
218 | pub trait AsRef<T: ?Sized> {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: items from traits can only be used if the trait is implemented and in scope
    = note: the following trait defines an item `as_ref`, perhaps you need to implement it:
            candidate rust-lang/rust#1: `std::convert::AsRef`

error: aborting due to 2 previous errors

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by checking the initial commit b971066734479f1bae779a0fa481fdc0d2b4e458 and reproducing the failure with the listed cargo clippy --fix versions. Inspect src/lib.rs around lines 30 and 57, then compare the automatically applied changes with the original diagnostics. Done means identifying whether Clippy or the compiler causes the invalid fix and documenting a verified correction or minimal reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.