Skip to content

internal compiler error: impossible case reached #52688

Closed
@jbg

Description

@jbg

rustc 1.29.0-nightly (6a1c063 2018-07-23) running on x86_64-apple-darwin

The below code has a bug (passing &f instead of f to wait) which should trigger a compilation error. The bug is that after printing the error the compiler panics.

fn wait<I, E>(f: Box<Future<Item=I, Error=E>>) -> Result<I, E> {
    f.wait()
}

fn or_default<I, E>(r: Result<I, E>) -> I where I: Default {
    r.unwrap_or_else(|_| I::default())
}

let f: Box<Future<Item=rust_decimal::Decimal, Error=String> + Send> = Box::new(something_returning_a_future());

or_default(wait(&f));

Compiler output (note that the above code is a simplified testcase; the actual error happens in an askama template)

error[E0308]: mismatched types
   --> src/templates.rs:122:10
    |
122 | #[derive(Template)]
    |          ^^^^^^^^ expected struct `std::boxed::Box`, found reference
    |
    = note: expected type `std::boxed::Box<(dyn futures::Future<Item=_, Error=_> + 'static)>`
               found type `&std::boxed::Box<dyn futures::Future<Item=rust_decimal::Decimal, Error=std::string::String> + std::marker::Send>`

error: internal compiler error: librustc/traits/structural_impls.rs:178: impossible case reached

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:580:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::session::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::session::opt_span_bug_fmt
  13: rustc::session::bug_fmt
  14: rustc::traits::structural_impls::<impl rustc::ty::context::Lift<'tcx> for rustc::traits::SelectionError<'a>>::lift_to_tcx
  15: rustc::ty::context::TyCtxt::lift_to_global
  16: rustc::traits::select::SelectionContext::candidate_from_obligation
  17: rustc::traits::select::SelectionContext::evaluate_stack
  18: rustc::dep_graph::graph::DepGraph::with_anon_task
  19: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  20: rustc::infer::InferCtxt::probe
  21: <&'a mut I as core::iter::iterator::Iterator>::next
  22: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  23: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  24: rustc::dep_graph::graph::DepGraph::with_anon_task
  25: rustc::traits::select::SelectionContext::candidate_from_obligation
  26: rustc::traits::select::SelectionContext::evaluate_stack
  27: rustc::dep_graph::graph::DepGraph::with_anon_task
  28: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  29: rustc::infer::InferCtxt::probe
  30: <&'a mut I as core::iter::iterator::Iterator>::next
  31: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  32: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  33: rustc::dep_graph::graph::DepGraph::with_anon_task
  34: rustc::traits::select::SelectionContext::candidate_from_obligation
  35: rustc::traits::select::SelectionContext::evaluate_stack
  36: rustc::dep_graph::graph::DepGraph::with_anon_task
  37: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  38: rustc::infer::InferCtxt::probe
  39: <&'a mut I as core::iter::iterator::Iterator>::next
  40: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  41: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  42: rustc::dep_graph::graph::DepGraph::with_anon_task
  43: rustc::traits::select::SelectionContext::candidate_from_obligation
  44: rustc::traits::select::SelectionContext::evaluate_stack
  45: rustc::dep_graph::graph::DepGraph::with_anon_task
  46: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  47: rustc::infer::InferCtxt::probe
  48: <&'a mut I as core::iter::iterator::Iterator>::next
  49: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  50: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  51: rustc::dep_graph::graph::DepGraph::with_anon_task
  52: rustc::traits::select::SelectionContext::candidate_from_obligation
  53: rustc::traits::select::SelectionContext::evaluate_stack
  54: rustc::dep_graph::graph::DepGraph::with_anon_task
  55: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  56: rustc::infer::InferCtxt::probe
  57: <&'a mut I as core::iter::iterator::Iterator>::next
  58: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  59: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  60: rustc::dep_graph::graph::DepGraph::with_anon_task
  61: rustc::traits::select::SelectionContext::candidate_from_obligation
  62: rustc::traits::select::SelectionContext::evaluate_stack
  63: rustc::dep_graph::graph::DepGraph::with_anon_task
  64: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  65: rustc::infer::InferCtxt::probe
  66: <&'a mut I as core::iter::iterator::Iterator>::next
  67: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  68: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  69: rustc::dep_graph::graph::DepGraph::with_anon_task
  70: rustc::traits::select::SelectionContext::candidate_from_obligation
  71: rustc::traits::select::SelectionContext::evaluate_stack
  72: rustc::dep_graph::graph::DepGraph::with_anon_task
  73: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  74: rustc::infer::InferCtxt::probe
  75: <&'a mut I as core::iter::iterator::Iterator>::next
  76: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  77: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  78: rustc::dep_graph::graph::DepGraph::with_anon_task
  79: rustc::traits::select::SelectionContext::candidate_from_obligation
  80: rustc::traits::select::SelectionContext::evaluate_stack
  81: rustc::dep_graph::graph::DepGraph::with_anon_task
  82: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  83: rustc::infer::InferCtxt::probe
  84: <&'a mut I as core::iter::iterator::Iterator>::next
  85: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  86: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  87: rustc::dep_graph::graph::DepGraph::with_anon_task
  88: rustc::traits::select::SelectionContext::candidate_from_obligation
  89: rustc::traits::select::SelectionContext::evaluate_stack
  90: rustc::dep_graph::graph::DepGraph::with_anon_task
  91: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  92: rustc::infer::InferCtxt::probe
  93: <&'a mut I as core::iter::iterator::Iterator>::next
  94: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  95: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  96: rustc::dep_graph::graph::DepGraph::with_anon_task
  97: rustc::traits::select::SelectionContext::candidate_from_obligation
  98: rustc::traits::select::SelectionContext::evaluate_stack
  99: rustc::dep_graph::graph::DepGraph::with_anon_task
query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `&'_ _: tokio::io::AsyncWrite`
#1 [typeck_tables_of] processing `<templates::Template<'a> as templates::Template>::render_block_content_into`
#2 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.

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.29.0-nightly (6a1c0637c 2018-07-23) running on x86_64-apple-darwin
note: compiler flags: -C opt-level=3 -C debuginfo=2 --crate-type lib
note: some of the compiler flags provided by cargo are hidden

Metadata

Metadata

Assignees

No one assigned

    Labels

    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.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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions