Skip to content

ICE with const_generics + const_compare_raw_pointers: broken MIR / NoSolution #72352

Closed

Description

@jplatte

I've tried reducing this but wasn't really able to so far. I might try again some other time.

The code below currently ICEs on Nightly (a74d1862d 2020-05-14). When trying to reproduce locally for the backtrace, I had an older Nightly first (5d04ce67f 2020-02-13) where this actually didn't crash the compiler, so it's apparently a regression.

Code

#![allow(incomplete_features)]
#![feature(const_compare_raw_pointers)]
#![feature(const_generics)]

use std::ffi::{CStr, CString};

fn main() {
    let baguette = CString::new("baguette").unwrap();
    let ptr = baguette.as_ptr();
    println!("{}", unsafe {
        unsafely_do_the_thing::<safely_do_the_thing>(ptr)
    });
}

unsafe fn unsafely_do_the_thing<const F: fn(&CStr) -> usize>(ptr: *const i8) -> usize {
    F(CStr::from_ptr(ptr))
}

fn safely_do_the_thing(s: &CStr) -> usize {
    s.to_bytes().len()
}

Playground

Error output

error: internal compiler error: broken MIR in DefId(0:6 ~ foo[317d]::main[0]) (CanonicalUserTypeAnnotation { user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:7 ~ foo[317d]::unsafely_do_the_thing[0]), UserSubsts { substs: [Const { ty: for<'r> fn(&'r std::ffi::CStr) -> usize, val: Unevaluated(DefId(0:14 ~ foo[317d]::main[0]::{{constant}}[0]), [], None) }], user_self_ty: None }) }, span: foo.rs:11:9: 11:53, inferred_ty: unsafe fn(*const i8) -> usize {unsafely_do_the_thing::<{safely_do_the_thing as for<'r> fn(&'r std::ffi::CStr) -> usize}>} }): bad user type AscribeUserType(unsafe fn(*const i8) -> usize {unsafely_do_the_thing::<{safely_do_the_thing as for<'r> fn(&'r std::ffi::CStr) -> usize}>}, DefId(0:7 ~ foo[317d]::unsafely_do_the_thing[0]) UserSubsts { substs: [Const { ty: for<'r> fn(&'r std::ffi::CStr) -> usize, val: Unevaluated(DefId(0:14 ~ foo[317d]::main[0]::{{constant}}[0]), [], None) }], user_self_ty: None }): NoSolution

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:366:17
Backtrace

   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1069
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1537
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:218
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:481
  12: std::panicking::begin_panic
  13: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
  14: core::ptr::drop_in_place
  15: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
  16: core::ptr::drop_in_place
  17: rustc_interface::interface::run_compiler_in_existing_thread_pool
  18: scoped_tls::ScopedKey<T>::set
  19: rustc_ast::attr::with_globals

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on May 19, 2020
  2. added
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on May 19, 2020
  3. tones111 commented on May 27, 2020

    @tones111
    Contributor

    This is my first time using cargo-bisect-rustc and it's fantastic. It identified the regression as...

    searched nightlies: from nightly-2020-02-13 to nightly-2020-05-14
    regressed nightly: nightly-2020-03-20
    searched commits: from f509b26 to f4c675c
    regressed commit: 57e1da5

    bisected with cargo-bisect-rustc v0.5.2

    Host triple: x86_64-unknown-linux-gnu
    Reproduce with:

    cargo bisect-rustc --test-dir=ice --start=2020-02-13 --end=2020-05-14
  4. jplatte commented on May 27, 2020

    @jplatte
    ContributorAuthor

    57e1da5 is a rollup commit. The only PR which was part of that and (to me) looks like it could have caused this issue is #69189 .

  5. JohnTitor commented on Jun 24, 2020

    @JohnTitor
    Member

    Triage: the const_compare_raw_pointers feature was removed by #73398 and the ICE no longer occurs with the latest nightly.

  6. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Jun 27, 2020
  7. added a commit that references this issue on Jun 28, 2020
    2c1b732
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.F-const_generics`#![feature(const_generics)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions