Skip to content

ICE: cannot convert RePlaceholder to a region vid #76168

Closed

Description

@ririsoft

Hello,

I am getting an ICE while "playing" with unboxed_closure

Code

MCVE can be found here: #76168 (comment)

Original
#![feature(unboxed_closures)]
use futures::executor::block_on;
use std::future::Future;

async fn walk<F>(mut filter: F)
where
    for<'a> F: FnMut<(&'a u32,)> + 'a,
    for<'a> <F as FnOnce<(&'a u32,)>>::Output: Future<Output = bool> + 'a,
{
    let res = filter(&5u32).await;
    println!("res: {}", res);
}

fn main() {
    block_on(async { walk(|&i| async move { true }).await });
}

Meta

rustc --version --verbose: (from Playground)

rustc 1.48.0-nightly (d006f5734 2020-08-28) running on x86_64-unknown-linux-gnu

Error output

error: internal compiler error: src/librustc_mir/borrow_check/universal_regions.rs:768:36: cannot convert `RePlaceholder(Placeholder { universe: U5, name: BrNamed(DefId(0:8 ~ playground[a09e]::walk[0]::'a[1]), 'a) })` to a region vid

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

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:918:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::bug
   2: rustc_errors::Handler::bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt
   6: rustc_middle::util::bug::opt_span_bug_fmt
   7: rustc_middle::util::bug::bug_fmt
   8: rustc_mir::borrow_check::universal_regions::UniversalRegionIndices::to_region_vid::{{closure}}
   9: rustc_mir::borrow_check::universal_regions::UniversalRegionIndices::to_region_vid
  10: rustc_mir::borrow_check::region_infer::RegionInferenceContext::eval_verify_bound
  11: rustc_mir::borrow_check::region_infer::RegionInferenceContext::eval_verify_bound
  12: rustc_mir::borrow_check::region_infer::RegionInferenceContext::solve
  13: rustc_mir::borrow_check::nll::compute_regions
  14: rustc_mir::borrow_check::do_mir_borrowck
  15: rustc_infer::infer::InferCtxtBuilder::enter
  16: rustc_mir::borrow_check::mir_borrowck
  17: core::ops::function::FnOnce::call_once
  18: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_borrowck>::compute
  19: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  20: rustc_data_structures::stack::ensure_sufficient_stack
  21: rustc_query_system::query::plumbing::get_query_impl
  22: rustc_typeck::collect::type_of::type_of
  23: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  24: rustc_data_structures::stack::ensure_sufficient_stack
  25: rustc_query_system::query::plumbing::get_query_impl
  26: rustc_middle::ty::util::OpaqueTypeExpander::expand_opaque_ty
  27: rustc_middle::ty::util::<impl rustc_middle::ty::context::TyCtxt>::try_expand_impl_trait_type
  28: rustc_typeck::check::check_item_type
  29: rustc_middle::hir::map::Map::visit_item_likes_in_module
  30: rustc_typeck::check::check_mod_item_types
  31: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::check_mod_item_types>::compute
  32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  33: rustc_data_structures::stack::ensure_sufficient_stack
  34: rustc_query_system::query::plumbing::get_query_impl
  35: rustc_query_system::query::plumbing::ensure_query_impl
  36: rustc_session::utils::<impl rustc_session::session::Session>::time
  37: rustc_typeck::check_crate
  38: rustc_interface::passes::analysis
  39: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  40: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  41: rustc_data_structures::stack::ensure_sufficient_stack
  42: rustc_query_system::query::plumbing::get_query_impl
  43: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  44: rustc_span::with_source_map
  45: rustc_interface::interface::create_compiler_and_run
  46: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Activity

  1. added
    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.
    on Aug 31, 2020
  2. ririsoft commented on Aug 31, 2020

    @ririsoft
    Author

    A project maintainer might want to add the F-unboxed_closures label.

  3. SNCPlay42 commented on Aug 31, 2020

    @SNCPlay42
    Contributor

    Reduced, no nightly features:

    trait Trait<Input> {
        type Output;
    }
    
    async fn walk<F>(filter: F)
    where
        for<'a> F: Trait<&'a u32> + 'a,
        for<'a> <F as Trait<&'a u32>>::Output: 'a,
    {
    }

    Output on stable:

    error[E0310]: the parameter type `F` may not live long enough
      --> src/lib.rs:9:1
       |
    9  | / {
    10 | | }
       | |_^
       |
       = help: consider adding an explicit lifetime bound `F: 'static`...
    
    error: aborting due to previous error
    
    For more information about this error, try `rustc --explain E0310`.
    

    ICEs on beta and nightly.

  4. SNCPlay42 commented on Aug 31, 2020

    @SNCPlay42
    Contributor

    Adding a F: 'static bound as suggested gives this ICE on stable:

    warning: unused variable: `filter`
     --> src/lib.rs:5:27
      |
    5 | async fn walk<F: 'static>(filter: F)
      |                           ^^^^^^ help: if this is intentional, prefix it with an underscore: `_filter`
      |
      = note: `#[warn(unused_variables)]` on by default
    
    warning: function is never used: `walk`
     --> src/lib.rs:5:10
      |
    5 | async fn walk<F: 'static>(filter: F)
      |          ^^^^
      |
      = note: `#[warn(dead_code)]` on by default
    
    warning: 2 warnings emitted
    
    error: internal compiler error: broken MIR in DefId(0:6 ~ playground[caf5]::walk[0]) (NoSolution): could not prove Binder(OutlivesPredicate(<F as Trait<&'a u32>>::Output, ReLateBound(DebruijnIndex(0), BrNamed(DefId(0:9 ~ playground[caf5]::walk[0]::'a[1]), 'a))))
      --> src/lib.rs:9:1
       |
    9  | / {
    10 | | }
       | |_^
       |
       = note: delayed at src/librustc_mir/borrow_check/type_check/mod.rs:258:27
    
    Backtrace
    thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:367:17
    stack backtrace:
       0: backtrace::backtrace::libunwind::trace
                 at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
       1: backtrace::backtrace::trace_unsynchronized
                 at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
       2: std::sys_common::backtrace::_print_fmt
                 at src/libstd/sys_common/backtrace.rs:78
       3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
                 at src/libstd/sys_common/backtrace.rs:59
       4: core::fmt::write
                 at src/libcore/fmt/mod.rs:1076
       5: std::io::Write::write_fmt
                 at src/libstd/io/mod.rs:1537
       6: std::sys_common::backtrace::_print
                 at src/libstd/sys_common/backtrace.rs:62
       7: std::sys_common::backtrace::print
                 at src/libstd/sys_common/backtrace.rs:49
       8: std::panicking::default_hook::{{closure}}
                 at src/libstd/panicking.rs:198
       9: std::panicking::default_hook
                 at src/libstd/panicking.rs:217
      10: rustc_driver::report_ice
      11: std::panicking::rust_panic_with_hook
                 at src/libstd/panicking.rs:530
      12: std::panicking::begin_panic
      13: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
      14: core::ptr::drop_in_place
      15: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
      16: core::ptr::drop_in_place
      17: rustc_span::with_source_map
      18: rustc_interface::interface::create_compiler_and_run
      19: scoped_tls::ScopedKey<T>::set
    note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    
    error: internal compiler error: unexpected panic
    
    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.46.0 (04488afe3 2020-08-24) running on x86_64-unknown-linux-gnu
    
    note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib
    
    note: some of the compiler flags provided by cargo are hidden
    
    query stack during panic:
    end of query stack
    

    Which looks like #71546. It still gives the original ICE on beta and stable, and it looks like #71546's code now produces the original ICE of this issue on beta and stable.

    Does that make this a duplicate?

  5. added
    A-closuresArea: Closures (`|…| { … }`)
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Nov 17, 2020
  6. estebank commented on Nov 17, 2020

    @estebank
    Contributor

    Another repro case relying on tokio:

    #![feature(unboxed_closures)]
    
    async fn wrapper<F>(f: F) 
    where for<'a> F: FnOnce<(&'a mut i32,)>,
        for<'a> <F as FnOnce<(&'a mut i32,)>>::Output: Future<Output=()> + 'a
    {
        let mut i = 41;
        f(&mut i).await;
    }
    
    async fn add_one(i: &mut i32) {
        *i = *i + 1;
    }
  7. SNCPlay42 commented on Nov 17, 2020

    @SNCPlay42
    Contributor

    @rustbot modify labels: -F-unboxed_closures -requires-nightly

    per #76168 (comment)

  8. removed
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Nov 17, 2020
  9. 2 remaining items

  10. tmandry commented on Nov 19, 2020

    @tmandry
    Member

    This is now reproducing on stable. This feels like more of a "guts of the borrow checker" kind of issue than async/await-specific, so I'm tagging with A-borrow-checker.

  11. added
    AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.
    on Nov 19, 2020
  12. spastorino commented on Nov 25, 2020

    @spastorino
    Member

    Assigning P-high as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

  13. added
    P-highHigh priority
    and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Nov 25, 2020
  14. estebank commented on Jan 25, 2021

    @estebank
    Contributor

    Another repro from #81273:

    #![feature(unboxed_closures)]
    
    use std::future::Future;
    
    use futures::future::LocalBoxFuture;
    
    
    pub trait GenericTask<C>: 'static {
        fn execute<'a>(&'a self, ctx: &'a C) -> LocalBoxFuture<'a, ()>;
    }
    
    impl<C: 'static, T: 'static> GenericTask<C> for T
    where
        T: for<'a> Fn<(&'a C, )>,
        for<'a> <T as FnOnce<(&'a C, )>>::Output: Future<Output = ()> + 'a,
    {
        fn execute<'a>(&'a self, ctx: &'a C) -> LocalBoxFuture<'a, ()> {
            let future = (self)(ctx);
    
            Box::pin(async move {
                future.await;
            })
        }
    }
  15. changed the title [-]ICE: cannot convert `RePlaceholder to a region vid[/-] [+]ICE: cannot convert `RePlaceholder` to a region vid[/+] on Jun 24, 2021
  16. added a commit that references this issue on Dec 2, 2021
    b56e3d9
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-async-awaitArea: Async & AwaitA-borrow-checkerArea: The borrow checkerA-closuresArea: Closures (`|…| { … }`)AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions