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 with const generics over a &'static str #60813

Closed
moxian opened this issue May 14, 2019 · 3 comments · Fixed by #64858
Closed

ICE with const generics over a &'static str #60813

moxian opened this issue May 14, 2019 · 3 comments · Fixed by #64858
Labels
A-const-generics Area: const generics (parameters and arguments) A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@moxian
Copy link
Contributor

moxian commented May 14, 2019

#![feature(const_generics)]

pub fn function_with_str<const STRING: &'static str>() {
}

pub fn use_it() {
    function_with_str::<"Hello, world!">()
}

Results in

   Compiling playground v0.0.1 (/playground)
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/lib.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(0:14 ~ playground[d52b]::use_it[0]) (CanonicalUserTypeAnnotation { user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:12 ~ playground[d52b]::function_with_str[0]), UserSubsts { substs: [Const { ty: &'static str, val: Unevaluated(DefId(0:15 ~ playground[d52b]::use_it[0]::{{constant}}[0]), []) }], user_self_ty: None }) }, span: src/lib.rs:7:5: 7:41, inferred_ty: fn() {function_with_str::<Const { ty: &str, val: Slice(Ptr(Pointer { alloc_id: AllocId(0), offset: Size { raw: 0 }, tag: () }), 13) }>} }): bad user type AscribeUserType(fn() {function_with_str::<Const { ty: &str, val: Slice(Ptr(Pointer { alloc_id: AllocId(0), offset: Size { raw: 0 }, tag: () }), 13) }>}, DefId(0:12 ~ playground[d52b]::function_with_str[0]) UserSubsts { substs: [Const { ty: &'static str, val: Unevaluated(DefId(0:15 ~ playground[d52b]::use_it[0]::{{constant}}[0]), []) }], user_self_ty: None }): NoSolution

error: internal compiler error: broken MIR in DefId(0:14 ~ playground[d52b]::use_it[0]) (const function_with_str): constant const function_with_str should have type fn() {function_with_str::<Const { ty: &str, val: Slice(Ptr(Pointer { alloc_id: AllocId(0), offset: Size { raw: 0 }, tag: () }), 13) }>} but has fn() {function_with_str::<Const { ty: &str, val: Slice(Ptr(Pointer { alloc_id: AllocId(0), offset: Size { raw: 0 }, tag: () }), 13) }>} (NoSolution)
 --> src/lib.rs:7:5
  |
7 |     function_with_str::<"Hello, world!">()
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(0:14 ~ playground[d52b]::use_it[0]) (const function_with_str): bad constant user type CanonicalUserTypeAnnotation { user_ty: Canonical { max_universe: U0, variables: [], value: TypeOf(DefId(0:12 ~ playground[d52b]::function_with_str[0]), UserSubsts { substs: [Const { ty: &'static str, val: Unevaluated(DefId(0:15 ~ playground[d52b]::use_it[0]::{{constant}}[0]), []) }], user_self_ty: None }) }, span: src/lib.rs:7:5: 7:41, inferred_ty: fn() {function_with_str::<Const { ty: &str, val: Slice(Ptr(Pointer { alloc_id: AllocId(0), offset: Size { raw: 0 }, tag: () }), 13) }>} } vs fn() {function_with_str::<Const { ty: &str, val: Slice(Ptr(Pointer { alloc_id: AllocId(0), offset: Size { raw: 0 }, tag: () }), 13) }>}: NoSolution
 --> src/lib.rs:7:5
  |
7 |     function_with_str::<"Hello, world!">()
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:356:17
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:197
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   6: std::panicking::begin_panic
   7: <rustc_errors::Handler as core::ops::drop::Drop>::drop
   8: core::ptr::real_drop_in_place
   9: core::ptr::real_drop_in_place
  10: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
  11: core::ptr::real_drop_in_place
  12: rustc_interface::interface::run_compiler_in_existing_thread_pool
  13: std::thread::local::LocalKey<T>::with
  14: scoped_tls::ScopedKey<T>::set
  15: syntax::with_globals
query stack during panic:
end of query stack

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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.36.0-nightly (a9ec99f42 2019-05-13) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type lib

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

error: Could not compile `playground`.

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

Playground link

cc @Serentty

@hellow554
Copy link
Contributor

@rustbot modify labels: I-ICE C-Bug T-compiler A-const-generics

@rustbot rustbot added A-const-generics Area: const generics (parameters and arguments) 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 May 14, 2019
@jonas-schievink jonas-schievink added the A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html label May 14, 2019
@varkor varkor removed their assignment May 30, 2019
@yodaldevoid
Copy link
Contributor

I'm looking into this currently.

@yodaldevoid
Copy link
Contributor

Partially as a note to myself and partially as an update to anyone interested

The root cause of this bug seems to be the fact that we currently don't explicitly handle slice const values in super_relate_consts, and therefore we always say they cannot match.

_ => Err(TypeError::ConstMismatch(expected_found(relation, &a, &b))),

This error eventually bubbles up to to produce all three errors.

@Centril Centril added requires-nightly This issue requires a nightly compiler in some way. F-const_generics `#![feature(const_generics)]` labels Aug 6, 2019
Centril added a commit to Centril/rust that referenced this issue Sep 29, 2019
Add support for relating slices in `super_relate_consts`

This allows passing strings as generic arguments.

Fixes rust-lang#63773
Fixes rust-lang#60813

r? @varkor
@bors bors closed this as completed in 4ada68e Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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.

7 participants