Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ice: already mutably borrowed: BorrowError #117144

Closed
matthiaskrgr opened this issue Oct 24, 2023 · 4 comments · Fixed by #117152
Closed

ice: already mutably borrowed: BorrowError #117144

matthiaskrgr opened this issue Oct 24, 2023 · 4 comments · Fixed by #117152
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

snippet:

async fn foo() -> i32 {
    if false {
        return Ok(6);
    }

    5
}

Version information

rustc 1.75.0-nightly (151256bd4 2023-10-24)
binary: rustc
commit-hash: 151256bd4b577f92922c0fbdf94b12d69cfb08d3
commit-date: 2023-10-24
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.3

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0670]: `async fn` is not permitted in Rust 2015
 --> /tmp/icemaker_global_tempdir.ZU4fQKJN0tkY/rustc_testrunner_tmpdir_reporting.uCeeA8ozkRl0/mvce.rs:1:1
  |
1 | async fn foo() -> i32 {
  | ^^^^^ to use `async fn`, switch to Rust 2018 or later
  |
  = help: pass `--edition 2021` to `rustc`
  = note: for more on editions, read https://doc.rust-lang.org/edition-guide

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.ZU4fQKJN0tkY/rustc_testrunner_tmpdir_reporting.uCeeA8ozkRl0/mvce.rs:7:2
  |
7 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.ZU4fQKJN0tkY/rustc_testrunner_tmpdir_reporting.uCeeA8ozkRl0/mvce.rs`

thread 'rustc' panicked at compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs:1755:62:
already mutably borrowed: BorrowError
stack backtrace:
   0:     0x7fb3c596917c - std::backtrace_rs::backtrace::libunwind::trace::hcc0166ed719b5803
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fb3c596917c - std::backtrace_rs::backtrace::trace_unsynchronized::hbbfdb0cdfd5a3694
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fb3c596917c - std::sys_common::backtrace::_print_fmt::h2acdf0dd6d88fb6d
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7fb3c596917c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8c769e1ecfb97334
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fb3c59cb400 - core::fmt::rt::Argument::fmt::h0b648738cd9c3905
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/core/src/fmt/rt.rs:142:9
   5:     0x7fb3c59cb400 - core::fmt::write::h8a5a209f873b8707
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/core/src/fmt/mod.rs:1117:17
   6:     0x7fb3c595d00f - std::io::Write::write_fmt::h78561a5ec2d97aeb
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/std/src/io/mod.rs:1762:15
   7:     0x7fb3c5968f64 - std::sys_common::backtrace::_print::ha6123e36392a6105
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fb3c5968f64 - std::sys_common::backtrace::print::h1b26d911e86a441a
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fb3c596bbf7 - std::panicking::default_hook::{{closure}}::h0eac92245a13cc26
  10:     0x7fb3c596b95f - std::panicking::default_hook::ha6311ff3ada643b9
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/std/src/panicking.rs:292:9
  11:     0x7fb3c84c47b0 - std[59eea237a8c90763]::panicking::update_hook::<alloc[63ea5590ce573fa8]::boxed::Box<rustc_driver_impl[4dab64b5eaf3dea0]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fb3c596c338 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h6c50cfa831996edb
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/alloc/src/boxed.rs:2021:9
  13:     0x7fb3c596c338 - std::panicking::rust_panic_with_hook::h57526d95e3d6ee7d
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/std/src/panicking.rs:735:13
  14:     0x7fb3c596c08e - std::panicking::begin_panic_handler::{{closure}}::h0e4be4e1cec2f135
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/std/src/panicking.rs:609:13
  15:     0x7fb3c5969646 - std::sys_common::backtrace::__rust_end_short_backtrace::h5b8d993df457b165
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7fb3c596bdf2 - rust_begin_unwind
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/std/src/panicking.rs:597:5
  17:     0x7fb3c59c7b25 - core::panicking::panic_fmt::h6845268c474f8c17
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/core/src/panicking.rs:72:14
  18:     0x7fb3c59c4399 - core::cell::panic_already_mutably_borrowed::hf576b634f1a52691
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/core/src/cell.rs:770:5
  19:     0x7fb3c8677be7 - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::suggest_missing_unwrap_expect
  20:     0x7fb3c864be3e - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::emit_type_mismatch_suggestions
  21:     0x7fb3c864c7c5 - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::emit_coerce_suggestions
  22:     0x7fb3ca0b2a06 - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::check_return_expr
  23:     0x7fb3ca0b5096 - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  24:     0x7fb3c9bb0f59 - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::check_block_with_expected
  25:     0x7fb3ca0b3f23 - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  26:     0x7fb3ca0b5224 - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  27:     0x7fb3c9bb2516 - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::check_block_with_expected
  28:     0x7fb3ca0b3f23 - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  29:     0x7fb3ca0b566c - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  30:     0x7fb3c9bb1019 - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::check_block_with_expected
  31:     0x7fb3ca0b3f23 - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  32:     0x7fb3c9de6dd2 - rustc_hir_typeck[ce3649d5ecae49b1]::check::check_fn
  33:     0x7fb3ca03b124 - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::check_expr_closure
  34:     0x7fb3ca0b7729 - <rustc_hir_typeck[ce3649d5ecae49b1]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  35:     0x7fb3c9de6dd2 - rustc_hir_typeck[ce3649d5ecae49b1]::check::check_fn
  36:     0x7fb3c98fe526 - rustc_hir_typeck[ce3649d5ecae49b1]::typeck
  37:     0x7fb3c98fd9bd - rustc_query_impl[cc19e181f2c3ddb7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cc19e181f2c3ddb7]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecb43faa60cb20bb]::query::erase::Erased<[u8; 8usize]>>
  38:     0x7fb3c974702c - rustc_query_system[1e36878fdb69a02b]::query::plumbing::try_execute_query::<rustc_query_impl[cc19e181f2c3ddb7]::DynamicConfig<rustc_query_system[1e36878fdb69a02b]::query::caches::VecCache<rustc_span[a9e0b1e4bb2a439]::def_id::LocalDefId, rustc_middle[ecb43faa60cb20bb]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[cc19e181f2c3ddb7]::plumbing::QueryCtxt, false>
  39:     0x7fb3c9746d10 - rustc_query_impl[cc19e181f2c3ddb7]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  40:     0x7fb3ca03f105 - rustc_hir_analysis[6111f3b64fe2cd70]::collect::type_of::type_of_opaque
  41:     0x7fb3ca03f01b - rustc_query_impl[cc19e181f2c3ddb7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cc19e181f2c3ddb7]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecb43faa60cb20bb]::query::erase::Erased<[u8; 8usize]>>
  42:     0x7fb3c9669cc5 - rustc_query_system[1e36878fdb69a02b]::query::plumbing::try_execute_query::<rustc_query_impl[cc19e181f2c3ddb7]::DynamicConfig<rustc_query_system[1e36878fdb69a02b]::query::caches::DefaultCache<rustc_span[a9e0b1e4bb2a439]::def_id::DefId, rustc_middle[ecb43faa60cb20bb]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[cc19e181f2c3ddb7]::plumbing::QueryCtxt, false>
  43:     0x7fb3ca4ca6de - rustc_query_impl[cc19e181f2c3ddb7]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace
  44:     0x7fb3c971e6b7 - rustc_middle[ecb43faa60cb20bb]::query::plumbing::query_get_at::<rustc_query_system[1e36878fdb69a02b]::query::caches::DefaultCache<rustc_span[a9e0b1e4bb2a439]::def_id::DefId, rustc_middle[ecb43faa60cb20bb]::query::erase::Erased<[u8; 8usize]>>>
  45:     0x7fb3c966cc09 - rustc_hir_analysis[6111f3b64fe2cd70]::collect::type_of::type_of
  46:     0x7fb3c966a929 - rustc_query_impl[cc19e181f2c3ddb7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cc19e181f2c3ddb7]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecb43faa60cb20bb]::query::erase::Erased<[u8; 8usize]>>
  47:     0x7fb3c9669cc5 - rustc_query_system[1e36878fdb69a02b]::query::plumbing::try_execute_query::<rustc_query_impl[cc19e181f2c3ddb7]::DynamicConfig<rustc_query_system[1e36878fdb69a02b]::query::caches::DefaultCache<rustc_span[a9e0b1e4bb2a439]::def_id::DefId, rustc_middle[ecb43faa60cb20bb]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[cc19e181f2c3ddb7]::plumbing::QueryCtxt, false>
  48:     0x7fb3c96698eb - rustc_query_impl[cc19e181f2c3ddb7]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  49:     0x7fb3c971e6b7 - rustc_middle[ecb43faa60cb20bb]::query::plumbing::query_get_at::<rustc_query_system[1e36878fdb69a02b]::query::caches::DefaultCache<rustc_span[a9e0b1e4bb2a439]::def_id::DefId, rustc_middle[ecb43faa60cb20bb]::query::erase::Erased<[u8; 8usize]>>>
  50:     0x7fb3ca1395db - rustc_hir_analysis[6111f3b64fe2cd70]::check::check::check_mod_item_types
  51:     0x7fb3ca137f79 - rustc_query_impl[cc19e181f2c3ddb7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cc19e181f2c3ddb7]::query_impl::check_mod_item_types::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecb43faa60cb20bb]::query::erase::Erased<[u8; 0usize]>>
  52:     0x7fb3ca135eb4 - rustc_query_system[1e36878fdb69a02b]::query::plumbing::try_execute_query::<rustc_query_impl[cc19e181f2c3ddb7]::DynamicConfig<rustc_query_system[1e36878fdb69a02b]::query::caches::DefaultCache<rustc_span[a9e0b1e4bb2a439]::def_id::LocalModDefId, rustc_middle[ecb43faa60cb20bb]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[cc19e181f2c3ddb7]::plumbing::QueryCtxt, false>
  53:     0x7fb3ca135843 - rustc_query_impl[cc19e181f2c3ddb7]::query_impl::check_mod_item_types::get_query_non_incr::__rust_end_short_backtrace
  54:     0x7fb3c99ef51b - rustc_hir_analysis[6111f3b64fe2cd70]::check_crate
  55:     0x7fb3c9bfec1f - rustc_interface[a6146946eb64d03a]::passes::analysis
  56:     0x7fb3c9bfe621 - rustc_query_impl[cc19e181f2c3ddb7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cc19e181f2c3ddb7]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ecb43faa60cb20bb]::query::erase::Erased<[u8; 1usize]>>
  57:     0x7fb3ca122c26 - rustc_query_system[1e36878fdb69a02b]::query::plumbing::try_execute_query::<rustc_query_impl[cc19e181f2c3ddb7]::DynamicConfig<rustc_query_system[1e36878fdb69a02b]::query::caches::SingleCache<rustc_middle[ecb43faa60cb20bb]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[cc19e181f2c3ddb7]::plumbing::QueryCtxt, false>
  58:     0x7fb3ca122a55 - rustc_query_impl[cc19e181f2c3ddb7]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  59:     0x7fb3ca30300d - std[59eea237a8c90763]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[a6146946eb64d03a]::util::run_in_thread_with_globals<rustc_interface[a6146946eb64d03a]::interface::run_compiler<core[7a9d9f52bc7b45fb]::result::Result<(), rustc_span[a9e0b1e4bb2a439]::ErrorGuaranteed>, rustc_driver_impl[4dab64b5eaf3dea0]::run_compiler::{closure#1}>::{closure#0}, core[7a9d9f52bc7b45fb]::result::Result<(), rustc_span[a9e0b1e4bb2a439]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7a9d9f52bc7b45fb]::result::Result<(), rustc_span[a9e0b1e4bb2a439]::ErrorGuaranteed>>
  60:     0x7fb3ca3022f3 - <<std[59eea237a8c90763]::thread::Builder>::spawn_unchecked_<rustc_interface[a6146946eb64d03a]::util::run_in_thread_with_globals<rustc_interface[a6146946eb64d03a]::interface::run_compiler<core[7a9d9f52bc7b45fb]::result::Result<(), rustc_span[a9e0b1e4bb2a439]::ErrorGuaranteed>, rustc_driver_impl[4dab64b5eaf3dea0]::run_compiler::{closure#1}>::{closure#0}, core[7a9d9f52bc7b45fb]::result::Result<(), rustc_span[a9e0b1e4bb2a439]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7a9d9f52bc7b45fb]::result::Result<(), rustc_span[a9e0b1e4bb2a439]::ErrorGuaranteed>>::{closure#1} as core[7a9d9f52bc7b45fb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  61:     0x7fb3c5977105 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1e5011952b28f75a
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/alloc/src/boxed.rs:2007:9
  62:     0x7fb3c5977105 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha8fd064af386c0c4
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/alloc/src/boxed.rs:2007:9
  63:     0x7fb3c5977105 - std::sys::unix::thread::Thread::new::thread_start::h8b6a97c3db8ef5a6
                               at /rustc/151256bd4b577f92922c0fbdf94b12d69cfb08d3/library/std/src/sys/unix/thread.rs:108:17
  64:     0x7fb3c57409eb - <unknown>
  65:     0x7fb3c57c47cc - <unknown>
  66:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.75.0-nightly (151256bd4 2023-10-24) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `foo`
#1 [type_of_opaque] computing type of opaque `foo::{opaque#0}`
#2 [type_of] computing type of `foo::{opaque#0}`
#3 [check_mod_item_types] checking item types in top-level module
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0601, E0670.
For more information about an error, try `rustc --explain E0601`.

@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Oct 24, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 24, 2023
@matthiaskrgr matthiaskrgr changed the title ice: `already mutably borrowed: BorrowError ice: already mutably borrowed: BorrowError Oct 24, 2023
@matthiaskrgr
Copy link
Member Author

Regression in 151256b

probably #116792 ? cc @JonasAlaif

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 25, 2023
@compiler-errors
Copy link
Member

This is due to #116841. The function name suggest_missing_unwrap_expect in the stack trace matches the title of that PR.

cc @chenyukang

@chenyukang chenyukang self-assigned this Oct 25, 2023
@compiler-errors
Copy link
Member

compiler-errors commented Oct 25, 2023

oops @chenyukang race condition, clicked the button before I saw you self-assigned -- I already found a fix 😆

@chenyukang
Copy link
Member

yeah, go ahead please.

@bors bors closed this as completed in 585a122 Oct 25, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 25, 2023
Rollup merge of rust-lang#117152 - compiler-errors:no-ret-coercion, r=chenyukang

Fix unwrap suggestion for async fn

Use `body_fn_sig` to get the expected return type of the function instead of `ret_coercion` in `FnCtxt`. This avoids accessing the `ret_coercion` when it's already mutably borrowed (e.g. when checking `return` expressions).

Fixes rust-lang#117144

r? `@chenyukang`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants