Skip to content

ICE: the trait bound T: ~const Deref is not satisfied #136273

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Sky9x opened this issue Jan 30, 2025 · 4 comments · Fixed by #136314
Closed

ICE: the trait bound T: ~const Deref is not satisfied #136273

Sky9x opened this issue Jan 30, 2025 · 4 comments · Fixed by #136314
Labels
C-bug Category: This is a bug. F-const_trait_impl `#![feature(const_trait_impl)]` 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

@Sky9x
Copy link
Contributor

Sky9x commented Jan 30, 2025

Code

Playground link

#![feature(const_trait_impl)]
#![feature(const_deref)]

use std::ops::{Deref, DerefMut};
use std::pin::Pin;

pub struct Wrap<T>(T);

impl<T> const Deref for Wrap<T> {
    type Target = T;

    fn deref(&self) -> &T {
        &self.0
    }
}

impl<T> const DerefMut for Wrap<T> {
    fn deref_mut(&mut self) -> &mut T {
        &mut self.0
    }
}

impl<T> Wrap<T> {
    pub const fn get_pinned_mut(this: Pin<&mut Self>) -> Pin<&mut T> {
        // SAFETY: this type follows structural pinning
        unsafe { Pin::new_unchecked(this.get_unchecked_mut()) }
    }
}

Meta

rustc --version --verbose:

rustc 1.86.0-nightly (ae5de6c75 2025-01-29)
binary: rustc
commit-hash: ae5de6c759cd337ecdb2de4e94f47eaafb5d4606
commit-date: 2025-01-29
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Error output

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error[E0277]: the trait bound `T: ~const Deref` is not satisfied
  --> src/lib.rs:26:37
   |
26 |         unsafe { Pin::new_unchecked(this.get_unchecked_mut()) }
   |                                     ^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: delayed at compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs:771:24 - disabled backtrace
  --> src/lib.rs:26:37
   |
26 |         unsafe { Pin::new_unchecked(this.get_unchecked_mut()) }
   |                                     ^^^^^^^^^^^^^^^^^^^^^^^^

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 make sure that you have updated to the latest nightly

note: please attach the file at `rustc-ice-2025-01-30T03_47_52-30101.txt` to your bug report

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
Backtrace

delayed bug: the trait bound `T: ~const std::ops::Deref` is not satisfied
   0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
   1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
   2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   3: <rustc_trait_selection::error_reporting::TypeErrCtxt>::report_selection_error
   4: <rustc_trait_selection::error_reporting::TypeErrCtxt>::report_fulfillment_error
   5: <rustc_trait_selection::error_reporting::TypeErrCtxt>::report_fulfillment_errors
   6: <rustc_hir_typeck::fn_ctxt::FnCtxt>::confirm_builtin_call
   7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
   8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_block
   9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_block
  11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  12: rustc_hir_typeck::check::check_fn
  13: rustc_hir_typeck::typeck_with_inspect::{closure#0}
  14: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
  15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  16: rustc_query_impl::query_impl::typeck::get_query_incr::__rust_end_short_backtrace
  17: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_hir_analysis::check_crate::{closure#4}>::{closure#0}
  18: rustc_hir_analysis::check_crate
  19: rustc_interface::passes::run_required_analyses
  20: rustc_interface::passes::analysis
  21: 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; 0]>>
  22: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
  23: rustc_query_impl::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  24: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  25: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
  26: std::sys::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<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  27: <<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<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  28: std::sys::pal::unix::thread::Thread::new::thread_start
  29: start_thread
             at ./nptl/pthread_create.c:442:8
  30: __GI___clone3
             at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81:0



rustc version: 1.86.0-nightly (ae5de6c75 2025-01-29)
platform: x86_64-unknown-linux-gnu

@Sky9x Sky9x 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 Jan 30, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 30, 2025
@Sky9x
Copy link
Contributor Author

Sky9x commented Jan 30, 2025

@rustbot label +F-const_trait_impl

@rustbot rustbot added the F-const_trait_impl `#![feature(const_trait_impl)]` label Jan 30, 2025
@theemathas
Copy link
Contributor

Minimized:

#![feature(const_trait_impl)]
#![feature(const_deref)]

pub struct Foo;

impl const std::ops::Deref for Foo {
    type Target = i32;
    fn deref(&self) -> &i32 {
        &0
    }
}

pub const fn coerce(x: &Foo) -> &i32 {
    // deref coercion
    x
}
Error output
note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error[E0277]: the trait bound `i32: ~const Deref` is not satisfied
  --> src/lib.rs:15:5
   |
15 |     x
   |     ^
   |
note: delayed at compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs:771:24 - disabled backtrace
  --> src/lib.rs:15:5
   |
15 |     x
   |     ^

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 make sure that you have updated to the latest nightly

note: please attach the file at `/playground/rustc-ice-2025-01-30T04_30_49-22.txt` to your bug report

note: compiler flags: --crate-type lib -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

@theemathas
Copy link
Contributor

This error can currently be worked around by explicitly doing dereferences. In the original code, this would be:

unsafe { Pin::new_unchecked(&mut **this.get_unchecked_mut()) }

@matthiaskrgr
Copy link
Member

probably duplicate of #135210

workingjubilee added a commit to workingjubilee/rustc that referenced this issue Jan 31, 2025
…=fee1-dead

Use proper type when applying deref adjustment in const

When applying a deref adjustment to some type `Wrap<T>` which derefs to `T`, we were checking that `T: ~const Deref`, not `Wrap<T>: ~const Deref` like we should have been.

r? project-const-traits

Fixes rust-lang#136273
Fixes rust-lang#135210 -- I just deleted the test since the regression test is uninteresting
@bors bors closed this as completed in 47e6684 Feb 1, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 1, 2025
Rollup merge of rust-lang#136314 - compiler-errors:const-deref-adj, r=fee1-dead

Use proper type when applying deref adjustment in const

When applying a deref adjustment to some type `Wrap<T>` which derefs to `T`, we were checking that `T: ~const Deref`, not `Wrap<T>: ~const Deref` like we should have been.

r? project-const-traits

Fixes rust-lang#136273
Fixes rust-lang#135210 -- I just deleted the test since the regression test is uninteresting
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 1, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. F-const_trait_impl `#![feature(const_trait_impl)]` 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