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: control flow ensures we have a BindingObligation or WhereClauseInExpr here #130012

Closed
dtolnay opened this issue Sep 6, 2024 · 2 comments · Fixed by #130137
Closed

ICE: control flow ensures we have a BindingObligation or WhereClauseInExpr here #130012

dtolnay opened this issue Sep 6, 2024 · 2 comments · Fixed by #130137
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented Sep 6, 2024

Code

trait Fun {
    type Assoc;
}

trait Trait: for<'v> Fun<Assoc = &'v ()> {}

impl<F: for<'v> Fun<Assoc = &'v ()>> Trait for F {}

fn main() {}

Meta

rustc --version --verbose: current nightly

rustc 1.83.0-nightly (9c01301c5 2024-09-05)
binary: rustc
commit-hash: 9c01301c52df5d2d7b6fe337707a74e011d68d6f
commit-date: 2024-09-05
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

Error output

rustc main.rs

error[E0582]: binding for associated type `Assoc` references lifetime `'v`, which does not appear in the trait input types
 --> src/main.rs:5:26
  |
5 | trait Trait: for<'v> Fun<Assoc = &'v ()> {}
  |                          ^^^^^^^^^^^^^^

error[E0582]: binding for associated type `Assoc` references lifetime `'v`, which does not appear in the trait input types
 --> src/main.rs:7:21
  |
7 | impl<F: for<'v> Fun<Assoc = &'v ()>> Trait for F {}
  |                     ^^^^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_trait_selection/src/error_reporting/infer/region.rs:634:21:
internal error: entered unreachable code: control flow ensures we have a `BindingObligation` or `WhereClauseInExpr` here...
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_trait_selection::error_reporting::TypeErrCtxt>::report_placeholder_failure
   3: <rustc_trait_selection::error_reporting::TypeErrCtxt>::report_region_errors
   4: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 1 frame ...]
   5: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
      [... omitted 1 frame ...]
   6: rustc_hir_analysis::check_crate
   7: rustc_interface::passes::run_required_analyses
   8: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
   9: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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

query stack during panic:
#0 [check_well_formed] checking that `<impl at src/main.rs:7:1: 7:49>` 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
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0582`.
Backtrace

stack backtrace:
   0:     0x714380c67be5 - std::backtrace::Backtrace::create::h0b20d70bbd20825c
   1:     0x71437f42bb05 - std::backtrace::Backtrace::force_capture::heb2536b9591609d6
   2:     0x71437e55c457 - std[c093c6b05171ebdd]::panicking::update_hook::<alloc[78698482508a29ba]::boxed::Box<rustc_driver_impl[ff0605cbafb5cd86]::install_ice_hook::{closure#0}>>::{closure#0}
   3:     0x71437f442f28 - std::panicking::rust_panic_with_hook::hbc158dc145985f20
   4:     0x71437f442cc3 - std::panicking::begin_panic_handler::{{closure}}::ha4ff8d0a34f0db3b
   5:     0x71437f440939 - std::sys::backtrace::__rust_end_short_backtrace::h99054fe005abe325
   6:     0x71437f4429c4 - rust_begin_unwind
   7:     0x71437c2aaa43 - core::panicking::panic_fmt::h700376aebf176cba
   8:     0x71437f26b152 - <rustc_trait_selection[cbbf0906eb8ebddd]::error_reporting::TypeErrCtxt>::report_placeholder_failure
   9:     0x71437f2676de - <rustc_trait_selection[cbbf0906eb8ebddd]::error_reporting::TypeErrCtxt>::report_region_errors
  10:     0x71437d264874 - rustc_hir_analysis[cf1168cfed07072a]::check::wfcheck::check_well_formed
  11:     0x714380016ce7 - rustc_query_impl[33864bfff5ddc18b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[33864bfff5ddc18b]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[680a3b16fcb54e30]::query::erase::Erased<[u8; 1usize]>>
  12:     0x714380016f74 - rustc_query_system[1d740a2f543ea37c]::query::plumbing::try_execute_query::<rustc_query_impl[33864bfff5ddc18b]::DynamicConfig<rustc_query_system[1d740a2f543ea37c]::query::caches::VecCache<rustc_hir[f1bc196970cb7291]::hir_id::OwnerId, rustc_middle[680a3b16fcb54e30]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[33864bfff5ddc18b]::plumbing::QueryCtxt, false>
  13:     0x714380016cc6 - rustc_query_impl[33864bfff5ddc18b]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  14:     0x714380017a8b - rustc_hir_analysis[cf1168cfed07072a]::check::wfcheck::check_mod_type_wf
  15:     0x7143800178c9 - rustc_query_impl[33864bfff5ddc18b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[33864bfff5ddc18b]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[680a3b16fcb54e30]::query::erase::Erased<[u8; 1usize]>>
  16:     0x714380b58e7b - rustc_query_system[1d740a2f543ea37c]::query::plumbing::try_execute_query::<rustc_query_impl[33864bfff5ddc18b]::DynamicConfig<rustc_query_system[1d740a2f543ea37c]::query::caches::DefaultCache<rustc_span[d096ceaba54bbd14]::def_id::LocalModDefId, rustc_middle[680a3b16fcb54e30]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[33864bfff5ddc18b]::plumbing::QueryCtxt, false>
  17:     0x714380b58c2d - rustc_query_impl[33864bfff5ddc18b]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  18:     0x7143803c303d - rustc_hir_analysis[cf1168cfed07072a]::check_crate
  19:     0x714380653bd1 - rustc_interface[a1713937163ca6a0]::passes::run_required_analyses
  20:     0x7143809c895e - rustc_interface[a1713937163ca6a0]::passes::analysis
  21:     0x7143809c8931 - rustc_query_impl[33864bfff5ddc18b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[33864bfff5ddc18b]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[680a3b16fcb54e30]::query::erase::Erased<[u8; 1usize]>>
  22:     0x714380b76c6e - rustc_query_system[1d740a2f543ea37c]::query::plumbing::try_execute_query::<rustc_query_impl[33864bfff5ddc18b]::DynamicConfig<rustc_query_system[1d740a2f543ea37c]::query::caches::SingleCache<rustc_middle[680a3b16fcb54e30]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[33864bfff5ddc18b]::plumbing::QueryCtxt, false>
  23:     0x714380b769cf - rustc_query_impl[33864bfff5ddc18b]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  24:     0x7143809ab9fa - rustc_interface[a1713937163ca6a0]::interface::run_compiler::<core[ec44d53398c8912e]::result::Result<(), rustc_span[d096ceaba54bbd14]::ErrorGuaranteed>, rustc_driver_impl[ff0605cbafb5cd86]::run_compiler::{closure#0}>::{closure#1}
  25:     0x714380a64e10 - std[c093c6b05171ebdd]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[a1713937163ca6a0]::util::run_in_thread_with_globals<rustc_interface[a1713937163ca6a0]::util::run_in_thread_pool_with_globals<rustc_interface[a1713937163ca6a0]::interface::run_compiler<core[ec44d53398c8912e]::result::Result<(), rustc_span[d096ceaba54bbd14]::ErrorGuaranteed>, rustc_driver_impl[ff0605cbafb5cd86]::run_compiler::{closure#0}>::{closure#1}, core[ec44d53398c8912e]::result::Result<(), rustc_span[d096ceaba54bbd14]::ErrorGuaranteed>>::{closure#0}, core[ec44d53398c8912e]::result::Result<(), rustc_span[d096ceaba54bbd14]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ec44d53398c8912e]::result::Result<(), rustc_span[d096ceaba54bbd14]::ErrorGuaranteed>>
  26:     0x714380a6547a - <<std[c093c6b05171ebdd]::thread::Builder>::spawn_unchecked_<rustc_interface[a1713937163ca6a0]::util::run_in_thread_with_globals<rustc_interface[a1713937163ca6a0]::util::run_in_thread_pool_with_globals<rustc_interface[a1713937163ca6a0]::interface::run_compiler<core[ec44d53398c8912e]::result::Result<(), rustc_span[d096ceaba54bbd14]::ErrorGuaranteed>, rustc_driver_impl[ff0605cbafb5cd86]::run_compiler::{closure#0}>::{closure#1}, core[ec44d53398c8912e]::result::Result<(), rustc_span[d096ceaba54bbd14]::ErrorGuaranteed>>::{closure#0}, core[ec44d53398c8912e]::result::Result<(), rustc_span[d096ceaba54bbd14]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ec44d53398c8912e]::result::Result<(), rustc_span[d096ceaba54bbd14]::ErrorGuaranteed>>::{closure#1} as core[ec44d53398c8912e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  27:     0x714380a6586b - std::sys::pal::unix::thread::Thread::new::thread_start::h7725d3f895339174
  28:     0x71437ac94ac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  29:     0x71437ad26850 - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  30:                0x0 - <unknown>

@dtolnay dtolnay 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 Sep 6, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 6, 2024
@gurry
Copy link
Contributor

gurry commented Sep 7, 2024

@rustbot claim

@dtolnay
Copy link
Member Author

dtolnay commented Sep 7, 2024

This did not used to ICE prior to #124988. The PR is in nightly-2024-05-12 and Rust 1.80. The diagnostic from nightly-2024-05-11 before that PR is:

error[E0582]: binding for associated type `Assoc` references lifetime `'v`, which does not appear in the trait input types
 --> src/lib.rs:5:26
  |
5 | trait Trait: for<'v> Fun<Assoc = &'v ()> {}
  |                          ^^^^^^^^^^^^^^

error[E0582]: binding for associated type `Assoc` references lifetime `'v`, which does not appear in the trait input types
 --> src/lib.rs:7:21
  |
7 | impl<F: for<'v> Fun<Assoc = &'v ()>> Trait for F {}
  |                     ^^^^^^^^^^^^^^

error[E0308]: mismatched types
 --> src/lib.rs:7:48
  |
7 | impl<F: for<'v> Fun<Assoc = &'v ()>> Trait for F {}
  |                                                ^ one type is more general than the other
  |
  = note: expected reference `&()`
             found reference `&'v ()`

@dtolnay dtolnay added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Sep 7, 2024
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 7, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 9, 2024
Fix ICE caused by missing span in a region error

Fixes rust-lang#130012

The ICE occurs on line 634 in this error handling code: https://github.com/rust-lang/rust/blob/085744b7ad8b227239bcee0a44cd78dcd0310ab9/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs#L617-L637 It is caused by the span being a dummy span and `!span.is_dummy()` on line 628 evaluating to `false`.

A dummy span, however, is expected here thanks to the `Self: Trait` predicate from `predicates_of` (see line 61): https://github.com/rust-lang/rust/blob/085744b7ad8b227239bcee0a44cd78dcd0310ab9/compiler/rustc_hir_analysis/src/collect/predicates_of.rs#L61-L69

This PR changes the error handling code to omit the note which needed the span instead of ICE'ing in the presence of a dummy span.
@bors bors closed this as completed in 3b0221b Sep 9, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 9, 2024
Rollup merge of rust-lang#130137 - gurry:master, r=cjgillot

Fix ICE caused by missing span in a region error

Fixes rust-lang#130012

The ICE occurs on line 634 in this error handling code: https://github.com/rust-lang/rust/blob/085744b7ad8b227239bcee0a44cd78dcd0310ab9/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs#L617-L637 It is caused by the span being a dummy span and `!span.is_dummy()` on line 628 evaluating to `false`.

A dummy span, however, is expected here thanks to the `Self: Trait` predicate from `predicates_of` (see line 61): https://github.com/rust-lang/rust/blob/085744b7ad8b227239bcee0a44cd78dcd0310ab9/compiler/rustc_hir_analysis/src/collect/predicates_of.rs#L61-L69

This PR changes the error handling code to omit the note which needed the span instead of ICE'ing in the presence of a dummy span.
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 10, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 10, 2024
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) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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