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: calling ~const trait method in non const fn raises no host param id #117004

Closed
YakoYakoYokuYoku opened this issue Oct 21, 2023 · 3 comments · Fixed by #119059
Closed

ice: calling ~const trait method in non const fn raises no host param id #117004

YakoYakoYokuYoku opened this issue Oct 21, 2023 · 3 comments · Fixed by #119059
Assignees
Labels
C-bug Category: This is a bug. F-const_trait_impl `#![feature(const_trait_impl)]` F-effects `#![feature(effects)]` 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.

Comments

@YakoYakoYokuYoku
Copy link

Code

#![feature(const_trait_impl, effects)]

#[const_trait]
pub trait Stone {
    type Recorded: Copy;

    fn get_record(&self) -> Self::Recorded;
}

pub struct Wall<T: Stone>(T::Recorded);

pub struct Brick;

impl const Stone for Brick {
    type Recorded = i32;
    
    fn get_record(&self) -> i32 {
        0
    }
}

impl<T: ~const Stone> Wall<T> {
    fn new(value: T) -> Self {
        Self(value.get_record())
    }
}

fn main() {
    let _ = Wall::new(Brick);
}

Meta

rustc --version --verbose:

rustc 1.75.0-nightly (4578435e1 2023-10-19)
binary: rustc
commit-hash: 4578435e1695863d921c7763d5a0add98f8e3869
comit-date: 2023-10-19
host: ...
release: 1.75.0-nightly
LLVM version: ...

Error output

   Compiling playground v0.0.1 (/playground)
error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: no host param id for call in const yet no errors reported
  |
  = note: delayed at compiler/rustc_ast_lowering/src/lib.rs:2490:18
          ... see backtrace ...

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 `/playground/rustc-ice-2023-10-21T00_13_07-20.txt` to your bug report

note: compiler flags: --crate-type bin -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `playground` (bin "playground")
Backtrace

             0: <rustc_errors::HandlerInner>::emit_diagnostic
             1: <rustc_session::session::Session>::delay_span_bug::<rustc_span::span_encoding::Span, &str>
             2: <rustc_ast_lowering::LoweringContext>::lower_qpath
             3: <rustc_ast_lowering::LoweringContext>::lower_param_bounds
             4: <rustc_ast_lowering::LoweringContext>::lower_item_kind
             5: <rustc_ast_lowering::item::ItemLowerer>::lower_node
             6: rustc_ast_lowering::lower_to_hir
             7: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::hir_crate::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
             8: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
             9: rustc_query_impl::query_impl::hir_crate::get_query_non_incr::__rust_end_short_backtrace
            10: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::hir_attrs::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
            11: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_hir::hir_id::OwnerId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            12: rustc_query_impl::query_impl::hir_attrs::get_query_non_incr::__rust_end_short_backtrace
            13: <rustc_middle::hir::map::Map>::attrs
            14: rustc_passes::entry::entry_fn
            15: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::entry_fn::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 12]>>
            16: <rustc_query_impl::query_impl::entry_fn::dynamic_query::{closure#2} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, ())>>::call_once
            17: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 12]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            18: rustc_query_impl::query_impl::entry_fn::get_query_non_incr::__rust_end_short_backtrace
            19: rustc_interface::passes::analysis
            20: 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]>>
            21: 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>
            22: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
            23: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
            24: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{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}
            25: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/4578435e1695863d921c7763d5a0add98f8e3869/library/alloc/src/boxed.rs:2007:9
            26: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/4578435e1695863d921c7763d5a0add98f8e3869/library/alloc/src/boxed.rs:2007:9
            27: std::sys::unix::thread::Thread::new::thread_start
                       at /rustc/4578435e1695863d921c7763d5a0add98f8e3869/library/std/src/sys/unix/thread.rs:108:17
            28: start_thread
            29: clone

@YakoYakoYokuYoku YakoYakoYokuYoku added C-bug Category: This is a bug. 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. labels Oct 21, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 21, 2023
@fmease fmease added F-const_trait_impl `#![feature(const_trait_impl)]` F-effects `#![feature(effects)]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 21, 2023
@compiler-errors
Copy link
Member

We should probably just deny ~const bounds outside of const contexts.

@YakoYakoYokuYoku
Copy link
Author

We should probably just deny ~const bounds outside of const contexts.

I hit this one out of mere casuality, if I change Wall::new to be const then I hit this error...

   Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
  --> src/main.rs:24:14
   |
24 |         Self(value.get_record())
   |              ^^^^^^^^^^^^^^^^^^ expected `host`, found `true`
   |
   = note: expected constant `host`
              found constant `true`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (bin "playground") due to previous error

Still, denying this usage of ~const should be done regardless.

@YakoYakoYokuYoku YakoYakoYokuYoku changed the title ice: calling const trait method in const fn raises no host param id ice: calling ~const trait method in non const fn raises no host param id Oct 21, 2023
@fee1-dead
Copy link
Member

We should probably just deny ~const bounds outside of const contexts.

Yep.

@fmease fmease self-assigned this Dec 17, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 18, 2023
…headers, r=fee1-dead

Deny `~const` trait bounds in inherent impl headers

Follow-up to rust-lang#117817.
Implements rust-lang#117817 (comment).

Fixes rust-lang#117004.

r? fee1-dead or compiler
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 18, 2023
Rollup merge of rust-lang#119059 - fmease:no-tilde-const-in-inh-impl-headers, r=fee1-dead

Deny `~const` trait bounds in inherent impl headers

Follow-up to rust-lang#117817.
Implements rust-lang#117817 (comment).

Fixes rust-lang#117004.

r? fee1-dead or compiler
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-const_trait_impl `#![feature(const_trait_impl)]` F-effects `#![feature(effects)]` 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants