Skip to content

ICE: Compiler incorrectly assumes a Copy bound is met for a type. #119915

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

Closed
Yurihaia opened this issue Jan 13, 2024 · 0 comments · Fixed by #119934
Closed

ICE: Compiler incorrectly assumes a Copy bound is met for a type. #119915

Yurihaia opened this issue Jan 13, 2024 · 0 comments · Fixed by #119934
Assignees
Labels
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

@Yurihaia
Copy link

Yurihaia commented Jan 13, 2024

This ICEs on both the latest beta and the latest nightly with the same error.
stable is not affected.

I'm not quite sure what the name of the issue should be so sorry for the bad description.
I tried to comment the code on what seems to be causing the problem however.

Code

The minimal reproduction code is also here in the playground.
https://play.rust-lang.org/?version=beta&mode=debug&edition=2021&gist=3f34d3bdda874425b1333311501e54e2

use std::marker::PhantomData;

// The variance of both generics don't seem to matter.
// I tried with *mut E, *const E, and fn(E). Every one gives the same result.
struct Example<E, FakeParam>(PhantomData<(E, FakeParam)>);

 // This can also have a lifetime of any variance, it doesn't appear to matter.
struct NoLifetime;
// Likewise, the variance of `'a` here also doesn't seem to matter.
struct Immutable<'a>(PhantomData<&'a ()>);

// The E: 'a is part of what causes the ICE. if it is just `E`, the compiler correctly
// finds the `Copy` bound missing on `Example<E, Mutable<'a>>`
impl<'a, E: 'a> Copy for Example<E, Immutable<'a>> {}
impl<'a, E: 'a> Clone for Example<E, Immutable<'a>> {
    fn clone(&self) -> Self { *self }
}

impl<E, FakeParam> Example<E, FakeParam> {
    // there is no ICE if this (correctly) takes `&self`.
    unsafe fn change<NewFakeParam>(self) -> Example<E, NewFakeParam> {
        Example(PhantomData)
    }
}

impl<E> Example<E, NoLifetime> {
    fn the_ice(&mut self) -> Example<E, Immutable<'_>> {
        unsafe { self.change() }
    }
}

Meta

rustc --version --verbose:

beta:

rustc 1.76.0-beta.5 (f732c37b4 2024-01-12)
binary: rustc
commit-hash: f732c37b4175158d3af9e2e156142ffb0bff8969
commit-date: 2024-01-12
host: x86_64-pc-windows-msvc
release: 1.76.0-beta.5
LLVM version: 17.0.6

nightly:

rustc 1.77.0-nightly (2319be8e2 2024-01-12)
binary: rustc
commit-hash: 2319be8e265dd19973574eb581d28297baf44b11
commit-date: 2024-01-12
host: x86_64-pc-windows-msvc
release: 1.77.0-nightly
LLVM version: 17.0.6

Error output

error: internal compiler error: compiler\rustc_middle\src\ty\generic_args.rs:817:13: Unexpected parameter Type(E/#1) when substituting in region 'a (index=0)
thread 'rustc' panicked at /rustc/f732c37b4175158d3af9e2e156142ffb0bff8969\compiler\rustc_errors\src\lib.rs:1119:75:
Box<dyn Any>
Backtrace

beta backtrace:
beta-ice-backtrace.txt

nightly backtrace:
rustc-ice-2024-01-13T04_35_40-20512.txt

@Yurihaia Yurihaia added 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. labels Jan 13, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 13, 2024
@compiler-errors compiler-errors self-assigned this Jan 13, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 13, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 14, 2024
Make `InferCtxtExt::could_impl_trait` more precise, less ICEy

The implementation for `InferCtxtExt::could_impl_trait` was very wrong. Along with being pretty poorly named, way too specific to ADTs, it was also doing impl substitution wrong -- this caused an ICE (rust-lang#119915).

This PR generalizes that code, gives it a clearer name, makes it stop using the new trait solver (lol), and fixes some fallout bad suggestions that are made worse with the code fix.

Fixes rust-lang#119915
@bors bors closed this as completed in 0dab65b Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants