Closed
Description
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
Metadata
Metadata
Assignees
Labels
Category: This is a bug.`#![feature(dyn_compatible_for_dispatch)]`; formerly `object_safe_for_dispatch`Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Status: This bug is tracked inside the repo by a `known-bug` test.Relevant to the compiler team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.