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

ICE when invoking cargo clippy --fix #12784

Closed
Zoybean opened this issue May 9, 2024 · 4 comments · Fixed by rust-lang/rust#124926
Closed

ICE when invoking cargo clippy --fix #12784

Zoybean opened this issue May 9, 2024 · 4 comments · Fixed by rust-lang/rust#124926
Labels
C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Zoybean
Copy link

Zoybean commented May 9, 2024

Summary

I encountered an ICE when invoking cargo clippy --fix

Version

rustc 1.80.0-nightly (87293c958 2024-05-08)
binary: rustc
commit-hash: 87293c9585a7fb2cc83ca9949ae79661d5d3c31a
commit-date: 2024-05-08
host: x86_64-pc-windows-msvc
release: 1.80.0-nightly
LLVM version: 18.1.4

Error output

Backtrace

  warning: failed to automatically apply fixes suggested by rustc to crate `work_log`

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-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[E0034]: multiple applicable items in scope
  --> src\lib.rs:1450:18
   |
1450 |                 .intersperse(", ")
   |                  ^^^^^^^^^^^ multiple `intersperse` found
   |
   = note: candidate #1 is defined in an impl of the trait `itertools::Itertools` for the type `T`
   = note: candidate #2 is defined in an impl of the trait `std::iter::Iterator` for the type `std::collections::hash_set::IntoIter<K>`
help: disambiguate the method for candidate #1
   |
1448 ~             let comments = itertools::Itertools::intersperse(nub_comments(vec.iter().map(|(_, p)| &*p.comment))
1449 +                 .into_iter(), ", ")
   |
help: disambiguate the method for candidate #2
   |
1448 ~             let comments = std::iter::Iterator::intersperse(nub_comments(vec.iter().map(|(_, p)| &*p.comment))
1449 +                 .into_iter(), ", ")
   |

error[E0034]: multiple applicable items in scope
  --> src\lib.rs:1488:18
   |
1488 |                 .intersperse("\n")
   |                  ^^^^^^^^^^^ multiple `intersperse` found
   |
   = note: candidate #1 is defined in an impl of the trait `itertools::Itertools` for the type `T`
   = note: candidate #2 is defined in an impl of the trait `std::iter::Iterator` for the type `std::collections::hash_set::IntoIter<K>`
help: disambiguate the method for candidate #1
   |
1486 ~             let comments: String = itertools::Itertools::intersperse(nub_comments(vec.iter().map(|(_, j)| &*j.comment))
1487 +                 .into_iter(), "\n")
   |
help: disambiguate the method for candidate #2
   |
1486 ~             let comments: String = std::iter::Iterator::intersperse(nub_comments(vec.iter().map(|(_, j)| &*j.comment))
1487 +                 .into_iter(), "\n")
   |

warning: unused import: `io::Write`
--> src\lib.rs:10:33
 |
10 | use std::{collections::HashSet, io::Write, iter::Sum, mem};
 |                                 ^^^^^^^^^
 |
 = note: `#[warn(unused_imports)]` on by default

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

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

warning: unused import: `info`
--> src\io.rs:7:25
|
7 | use log::{debug, error, info};
|                         ^^^^
|
= note: `#[warn(unused_imports)]` on by default

warning: a method with this name may be added to the standard library in the future
  --> src\lib.rs:1449:18
   |
1449 |                 .intersperse(", ")
   |                  ^^^^^^^^^^^
   |
   = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
   = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
   = help: call with fully qualified syntax `itertools::Itertools::intersperse(...)` to keep using the current method
   = note: `#[warn(unstable_name_collisions)]` on by default
help: add `#![feature(iter_intersperse)]` to the crate attributes to enable `std::iter::Iterator::intersperse`
   |
2    + #![feature(iter_intersperse)]
   |

warning: a method with this name may be added to the standard library in the future
  --> src\lib.rs:1487:18
   |
1487 |                 .intersperse("\n")
   |                  ^^^^^^^^^^^
   |
   = warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
   = note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
   = help: call with fully qualified syntax `itertools::Itertools::intersperse(...)` to keep using the current method
help: add `#![feature(iter_intersperse)]` to the crate attributes to enable `std::iter::Iterator::intersperse`
   |
2    + #![feature(iter_intersperse)]
   |

warning: unused import: `io::Write`
--> src\lib.rs:9:33
|
9 | use std::{collections::HashSet, io::Write, iter::Sum, mem};
|                                 ^^^^^^^^^

warning: method `archive_all` is never used
  --> src\lib.rs:1116:8
   |
762  | impl Log {
   | -------- method in this implementation
...
1116 |     fn archive_all(&mut self) {
   |        ^^^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: function `with_index` is never used
  --> src\lib.rs:1626:4
   |
1626 | fn with_index<T, R>(mut f: impl FnMut(usize, &T) -> R) -> impl FnMut(&T) -> R {
   |    ^^^^^^^^^^

warning: method `retain_indices` is never used
  --> src\lib.rs:1632:8
   |
1631 | trait VecExt<T> {
   |       ------ method in this trait
1632 |     fn retain_indices(&mut self, indices: &[usize]);
   |        ^^^^^^^^^^^^^^

warning: function cannot return without recursing
 --> src\hours.rs:169:5
  |
169 | /     fn from(hours: Hours) -> Self {
170 | |         hours.into()
171 | |     }
  | |_____^
  |
note: recursive call site
 --> src\hours.rs:170:9
  |
170 |         hours.into()
  |         ^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unconditional_recursion
  = note: `#[warn(clippy::unconditional_recursion)]` on by default

warning: this pattern takes a reference on something that is being dereferenced
  --> src\lib.rs:1070:25
   |
1070 |                 .map(|&(&ref a, ref b)| (a, b))
   |                         ^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrowed_reference
   = note: `#[warn(clippy::needless_borrowed_reference)]` on by default
help: try removing the `&ref` part
   |
1070 -                 .map(|&(&ref a, ref b)| (a, b))
1070 +                 .map(|&(a, ref b)| (a, b))
   |

warning: `work-log` (lib) generated 9 warnings (run `cargo clippy --fix --lib -p work-log` to apply 4 suggestions)
warning: failed to automatically apply fixes suggested by rustc to crate `work_log`

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-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[E0034]: multiple applicable items in scope
  --> src\lib.rs:1450:18
   |
1450 |                 .intersperse(", ")
   |                  ^^^^^^^^^^^ multiple `intersperse` found
   |
   = note: candidate #1 is defined in an impl of the trait `itertools::Itertools` for the type `T`
   = note: candidate #2 is defined in an impl of the trait `std::iter::Iterator` for the type `std::collections::hash_set::IntoIter<K>`
help: disambiguate the method for candidate #1
   |
1448 ~             let comments = itertools::Itertools::intersperse(nub_comments(vec.iter().map(|(_, p)| &*p.comment))
1449 +                 .into_iter(), ", ")
   |
help: disambiguate the method for candidate #2
   |
1448 ~             let comments = std::iter::Iterator::intersperse(nub_comments(vec.iter().map(|(_, p)| &*p.comment))
1449 +                 .into_iter(), ", ")
   |

error[E0034]: multiple applicable items in scope
  --> src\lib.rs:1488:18
   |
1488 |                 .intersperse("\n")
   |                  ^^^^^^^^^^^ multiple `intersperse` found
   |
   = note: candidate #1 is defined in an impl of the trait `itertools::Itertools` for the type `T`
   = note: candidate #2 is defined in an impl of the trait `std::iter::Iterator` for the type `std::collections::hash_set::IntoIter<K>`
help: disambiguate the method for candidate #1
   |
1486 ~             let comments: String = itertools::Itertools::intersperse(nub_comments(vec.iter().map(|(_, j)| &*j.comment))
1487 +                 .into_iter(), "\n")
   |
help: disambiguate the method for candidate #2
   |
1486 ~             let comments: String = std::iter::Iterator::intersperse(nub_comments(vec.iter().map(|(_, j)| &*j.comment))
1487 +                 .into_iter(), "\n")
   |

warning: unused import: `io::Write`
--> src\lib.rs:10:33
 |
10 | use std::{collections::HashSet, io::Write, iter::Sum, mem};
 |                                 ^^^^^^^^^
 |
 = note: `#[warn(unused_imports)]` on by default

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

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

warning: `work-log` (lib test) generated 9 warnings (9 duplicates)

@Zoybean Zoybean added C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ labels May 9, 2024
@Zoybean
Copy link
Author

Zoybean commented May 9, 2024

Not sure if its useful but I initially encountered this at an earlier version. ICE still present after updating.
Previous version:

rustc 1.79.0-nightly (fb898629a 2024-04-21)
binary: rustc
commit-hash: fb898629a26e4acec59c928ce3ec00a62675d1cc
commit-date: 2024-04-21
host: x86_64-pc-windows-msvc
release: 1.79.0-nightly
LLVM version: 18.1.4

@Zoybean
Copy link
Author

Zoybean commented May 9, 2024

Reproduced this at home, on a fairly minimum project, using the same compiler version (besides the host triple: x86_64-unknown-linux-gnu).

Project contents:

src/main.rs:

use itertools::Itertools;
fn main() {
    let x = [1, 2, 3];
    let y = x.into_iter().intersperse(0).collect_vec();
}

rust-toolchain.toml:

[toolchain]
channel = "nightly"

Cargo.toml:

[package]
name = "sandbox"
version = "0.1.0"
edition = "2021"

[dependencies]
itertools = "0.12.1"

Cargo.lock:

# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3

[[package]]
name = "either"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2"

[[package]]
name = "itertools"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
dependencies = [
 "either",
]

[[package]]
name = "sandbox"
version = "0.1.0"
dependencies = [
 "itertools",
]

@Zoybean
Copy link
Author

Zoybean commented May 9, 2024

My read is that clippy is suggesting adding the iter_intersperse feature flag because I'm on nightly. clippy --fix adding the flag is then causing a name collision between the Itertools and Iterator versions of the intersperse method. And then it's seeing that the resulting code has compile errors.

I don't know if that alone is enough to cause an ICE, or if it's deeper than that.

@Alexendoo
Copy link
Member

Yeah the fixed code failing to compile is enough to produce that error, the problem here is the rustc lint suggests adding the feature gate as a machine applicable suggestion

rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 9, 2024
Rollup merge of rust-lang#124926 - Alexendoo:feature-maybe-incorrect, r=est31

Make `#![feature]` suggestion MaybeIncorrect

Fixes rust-lang/rust-clippy#12784

The `unstable_name_collisions` lint uses `disabled_nightly_features` to mention the feature name, but accepting the suggestion would result in an ambiguity error

There are other calls where accepting the feature gate would fix code when ran with `cargo fix --broken-code`, though it's not always desirable to add a feature gate even if the user is currently on nightly so MaybeIncorrect seems appropriate
github-actions bot pushed a commit to rust-lang/miri that referenced this issue May 11, 2024
Make `#![feature]` suggestion MaybeIncorrect

Fixes rust-lang/rust-clippy#12784

The `unstable_name_collisions` lint uses `disabled_nightly_features` to mention the feature name, but accepting the suggestion would result in an ambiguity error

There are other calls where accepting the feature gate would fix code when ran with `cargo fix --broken-code`, though it's not always desirable to add a feature gate even if the user is currently on nightly so MaybeIncorrect seems appropriate
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-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants