Skip to content

Compiler panicks when impl for async trait has a mismatch #104183

Closed
@WhyNotHugo

Description

@WhyNotHugo

Essentially, if my trait has async fn do(s: &String) and my impl has async fn do(s: String) the compiler panics.

Note that the code is invalid and compilation should fail.

Meta

rustc --version --verbose:

x rustc --version --verbose
rustc 1.67.0-nightly (1286ee23e 2022-11-05)
binary: rustc
commit-hash: 1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82
commit-date: 2022-11-05
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Error output

> cargo build
   Compiling vstorage v0.1.0 (/home/hugo/clones/codeberg.org/WhyNotHugo/vdirsyncer.rs/vstorage)
warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
 --> vstorage/src/lib.rs:4:12
  |
4 | #![feature(async_fn_in_trait)]
  |            ^^^^^^^^^^^^^^^^^
  |
  = note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: field `read_only` is never read
  --> vstorage/src/filesystem.rs:25:5
   |
23 | pub struct FilesystemStorage {
   |            ----------------- field in this struct
24 |     path: PathBuf,
25 |     read_only: bool,
   |     ^^^^^^^^^
   |
   = note: `#[warn(dead_code)]` on by default

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: could not unify `fn(&FilesystemCollection, &String) -> _` and `fn(&FilesystemCollection, String) -> impl Future<Output = Result<(Item, String), std::io::Error>>`: ArgumentSorts(ExpectedFound { expected: &std::string::String, found: std::string::String }, 1)
   --> vstorage/src/filesystem.rs:132:42
    |
132 |     async fn get(&self, href: String) -> Result<(Item, Etag)> {
    |                                          ^^^^^^^^^^^^^^^^^^^^
    |
    = note: delayed at compiler/rustc_hir_analysis/src/check/compare_method.rs:529:33

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/project.rs:2295:41

error: internal compiler error[E0053]: method `get` has an incompatible type for trait
   --> vstorage/src/filesystem.rs:132:31
    |
132 |     async fn get(&self, href: String) -> Result<(Item, Etag)> {
    |                               ^^^^^^ help: change the parameter type to match the trait: `&String`
    |
note: while checking the return type of the `async fn`
   --> vstorage/src/filesystem.rs:132:42
    |
132 |     async fn get(&self, href: String) -> Result<(Item, Etag)> {
    |                                          ^^^^^^^^^^^^^^^^^^^^ checked the `Output` of this `async fn`, found opaque type

error: internal compiler error: could not unify `fn(&FilesystemCollection, &Vec<String>) -> _` and `fn(&FilesystemCollection, Vec<String>) -> impl Future<Output = Result<Vec<(Item, String)>, std::io::Error>>`: ArgumentSorts(ExpectedFound { expected: &std::vec::Vec<std::string::String>, found: std::vec::Vec<std::string::String> }, 1)
   --> vstorage/src/filesystem.rs:144:53
    |
144 |     async fn get_many(&self, hrefs: Vec<String>) -> Result<Vec<(Item, Etag)>> {
    |                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: delayed at compiler/rustc_hir_analysis/src/check/compare_method.rs:529:33

error: internal compiler error[E0053]: method `get_many` has an incompatible type for trait
   --> vstorage/src/filesystem.rs:144:37
    |
144 |     async fn get_many(&self, hrefs: Vec<String>) -> Result<Vec<(Item, Etag)>> {
    |                                     ^^^^^^^^^^^ help: change the parameter type to match the trait: `&Vec<String>`
    |
note: while checking the return type of the `async fn`
   --> vstorage/src/filesystem.rs:144:53
    |
144 |     async fn get_many(&self, hrefs: Vec<String>) -> Result<Vec<(Item, Etag)>> {
    |                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^ checked the `Output` of this `async fn`, found opaque type

error: internal compiler error: could not unify `fn(&mut FilesystemCollection, &String, &String, &Item) -> _` and `fn(&mut FilesystemCollection, String, String, &Item) -> impl Future<Output = Result<String, std::io::Error>>`: ArgumentSorts(ExpectedFound { expected: &std::string::String, found: std::string::String }, 1)
   --> vstorage/src/filesystem.rs:198:76
    |
198 |     async fn update(&mut self, href: String, etag: String, item: &Item) -> Result<Etag> {
    |                                                                            ^^^^^^^^^^^^
    |
    = note: delayed at compiler/rustc_hir_analysis/src/check/compare_method.rs:529:33

error: internal compiler error[E0053]: method `update` has an incompatible type for trait
   --> vstorage/src/filesystem.rs:198:38
    |
198 |     async fn update(&mut self, href: String, etag: String, item: &Item) -> Result<Etag> {
    |                                      ^^^^^^ help: change the parameter type to match the trait: `&String`
    |
note: while checking the return type of the `async fn`
   --> vstorage/src/filesystem.rs:198:76
    |
198 |     async fn update(&mut self, href: String, etag: String, item: &Item) -> Result<Etag> {
    |                                                                            ^^^^^^^^^^^^ checked the `Output` of this `async fn`, found opaque type

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs:730:23

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_hir_typeck/src/coercion.rs:176:49

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs:118:29

error: internal compiler error: `InferCtxt` incorrectly tainted by errors
  |
  = note: delayed at compiler/rustc_infer/src/infer/mod.rs:1256:27

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_hir_typeck/src/coercion.rs:1028:53

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_hir_typeck/src/fallback.rs:109:58

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/compiler/rustc_middle/src/ty/relate.rs:419:59

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/project.rs:1242:30

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_infer/src/infer/sub.rs:121:31

error: internal compiler error: expected fullfillment errors
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs:459:23

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_mir_build/src/build/mod.rs:621:18

error: internal compiler error: broken MIR in DefId(0:183 ~ vstorage[9b4b]::filesystem::{impl#2}::get_many) ("return type"): bad type [type error]
   --> vstorage/src/filesystem.rs:144:5
    |
144 |     async fn get_many(&self, hrefs: Vec<String>) -> Result<Vec<(Item, Etag)>> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:520:13

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:797:20

error: internal compiler error: broken MIR in DefId(0:183 ~ vstorage[9b4b]::filesystem::{impl#2}::get_many) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: vstorage/src/filesystem.rs:144:5: 144:78 (#0), scope: scope[0] } }): bad type [type error]
   --> vstorage/src/filesystem.rs:144:5
    |
144 |     async fn get_many(&self, hrefs: Vec<String>) -> Result<Vec<(Item, Etag)>> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:520:13

error: internal compiler error: TyKind::Error constructed but no error reported
  |
  = note: delayed at compiler/rustc_hir_analysis/src/collect/type_of.rs:824:17

error: internal compiler error: broken MIR in DefId(0:185 ~ vstorage[9b4b]::filesystem::{impl#2}::get_many::{closure#0}) ("return type"): bad type [type error]
   --> vstorage/src/filesystem.rs:144:79
    |
144 |       async fn get_many(&self, hrefs: Vec<String>) -> Result<Vec<(Item, Etag)>> {
    |  _______________________________________________________________________________^
145 | |         // No specialisation for this type; it's fast enough for now.
146 | |         let mut items = Vec::with_capacity(hrefs.len());
147 | |         for href in hrefs {
...   |
150 | |         Ok(items)
151 | |     }
    | |_____^
    |
    = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:520:13

error: internal compiler error: broken MIR in DefId(0:185 ~ vstorage[9b4b]::filesystem::{impl#2}::get_many::{closure#0}) (LocalDecl { mutability: Mut, local_info: None, internal: false, is_block_tail: None, ty: [type error], user_ty: None, source_info: SourceInfo { span: vstorage/src/filesystem.rs:144:79: 151:6 (#0), scope: scope[0] } }): bad type [type error]
   --> vstorage/src/filesystem.rs:144:79
    |
144 |       async fn get_many(&self, hrefs: Vec<String>) -> Result<Vec<(Item, Etag)>> {
    |  _______________________________________________________________________________^
145 | |         // No specialisation for this type; it's fast enough for now.
146 | |         let mut items = Vec::with_capacity(hrefs.len());
147 | |         for href in hrefs {
...   |
150 | |         Ok(items)
151 | |     }
    | |_____^
    |
    = note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:520:13

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1585:13
stack backtrace:
   0:     0x7f8e36468f90 - std::backtrace_rs::backtrace::libunwind::trace::he1ec9308d56754ef
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f8e36468f90 - std::backtrace_rs::backtrace::trace_unsynchronized::h5c2c7548e45673aa
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f8e36468f90 - std::sys_common::backtrace::_print_fmt::h8a3c0940409c1027
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f8e36468f90 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h61aef9b82866f95a
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f8e325c8bae - core::fmt::write::h7d5b70072d28dbfa
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/core/src/fmt/mod.rs:1209:17
   5:     0x7f8e3645d075 - std::io::Write::write_fmt::h3d31360947679d21
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/std/src/io/mod.rs:1682:15
   6:     0x7f8e36468d55 - std::sys_common::backtrace::_print::h6759e5b850bdca22
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f8e36468d55 - std::sys_common::backtrace::print::h1ad0f6b710bf019e
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f8e3646b06f - std::panicking::default_hook::{{closure}}::hd26f3c852c581cdf
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/std/src/panicking.rs:267:22
   9:     0x7f8e3646adaa - std::panicking::default_hook::h92c20606c36e74d2
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/std/src/panicking.rs:286:9
  10:     0x7f8e356ef154 - rustc_driver[f3db849b868bf2ae]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f8e3646b85d - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h33523ae862b9476b
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/alloc/src/boxed.rs:2001:9
  12:     0x7f8e3646b85d - std::panicking::rust_panic_with_hook::hc9f74d355270b517
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/std/src/panicking.rs:692:13
  13:     0x7f8e35756511 - std[3f3511bd14de1a0b]::panicking::begin_panic::<rustc_errors[35630e0ab5d06bf2]::ExplicitBug>::{closure#0}
  14:     0x7f8e35754ca6 - std[3f3511bd14de1a0b]::sys_common::backtrace::__rust_end_short_backtrace::<std[3f3511bd14de1a0b]::panicking::begin_panic<rustc_errors[35630e0ab5d06bf2]::ExplicitBug>::{closure#0}, !>
  15:     0x7f8e35754c76 - std[3f3511bd14de1a0b]::panicking::begin_panic::<rustc_errors[35630e0ab5d06bf2]::ExplicitBug>
  16:     0x7f8e357510c6 - std[3f3511bd14de1a0b]::panic::panic_any::<rustc_errors[35630e0ab5d06bf2]::ExplicitBug>
  17:     0x7f8e34cac288 - <rustc_errors[35630e0ab5d06bf2]::HandlerInner>::flush_delayed::<alloc[8a94a0f38e11af27]::vec::Vec<rustc_errors[35630e0ab5d06bf2]::diagnostic::Diagnostic>, &str>
  18:     0x7f8e34aa5dbe - <rustc_interface[524480e3db7d7602]::passes::QueryContext>::enter::<<rustc_interface[524480e3db7d7602]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[449086d7d8ac0eaf]::result::Result<alloc[8a94a0f38e11af27]::boxed::Box<dyn core[449086d7d8ac0eaf]::any::Any>, rustc_errors[35630e0ab5d06bf2]::ErrorGuaranteed>>
  19:     0x7f8e34a660b3 - <rustc_interface[524480e3db7d7602]::queries::Queries>::ongoing_codegen
  20:     0x7f8e34a651c2 - <rustc_interface[524480e3db7d7602]::interface::Compiler>::enter::<rustc_driver[f3db849b868bf2ae]::run_compiler::{closure#1}::{closure#2}, core[449086d7d8ac0eaf]::result::Result<core[449086d7d8ac0eaf]::option::Option<rustc_interface[524480e3db7d7602]::queries::Linker>, rustc_errors[35630e0ab5d06bf2]::ErrorGuaranteed>>
  21:     0x7f8e34a60202 - rustc_span[a814485cde60f581]::with_source_map::<core[449086d7d8ac0eaf]::result::Result<(), rustc_errors[35630e0ab5d06bf2]::ErrorGuaranteed>, rustc_interface[524480e3db7d7602]::interface::run_compiler<core[449086d7d8ac0eaf]::result::Result<(), rustc_errors[35630e0ab5d06bf2]::ErrorGuaranteed>, rustc_driver[f3db849b868bf2ae]::run_compiler::{closure#1}>::{closure#0}::{closure#1}>
  22:     0x7f8e34a5fcf9 - <scoped_tls[d7bcc67860d72135]::ScopedKey<rustc_span[a814485cde60f581]::SessionGlobals>>::set::<rustc_interface[524480e3db7d7602]::interface::run_compiler<core[449086d7d8ac0eaf]::result::Result<(), rustc_errors[35630e0ab5d06bf2]::ErrorGuaranteed>, rustc_driver[f3db849b868bf2ae]::run_compiler::{closure#1}>::{closure#0}, core[449086d7d8ac0eaf]::result::Result<(), rustc_errors[35630e0ab5d06bf2]::ErrorGuaranteed>>
  23:     0x7f8e34a5f308 - std[3f3511bd14de1a0b]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[524480e3db7d7602]::util::run_in_thread_pool_with_globals<rustc_interface[524480e3db7d7602]::interface::run_compiler<core[449086d7d8ac0eaf]::result::Result<(), rustc_errors[35630e0ab5d06bf2]::ErrorGuaranteed>, rustc_driver[f3db849b868bf2ae]::run_compiler::{closure#1}>::{closure#0}, core[449086d7d8ac0eaf]::result::Result<(), rustc_errors[35630e0ab5d06bf2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[449086d7d8ac0eaf]::result::Result<(), rustc_errors[35630e0ab5d06bf2]::ErrorGuaranteed>>
  24:     0x7f8e34a5f02c - <<std[3f3511bd14de1a0b]::thread::Builder>::spawn_unchecked_<rustc_interface[524480e3db7d7602]::util::run_in_thread_pool_with_globals<rustc_interface[524480e3db7d7602]::interface::run_compiler<core[449086d7d8ac0eaf]::result::Result<(), rustc_errors[35630e0ab5d06bf2]::ErrorGuaranteed>, rustc_driver[f3db849b868bf2ae]::run_compiler::{closure#1}>::{closure#0}, core[449086d7d8ac0eaf]::result::Result<(), rustc_errors[35630e0ab5d06bf2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[449086d7d8ac0eaf]::result::Result<(), rustc_errors[35630e0ab5d06bf2]::ErrorGuaranteed>>::{closure#1} as core[449086d7d8ac0eaf]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  25:     0x7f8e36472793 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9dd8eb50b3cb442b
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/alloc/src/boxed.rs:1987:9
  26:     0x7f8e36472793 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb9b1fdf3a82a5af1
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/alloc/src/boxed.rs:1987:9
  27:     0x7f8e36472793 - std::sys::unix::thread::Thread::new::thread_start::h768bb18f08276a43
                               at /rustc/1286ee23e4e2dec8c1696d3d76c6b26d97bbcf82/library/std/src/sys/unix/thread.rs:108:17
  28:     0x7f8e323198fd - <unknown>
  29:     0x7f8e3239ba60 - <unknown>
  30:                0x0 - <unknown>

note: 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.67.0-nightly (1286ee23e 2022-11-05) running on x86_64-unknown-linux-gnu

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:
end of query stack
For more information about this error, try `rustc --explain E0053`.
warning: `vstorage` (lib) generated 2 warnings
error: could not compile `vstorage`; 2 warnings emitted

Note that I'm using #![feature(async_fn_in_trait)] which is experimental.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions