Skip to content

Problem with cargo clippy --fix #10718

@holtgrewe

Description

@holtgrewe

I tried to run cargo clippy --fix on this code:

I expected to see this happen: not a failure

Instead, this happened: failure see below

Meta

# rustc --version --verbose
rustc 1.67.0 (fc594f156 2023-01-24)
binary: rustc
commit-hash: fc594f15669680fa70d255faec3ca3fb507c3405
commit-date: 2023-01-24
host: x86_64-unknown-linux-gnu
release: 1.67.0
LLVM version: 15.0.6
# cargo clippy --version
clippy 0.1.67 (fc594f1 2023-01-24)
Click here for full output
```
cargo clippy --fix
    Checking mehari v0.1.0 (/home/holtgrem_c/Development/mehari)
warning: failed to automatically apply fixes suggested by rustc to crate `mehari`

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

* /home/holtgrem_c/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs
* /home/holtgrem_c/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/pin.rs
* src/db/create/seqvar_freqs/reading.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[E0308]: mismatched types
--> src/db/create/seqvar_freqs/reading.rs:86:13
|
86 |             readers,
|             ^^^^^^^ expected struct `noodles_util::variant::Reader`, found struct `std::boxed::Box`
|
= note: expected struct `std::vec::Vec<noodles_util::variant::Reader<std::boxed::Box<(dyn std::io::BufRead + 'static)>>>`
            found struct `std::vec::Vec<std::boxed::Box<noodles_util::variant::Reader<std::boxed::Box<(dyn std::io::BufRead + 'static)>>>>`

error[E0308]: mismatched types
--> src/db/create/seqvar_freqs/reading.rs:87:13
|
87 |             headers,
|             ^^^^^^^ expected struct `noodles::noodles_vcf::Header`, found struct `std::boxed::Box`
|
= note: expected struct `std::vec::Vec<noodles::noodles_vcf::Header>`
            found struct `std::vec::Vec<std::boxed::Box<noodles::noodles_vcf::Header>>`

error[E0599]: no method named `as_mut` found for struct `noodles_util::variant::Reader` in the current scope
--> src/db/create/seqvar_freqs/reading.rs:114:14
    |
114 |             .as_mut()
    |              ^^^^^^ method not found in `noodles_util::variant::Reader<std::boxed::Box<(dyn std::io::BufRead + 'static)>>`
    |
::: /home/holtgrem_c/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:373:8
    |
373 |     fn as_mut(&mut self) -> &mut T;
    |        ------
    |        |
    |        the method is available for `std::boxed::Box<noodles_util::variant::Reader<std::boxed::Box<(dyn std::io::BufRead + 'static)>>>` here
    |        the method is available for `std::boxed::Box<&mut noodles_util::variant::Reader<std::boxed::Box<(dyn std::io::BufRead + 'static)>>>` here
    |        the method is available for `std::boxed::Box<&noodles_util::variant::Reader<std::boxed::Box<(dyn std::io::BufRead + 'static)>>>` here
    |
::: /home/holtgrem_c/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/pin.rs:701:12
    |
701 |     pub fn as_mut(&mut self) -> Pin<&mut P::Target> {
    |            ------ the method is available for `std::pin::Pin<&mut noodles_util::variant::Reader<std::boxed::Box<(dyn std::io::BufRead + 'static)>>>` here
    |
help: consider wrapping the receiver expression with the appropriate type
    |
113 |         self.nexts[self.next] = Box::new(self.readers[self.next])
    |                                 +++++++++                       +
help: consider wrapping the receiver expression with the appropriate type
    |
113 |         self.nexts[self.next] = Box::new(&mut self.readers[self.next])
    |                                 +++++++++++++                        +
help: consider wrapping the receiver expression with the appropriate type
    |
113 |         self.nexts[self.next] = Pin::new(&mut self.readers[self.next])
    |                                 +++++++++++++                        +
help: consider wrapping the receiver expression with the appropriate type
    |
113 |         self.nexts[self.next] = Box::new(&self.readers[self.next])
    |                                 ++++++++++                       +

error: aborting due to 3 previous errors

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

error[E0308]: mismatched types
--> src/db/create/seqvar_freqs/reading.rs:86:13
|
86 |             readers,
|             ^^^^^^^ expected struct `noodles_util::variant::Reader`, found struct `std::boxed::Box`
|
= note: expected struct `std::vec::Vec<noodles_util::variant::Reader<std::boxed::Box<(dyn std::io::BufRead + 'static)>>>`
            found struct `std::vec::Vec<std::boxed::Box<noodles_util::variant::Reader<std::boxed::Box<(dyn std::io::BufRead + 'static)>>>>`

error[E0308]: mismatched types
--> src/db/create/seqvar_freqs/reading.rs:87:13
|
87 |             headers,
|             ^^^^^^^ expected struct `noodles::noodles_vcf::Header`, found struct `std::boxed::Box`
|
= note: expected struct `std::vec::Vec<noodles::noodles_vcf::Header>`
            found struct `std::vec::Vec<std::boxed::Box<noodles::noodles_vcf::Header>>`

error[E0599]: no method named `as_mut` found for struct `noodles_util::variant::Reader` in the current scope
--> src/db/create/seqvar_freqs/reading.rs:114:14
    |
114 |             .as_mut()
    |              ^^^^^^ method not found in `noodles_util::variant::Reader<std::boxed::Box<(dyn std::io::BufRead + 'static)>>`
    |
::: /home/holtgrem_c/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/convert/mod.rs:373:8
    |
373 |     fn as_mut(&mut self) -> &mut T;
    |        ------
    |        |
    |        the method is available for `std::boxed::Box<noodles_util::variant::Reader<std::boxed::Box<(dyn std::io::BufRead + 'static)>>>` here
    |        the method is available for `std::boxed::Box<&mut noodles_util::variant::Reader<std::boxed::Box<(dyn std::io::BufRead + 'static)>>>` here
    |        the method is available for `std::boxed::Box<&noodles_util::variant::Reader<std::boxed::Box<(dyn std::io::BufRead + 'static)>>>` here
    |
::: /home/holtgrem_c/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/pin.rs:701:12
    |
701 |     pub fn as_mut(&mut self) -> Pin<&mut P::Target> {
    |            ------ the method is available for `std::pin::Pin<&mut noodles_util::variant::Reader<std::boxed::Box<(dyn std::io::BufRead + 'static)>>>` here
    |
help: consider wrapping the receiver expression with the appropriate type
    |
113 |         self.nexts[self.next] = Box::new(self.readers[self.next])
    |                                 +++++++++                       +
help: consider wrapping the receiver expression with the appropriate type
    |
113 |         self.nexts[self.next] = Box::new(&mut self.readers[self.next])
    |                                 +++++++++++++                        +
help: consider wrapping the receiver expression with the appropriate type
    |
113 |         self.nexts[self.next] = Pin::new(&mut self.readers[self.next])
    |                                 +++++++++++++                        +
help: consider wrapping the receiver expression with the appropriate type
    |
113 |         self.nexts[self.next] = Box::new(&self.readers[self.next])
    |                                 ++++++++++                       +

Some errors have detailed explanations: E0308, E0599.
For more information about an error, try `rustc --explain E0308`.
error: could not compile `mehari` due to 3 previous errors
warning: build failed, waiting for other jobs to finish...
warning: use of `expect` followed by a function call
--> src/db/create/seqvar_freqs/reading.rs:40:18
|
40 |                 .expect(&format!("Invalid contig {}", s)),
|                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("Invalid contig {}", s))`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#expect_fun_call
= note: `#[warn(clippy::expect_fun_call)]` on by default

warning: variables can be used directly in the `format!` string
--> src/db/create/seqvar_freqs/reading.rs:40:26
|
40 |                 .expect(&format!("Invalid contig {}", s)),
|                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
= note: `#[warn(clippy::uninlined_format_args)]` on by default
help: change this to
|
40 -                 .expect(&format!("Invalid contig {}", s)),
40 +                 .expect(&format!("Invalid contig {s}")),
|

warning: `Vec<T>` is already on the heap, the boxing is unnecessary
--> src/db/create/seqvar_freqs/reading.rs:50:14
|
50 |     readers: Vec<Box<VariantReader<Box<dyn BufRead>>>>,
|              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Vec<VariantReader<Box<dyn BufRead>>>`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#vec_box
= note: `#[warn(clippy::vec_box)]` on by default

warning: `Vec<T>` is already on the heap, the boxing is unnecessary
--> src/db/create/seqvar_freqs/reading.rs:52:14
|
52 |     headers: Vec<Box<VcfHeader>>,
|              ^^^^^^^^^^^^^^^^^^^ help: try: `Vec<VcfHeader>`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#vec_box

warning: using `clone` on type `usize` which implements the `Copy` trait
--> src/db/create/seqvar_freqs/reading.rs:179:28
    |
179 |                         if lengths.get(idx).unwrap().clone() == length {
    |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*lengths.get(idx).unwrap()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
    = note: `#[warn(clippy::clone_on_copy)]` on by default

warning: useless use of `vec!`
--> src/db/create/seqvar_freqs/reading.rs:288:13
    |
288 | /             &vec![
289 | |                 "tests/data/db/create/seqvar_freqs/gnomad.chrM.vcf",
290 | |                 "tests/data/db/create/seqvar_freqs/helix.chrM.vcf",
291 | |             ],
    | |_____________^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec
    = note: `#[warn(clippy::useless_vec)]` on by default
help: you can use a slice directly
    |
288 ~             &["tests/data/db/create/seqvar_freqs/gnomad.chrM.vcf",
289 ~                 "tests/data/db/create/seqvar_freqs/helix.chrM.vcf"],
    |

warning: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
--> src/db/create/seqvar_freqs/serialized.rs:132:1
    |
132 | impl Into<Vec<u8>> for VcfVar {
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = help: `impl From<Local> for Foreign` is allowed by the orphan rules, for more information see
            https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into
    = note: `#[warn(clippy::from_over_into)]` on by default
help: replace the `Into` implentation with `From<db::create::seqvar_freqs::serialized::VcfVar>`
    |
132 ~ impl From<VcfVar> for Vec<u8> {
133 ~     fn from(val: VcfVar) -> Self {
134 |         let mut result = Vec::new();
135 | 
136 ~         result.extend_from_slice(chrom_name_to_key(&val.chrom).as_bytes());
137 ~         result.extend_from_slice(&val.pos.to_be_bytes());
138 ~         result.extend_from_slice(val.reference.as_bytes());
139 |         result.push(b'>');
140 ~         result.extend_from_slice(val.alternative.as_bytes());
    |

warning: redundant clone
--> src/db/create/seqvar_freqs/serialized.rs:165:14
    |
165 |         chrom.to_string()
    |              ^^^^^^^^^^^^ help: remove this
    |
note: this value is dropped without further use
--> src/db/create/seqvar_freqs/serialized.rs:165:9
    |
165 |         chrom.to_string()
    |         ^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone
    = note: `#[warn(clippy::redundant_clone)]` on by default

warning: stripping a prefix manually
--> src/db/create/seqvar_freqs/serialized.rs:149:9
    |
149 |         &name[3..]
    |         ^^^^^^^^^^
    |
note: the prefix was tested here
--> src/db/create/seqvar_freqs/serialized.rs:148:17
    |
148 |     let chrom = if name.starts_with("chr") {
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip
    = note: `#[warn(clippy::manual_strip)]` on by default
help: try using the `strip_prefix` method
    |
148 ~     let chrom = if let Some(<stripped>) = name.strip_prefix("chr") {
149 ~         <stripped>
    |

warning: redundant slicing of the whole range
--> src/db/create/seqvar_freqs/serialized.rs:151:9
    |
151 |         &name[..]
    |         ^^^^^^^^^ help: use the original value instead: `name`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_slicing
    = note: `#[warn(clippy::redundant_slicing)]` on by default

warning: variables can be used directly in the `format!` string
--> src/db/create/seqvar_freqs/serialized.rs:156:9
    |
156 |         format!(" {}", chrom)
    |         ^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
help: change this to
    |
156 -         format!(" {}", chrom)
156 +         format!(" {chrom}")
    |

warning: length comparison to one
--> src/db/create/seqvar_freqs/serialized.rs:161:13
    |
161 |     assert!(chrom.len() >= 1);
    |             ^^^^^^^^^^^^^^^^ help: using `!is_empty` is clearer and more explicit: `!chrom.is_empty()`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_zero
    = note: `#[warn(clippy::len_zero)]` on by default

warning: variables can be used directly in the `format!` string
--> src/db/create/seqvar_freqs/serialized.rs:163:9
    |
163 |         format!("0{}", chrom)
    |         ^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
help: change this to
    |
163 -         format!("0{}", chrom)
163 +         format!("0{chrom}")
    |

warning: single-character string constant used as pattern
--> src/db/create/seqvar_freqs/serialized.rs:172:24
    |
172 |     if key.starts_with("0") || key.starts_with(" ") {
    |                        ^^^ help: try using a `char` instead: `'0'`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern
    = note: `#[warn(clippy::single_char_pattern)]` on by default

warning: single-character string constant used as pattern
--> src/db/create/seqvar_freqs/serialized.rs:172:48
    |
172 |     if key.starts_with("0") || key.starts_with(" ") {
    |                                                ^^^ help: try using a `char` instead: `' '`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern

warning: this expression creates a reference which is immediately dereferenced by the compiler
--> src/db/create/seqvar_freqs/mod.rs:75:39
|
75 |                 MultiVcfReader::new(&[&path_gnomad], assembly)
|                                       ^^^^^^^^^^^^ help: change this to: `path_gnomad`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
= note: `#[warn(clippy::needless_borrow)]` on by default

warning: this expression creates a reference which is immediately dereferenced by the compiler
--> src/db/create/seqvar_freqs/mod.rs:82:39
|
82 |                 MultiVcfReader::new(&[&path_helix], assembly)
|                                       ^^^^^^^^^^^ help: change this to: `path_helix`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: redundant clone
--> src/db/create/seqvar_freqs/mod.rs:145:87
    |
145 |                         self.helix_next = self.helix_reader.as_mut().unwrap().pop()?.0.clone();
    |                                                                                       ^^^^^^^^ help: remove this
    |
note: this value is dropped without further use
--> src/db/create/seqvar_freqs/mod.rs:145:43
    |
145 |                         self.helix_next = self.helix_reader.as_mut().unwrap().pop()?.0.clone();
    |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone

warning: redundant clone
--> src/db/create/seqvar_freqs/mod.rs:146:89
    |
146 |                         self.gnomad_next = self.gnomad_reader.as_mut().unwrap().pop()?.0.clone();
    |                                                                                         ^^^^^^^^ help: remove this
    |
note: this value is dropped without further use
--> src/db/create/seqvar_freqs/mod.rs:146:44
    |
146 |                         self.gnomad_next = self.gnomad_reader.as_mut().unwrap().pop()?.0.clone();
    |                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone

warning: redundant clone
--> src/db/create/seqvar_freqs/mod.rs:150:87
    |
150 |                         self.helix_next = self.helix_reader.as_mut().unwrap().pop()?.0.clone();
    |                                                                                       ^^^^^^^^ help: remove this
    |
note: this value is dropped without further use
--> src/db/create/seqvar_freqs/mod.rs:150:43
    |
150 |                         self.helix_next = self.helix_reader.as_mut().unwrap().pop()?.0.clone();
    |                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone

warning: this expression creates a reference which is immediately dereferenced by the compiler
--> src/db/create/seqvar_freqs/mod.rs:117:38
    |
117 |                     VcfVar::from_vcf(&helix),
    |                                      ^^^^^^ help: change this to: `helix`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: this expression creates a reference which is immediately dereferenced by the compiler
--> src/db/create/seqvar_freqs/mod.rs:119:40
    |
119 |                     MtCounts::from_vcf(&helix),
    |                                        ^^^^^^ help: change this to: `helix`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: this expression creates a reference which is immediately dereferenced by the compiler
--> src/db/create/seqvar_freqs/mod.rs:125:38
    |
125 |                     VcfVar::from_vcf(&gnomad),
    |                                      ^^^^^^^ help: change this to: `gnomad`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: this expression creates a reference which is immediately dereferenced by the compiler
--> src/db/create/seqvar_freqs/mod.rs:126:40
    |
126 |                     MtCounts::from_vcf(&gnomad),
    |                                        ^^^^^^^ help: change this to: `gnomad`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: this expression creates a reference which is immediately dereferenced by the compiler
--> src/db/create/seqvar_freqs/mod.rs:136:61
    |
136 |                         func(var_gnomad, MtCounts::from_vcf(&gnomad), MtCounts::default())?;
    |                                                             ^^^^^^^ help: change this to: `gnomad`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: this expression creates a reference which is immediately dereferenced by the compiler
--> src/db/create/seqvar_freqs/mod.rs:142:48
    |
142 | ...                   MtCounts::from_vcf(&gnomad),
    |                                          ^^^^^^^ help: change this to: `gnomad`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: this expression creates a reference which is immediately dereferenced by the compiler
--> src/db/create/seqvar_freqs/mod.rs:143:48
    |
143 | ...                   MtCounts::from_vcf(&helix),
    |                                          ^^^^^^ help: change this to: `helix`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: this expression creates a reference which is immediately dereferenced by the compiler
--> src/db/create/seqvar_freqs/mod.rs:149:81
    |
149 |                         func(var_helix, MtCounts::default(), MtCounts::from_vcf(&helix))?;
    |                                                                                 ^^^^^^ help: change this to: `helix`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: the borrowed expression implements the required traits
--> src/db/create/seqvar_freqs/mod.rs:184:9
    |
184 |         &["meta", "nuclear", "mitochondrial"],
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `["meta", "nuclear", "mitochondrial"]`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow

warning: in an `if` condition, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
--> src/db/create/seqvar_freqs/mod.rs:207:61
    |
207 |       while mt_reader.run(|variant, gnomad_mtdna, helix_mtdb| {
    |  _____________________________________________________________^
208 | |         tracing::trace!(
209 | |             "at {:?} | {:?} | {:?}",
210 | |             &variant,
...   |
223 | |         Ok(())
224 | |     })? {
    | |_____^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_if_conditions
    = note: `#[warn(clippy::blocks_in_if_conditions)]` on by default

warning: `mehari` (bin "mehari" test) generated 30 warnings
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions