Skip to content

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

Closed
@jplatte

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

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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions