Skip to content

ICE: can't find an upper bound in nll::compute_regions in rustc_borrowck #122704

Description

@shkoo

Code

use std::any::Any;

pub struct Foo {
    bar: Box<dyn for<'a> Fn(&'a usize) -> Box<dyn Any + 'a>>,
}

impl Foo {
    pub fn ack<I>(&mut self, f: impl for<'a> Fn(&'a usize) -> Box<I>) {
        self.bar = Box::new(|baz| Box::new(f(baz)));
    }
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (eb45c8444 2024-03-17)
binary: rustc
commit-hash: eb45c844407968ea54df0d9870ebce9e3235b706
commit-date: 2024-03-17
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

Error output

thread 'rustc' panicked at compiler/rustc_borrowck/src/type_check/free_region_relations.rs:97:9:
can't find an upper bound!?
stack backtrace:
   0:     0x7fcf37ef030f - std::backtrace_rs::backtrace::libunwind::trace::hd1b8e7bf69bd2659
                               at /rustc/eb45c844407968ea54df0d9870ebce9e3235b706/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7fcf37ef030f - std::backtrace_rs::backtrace::trace_unsynchronized::ha2541878f17a8bf5
                               at /rustc/eb45c844407968ea54df0d9870ebce9e3235b706/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fcf37ef030f - std::backtrace::Backtrace::create::h2489761f8d713f8d
                               at /rustc/eb45c844407968ea54df0d9870ebce9e3235b706/library/std/src/backtrace.rs:331:13
   3:     0x7fcf37ef0250 - std::backtrace::Backtrace::force_capture::h212b9648ae6a4e34
                               at /rustc/eb45c844407968ea54df0d9870ebce9e3235b706/library/std/src/backtrace.rs:312:9
   4:     0x7fcf3af33762 - std[f30794364a8567e8]::panicking::update_hook::<alloc[d4fc0c1400399e53]::boxed::Box<rustc_driver_impl[977aa2f7506c0463]::install_ice_hook::{closure#0}>>::{closure#0}
   5:     0x7fcf37f0ab50 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::he9235fc142cfefbc
                               at /rustc/eb45c844407968ea54df0d9870ebce9e3235b706/library/alloc/src/boxed.rs:2034:9
   6:     0x7fcf37f0ab50 - std::panicking::rust_panic_with_hook::hcb10f10b9294465e
                               at /rustc/eb45c844407968ea54df0d9870ebce9e3235b706/library/std/src/panicking.rs:783:13
   7:     0x7fcf37f0a859 - std::panicking::begin_panic_handler::{{closure}}::h1df158136e631df7
                               at /rustc/eb45c844407968ea54df0d9870ebce9e3235b706/library/std/src/panicking.rs:649:13
   8:     0x7fcf37f07de6 - std::sys_common::backtrace::__rust_end_short_backtrace::h3eabad15a30d1baa
                               at /rustc/eb45c844407968ea54df0d9870ebce9e3235b706/library/std/src/sys_common/backtrace.rs:171:18
   9:     0x7fcf37f0a5c4 - rust_begin_unwind
                               at /rustc/eb45c844407968ea54df0d9870ebce9e3235b706/library/std/src/panicking.rs:645:5
  10:     0x7fcf37f551a5 - core::panicking::panic_fmt::hc408b30751ce7310
                               at /rustc/eb45c844407968ea54df0d9870ebce9e3235b706/library/core/src/panicking.rs:72:14
  11:     0x7fcf3ad4253d - <rustc_borrowck[19dbd917483b2da6]::type_check::free_region_relations::UniversalRegionRelations>::non_local_upper_bounds
  12:     0x7fcf39a48644 - rustc_borrowck[19dbd917483b2da6]::nll::compute_regions
  13:     0x7fcf3d1605ef - rustc_borrowck[19dbd917483b2da6]::do_mir_borrowck
  14:     0x7fcf3c349228 - rustc_borrowck[19dbd917483b2da6]::mir_borrowck
  15:     0x7fcf3c348d17 - rustc_query_impl[29f35dd1a1f5675d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[29f35dd1a1f5675d]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e264bbe93e45f6ca]::query::erase::Erased<[u8; 8usize]>>
  16:     0x7fcf3c34ad2e - rustc_query_system[7e5eced594b3b3e4]::query::plumbing::try_execute_query::<rustc_query_impl[29f35dd1a1f5675d]::DynamicConfig<rustc_query_system[7e5eced594b3b3e4]::query::caches::VecCache<rustc_span[30575adc3f012a9d]::def_id::LocalDefId, rustc_middle[e264bbe93e45f6ca]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[29f35dd1a1f5675d]::plumbing::QueryCtxt, false>
  17:     0x7fcf3c34a84c - rustc_query_impl[29f35dd1a1f5675d]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  18:     0x7fcf3cc5d29c - rustc_middle[e264bbe93e45f6ca]::query::plumbing::query_get_at::<rustc_query_system[7e5eced594b3b3e4]::query::caches::VecCache<rustc_span[30575adc3f012a9d]::def_id::LocalDefId, rustc_middle[e264bbe93e45f6ca]::query::erase::Erased<[u8; 8usize]>>>
  19:     0x7fcf3cc5d30e - <rustc_borrowck[19dbd917483b2da6]::type_check::TypeChecker>::prove_closure_bounds
  20:     0x7fcf3c6873a3 - <rustc_borrowck[19dbd917483b2da6]::type_check::TypeChecker>::typeck_mir
  21:     0x7fcf39a024ea - rustc_borrowck[19dbd917483b2da6]::type_check::type_check
  22:     0x7fcf39a3c137 - rustc_borrowck[19dbd917483b2da6]::nll::compute_regions
  23:     0x7fcf3d1605ef - rustc_borrowck[19dbd917483b2da6]::do_mir_borrowck
  24:     0x7fcf3c349228 - rustc_borrowck[19dbd917483b2da6]::mir_borrowck
  25:     0x7fcf3c348d17 - rustc_query_impl[29f35dd1a1f5675d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[29f35dd1a1f5675d]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e264bbe93e45f6ca]::query::erase::Erased<[u8; 8usize]>>
  26:     0x7fcf3c34ad2e - rustc_query_system[7e5eced594b3b3e4]::query::plumbing::try_execute_query::<rustc_query_impl[29f35dd1a1f5675d]::DynamicConfig<rustc_query_system[7e5eced594b3b3e4]::query::caches::VecCache<rustc_span[30575adc3f012a9d]::def_id::LocalDefId, rustc_middle[e264bbe93e45f6ca]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[29f35dd1a1f5675d]::plumbing::QueryCtxt, false>
  27:     0x7fcf3c34a84c - rustc_query_impl[29f35dd1a1f5675d]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7fcf3c61d95d - rustc_interface[2a44f2ea1a7c30d3]::passes::analysis
  29:     0x7fcf3c61cb19 - rustc_query_impl[29f35dd1a1f5675d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[29f35dd1a1f5675d]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e264bbe93e45f6ca]::query::erase::Erased<[u8; 1usize]>>
  30:     0x7fcf3cfc7ec3 - rustc_query_system[7e5eced594b3b3e4]::query::plumbing::try_execute_query::<rustc_query_impl[29f35dd1a1f5675d]::DynamicConfig<rustc_query_system[7e5eced594b3b3e4]::query::caches::SingleCache<rustc_middle[e264bbe93e45f6ca]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[29f35dd1a1f5675d]::plumbing::QueryCtxt, false>
  31:     0x7fcf3cfc7c3f - rustc_query_impl[29f35dd1a1f5675d]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7fcf3cdf3084 - rustc_interface[2a44f2ea1a7c30d3]::interface::run_compiler::<core[451cccbd72d71aca]::result::Result<(), rustc_span[30575adc3f012a9d]::ErrorGuaranteed>, rustc_driver_impl[977aa2f7506c0463]::run_compiler::{closure#0}>::{closure#0}
  33:     0x7fcf3cedf685 - std[f30794364a8567e8]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[2a44f2ea1a7c30d3]::util::run_in_thread_with_globals<rustc_interface[2a44f2ea1a7c30d3]::util::run_in_thread_pool_with_globals<rustc_interface[2a44f2ea1a7c30d3]::interface::run_compiler<core[451cccbd72d71aca]::result::Result<(), rustc_span[30575adc3f012a9d]::ErrorGuaranteed>, rustc_driver_impl[977aa2f7506c0463]::run_compiler::{closure#0}>::{closure#0}, core[451cccbd72d71aca]::result::Result<(), rustc_span[30575adc3f012a9d]::ErrorGuaranteed>>::{closure#0}, core[451cccbd72d71aca]::result::Result<(), rustc_span[30575adc3f012a9d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[451cccbd72d71aca]::result::Result<(), rustc_span[30575adc3f012a9d]::ErrorGuaranteed>>
  34:     0x7fcf3cedf4b2 - <<std[f30794364a8567e8]::thread::Builder>::spawn_unchecked_<rustc_interface[2a44f2ea1a7c30d3]::util::run_in_thread_with_globals<rustc_interface[2a44f2ea1a7c30d3]::util::run_in_thread_pool_with_globals<rustc_interface[2a44f2ea1a7c30d3]::interface::run_compiler<core[451cccbd72d71aca]::result::Result<(), rustc_span[30575adc3f012a9d]::ErrorGuaranteed>, rustc_driver_impl[977aa2f7506c0463]::run_compiler::{closure#0}>::{closure#0}, core[451cccbd72d71aca]::result::Result<(), rustc_span[30575adc3f012a9d]::ErrorGuaranteed>>::{closure#0}, core[451cccbd72d71aca]::result::Result<(), rustc_span[30575adc3f012a9d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[451cccbd72d71aca]::result::Result<(), rustc_span[30575adc3f012a9d]::ErrorGuaranteed>>::{closure#1} as core[451cccbd72d71aca]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  35:     0x7fcf37f141e5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h746ad893ba25d760
                               at /rustc/eb45c844407968ea54df0d9870ebce9e3235b706/library/alloc/src/boxed.rs:2020:9
  36:     0x7fcf37f141e5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6b3d742dc2cb92e7
                               at /rustc/eb45c844407968ea54df0d9870ebce9e3235b706/library/alloc/src/boxed.rs:2020:9
  37:     0x7fcf37f141e5 - std::sys::pal::unix::thread::Thread::new::thread_start::h23f93afbf81ba466
                               at /rustc/eb45c844407968ea54df0d9870ebce9e3235b706/library/std/src/sys/pal/unix/thread.rs:108:17
  38:     0x7fcf37e14609 - start_thread
                               at /build/glibc-wuryBv/glibc-2.31/nptl/pthread_create.c:477:8
  39:     0x7fcf37d39353 - clone
                               at /build/glibc-wuryBv/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  40:                0x0 - <unknown>


rustc version: 1.79.0-nightly (eb45c8444 2024-03-17)
platform: x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `<impl at repro.rs:7:1: 7:9>::ack::{closure#0}`
#1 [mir_borrowck] borrow-checking `<impl at repro.rs:7:1: 7:9>::ack`
#2 [analysis] running analysis passes on this crate
end of query stack

Activity

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-borrow-checkerArea: The borrow checkerC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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