Skip to content

ICE: Encountered ambiguity selecting Binder(<[type error] as Bar>) during trans, presuming due to overflow #48027

@Badel2

Description

@Badel2
Contributor

This code ICEs, both on stable and nightly:

trait Bar {
    const X: usize;
    fn return_n(&self) -> [u8; Bar::X];
}

impl Bar {}

The first error is expected, the second one is a ICE:

error[E0038]: the trait `Bar` cannot be made into an object
 --> ice.rs:6:6
  |
6 | impl Bar {}
  |      ^^^ the trait `Bar` cannot be made into an object
  |
  = note: the trait cannot contain associated consts like `X`

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

thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:535:9
Backtrace

rustc version:

rustc 1.25.0-nightly (6c04c4103 2018-02-05)
binary: rustc
commit-hash: 6c04c41034c46730fba97bfe9cfa2dd0687c2a5f
commit-date: 2018-02-05
host: x86_64-unknown-linux-gnu
release: 1.25.0-nightly
LLVM version: 4.0

Backtrace:

thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:535:9
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 libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:59
             at libstd/panicking.rs:380
   3: std::panicking::default_hook
             at libstd/panicking.rs:396
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:576
   5: std::panicking::begin_panic
   6: rustc_errors::Handler::bug
   7: rustc::session::opt_span_bug_fmt::{{closure}}
   8: rustc::session::opt_span_bug_fmt
   9: rustc::session::bug_fmt
  10: rustc::traits::trans::trans_fulfill_obligation
  11: rustc::dep_graph::graph::DepGraph::with_task_impl
  12: rustc::ty::maps::<impl rustc::ty::maps::queries::trans_fulfill_obligation<'tcx>>::force
  13: rustc::ty::maps::<impl rustc::ty::maps::queries::trans_fulfill_obligation<'tcx>>::try_get
  14: rustc::ty::maps::TyCtxtAt::trans_fulfill_obligation
  15: rustc::ty::instance::Instance::resolve
  16: rustc_const_eval::eval::lookup_const_by_id
  17: rustc_mir::interpret::const_eval::const_eval_provider
  18: rustc::dep_graph::graph::DepGraph::with_task_impl
  19: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::force
  20: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::try_get
  21: rustc::ty::maps::TyCtxtAt::const_eval
  22: rustc_const_eval::eval::eval_const_expr_partial
  23: rustc_const_eval::eval::ConstContext::eval
  24: rustc_mir::interpret::const_eval::const_eval_provider
  25: rustc::dep_graph::graph::DepGraph::with_task_impl
  26: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::force
  27: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::try_get
  28: rustc::ty::maps::TyCtxtAt::const_eval
  29: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_const
  30: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
  31: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  32: rustc::ty::fold::TypeFoldable::fold_with
  33: rustc::infer::InferCtxt::partially_normalize_associated_types_in
  34: rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor::check_associated_item
  35: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'v>>::visit_trait_item
  36: rustc_typeck::check_crate::{{closure}}
  37: rustc_typeck::check_crate
  38: rustc::ty::context::TyCtxt::create_and_enter
  39: rustc_driver::driver::compile_input
  40: rustc_driver::run_compiler

Activity

added
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
A-associated-itemsArea: Associated items (types, constants & functions)
C-bugCategory: This is a bug.
on Feb 6, 2018
Badel2

Badel2 commented on Feb 7, 2018

@Badel2
ContributorAuthor

I thought the impl Bar {} was necessary for the ICE, but other errors like a missing main function also produce it:

trait Bar {
    const X: usize;
    fn return_n(&self) -> [u8; Bar::X];
}

//fn main() {}

Playground link. Uncommenting the main function produces an error, not sure if correct, but doesn't ICE:

error[E0283]: type annotations required: cannot resolve `_: Bar`
 --> src/main.rs:3:32
  |
3 |     fn return_n(&self) -> [u8; Bar::X];
  |                                ^^^^^^
  |
  = note: required by `Bar::X`
VictorKoenders

VictorKoenders commented on May 15, 2018

@VictorKoenders

I'm running into a similar issue: playground

For some reason it compiles fine if you remove the Network and Layer struct, even though those are seemingly not related to the error at all.

   Compiling playground v0.0.1 (file:///playground)
error[E0401]: can't use type parameters from outer function
  --> src/main.rs:24:36
   |
22 | impl<TConfig: NodeConfig> NeuralNetwork<TConfig> {
   |      ------- type variable from outer function
23 |     pub fn new(id: u32) -> Self {
   |            --- try adding a local type parameter in this method instead
24 |         const LAYER_COUNT: usize = TConfig::LAYER_DEPTH + 2;
   |                                    ^^^^^^^^^^^^^^^^^^^^ use of type variable from outer function

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

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:554:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: aborting due to 2 previous errors

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

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.27.0-nightly (ac5c0848d 2018-05-14) running on x86_64-unknown-linux-gnu

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

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

JohnTitor commented on Oct 14, 2019

@JohnTitor
Member

Cannot reproduce ICEs with both examples on latest nightly. marked as E-needstest

added
E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
on Oct 14, 2019
added 2 commits that reference this issue on Oct 14, 2019
045339c
a73e073
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)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) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @TimNN@VictorKoenders@Badel2@JohnTitor

      Issue actions

        ICE: Encountered ambiguity selecting `Binder(<[type error] as Bar>)` during trans, presuming due to overflow · Issue #48027 · rust-lang/rust