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

Internal compiler error: Encountered ambiguity during codegen #58022

Closed
brycx opened this issue Jan 31, 2019 · 2 comments · Fixed by #64928
Closed

Internal compiler error: Encountered ambiguity during codegen #58022

brycx opened this issue Jan 31, 2019 · 2 comments · Fixed by #64928
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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.

Comments

@brycx
Copy link

brycx commented Jan 31, 2019

I'm not exactly sure what's happening here, but It seems as though calling a trait as a function, with Box<Any> leads to a codegen bug.

I tried this code (playground link):

pub trait Foo: Sized {
    const SIZE: usize;
    
    fn new(slice: &[u8; Foo::SIZE]) -> Self;
}

pub struct Bar<T: ?Sized>(T);

impl Bar<[u8]> {
    const SIZE: usize = 32;

    fn new(slice: &[u8; Self::SIZE]) -> Self {
        Foo(Box::new(*slice))
    }
}

fn main() {
    println!("Hello, world!");
}

I expected to see this happen:
That the compiler throws error[E0423]: expected function, found trait Foo, which it does, but without an internal compiler error.

Instead, this happened:

error: internal compiler error: src/librustc/traits/codegen/mod.rs:63: Encountered ambiguity selecting `Binder(<[type error] as Foo>)` during codegen, presuming due to overflow

thread 'main' panicked at 'Box<Any>', src/librustc_errors/lib.rs:600:9

Meta

note: rustc 1.32.0 (9fda7c223 2019-01-16) running on x86_64-unknown-linux-gnu

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

Backtrace:

thread 'main' panicked at 'Box<Any>', src/librustc_errors/lib.rs:600:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   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:211
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:495
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::util::bug::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::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::bug_fmt
  14: rustc::ty::context::tls::with_related_context
  15: rustc::infer::InferCtxtBuilder::enter
  16: rustc::traits::codegen::codegen_fulfill_obligation
  17: rustc::ty::query::__query_compute::codegen_fulfill_obligation
  18: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::codegen_fulfill_obligation<'tcx>>::compute
  19: rustc::dep_graph::graph::DepGraph::with_task_impl
  20: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  21: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  23: rustc::ty::instance::Instance::resolve
  24: <rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::resolve
  25: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::const_value_to_op
  26: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::eval_operand
  27: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::run
  28: rustc_mir::const_eval::eval_body_using_ecx
  29: rustc_mir::const_eval::const_eval_raw_provider
  30: rustc::ty::query::__query_compute::const_eval_raw
  31: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::const_eval_raw<'tcx>>::compute
  32: rustc::dep_graph::graph::DepGraph::with_task_impl
  33: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  35: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  36: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::const_eval_raw
  37: rustc_mir::const_eval::const_eval_provider
  38: rustc::ty::query::__query_compute::const_eval
  39: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::const_eval<'tcx>>::compute
  40: rustc::dep_graph::graph::DepGraph::with_task_impl
  41: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  42: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  43: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  44: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_const
  45: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
  46: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  47: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
  48: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  49: <smallvec::SmallVec<A> as core::iter::traits::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  50: rustc::ty::fold::TypeFoldable::fold_with
  51: rustc::traits::project::normalize
  52: rustc::infer::InferCtxt::partially_normalize_associated_types_in
  53: rustc::ty::context::tls::with_related_context
  54: rustc::infer::InferCtxtBuilder::enter
  55: rustc_typeck::check::wfcheck::check_associated_item
  56: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::check_trait_item_well_formed<'tcx>>::compute
  57: rustc::dep_graph::graph::DepGraph::with_task_impl
  58: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  59: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  60: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  61: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
  62: rustc::session::Session::track_errors
  63: rustc::util::common::time
  64: rustc_typeck::check_crate
  65: rustc::ty::context::tls::enter_context
  66: <std::thread::local::LocalKey<T>>::with
  67: rustc::ty::context::TyCtxt::create_and_enter
  68: rustc_driver::driver::compile_input
  69: rustc_driver::run_compiler_with_pool
  70: <scoped_tls::ScopedKey<T>>::set
  71: rustc_driver::run_compiler
  72: rustc_driver::monitor::{{closure}}
  73: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:102
  74: rustc_driver::run
  75: rustc_driver::main
  76: std::rt::lang_start::{{closure}}
  77: std::panicking::try::do_call
             at src/libstd/rt.rs:59
             at src/libstd/panicking.rs:310
  78: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:102
  79: std::rt::lang_start_internal
             at src/libstd/panicking.rs:289
             at src/libstd/panic.rs:398
             at src/libstd/rt.rs:58
  80: main
  81: __libc_start_main
  82: <unknown>
query stack during panic:
#0 [codegen_fulfill_obligation] checking if `Foo` fulfills its obligations
#1 [const_eval_raw] const-evaluating `Foo::new::{{constant}}`
#2 [const_eval] const-evaluating + checking `Foo::new::{{constant}}`
#3 [check_trait_item_well_formed] processing `Foo::new`
end of query stack
@jonas-schievink jonas-schievink added 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. C-bug Category: This is a bug. labels Jan 31, 2019
@brycx
Copy link
Author

brycx commented Feb 4, 2019

Possible duplicate of #57924 and #47713.

@jakubadamw
Copy link
Contributor

The example provided does not produce any ICE in the nightly channel (it does in stable and beta).

@rustbot modify labels: E-needstest

@rustbot rustbot added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Sep 29, 2019
JohnTitor added a commit to JohnTitor/rust that referenced this issue Sep 30, 2019
Centril added a commit to Centril/rust that referenced this issue Oct 1, 2019
@bors bors closed this as completed in dc1c1fe Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants