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

MIR type-checking ICE ("is not a subtype of") from lifetime parameter in scope of AnonConst. #70773

Closed
eddyb opened this issue Apr 4, 2020 · 4 comments · Fixed by #70452
Closed
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@eddyb
Copy link
Member

eddyb commented Apr 4, 2020

This example was found in #70452 (where it does not require #![feature(const_generics)], the only reason I have it here is to get around #43408) (playground):

#![feature(const_generics)]

const HASH_LEN: usize = 20;
struct Hash([u8; HASH_LEN]);

pub fn foo<'a>() -> &'a () {
    Hash([0; HASH_LEN]);
    &()
}

The ICE is:

error: internal compiler error:
    broken MIR in DefId(0:8 ~ playground[8116]::foo[0]) (Hash(move _2,)):
        [u8; _] is not a subtype of [u8; 20]: NoSolution

The ICE goes away when the lifetime parameter ('a) is removed, or when replaced with a type parameter, so my guess is that the MIR type-checker triggers an attempt at normalization (otherwise it would also ICE with a type parameter) but has lifetime inference variables in the Substs of the ConstKind::Unevaluated, and that prevents the normalization.

It really shouldn't, I thought we both erased lifetimes and fell back on fully polymorphic evaluation (which should also succeed here), if there are any inference variables.

@eddyb eddyb added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html labels Apr 4, 2020
@eddyb

This comment has been minimized.

@eddyb

This comment has been minimized.

@eddyb
Copy link
Member Author

eddyb commented Apr 4, 2020

I'm going in circles, and the fact that I used HASH_LEN in both places isn't helping.

It's the type of the [0; HASH_LEN] passed to the Rvalue::Aggregate, that's never attempted to be normalized, not the field of Hash. So it's just another "missing normalization" bug.

@eddyb
Copy link
Member Author

eddyb commented Apr 8, 2020

Looks like calls are also affected (playground):

#![feature(const_generics)]

const HASH_LEN: usize = 20;
fn init_hash(_: &mut [u8; HASH_LEN]) {}

pub fn foo<'a>() -> &'a () {
    init_hash(&mut [0; HASH_LEN]);
    &()
}

This was found in rand (see #70452 (comment)), although I wish it was before a 3-day Crater run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants