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 initializing static array of struct containing function pointer using const function #86679

Closed
vamolessa opened this issue Jun 27, 2021 · 4 comments
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

@vamolessa
Copy link

vamolessa commented Jun 27, 2021

Code

I think it's worth noting that the error goes away if we either:

  • we remove the f field from Thing (or just remove the for<'a> from the function signature and replace the PhantomData<&'a ()> with just PhantomData<()>);
  • we substitute both calls to bad_hash in second Thing's h field initialization with a literal (e.g. 0 for example);
pub const fn bad_hash(_bytes: &[u8]) -> u64 {
    0
}

struct Thing {
    pub h: u64,
    pub f: for<'a> fn(std::marker::PhantomData<&'a ()>),
}

static THINGS: &[Thing] = &[
    Thing {
        h: bad_hash(b"abc"),
        f: |_| (),
    },
    Thing {
        h: bad_hash(b"abc"),
        f: |_| (),
    },
];

pub fn main() {
    for t in THINGS {
        dbg!(t.h);
    }
}

Meta

The bug also happens on beta and nightly.

rustc --version --verbose:

rustc 1.53.0 (53cb7b09b 2021-06-17)
binary: rustc
commit-hash: 53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b
commit-date: 2021-06-17
host: x86_64-pc-windows-msvc
release: 1.53.0
LLVM version: 12.0.1

Error output

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler\rustc_mir\src\borrow_check\region_infer\mod.rs:2136:35
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.53.0 (53cb7b09b 2021-06-17) running on x86_64-pc-windows-msvc

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_borrowck] borrow-checking `THINGS`
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `ice`
Backtrace

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler\rustc_mir\src\borrow_check\region_infer\mod.rs:2136:35
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.53.0 (53cb7b09b 2021-06-17) running on x86_64-pc-windows-msvc

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_borrowck] borrow-checking `THINGS`
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `ice`

To learn more, run the command again with --verbose.

@vamolessa vamolessa 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 Jun 27, 2021
@hellow554
Copy link
Contributor

Looks like a dup of #84957

@vamolessa
Copy link
Author

Oh, you're right!
Sorry about the dup, I found it hard to describe this issue so I didn't know what to search for.

Should we just close this then?
Is there value in pasting this code on that thread?

@hellow554
Copy link
Contributor

No worries! I happens to me a lot as well ;)

I found it hard to describe this issue so I didn't know what to search for.

I try to search for the line that causes the ICE, in your case I would search for compiler\rustc_mir\src\borrow_check\region_infer\mod.rs

Should we just close this then?

Yes please :)

Is there value in pasting this code on that thread?

Totally!
You could add a post saying "I used this code and have the same ICE", so it would (hopefully) be added to the test suite so this ICE will never be triggered again.

Hope that helps. Thanks for your report!

@vamolessa
Copy link
Author

Alright, thanks!

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

No branches or pull requests

2 participants