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: still mutable #121504

Closed
matthiaskrgr opened this issue Feb 23, 2024 · 1 comment
Closed

ICE: still mutable #121504

matthiaskrgr opened this issue Feb 23, 2024 · 1 comment
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

auto-reduced (treereduce-rust):

trait MyTrait<'a, 'b, T> {
    async fn foo(&'a self) -> (&'a Self, &'b T);
}

impl<'a, 'b, T, U> MyTrait<'a, 'b, T> for issue_42007_s::E {
    async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
        (self, key)
    }
}

fn main() {}

original:

//@ check-pass
//@ edition: 2021

use std::fmt::Debug;

trait MyTrait<'a, 'b, T> {
    #[allow(async_fn_in_trait)]
    async fn foo(&'a self, key: &'b T) -> (&'a Self, &'b T) where T: Debug + Sized;
}

impl<'a, 'b, T, U> MyTrait<'a, 'b, T> for issue_42007_s::E {
    async fn foo(&'a self, key: &'b T) -> (&'a U, &'b T) {
        (self, key)
    }
}

fn main() {}

Version information

rustc 1.78.0-nightly (6dadb6eb2 2024-02-23)
binary: rustc
commit-hash: 6dadb6eb23e7719da4e372d3e13d50282323d022
commit-date: 2024-02-23
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --edition=2021

Program output

thread 'rustc' panicked at compiler/rustc_middle/src/ty/context.rs:1081:49:
still mutable
stack backtrace:
   0:     0x7f7510649af6 - std::backtrace_rs::backtrace::libunwind::trace::ha65d3ff76184bc87
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f7510649af6 - std::backtrace_rs::backtrace::trace_unsynchronized::hf7ea96d3ce514b82
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f7510649af6 - std::sys_common::backtrace::_print_fmt::hfd298e4a770e9899
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f7510649af6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2323338a86fc81c9
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f751069aa7c - core::fmt::rt::Argument::fmt::h157eaeeeb24bb72e
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/core/src/fmt/rt.rs:142:9
   5:     0x7f751069aa7c - core::fmt::write::heaac4748a4770443
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f751063e4bf - std::io::Write::write_fmt::h9259032badca1042
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/std/src/io/mod.rs:1846:15
   7:     0x7f75106498a4 - std::sys_common::backtrace::_print::hc92d5e2a4404e26e
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f75106498a4 - std::sys_common::backtrace::print::ha2a94ce768edf33a
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f751064c5eb - std::panicking::default_hook::{{closure}}::h76871112b9e556f7
  10:     0x7f751064c339 - std::panicking::default_hook::hf74de90c4b5df7a9
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/std/src/panicking.rs:292:9
  11:     0x7f750d273c9c - std[dd5750cd74b4d211]::panicking::update_hook::<alloc[3a2d298fa1f4f8a8]::boxed::Box<rustc_driver_impl[c7e2e991238ea07f]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f751064cd50 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hb795ef914b920bc4
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/alloc/src/boxed.rs:2030:9
  13:     0x7f751064cd50 - std::panicking::rust_panic_with_hook::h098a2e3444b7237d
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/std/src/panicking.rs:786:13
  14:     0x7f751064ca92 - std::panicking::begin_panic_handler::{{closure}}::h5f48db142282f4a3
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/std/src/panicking.rs:660:13
  15:     0x7f7510649fd6 - std::sys_common::backtrace::__rust_end_short_backtrace::h796b10403fb4a449
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f751064c7c4 - rust_begin_unwind
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/std/src/panicking.rs:648:5
  17:     0x7f7510696f95 - core::panicking::panic_fmt::ha9656bb7a57ce9d1
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/core/src/panicking.rs:72:14
  18:     0x7f7510697161 - core::panicking::panic_display::hb31811a514c0b471
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/core/src/panicking.rs:196:5
  19:     0x7f7510696d4b - core::panicking::panic_str::h5160a5f49cb541c1
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/core/src/panicking.rs:171:5
  20:     0x7f7510696d4b - core::option::expect_failed::h66de889988625824
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/core/src/option.rs:1994:5
  21:     0x7f750bbc0f6e - <rustc_middle[e10bafab6a476256]::ty::context::TyCtxt>::create_def
  22:     0x7f750ed83f5d - <rustc_middle[e10bafab6a476256]::query::plumbing::TyCtxtAt>::create_def
  23:     0x7f750de024b3 - rustc_ty_utils[89e9476db130c1ea]::assoc::associated_type_for_impl_trait_in_impl
  24:     0x7f750ee88367 - rustc_ty_utils[89e9476db130c1ea]::assoc::associated_types_for_impl_traits_in_associated_fn
  25:     0x7f750ee87ff4 - rustc_query_impl[57e36b29e5bd967b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[57e36b29e5bd967b]::query_impl::associated_types_for_impl_traits_in_associated_fn::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e10bafab6a476256]::query::erase::Erased<[u8; 16usize]>>
  26:     0x7f750ee87fc9 - <rustc_query_impl[57e36b29e5bd967b]::query_impl::associated_types_for_impl_traits_in_associated_fn::dynamic_query::{closure#2} as core[169382930dc0d056]::ops::function::FnOnce<(rustc_middle[e10bafab6a476256]::ty::context::TyCtxt, rustc_span[ba27dc81bf59733]::def_id::DefId)>>::call_once
  27:     0x7f750e95e480 - rustc_query_system[2e43c3a675bb3873]::query::plumbing::try_execute_query::<rustc_query_impl[57e36b29e5bd967b]::DynamicConfig<rustc_query_system[2e43c3a675bb3873]::query::caches::DefIdCache<rustc_middle[e10bafab6a476256]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[57e36b29e5bd967b]::plumbing::QueryCtxt, false>
  28:     0x7f750ee87f21 - rustc_query_impl[57e36b29e5bd967b]::query_impl::associated_types_for_impl_traits_in_associated_fn::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7f750ee87d1a - rustc_middle[e10bafab6a476256]::query::plumbing::query_get_at::<rustc_query_system[2e43c3a675bb3873]::query::caches::DefIdCache<rustc_middle[e10bafab6a476256]::query::erase::Erased<[u8; 16usize]>>>
  30:     0x7f750ee8753b - rustc_arena[ebbf555319a4d9fc]::outline::<<rustc_arena[ebbf555319a4d9fc]::DroplessArena>::alloc_from_iter<rustc_span[ba27dc81bf59733]::def_id::DefId, core[169382930dc0d056]::iter::adapters::chain::Chain<core[169382930dc0d056]::iter::adapters::map::Map<core[169382930dc0d056]::slice::iter::Iter<rustc_hir[9f3737e52b7f217]::hir::ImplItemRef>, rustc_ty_utils[89e9476db130c1ea]::assoc::associated_item_def_ids::{closure#3}>, core[169382930dc0d056]::iter::adapters::flatten::FlatMap<core[169382930dc0d056]::option::Iter<rustc_hir[9f3737e52b7f217]::hir::TraitRef>, core[169382930dc0d056]::iter::adapters::copied::Copied<core[169382930dc0d056]::iter::adapters::flatten::FlatMap<core[169382930dc0d056]::iter::adapters::filter::Filter<core[169382930dc0d056]::slice::iter::Iter<rustc_hir[9f3737e52b7f217]::hir::ImplItemRef>, rustc_ty_utils[89e9476db130c1ea]::assoc::associated_item_def_ids::{closure#4}::{closure#0}>, &[rustc_span[ba27dc81bf59733]::def_id::DefId], rustc_ty_utils[89e9476db130c1ea]::assoc::associated_item_def_ids::{closure#4}::{closure#1}>>, rustc_ty_utils[89e9476db130c1ea]::assoc::associated_item_def_ids::{closure#4}>>>::{closure#0}, &mut [rustc_span[ba27dc81bf59733]::def_id::DefId]>
  31:     0x7f750e72858c - rustc_ty_utils[89e9476db130c1ea]::assoc::associated_item_def_ids
  32:     0x7f750e95e001 - rustc_query_impl[57e36b29e5bd967b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[57e36b29e5bd967b]::query_impl::associated_item_def_ids::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e10bafab6a476256]::query::erase::Erased<[u8; 16usize]>>
  33:     0x7f750e95dfd5 - <rustc_query_impl[57e36b29e5bd967b]::query_impl::associated_item_def_ids::dynamic_query::{closure#2} as core[169382930dc0d056]::ops::function::FnOnce<(rustc_middle[e10bafab6a476256]::ty::context::TyCtxt, rustc_span[ba27dc81bf59733]::def_id::DefId)>>::call_once
  34:     0x7f750e95e480 - rustc_query_system[2e43c3a675bb3873]::query::plumbing::try_execute_query::<rustc_query_impl[57e36b29e5bd967b]::DynamicConfig<rustc_query_system[2e43c3a675bb3873]::query::caches::DefIdCache<rustc_middle[e10bafab6a476256]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[57e36b29e5bd967b]::plumbing::QueryCtxt, false>
  35:     0x7f750e95dded - rustc_query_impl[57e36b29e5bd967b]::query_impl::associated_item_def_ids::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7f750f630f46 - rustc_passes[c03e7a54580598e2]::dead::live_symbols_and_ignored_derived_traits
  37:     0x7f750f62f254 - rustc_query_impl[57e36b29e5bd967b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[57e36b29e5bd967b]::query_impl::live_symbols_and_ignored_derived_traits::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e10bafab6a476256]::query::erase::Erased<[u8; 8usize]>>
  38:     0x7f750f38af4e - rustc_query_system[2e43c3a675bb3873]::query::plumbing::try_execute_query::<rustc_query_impl[57e36b29e5bd967b]::DynamicConfig<rustc_query_system[2e43c3a675bb3873]::query::caches::SingleCache<rustc_middle[e10bafab6a476256]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[57e36b29e5bd967b]::plumbing::QueryCtxt, false>
  39:     0x7f750f0bd642 - rustc_query_impl[57e36b29e5bd967b]::query_impl::live_symbols_and_ignored_derived_traits::get_query_non_incr::__rust_end_short_backtrace
  40:     0x7f750f0bd7e3 - rustc_passes[c03e7a54580598e2]::dead::check_mod_deathness
  41:     0x7f750f0bd667 - rustc_query_impl[57e36b29e5bd967b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[57e36b29e5bd967b]::query_impl::check_mod_deathness::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e10bafab6a476256]::query::erase::Erased<[u8; 0usize]>>
  42:     0x7f750f21036d - rustc_query_system[2e43c3a675bb3873]::query::plumbing::try_execute_query::<rustc_query_impl[57e36b29e5bd967b]::DynamicConfig<rustc_query_system[2e43c3a675bb3873]::query::caches::DefaultCache<rustc_span[ba27dc81bf59733]::def_id::LocalModDefId, rustc_middle[e10bafab6a476256]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[57e36b29e5bd967b]::plumbing::QueryCtxt, false>
  43:     0x7f750f20bfff - rustc_query_impl[57e36b29e5bd967b]::query_impl::check_mod_deathness::get_query_non_incr::__rust_end_short_backtrace
  44:     0x7f750f2080cb - rustc_interface[4e9aee6b98c8cda]::passes::analysis
  45:     0x7f750f206e19 - rustc_query_impl[57e36b29e5bd967b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[57e36b29e5bd967b]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e10bafab6a476256]::query::erase::Erased<[u8; 1usize]>>
  46:     0x7f750f3210a5 - rustc_query_system[2e43c3a675bb3873]::query::plumbing::try_execute_query::<rustc_query_impl[57e36b29e5bd967b]::DynamicConfig<rustc_query_system[2e43c3a675bb3873]::query::caches::SingleCache<rustc_middle[e10bafab6a476256]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[57e36b29e5bd967b]::plumbing::QueryCtxt, false>
  47:     0x7f750f320e09 - rustc_query_impl[57e36b29e5bd967b]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  48:     0x7f750f3302d6 - rustc_interface[4e9aee6b98c8cda]::interface::run_compiler::<core[169382930dc0d056]::result::Result<(), rustc_span[ba27dc81bf59733]::ErrorGuaranteed>, rustc_driver_impl[c7e2e991238ea07f]::run_compiler::{closure#0}>::{closure#0}
  49:     0x7f750f5c09cd - std[dd5750cd74b4d211]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[4e9aee6b98c8cda]::util::run_in_thread_with_globals<rustc_interface[4e9aee6b98c8cda]::util::run_in_thread_pool_with_globals<rustc_interface[4e9aee6b98c8cda]::interface::run_compiler<core[169382930dc0d056]::result::Result<(), rustc_span[ba27dc81bf59733]::ErrorGuaranteed>, rustc_driver_impl[c7e2e991238ea07f]::run_compiler::{closure#0}>::{closure#0}, core[169382930dc0d056]::result::Result<(), rustc_span[ba27dc81bf59733]::ErrorGuaranteed>>::{closure#0}, core[169382930dc0d056]::result::Result<(), rustc_span[ba27dc81bf59733]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[169382930dc0d056]::result::Result<(), rustc_span[ba27dc81bf59733]::ErrorGuaranteed>>
  50:     0x7f750f5c07fa - <<std[dd5750cd74b4d211]::thread::Builder>::spawn_unchecked_<rustc_interface[4e9aee6b98c8cda]::util::run_in_thread_with_globals<rustc_interface[4e9aee6b98c8cda]::util::run_in_thread_pool_with_globals<rustc_interface[4e9aee6b98c8cda]::interface::run_compiler<core[169382930dc0d056]::result::Result<(), rustc_span[ba27dc81bf59733]::ErrorGuaranteed>, rustc_driver_impl[c7e2e991238ea07f]::run_compiler::{closure#0}>::{closure#0}, core[169382930dc0d056]::result::Result<(), rustc_span[ba27dc81bf59733]::ErrorGuaranteed>>::{closure#0}, core[169382930dc0d056]::result::Result<(), rustc_span[ba27dc81bf59733]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[169382930dc0d056]::result::Result<(), rustc_span[ba27dc81bf59733]::ErrorGuaranteed>>::{closure#1} as core[169382930dc0d056]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  51:     0x7f7510656725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h805908c663ab5fb8
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/alloc/src/boxed.rs:2016:9
  52:     0x7f7510656725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h42041a05506d3149
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/alloc/src/boxed.rs:2016:9
  53:     0x7f7510656725 - std::sys::pal::unix::thread::Thread::new::thread_start::h93419657116bfcaf
                               at /rustc/6dadb6eb23e7719da4e372d3e13d50282323d022/library/std/src/sys/pal/unix/thread.rs:108:17
  54:     0x7f750a2aa9eb - <unknown>
  55:     0x7f750a32e7cc - <unknown>
  56:                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.78.0-nightly (6dadb6eb2 2024-02-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dump-mir-dir=dir

query stack during panic:
#0 [associated_types_for_impl_traits_in_associated_fn] creating associated items for impl trait in trait returned by `<impl at /tmp/icemaker_global_tempdir.CuM0Qo7qmTkw/rustc_testrunner_tmpdir_reporting.97qZh51fHmla/mvce.rs:5:1: 5:59>::foo`
#1 [associated_item_def_ids] collecting associated items or fields of `<impl at /tmp/icemaker_global_tempdir.CuM0Qo7qmTkw/rustc_testrunner_tmpdir_reporting.97qZh51fHmla/mvce.rs:5:1: 5:59>`
#2 [live_symbols_and_ignored_derived_traits] finding live symbols in crate
#3 [check_mod_deathness] checking deathness of variables in top-level module
#4 [analysis] running analysis passes on this crate
end of query stack
error[E0433]: failed to resolve: use of undeclared crate or module `issue_42007_s`
 --> /tmp/icemaker_global_tempdir.CuM0Qo7qmTkw/rustc_testrunner_tmpdir_reporting.97qZh51fHmla/mvce.rs:5:43
  |
5 | impl<'a, 'b, T, U> MyTrait<'a, 'b, T> for issue_42007_s::E {
  |                                           ^^^^^^^^^^^^^ use of undeclared crate or module `issue_42007_s`

error: aborting due to 1 previous error

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

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

#121206 cc @nnethercote

@nnethercote nnethercote self-assigned this Feb 26, 2024
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 26, 2024
nnethercote added a commit to nnethercote/rust that referenced this issue Feb 27, 2024
Stashed errors used to be counted as errors, but could then be
cancelled, leading to `ErrorGuaranteed` soundness holes. rust-lang#120828 changed
that, closing the soundness hole. But it introduced other difficulties
because you sometimes have to account for pending stashed errors when
making decisions about whether errors have occured/will occur and it's
easy to overlook these.

This commit aims for a middle ground.
- Stashed errors (not warnings) are counted immediately as emitted
  errors, avoiding the possibility of forgetting to consider them.
- The ability to cancel (or downgrade) stashed errors is eliminated, by
  disallowing the use of `steal_diagnostic` with errors, and introducing
  the more restrictive methods `try_steal_{modify,replace}_and_emit_err`
  that can be used instead.

Other things:
- `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both
  return `Option<ErrorGuaranteed>`, which enables the removal of two
  `delayed_bug` calls and one `Ty::new_error_with_message` call. This is
  possible because we store error guarantees in
  `DiagCtxt::stashed_diagnostics`.
- Storing the guarantees also saves us having to maintain a counter.
- Calls to the `stashed_err_count` method are no longer necessary
  alongside calls to `has_errors`, which is a nice simplification, and
  eliminates two more `span_delayed_bug` calls and one FIXME comment.
- Tests are added for three of the four fixed PRs mentioned below.
- `issue-121108.rs`'s output improved slightly, omitting a non-useful
  error message.

Fixes rust-lang#121451.
Fixes rust-lang#121477.
Fixes rust-lang#121504.
Fixes rust-lang#121508.
nnethercote added a commit to nnethercote/rust that referenced this issue Feb 27, 2024
Stashed errors used to be counted as errors, but could then be
cancelled, leading to `ErrorGuaranteed` soundness holes. rust-lang#120828 changed
that, closing the soundness hole. But it introduced other difficulties
because you sometimes have to account for pending stashed errors when
making decisions about whether errors have occured/will occur and it's
easy to overlook these.

This commit aims for a middle ground.
- Stashed errors (not warnings) are counted immediately as emitted
  errors, avoiding the possibility of forgetting to consider them.
- The ability to cancel (or downgrade) stashed errors is eliminated, by
  disallowing the use of `steal_diagnostic` with errors, and introducing
  the more restrictive methods `try_steal_{modify,replace}_and_emit_err`
  that can be used instead.

Other things:
- `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both
  return `Option<ErrorGuaranteed>`, which enables the removal of two
  `delayed_bug` calls and one `Ty::new_error_with_message` call. This is
  possible because we store error guarantees in
  `DiagCtxt::stashed_diagnostics`.
- Storing the guarantees also saves us having to maintain a counter.
- Calls to the `stashed_err_count` method are no longer necessary
  alongside calls to `has_errors`, which is a nice simplification, and
  eliminates two more `span_delayed_bug` calls and one FIXME comment.
- Tests are added for three of the four fixed PRs mentioned below.
- `issue-121108.rs`'s output improved slightly, omitting a non-useful
  error message.

Fixes rust-lang#121451.
Fixes rust-lang#121477.
Fixes rust-lang#121504.
Fixes rust-lang#121508.
nnethercote added a commit to nnethercote/rust that referenced this issue Feb 27, 2024
Stashed errors used to be counted as errors, but could then be
cancelled, leading to `ErrorGuaranteed` soundness holes. rust-lang#120828 changed
that, closing the soundness hole. But it introduced other difficulties
because you sometimes have to account for pending stashed errors when
making decisions about whether errors have occured/will occur and it's
easy to overlook these.

This commit aims for a middle ground.
- Stashed errors (not warnings) are counted immediately as emitted
  errors, avoiding the possibility of forgetting to consider them.
- The ability to cancel (or downgrade) stashed errors is eliminated, by
  disallowing the use of `steal_diagnostic` with errors, and introducing
  the more restrictive methods `try_steal_{modify,replace}_and_emit_err`
  that can be used instead.

Other things:
- `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both
  return `Option<ErrorGuaranteed>`, which enables the removal of two
  `delayed_bug` calls and one `Ty::new_error_with_message` call. This is
  possible because we store error guarantees in
  `DiagCtxt::stashed_diagnostics`.
- Storing the guarantees also saves us having to maintain a counter.
- Calls to the `stashed_err_count` method are no longer necessary
  alongside calls to `has_errors`, which is a nice simplification, and
  eliminates two more `span_delayed_bug` calls and one FIXME comment.
- Tests are added for three of the four fixed PRs mentioned below.
- `issue-121108.rs`'s output improved slightly, omitting a non-useful
  error message.

Fixes rust-lang#121451.
Fixes rust-lang#121477.
Fixes rust-lang#121504.
Fixes rust-lang#121508.
@bors bors closed this as completed in 260ae70 Feb 29, 2024
nnethercote added a commit to nnethercote/rust that referenced this issue Mar 1, 2024
Stashed errors used to be counted as errors, but could then be
cancelled, leading to `ErrorGuaranteed` soundness holes. rust-lang#120828 changed
that, closing the soundness hole. But it introduced other difficulties
because you sometimes have to account for pending stashed errors when
making decisions about whether errors have occured/will occur and it's
easy to overlook these.

This commit aims for a middle ground.
- Stashed errors (not warnings) are counted immediately as emitted
  errors, avoiding the possibility of forgetting to consider them.
- The ability to cancel (or downgrade) stashed errors is eliminated, by
  disallowing the use of `steal_diagnostic` with errors, and introducing
  the more restrictive methods `try_steal_{modify,replace}_and_emit_err`
  that can be used instead.

Other things:
- `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both
  return `Option<ErrorGuaranteed>`, which enables the removal of two
  `delayed_bug` calls and one `Ty::new_error_with_message` call. This is
  possible because we store error guarantees in
  `DiagCtxt::stashed_diagnostics`.
- Storing the guarantees also saves us having to maintain a counter.
- Calls to the `stashed_err_count` method are no longer necessary
  alongside calls to `has_errors`, which is a nice simplification, and
  eliminates two more `span_delayed_bug` calls and one FIXME comment.
- Tests are added for three of the four fixed PRs mentioned below.
- `issue-121108.rs`'s output improved slightly, omitting a non-useful
  error message.

Fixes rust-lang#121451.
Fixes rust-lang#121477.
Fixes rust-lang#121504.
Fixes rust-lang#121508.
flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 7, 2024
Stashed errors used to be counted as errors, but could then be
cancelled, leading to `ErrorGuaranteed` soundness holes. rust-lang#120828 changed
that, closing the soundness hole. But it introduced other difficulties
because you sometimes have to account for pending stashed errors when
making decisions about whether errors have occured/will occur and it's
easy to overlook these.

This commit aims for a middle ground.
- Stashed errors (not warnings) are counted immediately as emitted
  errors, avoiding the possibility of forgetting to consider them.
- The ability to cancel (or downgrade) stashed errors is eliminated, by
  disallowing the use of `steal_diagnostic` with errors, and introducing
  the more restrictive methods `try_steal_{modify,replace}_and_emit_err`
  that can be used instead.

Other things:
- `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both
  return `Option<ErrorGuaranteed>`, which enables the removal of two
  `delayed_bug` calls and one `Ty::new_error_with_message` call. This is
  possible because we store error guarantees in
  `DiagCtxt::stashed_diagnostics`.
- Storing the guarantees also saves us having to maintain a counter.
- Calls to the `stashed_err_count` method are no longer necessary
  alongside calls to `has_errors`, which is a nice simplification, and
  eliminates two more `span_delayed_bug` calls and one FIXME comment.
- Tests are added for three of the four fixed PRs mentioned below.
- `issue-121108.rs`'s output improved slightly, omitting a non-useful
  error message.

Fixes rust-lang#121451.
Fixes rust-lang#121477.
Fixes rust-lang#121504.
Fixes rust-lang#121508.
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

No branches or pull requests

4 participants