Skip to content

rustc panic after failing to resolve trait fn return lifetime #48963

Closed
@scowcron

Description

@scowcron

I have no idea if what I'm trying to do is even reasonable, but the compiler crash should probably be addressed.

I tried this code:

trait Broken<'a> {
    const LEN: usize;
    fn buf() -> &'a [u8; Broken::LEN];
    fn buf_mut() -> &'a mut [u8; Broken::LEN];
}

I expected to see this happen:

The same failure, but without a panic. Note that rustc does not panic when only one of the two methods is provided, although it still cannot resolve the lifetime.

What I hoped would happen:

The const value would be interpreted by the compiler and the impl would need to return a slice of size Broken::LEN

Instead, this happened:

rustc panicked.

Meta

rustc --version --verbose:

rustc 1.26.0-nightly (2789b067d 2018-03-06)
binary: rustc
commit-hash: 2789b067da2ac921b86199bde21dd231ace1da39
commit-date: 2018-03-06
host: x86_64-unknown-linux-gnu
release: 1.26.0-nightly
LLVM version: 6.0

Backtrace:

     Running `rustc --crate-name broken src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 -C metadata=d3500dba229a2885 -C extra-filename=-d3500dba229a2885 --out-dir /path/to/broken/target/debug/deps -C incremental=/path/to/broken/target/debug/incremental -L dependency=/path/to/broken/target/debug/deps`
error[E0283]: type annotations required: cannot resolve `_: Broken<'_>`
 --> src/lib.rs:3:26
  |
3 |     fn buf() -> &'a [u8; Broken::A];
  |                          ^^^^^^^^^
  |
note: required by `Broken::A`
 --> src/lib.rs:2:5
  |
2 |     const A: usize;
  |     ^^^^^^^^^^^^^^^

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

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:207
   3: std::panicking::default_hook
             at libstd/panicking.rs:223
   4: core::ops::function::Fn::call
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:403
   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: <std::thread::local::LocalKey<T>>::try_with
  11: <std::thread::local::LocalKey<T>>::with
  12: rustc::ty::context::tls::with
  13: rustc::ty::context::tls::with_opt
  14: rustc::session::opt_span_bug_fmt
  15: rustc::session::bug_fmt
  16: rustc::traits::trans::trans_fulfill_obligation
  17: rustc::dep_graph::graph::DepGraph::with_task_impl
  18: rustc::ty::maps::<impl rustc::ty::maps::queries::trans_fulfill_obligation<'tcx>>::force
  19: rustc::ty::maps::<impl rustc::ty::maps::queries::trans_fulfill_obligation<'tcx>>::try_get
  20: rustc::ty::maps::TyCtxtAt::trans_fulfill_obligation
  21: rustc::ty::instance::Instance::resolve
  22: rustc_const_eval::eval::lookup_const_by_id
  23: rustc_mir::interpret::const_eval::const_eval_provider
  24: rustc::dep_graph::graph::DepGraph::with_task_impl
  25: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::force
  26: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::try_get
  27: rustc::ty::maps::TyCtxtAt::const_eval
  28: rustc_const_eval::eval::eval_const_expr_partial
  29: rustc_const_eval::eval::ConstContext::eval
  30: rustc_mir::interpret::const_eval::const_eval_provider
  31: rustc::dep_graph::graph::DepGraph::with_task_impl
  32: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::force
  33: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::try_get
  34: rustc::ty::maps::TyCtxtAt::const_eval
  35: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_const
  36: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  37: <rustc::traits::project::AssociatedTypeNormalizer<'a, 'b, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  38: rustc::ty::fold::TypeFoldable::fold_with
  39: rustc::infer::InferCtxt::partially_normalize_associated_types_in
  40: rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor::check_associated_item
  41: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'v>>::visit_trait_item
  42: rustc_typeck::check_crate::{{closure}}
  43: rustc_typeck::check_crate
  44: rustc::ty::context::TyCtxt::create_and_enter
  45: rustc_driver::driver::compile_input
  46: rustc_driver::run_compiler
If you want more information on this error, try using "rustc --explain E0283"

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.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