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: error[E0782]: trait objects must include the dyn keyword #120482

Open
matthiaskrgr opened this issue Jan 29, 2024 · 7 comments
Open

ICE: error[E0782]: trait objects must include the dyn keyword #120482

matthiaskrgr opened this issue Jan 29, 2024 · 7 comments
Labels
C-bug Category: This is a bug. F-object_safe_for_dispatch `#![feature(object_safe_for_dispatch)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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):

#![feature(object_safe_for_dispatch)]

trait B {
    fn bar(&self, x: &Self);
}

trait A {
    fn g(new: B) -> B;
}

fn main() {}

original:

// revisions: old new
//[old] edition:2015
//[new] edition:2021
trait B { fn bar(&self, x: &Self); }
//~^ ERROR the trait `A` cannot be made into an object
// revisions: old new
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
//[old]~| WARN this is accepted in the current edition
// other object safety *hard errors* to be suppressed, because we currently
//[old]~| WARN this is accepted in the current edition
trait A { fn g(new: B) -> B; }
//~^ ERROR the trait `B` cannot be made into an object
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
//[old]~| WARN trait objects without an explicit `dyn` are deprecated
//[old]~| WARN this is accepted in the current edition
//[old]~| WARN this is accepted in the current edition
//[old]~| WARN this is accepted in the current edition
fn main() {}

Version information

rustc 1.77.0-nightly (af08c64e3 2024-01-29)
binary: rustc
commit-hash: af08c64e3800fd15f0afdb8651de8fa7dacc0026
commit-date: 2024-01-29
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(object_safe_for_dispatch) --edition=2021

Program output

note: no errors encountered even though `span_delayed_bug` issued

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error[E0782]: trait objects must include the `dyn` keyword
 --> /tmp/icemaker_global_tempdir.FSnI1dXGl0xd/rustc_testrunner_tmpdir_reporting.ycftxsMipEYM/mvce.rs:6:15
  |
6 |     fn g(new: B) -> B;
  |               ^
  |
  = note: `B` it is not object safe, so it can't be `dyn`
note: delayed at compiler/rustc_hir_analysis/src/astconv/lint.rs:228:21
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtInner>::emit_stashed_diagnostics
         2: <rustc_errors::DiagCtxt>::print_error_count
         3: <rustc_session::session::Session>::finish_diagnostics
         4: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
         5: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
         6: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
         7: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/af08c64e3800fd15f0afdb8651de8fa7dacc0026/library/alloc/src/boxed.rs:2015:9
         8: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/af08c64e3800fd15f0afdb8651de8fa7dacc0026/library/alloc/src/boxed.rs:2015:9
         9: std::sys::pal::unix::thread::Thread::new::thread_start
                   at /rustc/af08c64e3800fd15f0afdb8651de8fa7dacc0026/library/std/src/sys/pal/unix/thread.rs:108:17
        10: <unknown>
        11: <unknown>
 --> /tmp/icemaker_global_tempdir.FSnI1dXGl0xd/rustc_testrunner_tmpdir_reporting.ycftxsMipEYM/mvce.rs:6:15
  |
6 |     fn g(new: B) -> B;
  |               ^
help: use a new generic type parameter, constrained by `B`
  |
6 |     fn g<T: B>(new: T) -> B;
  |         ++++++      ~
help: you can also use an opaque type, but users won't be able to specify the type parameter when calling the `fn`, having to rely exclusively on type inference
  |
6 |     fn g(new: impl B) -> B;
  |               ++++

error: internal compiler error[E0782]: trait objects must include the `dyn` keyword
 --> /tmp/icemaker_global_tempdir.FSnI1dXGl0xd/rustc_testrunner_tmpdir_reporting.ycftxsMipEYM/mvce.rs:6:21
  |
6 |     fn g(new: B) -> B;
  |                     ^
  |
note: delayed at compiler/rustc_hir_analysis/src/astconv/lint.rs:228:21
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtInner>::emit_stashed_diagnostics
         2: <rustc_errors::DiagCtxt>::print_error_count
         3: <rustc_session::session::Session>::finish_diagnostics
         4: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
         5: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
         6: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
         7: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/af08c64e3800fd15f0afdb8651de8fa7dacc0026/library/alloc/src/boxed.rs:2015:9
         8: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/af08c64e3800fd15f0afdb8651de8fa7dacc0026/library/alloc/src/boxed.rs:2015:9
         9: std::sys::pal::unix::thread::Thread::new::thread_start
                   at /rustc/af08c64e3800fd15f0afdb8651de8fa7dacc0026/library/std/src/sys/pal/unix/thread.rs:108:17
        10: <unknown>
        11: <unknown>
 --> /tmp/icemaker_global_tempdir.FSnI1dXGl0xd/rustc_testrunner_tmpdir_reporting.ycftxsMipEYM/mvce.rs:6:21
  |
6 |     fn g(new: B) -> B;
  |                     ^
help: `B` is not object safe, use `impl B` to return an opaque type, as long as you return a single underlying type
  |
6 |     fn g(new: B) -> impl B;
  |                     ++++

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.77.0-nightly (af08c64e3 2024-01-29) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(object_safe_for_dispatch) -Z dump-mir-dir=dir

query stack during panic:
end of query stack

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

cc @estebank 😅

@estebank
Copy link
Contributor

💀

@fmease fmease added requires-nightly This issue requires a nightly compiler in some way. F-object_safe_for_dispatch `#![feature(object_safe_for_dispatch)]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 30, 2024
@nnethercote nnethercote self-assigned this Feb 9, 2024
@nnethercote
Copy link
Contributor

I can't reproduce this on the auto-reduced version, only on the original. The presence of the #![feature(object_safe_for_dispatch)] prevents the ICE.

Also, I can reproduce this on a Nightly from January 25, so it's not related to #120828.

@nnethercote nnethercote removed their assignment Feb 9, 2024
@matthiaskrgr
Copy link
Member Author

Sorry, what I mean is that with rustc 1.78.0-nightly (98aa3624b 2024-02-08) this reports

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error[E0782]: trait objects must include the `dyn` keyword
 --> stash.rs:8:15
  |
8 |     fn g(new: B) -> B;
....

but with master f4cfd87 , this talks about stashed errors now in the first ice segment

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: some stashed error is waiting for use
  |
  = note: delayed at compiler/rustc_interface/src/passes.rs:784:31
             0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
             1: <rustc_errors::DiagCtxt>::emit_diagnostic
             2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic_builder::EmissionGuarantee>::emit_producing_guarantee
             3: rustc_interface::passes::analysis
             4: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
             5: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
             6: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
             7: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
             8: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
             9: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            10: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/f4cfd872028398da2b2d85c368c51f4d007dc6af/library/alloc/src/boxed.rs:2015:9
            11: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/f4cfd872028398da2b2d85c368c51f4d007dc6af/library/alloc/src/boxed.rs:2015:9
            12: std::sys::pal::unix::thread::Thread::new::thread_start
                       at /rustc/f4cfd872028398da2b2d85c368c51f4d007dc6af/library/std/src/sys/pal/unix/thread.rs:108:17
            13: <unknown>
            14: <unknown>


error: internal compiler error[E0782]: trait objects must include the `dyn` keyword
 --> stash.rs:8:15
  |
8 |     fn g(new: B) -> B;

which made me think of your PR.

@matthiaskrgr
Copy link
Member Author

I can't reproduce this on the auto-reduced version, only on the original.

did you pass --edition=2021? (this is kinda hidden in the Command line...

@nnethercote
Copy link
Contributor

I did pass -Zcrate-attr='feature(object_safe_for_dispatch)' --edition=2021. But I didn't pay attention to the ICE contents. I'll take another look on Monday morning.

@nnethercote
Copy link
Contributor

I've worked out the basics of what is happening.

  • The "trait objects must include the dyn keyword" error is created and stashed here.
  • Before being stashed, the diagnostic is passed to AstConv::maybe_lint_impl_trait, which downgrades it from level Error to level DelayedBug, here.
  • The diagnostic is never stolen and emitted.
  • We get to the end of analysis. There have been no errors emitted but there is a stashed error, so we end up here, in code added by Fix ErrorGuaranteed unsoundness with stash/steal. #120828. This code emits the "some stashed error is waiting for use" delayed bug, which involves appending it to the (previously empty) list of delayed bugs.
  • We eventually get to emit_stashed_diagnostic. The stashed "trait objects must include the dyn keyword" error is emitted. Because it's a delayed bug, emission involves adding it to the list of delayed bugs, after the "some stashed error is waiting for use" delayed bug.
  • We eventually flush all the delayed bugs, and the "some stashed error is waiting for use" delayed bug is printed as an ICE, followed by the "trait objects must include the dyn keyword" error.

It's a pretty weird sequence, and the "some stashed error is waiting for use" delayed bug added in #120828 is an innocent bystander. The weird sequence causes it to ICE first, but really the "trait objects must include the dyn keyword" error is at fault. It's bizarre to create an error, downgrade it to a delayed bug, stash it, and never steal it and emit/cancel it. (That sequence causes an ICE.) I'm not sure where the problem lies. Perhaps it shouldn't be downgraded? Perhaps it shouldn't be stashed? Perhaps it should be stolen and emitted/cancelled? Any one of those would avoid the ICE. I don't know enough about that particular error to know which is appropriate, and I'll leave it to someone who does know more to take it from here.

I gotta say, the more I interact with stashed diagnostics, the less I like them. There is all sorts of complexity and opportunity for mistakes, as #120828 and this issue both demonstrate :(

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 15, 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. F-object_safe_for_dispatch `#![feature(object_safe_for_dispatch)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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

5 participants