rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.55k stars 12.74k forks source link

🧊 Failure to compile async function after moving from argument position `impl X` to `impl Supertrait` #109074

Open drahnr opened 1 year ago

drahnr commented 1 year ago

Code

I can't share the full code at this time.

Originally the code was like this

async fn f(
    hash: Hash,
    i: I
    sender: &mut impl TheTrait,
) -> Result<Vec<X>, Error>
{
// snip
   Ok(xs)
}

changing it to the following caused the ICE:

async fn f<S>(
    hash: Hash,
    i: I
    sender: &mut S,
) -> Result<Vec<X>, Error>
where
    S: Supertrait,  
{
// snip
   Ok(xs)
}

trait Supertrait: TheTrait {};
impl Supertrait for T where T: TheTrait {}

Meta

rustc --version --verbose:

rustc 1.67.1 (d5a82bbd2 2023-02-07)
binary: rustc
commit-hash: d5a82bbd26e1ad8b7401f6a718a9c57c96905483
commit-date: 2023-02-07
host: x86_64-unknown-linux-gnu
release: 1.67.1
LLVM version: 15.0.6

Error output

<output>
Backtrace

``` thread 'rustc' panicked at 'forcing query with already existing `DepNode` - query-key: Canonical { max_universe: U0, variables: [CanonicalVarInfo { kind: Region(U0) }, CanonicalVarInfo { kind: Region(U0) }], value: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [Binder(TraitPredicate(, polarity:Positive), []), Binder(TraitPredicate(, polarity:Positive), []), Binder(TraitPredicate(>, polarity:Positive), []), Binder(TraitPredicate(, polarity:Positive), []), Binder(TraitPredicate(>, polarity:Positive), []), Binder(TraitPredicate(>, polarity:Positive), []), Binder(TraitPredicate(>, polarity:Positive), []), Binder(TraitPredicate(>, polarity:Positive), []), Binder(TraitPredicate(, polarity:Positive), []), Binder(OutlivesPredicate(S, ReStatic), [])], reveal: UserFacing, constness: NotConst }, value: Normalize { value: [async fn body@node/subsystems/bitfield-signing/src/lib.rs:128:1: 164:2] } } } - dep-node: type_op_normalize_ty(bbf09b00168ce1f-fef12bcf2a38fd30)', /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/compiler/rustc_query_system/src/dep_graph/graph.rs:316:9 stack backtrace: 0: 0x7f5b44b656fa - std::backtrace_rs::backtrace::libunwind::trace::h79937bc171ada62c at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7f5b44b656fa - std::backtrace_rs::backtrace::trace_unsynchronized::h2292bca8571cb919 at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f5b44b656fa - std::sys_common::backtrace::_print_fmt::h9c461f248e4ae90d at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:65:5 3: 0x7f5b44b656fa - ::fmt::he9fe6bf1a39182e1 at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7f5b44bc825e - core::fmt::write::h032658c119c720d7 at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/fmt/mod.rs:1208:17 5: 0x7f5b44b55a85 - std::io::Write::write_fmt::h299fc90dfae41c0d at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/io/mod.rs:1682:15 6: 0x7f5b44b654c5 - std::sys_common::backtrace::_print::heb70d25df9937e3f at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:47:5 7: 0x7f5b44b654c5 - std::sys_common::backtrace::print::had745c0a76b8b521 at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:34:9 8: 0x7f5b44b6820f - std::panicking::default_hook::{{closure}}::h1ea782cdfa2fd097 at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:267:22 9: 0x7f5b44b67f4b - std::panicking::default_hook::h1cc3af63455a163c at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:286:9 10: 0x7f5b47e60ab1 - >::call_once::{shim:vtable#0} 11: 0x7f5b44b68a4d - as core::ops::function::Fn>::call::h6e4950ba7c0fd82a at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/alloc/src/boxed.rs:2032:9 12: 0x7f5b44b68a4d - std::panicking::rust_panic_with_hook::h5cafdc4b3bfd5528 at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:692:13 13: 0x7f5b44b687c9 - std::panicking::begin_panic_handler::{{closure}}::hf31c60f40775892c at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:579:13 14: 0x7f5b44b65bac - std::sys_common::backtrace::__rust_end_short_backtrace::h28a5c7be595826cd at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys_common/backtrace.rs:137:18 15: 0x7f5b44b684d2 - rust_begin_unwind at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/panicking.rs:575:5 16: 0x7f5b44bc4c43 - core::panicking::panic_fmt::h8fa27a0b37dd98b7 at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/core/src/panicking.rs:64:14 17: 0x7f5b4717f2e0 - >::with_task::>>, core[e6a29f2585b3d454]::result::Result<&rustc_middle[83f907612b22699d]::infer::canonical::Canonical>, rustc_middle[83f907612b22699d]::traits::query::NoSolution>> 18: 0x7f5b4717d7e9 - rustc_query_system[7dbbccfee5a2d054]::query::plumbing::try_execute_query::>>, core[e6a29f2585b3d454]::result::Result<&rustc_middle[83f907612b22699d]::infer::canonical::Canonical>, rustc_middle[83f907612b22699d]::traits::query::NoSolution>>> 19: 0x7f5b4717cf5d - rustc_query_system[7dbbccfee5a2d054]::query::plumbing::get_query:: 20: 0x7f5b4717cea3 - ::type_op_normalize_ty 21: 0x7f5b46cc6dce - > as rustc_trait_selection[945b70100f8dd3ec]::traits::query::type_op::TypeOp>::fully_perform 22: 0x7f5b46c8c1a6 - <&mut ::create::{closure#0} as core[e6a29f2585b3d454]::ops::function::FnOnce<(rustc_middle[83f907612b22699d]::ty::Ty,)>>::call_once 23: 0x7f5b46c8ba92 - as alloc[89959c1738bdde42]::vec::spec_from_iter::SpecFromIter<&rustc_middle[83f907612b22699d]::infer::canonical::QueryRegionConstraints, core[e6a29f2585b3d454]::iter::adapters::flatten::FlatMap>, core[e6a29f2585b3d454]::option::IntoIter>, core[e6a29f2585b3d454]::iter::adapters::chain::Chain, core[e6a29f2585b3d454]::option::IntoIter<&rustc_middle[83f907612b22699d]::infer::canonical::QueryRegionConstraints>>, core[e6a29f2585b3d454]::option::IntoIter<&rustc_middle[83f907612b22699d]::infer::canonical::QueryRegionConstraints>>, ::create::{closure#0}>>>::from_iter 24: 0x7f5b46c86b29 - rustc_borrowck[323b14a08f10fded]::type_check::free_region_relations::create 25: 0x7f5b46c7b248 - rustc_borrowck[323b14a08f10fded]::type_check::type_check 26: 0x7f5b46c52165 - rustc_borrowck[323b14a08f10fded]::nll::compute_regions 27: 0x7f5b46c2fdcb - rustc_borrowck[323b14a08f10fded]::do_mir_borrowck 28: 0x7f5b46c2bbf9 - rustc_borrowck[323b14a08f10fded]::mir_borrowck 29: 0x7f5b46c2b0d5 - >::call_once 30: 0x7f5b46f222ac - >::with_task:: 31: 0x7f5b46f20fbc - rustc_query_system[7dbbccfee5a2d054]::query::plumbing::try_execute_query::> 32: 0x7f5b4780640a - ::mir_borrowck 33: 0x7f5b46d1b811 - ::prove_closure_bounds 34: 0x7f5b46cf6a26 - ::typeck_mir 35: 0x7f5b46c7b5c3 - rustc_borrowck[323b14a08f10fded]::type_check::type_check 36: 0x7f5b46c52165 - rustc_borrowck[323b14a08f10fded]::nll::compute_regions 37: 0x7f5b46c2fdcb - rustc_borrowck[323b14a08f10fded]::do_mir_borrowck 38: 0x7f5b46c2bbf9 - rustc_borrowck[323b14a08f10fded]::mir_borrowck 39: 0x7f5b46c2b0d5 - >::call_once 40: 0x7f5b46f222ac - >::with_task:: 41: 0x7f5b46f20fbc - rustc_query_system[7dbbccfee5a2d054]::query::plumbing::try_execute_query::> 42: 0x7f5b4861bab6 - rustc_query_system[7dbbccfee5a2d054]::query::plumbing::force_query:: 43: 0x7f5b487901d1 - rustc_query_impl[e214cefb6de2a99d]::plumbing::force_from_dep_node:: 44: 0x7f5b45ebb039 - >::try_mark_previous_green:: 45: 0x7f5b45ebafdc - >::try_mark_previous_green:: 46: 0x7f5b4605f954 - rustc_query_system[7dbbccfee5a2d054]::query::plumbing::ensure_must_run:: 47: 0x7f5b47202a2e - rustc_query_system[7dbbccfee5a2d054]::query::plumbing::get_query:: 48: 0x7f5b474db4c5 - ::for_each_module:: 49: 0x7f5b4635ad42 - rustc_hir_analysis[44326659f1d3f01d]::check_crate 50: 0x7f5b4635a98b - rustc_interface[65dcc5dffb099e04]::passes::analysis 51: 0x7f5b4761291f - >::with_task::> 52: 0x7f5b47611a17 - rustc_query_system[7dbbccfee5a2d054]::query::plumbing::try_execute_query::>> 53: 0x7f5b47611470 - rustc_query_system[7dbbccfee5a2d054]::query::plumbing::get_query:: 54: 0x7f5b470241b3 - ::enter::> 55: 0x7f5b47020733 - ::enter::, rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>> 56: 0x7f5b4701b788 - rustc_span[41a321a6411ba4fa]::with_source_map::, rustc_interface[65dcc5dffb099e04]::interface::run_compiler, rustc_driver[5c3b90d1fb3964ba]::run_compiler::{closure#1}>::{closure#0}::{closure#0}> 57: 0x7f5b4701b275 - >::set::, rustc_driver[5c3b90d1fb3964ba]::run_compiler::{closure#1}>::{closure#0}, core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>> 58: 0x7f5b4701a862 - std[359ab902947f5f0b]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver[5c3b90d1fb3964ba]::run_compiler::{closure#1}>::{closure#0}, core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>> 59: 0x7f5b47713b7a - <::spawn_unchecked_, rustc_driver[5c3b90d1fb3964ba]::run_compiler::{closure#1}>::{closure#0}, core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e6a29f2585b3d454]::result::Result<(), rustc_errors[d24ea2395205e4f0]::ErrorGuaranteed>>::{closure#1} as core[e6a29f2585b3d454]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 60: 0x7f5b44b72803 - as core::ops::function::FnOnce>::call_once::hb77d8d72ebcf79c4 at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/alloc/src/boxed.rs:2000:9 61: 0x7f5b44b72803 - as core::ops::function::FnOnce>::call_once::hc08c3353e1568487 at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/alloc/src/boxed.rs:2000:9 62: 0x7f5b44b72803 - std::sys::unix::thread::Thread::new::thread_start::h7168e596cd5e5ce6 at /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/sys/unix/thread.rs:108:17 63: 0x7f5b4488cdcd - start_thread 64: 0x7f5b44912630 - clone3 65: 0x0 - error: internal compiler error: unexpected panic 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.1 (d5a82bbd2 2023-02-07) running on x86_64-unknown-linux-gnu note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C linker=clang -C incremental=[REDACTED] -C link-arg=-fuse-ld=/usr/bin/mold note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [type_op_normalize_ty] normalizing `[async fn body@node/subsystems/bitfield-signing/src/lib.rs:128:1: 164:2]` #1 [mir_borrowck] borrow-checking `construct_availability_bitfields::{closure#0}` #2 [mir_borrowck] borrow-checking `construct_availability_bitfields` #3 [analysis] running analysis passes on this crate end of query stack ```

drahnr commented 1 year ago

Cannot reproduce with:

rustc 1.68.0 (2c8cc3432 2023-03-06)
binary: rustc
commit-hash: 2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74
commit-date: 2023-03-06
host: x86_64-unknown-linux-gnu
release: 1.68.0
LLVM version: 15.0.6
Noratrieb commented 1 year ago

If you can't reproduce it on newer compilers, then it has probably been fixed already. Could you try the latest nightly just to be sure?

matthiaskrgr commented 1 year ago

Looks incremental. This will be fixed by https://github.com/rust-lang/rust/pull/109050/files#diff-10fa2a6e446268d48bc95cc934a36619bb825090dba730b7df7503e05d166487L333 as it removes the assert :slightly_smiling_face:

drahnr commented 1 year ago

Still exists in

Cannot reproduce with:

rustc 1.68.0 (2c8cc3432 2023-03-06)
binary: rustc
commit-hash: 2c8cc343237b8f7d5a3c3703e3a87f2eb2c54a74
commit-date: 2023-03-06
host: x86_64-unknown-linux-gnu
release: 1.68.0
LLVM version: 15.0.6

Can reproduce, but can work around by disabling incremental builds.