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 on async_fn_in_trait when trait implementation misses a lifetime in different crates #120648

Closed
guissalustiano opened this issue Feb 4, 2024 · 2 comments · Fixed by #120707
Assignees
Labels
A-lifetimes Area: Lifetimes / regions 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

@guissalustiano
Copy link

guissalustiano commented Feb 4, 2024

I was developing one trait in one crate, changing it to use a lifetime, and forgot to add it to the other crate's implementation.
The compiler shows de correct error message but breaks.
If I fix the code, adding the lifetime to the trait, de compiler works. If it is in the same crate also works.

Code

// lib.rs in crate jewel
#![no_std]
#[allow(async_fn_in_trait)]

pub trait BleRadio<'a> {
    fn set_buffer(&mut self, buffer: &'a [u8]);
    async fn transmit(&mut self);
}
//lib.rs in another crate that depends on the jewel crate
#![no_std]
#![allow(async_fn_in_trait)]

use jewel::BleRadio;

pub struct Radio {}

impl BleRadio for Radio {
    fn set_buffer(&mut self, buffer: &[u8]) {}
    async fn transmit(&mut self) {}
}

Repo with minimal reproduction

Meta

rustc --version --verbose:

rustc 1.77.0-nightly (88189a71e 2024-01-19)
binary: rustc
commit-hash: 88189a71e4e4376eea82ac61db6a539612eb200a
commit-date: 2024-01-19
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

Error output

$ cargo build
   Compiling embassy-nrf v0.1.0 (/home/guiss/projetos/ble/lifetime_different_crates_ice/embassy-nrf)
error[E0726]: implicit elided lifetime not allowed here
 --> src/lib.rs:8:6
  |
8 | impl BleRadio for Radio {
  |      ^^^^^^^^ expected lifetime parameter
  |
help: indicate the anonymous lifetime
  |
8 | impl BleRadio<'_> for Radio {
  |              ++++

thread 'rustc' panicked at compiler/rustc_middle/src/ty/context.rs:1196:53:
DefId::expect_local: `DefId(4:12 ~ jewel[24ae]::BleRadio::transmit::{opaque#0}::'a)` isn't local
stack backtrace:
   0:     0x73973e961816 - std::backtrace_rs::backtrace::libunwind::trace::he9b5424ca56bbca0
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x73973e961816 - std::backtrace_rs::backtrace::trace_unsynchronized::h3564b84f57da2e1b
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x73973e961816 - std::sys_common::backtrace::_print_fmt::h44ca1bab4cfe911b
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x73973e961816 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf57bf3a288fcf4bc
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x73973e9b3e10 - core::fmt::rt::Argument::fmt::h819418805491a499
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/core/src/fmt/rt.rs:142:9
   5:     0x73973e9b3e10 - core::fmt::write::hdf7249a8a29010f3
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/core/src/fmt/mod.rs:1120:17
   6:     0x73973e95514f - std::io::Write::write_fmt::h2bd186ffd57674cf
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/std/src/io/mod.rs:1810:15
   7:     0x73973e9615f4 - std::sys_common::backtrace::_print::h3fd3fec21323f445
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x73973e9615f4 - std::sys_common::backtrace::print::h63d79712d19c9376
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x73973e964387 - std::panicking::default_hook::{{closure}}::h5221b22f986bd5a4
  10:     0x73973e9640e9 - std::panicking::default_hook::h092cd25740c5f920
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/std/src/panicking.rs:292:9
  11:     0x73973b56dcdc - std[20dd01746d97080d]::panicking::update_hook::<alloc[e20806006b8c186d]::boxed::Box<rustc_driver_impl[5959fcfa8d1d1ca4]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x73973e964ad6 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h978c6082b45e43ce
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/alloc/src/boxed.rs:2030:9
  13:     0x73973e964ad6 - std::panicking::rust_panic_with_hook::h4c5290d4ef19b28b
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/std/src/panicking.rs:785:13
  14:     0x73973e964822 - std::panicking::begin_panic_handler::{{closure}}::h9a6cdc050fc1c54a
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/std/src/panicking.rs:659:13
  15:     0x73973e961d16 - std::sys_common::backtrace::__rust_end_short_backtrace::ha4d1156e558e4eed
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x73973e964574 - rust_begin_unwind
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/std/src/panicking.rs:647:5
  17:     0x73973e9b0515 - core::panicking::panic_fmt::h5f26cb9a8ff06e61
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/core/src/panicking.rs:72:14
  18:     0x73973b9e731d - <rustc_middle[a7a29c4e21e9b57]::ty::context::TyCtxt>::is_suitable_region
  19:     0x73973b81b544 - <rustc_infer[10d8ac8d71669794]::infer::error_reporting::nice_region_error::NiceRegionError>::try_report
  20:     0x73973b81a4c1 - <rustc_infer[10d8ac8d71669794]::infer::error_reporting::TypeErrCtxt>::try_report_nice_region_error
  21:     0x73973b822ddd - <rustc_infer[10d8ac8d71669794]::infer::error_reporting::TypeErrCtxt>::report_region_errors
  22:     0x73973ccee2db - <rustc_trait_selection[e1a86cdab96b6151]::traits::engine::ObligationCtxt>::resolve_regions_and_report_errors
  23:     0x73973d34e167 - rustc_hir_analysis[78382cd4123c02ec]::check::check::check_item_type
  24:     0x73973cc94590 - rustc_hir_analysis[78382cd4123c02ec]::check::wfcheck::check_well_formed
  25:     0x73973cc93559 - rustc_query_impl[c67c2b45fd6d76a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c67c2b45fd6d76a]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a7a29c4e21e9b57]::query::erase::Erased<[u8; 1usize]>>
  26:     0x73973cc8f001 - rustc_query_system[796ead6f43aea3ee]::query::plumbing::try_execute_query::<rustc_query_impl[c67c2b45fd6d76a]::DynamicConfig<rustc_query_system[796ead6f43aea3ee]::query::caches::VecCache<rustc_hir[1a82c26e5ac3d8a5]::hir_id::OwnerId, rustc_middle[a7a29c4e21e9b57]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[c67c2b45fd6d76a]::plumbing::QueryCtxt, true>
  27:     0x73973cc8eaff - rustc_query_impl[c67c2b45fd6d76a]::query_impl::check_well_formed::get_query_incr::__rust_end_short_backtrace
  28:     0x73973cc9044c - rustc_hir_analysis[78382cd4123c02ec]::check::wfcheck::check_mod_type_wf
  29:     0x73973cc9037d - rustc_query_impl[c67c2b45fd6d76a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c67c2b45fd6d76a]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a7a29c4e21e9b57]::query::erase::Erased<[u8; 1usize]>>
  30:     0x73973d57e731 - rustc_query_system[796ead6f43aea3ee]::query::plumbing::try_execute_query::<rustc_query_impl[c67c2b45fd6d76a]::DynamicConfig<rustc_query_system[796ead6f43aea3ee]::query::caches::DefaultCache<rustc_span[22bc0c0910288393]::def_id::LocalModDefId, rustc_middle[a7a29c4e21e9b57]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[c67c2b45fd6d76a]::plumbing::QueryCtxt, true>
  31:     0x73973d3f2f02 - rustc_query_impl[c67c2b45fd6d76a]::query_impl::check_mod_type_wf::get_query_incr::__rust_end_short_backtrace
  32:     0x73973ca7c445 - rustc_middle[a7a29c4e21e9b57]::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system[796ead6f43aea3ee]::query::caches::DefaultCache<rustc_span[22bc0c0910288393]::def_id::LocalModDefId, rustc_middle[a7a29c4e21e9b57]::query::erase::Erased<[u8; 1usize]>>, ()>
  33:     0x73973ca7cd8b - rustc_hir_analysis[78382cd4123c02ec]::check_crate
  34:     0x73973d22b052 - rustc_interface[a4c2db5fc6bd6a93]::passes::analysis
  35:     0x73973d22ac9f - rustc_query_impl[c67c2b45fd6d76a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c67c2b45fd6d76a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a7a29c4e21e9b57]::query::erase::Erased<[u8; 1usize]>>
  36:     0x73973d21f3e7 - rustc_query_system[796ead6f43aea3ee]::query::plumbing::try_execute_query::<rustc_query_impl[c67c2b45fd6d76a]::DynamicConfig<rustc_query_system[796ead6f43aea3ee]::query::caches::SingleCache<rustc_middle[a7a29c4e21e9b57]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[c67c2b45fd6d76a]::plumbing::QueryCtxt, true>
  37:     0x73973d21efe0 - rustc_query_impl[c67c2b45fd6d76a]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  38:     0x73973d71aeb3 - rustc_interface[a4c2db5fc6bd6a93]::interface::run_compiler::<core[7fbf663f9cc01fa9]::result::Result<(), rustc_span[22bc0c0910288393]::ErrorGuaranteed>, rustc_driver_impl[5959fcfa8d1d1ca4]::run_compiler::{closure#0}>::{closure#0}
  39:     0x73973d7fcdde - std[20dd01746d97080d]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[a4c2db5fc6bd6a93]::util::run_in_thread_with_globals<rustc_interface[a4c2db5fc6bd6a93]::util::run_in_thread_pool_with_globals<rustc_interface[a4c2db5fc6bd6a93]::interface::run_compiler<core[7fbf663f9cc01fa9]::result::Result<(), rustc_span[22bc0c0910288393]::ErrorGuaranteed>, rustc_driver_impl[5959fcfa8d1d1ca4]::run_compiler::{closure#0}>::{closure#0}, core[7fbf663f9cc01fa9]::result::Result<(), rustc_span[22bc0c0910288393]::ErrorGuaranteed>>::{closure#0}, core[7fbf663f9cc01fa9]::result::Result<(), rustc_span[22bc0c0910288393]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7fbf663f9cc01fa9]::result::Result<(), rustc_span[22bc0c0910288393]::ErrorGuaranteed>>
  40:     0x73973d7fcc0d - <<std[20dd01746d97080d]::thread::Builder>::spawn_unchecked_<rustc_interface[a4c2db5fc6bd6a93]::util::run_in_thread_with_globals<rustc_interface[a4c2db5fc6bd6a93]::util::run_in_thread_pool_with_globals<rustc_interface[a4c2db5fc6bd6a93]::interface::run_compiler<core[7fbf663f9cc01fa9]::result::Result<(), rustc_span[22bc0c0910288393]::ErrorGuaranteed>, rustc_driver_impl[5959fcfa8d1d1ca4]::run_compiler::{closure#0}>::{closure#0}, core[7fbf663f9cc01fa9]::result::Result<(), rustc_span[22bc0c0910288393]::ErrorGuaranteed>>::{closure#0}, core[7fbf663f9cc01fa9]::result::Result<(), rustc_span[22bc0c0910288393]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7fbf663f9cc01fa9]::result::Result<(), rustc_span[22bc0c0910288393]::ErrorGuaranteed>>::{closure#1} as core[7fbf663f9cc01fa9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x73973e96e3c5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h476ab21e86af8c38
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/alloc/src/boxed.rs:2016:9
  42:     0x73973e96e3c5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h03a8c656e3f61339
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/alloc/src/boxed.rs:2016:9
  43:     0x73973e96e3c5 - std::sys::pal::unix::thread::Thread::new::thread_start::h967fe69886e84602
                               at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/std/src/sys/pal/unix/thread.rs:108:17
  44:     0x7397386aa9eb - <unknown>
  45:     0x73973872e7cc - <unknown>
  46:                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: please attach the file at `/home/guiss/projetos/ble/lifetime_different_crates_ice/embassy-nrf/rustc-ice-2024-02-04T18_29_58-63482.txt` to your bug report

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [check_well_formed] checking that `<impl at src/lib.rs:8:1: 8:24>` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
For more information about this error, try `rustc --explain E0726`.
error: could not compile `embassy-nrf` (lib) due to 1 previous error
Backtrace

$ RUST_BACKTRACE=1 cargo build
   Compiling embassy-nrf v0.1.0 (/home/guiss/projetos/ble/lifetime_different_crates_ice/embassy-nrf)
error[E0726]: implicit elided lifetime not allowed here
 --> src/lib.rs:8:6
  |
8 | impl BleRadio for Radio {
  |      ^^^^^^^^ expected lifetime parameter
  |
help: indicate the anonymous lifetime
  |
8 | impl BleRadio<'_> for Radio {
  |              ++++

thread 'rustc' panicked at compiler/rustc_middle/src/ty/context.rs:1196:53:
DefId::expect_local: `DefId(4:12 ~ jewel[24ae]::BleRadio::transmit::{opaque#0}::'a)` isn't local
stack backtrace:
   0: rust_begin_unwind
             at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/std/src/panicking.rs:647:5
   1: core::panicking::panic_fmt
             at /rustc/88189a71e4e4376eea82ac61db6a539612eb200a/library/core/src/panicking.rs:72:14
   2: <rustc_middle::ty::context::TyCtxt>::is_suitable_region
   3: <rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError>::try_report
   4: <rustc_infer::infer::error_reporting::TypeErrCtxt>::try_report_nice_region_error
   5: <rustc_infer::infer::error_reporting::TypeErrCtxt>::report_region_errors
   6: <rustc_trait_selection::traits::engine::ObligationCtxt>::resolve_regions_and_report_errors
   7: rustc_hir_analysis::check::check::check_item_type
   8: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 1 frame ...]
   9: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
      [... omitted 1 frame ...]
  10: rustc_middle::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalModDefId, rustc_middle::query::erase::Erased<[u8; 1]>>, ()>
  11: rustc_hir_analysis::check_crate
  12: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  13: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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: please attach the file at `/home/guiss/projetos/ble/lifetime_different_crates_ice/embassy-nrf/rustc-ice-2024-02-04T18_30_27-63563.txt` to your bug report

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [check_well_formed] checking that `<impl at src/lib.rs:8:1: 8:24>` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
For more information about this error, try `rustc --explain E0726`.
error: could not compile `embassy-nrf` (lib) due to 1 previous error

@guissalustiano guissalustiano added 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. labels Feb 4, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 4, 2024
@fmease
Copy link
Member

fmease commented Feb 4, 2024

Same backtrace as #120638.

@saethlin saethlin added A-lifetimes Area: Lifetimes / regions and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 6, 2024
@compiler-errors compiler-errors self-assigned this Feb 6, 2024
@compiler-errors
Copy link
Member

Thanks for the minimized test! I'll fix this tomorrow.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 6, 2024
…=nnethercote

Don't expect early-bound region to be local when reporting errors in RPITIT well-formedness

The implicit lifetime in the example code gets replaced with `ReError`, which fails a `sub_regions` check in the lexical region solver. Error reporting ends up calling `is_suitable_region` on an early bound region in the *trait* definition. This causes an ICE because we `expect_local()`.

This is kind of a bad explanation, but this code just makes diagnostics reporting a bit more gracefully fallible. If the reviewer wants a thorough investigation of exactly where we get this region outlives obligation, I can write one up. Doesn't really seem worth it, though, imo.

Fixes rust-lang#120638
Fixes rust-lang#120648
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 7, 2024
Rollup merge of rust-lang#120707 - compiler-errors:suitable-region, r=nnethercote

Don't expect early-bound region to be local when reporting errors in RPITIT well-formedness

The implicit lifetime in the example code gets replaced with `ReError`, which fails a `sub_regions` check in the lexical region solver. Error reporting ends up calling `is_suitable_region` on an early bound region in the *trait* definition. This causes an ICE because we `expect_local()`.

This is kind of a bad explanation, but this code just makes diagnostics reporting a bit more gracefully fallible. If the reviewer wants a thorough investigation of exactly where we get this region outlives obligation, I can write one up. Doesn't really seem worth it, though, imo.

Fixes rust-lang#120638
Fixes rust-lang#120648
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions 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
5 participants