Skip to content

impossible case reached on lifetime inference for impl Trait in return position #49926

Closed
@nivkner

Description

@nivkner

summery

when the inferred associated types of the trait contain lifetimes, the compiler produces an internal error

details

I tried this code:

fn iter() -> impl Iterator {
    (1..2).map(|_| "hello")
}

I expected to see this happen:
the return type is inferred to be impl Iterator<Item=&'static str>,
which, when written like that, is accepted by the compiler.

Instead, this happened:

error: internal compiler error: librustc/infer/error_reporting/mod.rs:184: impossible case reached

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

Meta

rustc 1.25.0 (84203cac6 2018-03-25)  
binary: rustc                        
commit-hash: 84203cac67e65ca8640b8392348411098c856985
commit-date: 2018-03-25                              
host: x86_64-unknown-linux-gnu                      
release: 1.25.0                                       
LLVM version: 6.0
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
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:206
   3: std::panicking::default_hook
             at libstd/panicking.rs:222
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:401
   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::infer::error_reporting::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::msg_span_from_free_region
  15: <rustc::infer::anon_types::ReverseMapper<'cx, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_region
  16: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
  17: <rustc::infer::anon_types::ReverseMapper<'cx, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  18: <rustc_data_structures::accumulate_vec::AccumulateVec<A> as core::iter::traits::FromIterator<<A as rustc_data_structures::array_vec::Array>::Element>>::from_iter
  19: rustc::ty::fold::TypeFoldable::fold_with
  20: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
  21: <rustc::infer::anon_types::ReverseMapper<'cx, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  22: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &'a mut F>::call_once
  23: <rustc_data_structures::accumulate_vec::AccumulateVec<A> as core::iter::traits::FromIterator<<A as rustc_data_structures::array_vec::Array>::Element>>::from_iter
  24: <T as rustc::ty::context::InternIteratorElement<T, R>>::intern_with
  25: <rustc::infer::anon_types::ReverseMapper<'cx, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  26: <rustc_data_structures::accumulate_vec::AccumulateVec<A> as core::iter::traits::FromIterator<<A as rustc_data_structures::array_vec::Array>::Element>>::from_iter
  27: rustc::ty::fold::TypeFoldable::fold_with
  28: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable<'tcx> for &'tcx rustc::ty::TyS<'tcx>>::super_fold_with
  29: <rustc::infer::anon_types::ReverseMapper<'cx, 'gcx, 'tcx> as rustc::ty::fold::TypeFolder<'gcx, 'tcx>>::fold_ty
  30: rustc::infer::anon_types::<impl rustc::infer::InferCtxt<'a, 'gcx, 'tcx>>::infer_anon_definition_from_instantiation
  31: rustc_typeck::check::writeback::WritebackCx::visit_anon_types
  32: rustc_typeck::check::writeback::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::resolve_type_vars_in_body
  33: rustc::ty::context::tls::with_related_context
  34: rustc::infer::InferCtxtBuilder::enter
  35: rustc_typeck::check::typeck_tables_of
  36: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::compute_result
  37: rustc::dep_graph::graph::DepGraph::with_task_impl
  38: rustc::ty::context::tls::with_related_context
  39: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::force_with_lock
  40: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get          
  41: rustc::ty::maps::TyCtxtAt::typeck_tables_of                                                 
  42: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure           
  43: rustc::session::Session::track_errors                                                 
  44: rustc_typeck::check::typeck_item_bodies                                               
  45: rustc::dep_graph::graph::DepGraph::with_task_impl                                        
  46: rustc::ty::context::tls::with_related_context                                    
  47: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::force_with_lock
  48: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::try_get        
  49: rustc::ty::maps::TyCtxtAt::typeck_item_bodies                                      
  50: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_item_bodies
  51: rustc_typeck::check_crate                                                             
  52: rustc::ty::context::tls::enter_context       
  53: <std::thread::local::LocalKey<T>>::with                                                    
  54: rustc::ty::context::TyCtxt::create_and_enter                                       
  55: rustc_driver::driver::compile_input          
  56: rustc_driver::run_compiler_impl                                                       
  57: syntax::with_globals             
  58: rustc_driver::run                     
  59: rustc_driver::main                           
  60: std::rt::lang_start::{{closure}}              
  61: std::panicking::try::do_call             
             at libstd/rt.rs:59        
             at libstd/panicking.rs:305
  62: __rust_maybe_catch_panic               
             at libpanic_unwind/lib.rs:101                                                                       
  63: std::rt::lang_start_internal                                                                                      
             at libstd/panicking.rs:284                                                                                      
             at libstd/panic.rs:361                                                                                 
             at libstd/rt.rs:58                                                                                                                                        
  64: main                                    
  65: __libc_start_main                                                                                                      
  66: <unknown>                                                                                                     
query stack during panic:                                                                       
#0 [typeck_tables_of] processing `iter`                                                                                                                                
 --> src/main.rs:1:1                                                     
  |                                                                                                                 
1 | fn iter() -> impl Iterator {                                                                                                                                       
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^                      
#1 [typeck_item_bodies] type-checking all item bodies                                                                        
end of query stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-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.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions