Skip to content

effects: add: ConstContext::Maybe must have host effect param #121536

Closed
@matthiaskrgr

Description

@matthiaskrgr
#![feature(effects)]

#[derive(Debug, Clone, Copy)]
pub struct Vec3 {
    pub x: f32,
    pub y: f32,
    pub z: f32,
}

impl std::ops::Add<Vec3> for Vec3 {
    type Output = Vec3;
    const fn add(self, b: Vec3) -> Self::Output {
        Vec3 {
            x: self.x + b.x,
            y: self.y + b.y,
            z: self.z + b.z,
        }
    }
}

This crashes since #120381

error[E0379]: functions in trait impls cannot be declared const
  --> a.rs:12:5
   |
12 |     const fn add(self, b: Vec3) -> Self::Output {
   |     ^^^^^-
   |     |
   |     functions in trait impls cannot be const
   |     help: remove the `const`

error[E0601]: `main` function not found in crate `a`
  --> a.rs:19:2
   |
19 | }
   |  ^ consider adding a `main` function to `a.rs`

thread 'rustc' panicked at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/compiler/rustc_middle/src/ty/util.rs:847:22:
ConstContext::Maybe must have host effect param
stack backtrace:
   0:     0x7ff109bbeaf6 - std::backtrace_rs::backtrace::libunwind::trace::h4d16db2f784877bc
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7ff109bbeaf6 - std::backtrace_rs::backtrace::trace_unsynchronized::h584b4a9b0240fa46
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ff109bbeaf6 - std::sys_common::backtrace::_print_fmt::hd30229489add2f78
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7ff109bbeaf6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2c0d00d6b7d69808
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ff109c0fa7c - core::fmt::rt::Argument::fmt::hff9bfb4853f651d7
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/core/src/fmt/rt.rs:142:9
   5:     0x7ff109c0fa7c - core::fmt::write::h3421d3f24b10b162
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/core/src/fmt/mod.rs:1120:17
   6:     0x7ff109bb34bf - std::io::Write::write_fmt::hec18e9e87db322bb
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/io/mod.rs:1846:15
   7:     0x7ff109bbe8a4 - std::sys_common::backtrace::_print::hec336a3777e68e7b
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7ff109bbe8a4 - std::sys_common::backtrace::print::hde3a6d5d13170337
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7ff109bc15eb - std::panicking::default_hook::{{closure}}::h4a4905d59aca1811
  10:     0x7ff109bc1339 - std::panicking::default_hook::h33a18ce8d018f6fd
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/panicking.rs:292:9
  11:     0x7ff10688467c - std[d1f7731e2ff5974d]::panicking::update_hook::<alloc[6711342ad6595d8]::boxed::Box<rustc_driver_impl[db1009755931a507]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7ff109bc1d50 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h923e5082c0e2f790
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/alloc/src/boxed.rs:2030:9
  13:     0x7ff109bc1d50 - std::panicking::rust_panic_with_hook::he294011ca89c3e63
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/panicking.rs:783:13
  14:     0x7ff109bc1a92 - std::panicking::begin_panic_handler::{{closure}}::hd80de86623d4d7ef
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/panicking.rs:657:13
  15:     0x7ff109bbefd6 - std::sys_common::backtrace::__rust_end_short_backtrace::h310587e2e5c29372
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7ff109bc17c4 - rust_begin_unwind
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/panicking.rs:645:5
  17:     0x7ff109c0bf95 - core::panicking::panic_fmt::h275e2499dd810de9
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/core/src/panicking.rs:72:14
  18:     0x7ff109c0c161 - core::panicking::panic_display::h44ab4ddee4f483e8
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/core/src/panicking.rs:196:5
  19:     0x7ff109c0bd4b - core::panicking::panic_str::hb10c649a731587af
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/core/src/panicking.rs:171:5
  20:     0x7ff109c0bd4b - core::option::expect_failed::hfe838af18211af8c
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/core/src/option.rs:1995:5
  21:     0x7ff107ffe223 - <rustc_hir_typeck[4a7fd2fa90d52c2f]::fn_ctxt::FnCtxt>::enforce_context_effects
  22:     0x7ff107ffcd35 - <rustc_hir_typeck[4a7fd2fa90d52c2f]::fn_ctxt::FnCtxt>::write_method_call_and_enforce_effects
  23:     0x7ff107ff8e83 - <rustc_hir_typeck[4a7fd2fa90d52c2f]::fn_ctxt::FnCtxt>::check_overloaded_binop
  24:     0x7ff108655411 - <rustc_hir_typeck[4a7fd2fa90d52c2f]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  25:     0x7ff1084516b3 - <rustc_hir_typeck[4a7fd2fa90d52c2f]::fn_ctxt::FnCtxt>::check_expr_struct_fields
  26:     0x7ff108656218 - <rustc_hir_typeck[4a7fd2fa90d52c2f]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  27:     0x7ff1081ffb89 - <rustc_hir_typeck[4a7fd2fa90d52c2f]::fn_ctxt::FnCtxt>::check_block_with_expected
  28:     0x7ff108654646 - <rustc_hir_typeck[4a7fd2fa90d52c2f]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  29:     0x7ff108511f08 - rustc_hir_typeck[4a7fd2fa90d52c2f]::check::check_fn
  30:     0x7ff107d36225 - rustc_hir_typeck[4a7fd2fa90d52c2f]::typeck
  31:     0x7ff107d354e3 - rustc_query_impl[5f3fca9184d705d1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5f3fca9184d705d1]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[10e0138f1f482b76]::query::erase::Erased<[u8; 8usize]>>
  32:     0x7ff107e6bc30 - rustc_query_system[3c44b3ad726fdf36]::query::plumbing::try_execute_query::<rustc_query_impl[5f3fca9184d705d1]::DynamicConfig<rustc_query_system[3c44b3ad726fdf36]::query::caches::VecCache<rustc_span[6ccc48fe7a4f1f83]::def_id::LocalDefId, rustc_middle[10e0138f1f482b76]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[5f3fca9184d705d1]::plumbing::QueryCtxt, false>
  33:     0x7ff107e6b74c - rustc_query_impl[5f3fca9184d705d1]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7ff1085c46d2 - <rustc_middle[10e0138f1f482b76]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[85016fc5ed80b9f8]::check_crate::{closure#6}>::{closure#0}
  35:     0x7ff1085c2f9d - rustc_hir_analysis[85016fc5ed80b9f8]::check_crate
  36:     0x7ff1087edd6f - rustc_interface[94ec20dfe64cdcea]::passes::analysis
  37:     0x7ff1087ed9d9 - rustc_query_impl[5f3fca9184d705d1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5f3fca9184d705d1]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[10e0138f1f482b76]::query::erase::Erased<[u8; 1usize]>>
  38:     0x7ff108925643 - rustc_query_system[3c44b3ad726fdf36]::query::plumbing::try_execute_query::<rustc_query_impl[5f3fca9184d705d1]::DynamicConfig<rustc_query_system[3c44b3ad726fdf36]::query::caches::SingleCache<rustc_middle[10e0138f1f482b76]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[5f3fca9184d705d1]::plumbing::QueryCtxt, false>
  39:     0x7ff1089253bf - rustc_query_impl[5f3fca9184d705d1]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  40:     0x7ff108934896 - rustc_interface[94ec20dfe64cdcea]::interface::run_compiler::<core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>, rustc_driver_impl[db1009755931a507]::run_compiler::{closure#0}>::{closure#0}
  41:     0x7ff108bcaa4d - std[d1f7731e2ff5974d]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[94ec20dfe64cdcea]::util::run_in_thread_with_globals<rustc_interface[94ec20dfe64cdcea]::util::run_in_thread_pool_with_globals<rustc_interface[94ec20dfe64cdcea]::interface::run_compiler<core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>, rustc_driver_impl[db1009755931a507]::run_compiler::{closure#0}>::{closure#0}, core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>>::{closure#0}, core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>>
  42:     0x7ff108bca87a - <<std[d1f7731e2ff5974d]::thread::Builder>::spawn_unchecked_<rustc_interface[94ec20dfe64cdcea]::util::run_in_thread_with_globals<rustc_interface[94ec20dfe64cdcea]::util::run_in_thread_pool_with_globals<rustc_interface[94ec20dfe64cdcea]::interface::run_compiler<core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>, rustc_driver_impl[db1009755931a507]::run_compiler::{closure#0}>::{closure#0}, core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>>::{closure#0}, core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>>::{closure#1} as core[bd87c62ae3a7b4ee]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:     0x7ff109bcb725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h11737601996c7bc7
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/alloc/src/boxed.rs:2016:9
  44:     0x7ff109bcb725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb64bc4a2c7899523
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/alloc/src/boxed.rs:2016:9
  45:     0x7ff109bcb725 - std::sys::pal::unix::thread::Thread::new::thread_start::h9f6bca54366231ee
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/sys/pal/unix/thread.rs:108:17
  46:     0x7ff10386755a - <unknown>
  47:     0x7ff1038e4a3c - <unknown>
  48:                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: please attach the file at `/tmp/im/rustc-ice-2024-02-24T07_04_18-2942423.txt` to your bug report

query stack during panic:
#0 [typeck] type-checking `<impl at a.rs:10:1: 10:34>::add`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

Some errors have detailed explanations: E0379, E0601.
For more information about an error, try `rustc --explain E0379`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-const_trait_impl`#![feature(const_trait_impl)]`F-effects`#![feature(effects)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-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