Closed
Description
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()
}
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
Labels
Area: const generics (parameters and arguments)Category: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.`#![feature(const_generics)]`Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Relevant to the compiler team, which will review and decide on the PR/issue.ICE tracked in rust-lang/glacier.This issue requires a nightly compiler in some way.