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: translate_substs returned a struct containing inference types/regions (specialization) #36848

Closed
Stebalien opened this issue Sep 30, 2016 · 3 comments · Fixed by #38249
Closed
Labels
A-specialization Area: Trait impl specialization I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Stebalien
Copy link
Contributor

When trying to compile #36791, I ran into the following ICE:

rustc: x86_64-unknown-linux-gnu/stage0/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore
error: internal compiler error: ../src/librustc/traits/specialize/mod.rs:130: find_method: translate_substs returned Substs { params: ['_#0r, slice::Iter<u8>, u8] } which contains inference types/regions

Backtrace:

thread 'rustc' panicked at 'Box<Any>', ../src/librustc_errors/lib.rs:656
stack backtrace:
   1:      0x38ff588b5bf - std::sys::backtrace::tracing::imp::write::h15f4dcb9fc5cc76b
   2:      0x38ff589aacd - std::panicking::default_hook::{{closure}}::h122a1c9dfacef96f
   3:      0x38ff5897f8e - std::panicking::default_hook::h9cf83dcedc626223
   4:      0x38ff5898678 - std::panicking::rust_panic_with_hook::hc99436623a03228e
   5:      0x38fef05b5a7 - std::panicking::begin_panic::h17785a79ba05422e
   6:      0x38fef06b628 - rustc_errors::Handler::bug::h5d05e16f0218d91b
   7:      0x38ff2d4092a - rustc::session::opt_span_bug_fmt::{{closure}}::h213520e1e2445968
   8:      0x38ff2c80d75 - rustc::session::opt_span_bug_fmt::hc102cf6a330247e9
   9:      0x38ff2c80bb2 - rustc::session::bug_fmt::h211c71ac4131f84b
  10:      0x38ff2cb19b5 - rustc::traits::specialize::find_method::ha6bb912c0ad9a39f
  11:      0x38ff44831a9 - rustc_trans::collector::do_static_dispatch::hc550d11e69c0f037
  12:      0x38ff4482539 - <rustc_trans::collector::MirNeighborCollector<'a, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_operand::h73bc105d34a3f8ca
  13:      0x38ff4482e49 - <rustc_trans::collector::MirNeighborCollector<'a, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_terminator_kind::h03056abb13083520
  14:      0x38ff4414d95 - rustc::mir::visit::Visitor::visit_mir::h9178e76484decc93
  15:      0x38ff44802e2 - rustc_trans::collector::collect_items_rec::h11e2a54fada9d7ec
  16:      0x38ff44f1be2 - rustc_trans::base::collect_and_partition_translation_items::{{closure}}::h4c634b3f9d52d409
  17:      0x38ff4468088 - rustc_trans::base::collect_and_partition_translation_items::h9ba3b316253a0b6d
  18:      0x38ff44627bc - rustc_trans::base::trans_crate::hdcdc2e81a006e15c
  19:      0x38ff5c1de1d - rustc_driver::driver::phase_4_translate_to_llvm::h6ab5f49542a71b7c
  20:      0x38ff5c5923a - rustc_driver::driver::compile_input::{{closure}}::h0bbc2feaa811e66f
  21:      0x38ff5c4a613 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::h5dabeea7050cf7c2
  22:      0x38ff5c1b7bd - rustc_driver::driver::phase_3_run_analysis_passes::h79f20d1127b1dfba
  23:      0x38ff5c07f79 - rustc_driver::driver::compile_input::h8ef818979445c42c
  24:      0x38ff5c32616 - rustc_driver::run_compiler::ha981cef7568b5eb8
  25:      0x38ff5b6d2a3 - std::panicking::try::do_call::h4a286c81408a0d92
  26:      0x38ff58a29c6 - __rust_maybe_catch_panic
  27:      0x38ff5b8c499 - <F as alloc::boxed::FnBox<A>>::call_box::h5de1378b9690a33a
  28:      0x38ff58969e0 - std::sys::thread::Thread::new::thread_start::h2eacc7b7061d5d8c
  29:      0x38fee807453 - start_thread
  30:      0x38ff55677de - __GI___clone
  31:                0x0 - <unknown>

Unfortunately, I don't have a minimal example to reproduce this that doesn't require rebuilding core.

@Aatch Aatch added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-specialization Area: Trait impl specialization labels Sep 30, 2016
@TimNN
Copy link
Contributor

TimNN commented Sep 30, 2016

I got this ICE while trying to reduce #36804:

#![feature(specialization)]

pub trait Iterator {
    type Item;

    fn next(&self) -> Option<Self::Item>;
}

impl<'a> Iterator for &'a () {
    type Item = &'a u32;

    fn next(&self) -> Option<&'a u32> { None }
}

pub struct Cloned<I>(I);

impl<'a, I, T: 'a> Iterator for Cloned<I>
    where I: Iterator<Item=&'a T>, T: Clone
{
    type Item = T;

    fn next(&self) -> Option<T> { None }
}

impl<'a, I, T: 'a> Iterator for Cloned<I>
    where I: Iterator<Item=&'a T>, T: Copy
{

}

fn main() {
    Cloned(&()).next();
}

@tupshin
Copy link

tupshin commented Nov 1, 2016

I just got this as well. Am doing a bunch of stuff with monoidal patterns using Kinder.

@bluss
Copy link
Member

bluss commented Nov 2, 2016

I tried adding this to src/libcore/iter/iterator.rs

(This is a specialization of the general case which is I: Iterator + ?Sized).

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, I: Iterator> Iterator for &'a mut I {
    fn all<F>(&mut self, f: F) -> bool
        where Self: Sized, F: FnMut(Self::Item) -> bool
    {
        (*self).all(f)
    }
}

And it results in the same kind of ICE:

error: internal compiler error: ../src/librustc/traits/specialize/mod.rs:130: find_method: translate_substs returned Slice(['_#0r, str::Chars]) which contains inference types/regions

arielb1 added a commit to arielb1/rust that referenced this issue Dec 8, 2016
Projections can generate lifetime variables with equality constraints,
that will not be resolved by `resolve_type_vars_if_possible`, so substs
need to be lifetime-erased after that.

Fixes rust-lang#36848.
bors added a commit that referenced this issue Dec 11, 2016
erase lifetimes when translating specialized substs

Projections can generate lifetime variables with equality constraints,
that will not be resolved by `resolve_type_vars_if_possible`, so substs
need to be lifetime-erased after that.

Fixes #36848.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-specialization Area: Trait impl specialization I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants