Skip to content

Conversation

popzxc
Copy link
Contributor

@popzxc popzxc commented Aug 22, 2023

changelog: ICE: [`tuple_array_conversions`]: Don't expect array length to always be usize

tl;dr: changed Const::eval_target_usize to Consts::try_eval_target_usize to get rid of ICE.

I have encountered a problem with clippy: it caught ICE when working with a codebase that uses a lot of nightly features.
Here's a (stripped) ICE info:

error: internal compiler error: /rustc/5c6a7e71cd66705c31c9af94077901a220f0870c/compiler/rustc_middle/src/ty/consts.rs:361:32: expected usize, got Const { ty: usize, kind: N/#1 }

thread 'rustc' panicked at /rustc/5c6a7e71cd66705c31c9af94077901a220f0870c/compiler/rustc_errors/src/lib.rs:1635:9:
Box<dyn Any>
stack backtrace:
...
  16:        0x110b9c590 - rustc_middle[449edf845976488d]::util::bug::bug_fmt
  17:        0x102f76ae0 - clippy_lints[71754038dd04c2d2]::tuple_array_conversions::all_bindings_are_for_conv
...

I don't really know what's going on low-level-wise, but seems like this lin assumed that the length of the array can always be treated as usize, and I assume this doesn't play well with feat(generic_const_exprs).

I wasn't able to build a minimal reproducible example, but locally this fix does resolve the issue.

@rustbot
Copy link
Collaborator

rustbot commented Aug 22, 2023

r? @xFrednet

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 22, 2023
@y21
Copy link
Member

y21 commented Aug 22, 2023

Generic const exprs is not needed to reproduce that ICE. Here's a reproducer without any unstable features:

fn repro<const N: usize>() {
    let src = [0; N];
    let dest: (u8,) = (src[0],);
}
error: internal compiler error: /rustc/08d00b40aef2017fe6dba3ff7d6476efa0c10888/compiler/rustc_middle/src/ty/consts.rs:361:32: expected usize, got Const { ty: usize, kind: N/#0 }

Can you add this is a test case so that it doesn't regress?

@xFrednet
Copy link
Contributor

The changes look good to me, this is ready, once the test from @y21 is added.

Thank you for creating the example code @y21 ❤️

@popzxc
Copy link
Contributor Author

popzxc commented Aug 23, 2023

@y21 thanks for the suggestion! Test added.

@xFrednet
Copy link
Contributor

Looks good to me, thank you for the ICE fix!

@bors r+

@bors
Copy link
Contributor

bors commented Aug 23, 2023

📌 Commit f0eaa66 has been approved by xFrednet

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Aug 23, 2023

⌛ Testing commit f0eaa66 with merge edfee16...

@bors
Copy link
Contributor

bors commented Aug 23, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: xFrednet
Pushing edfee16 to master...

@bors bors merged commit edfee16 into rust-lang:master Aug 23, 2023
@popzxc popzxc deleted the fix-tuple-array-conversions branch August 23, 2023 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants