Skip to content

cannot relate bound region: ReErased <= ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:42 ~ mut_family[c9ba]::MutFamily::as_ptr::'a), 'a) }) #109975

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

Closed
JohnScience opened this issue Apr 5, 2023 · 2 comments
Labels
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.

Comments

@JohnScience
Copy link
Contributor

Code

#![no_std]
use core::marker::PhantomData;

struct RefCarrierTy<'a, T, const IS_SHARED: bool>(PhantomData<*const &'a T>);

// This has to be a trait in the absence of inherent associated types.
trait RefCarrier<'a, T> {
    type RefTy;
}

impl<'a, T> RefCarrier<'a, T> for RefCarrierTy<'a, T, true> {
    type RefTy = &'a T;
}

impl<'a, T> RefCarrier<'a, T> for RefCarrierTy<'a, T, false> {
    type RefTy = &'a mut T;
}

pub struct IdentityFamily;

pub struct UnsafeCellFamily;

pub struct CellFamily;

pub struct RefCellFamily;

pub trait MutFamily {
    type Target<T>;
    const IS_INTERIOR_MUT: bool;
    fn new<T>(value: T) -> Self::Target<T>;
    fn into_exterior_mut<T>(target: Self::Target<T>) -> T;
    fn as_ptr<'a, T>(reference: RefCarrierTy<'a, Self::Target<T>, { Self::IS_INTERIOR_MUT }>::RefTy) -> *mut T;
}

impl MutFamily for IdentityFamily {
    type Target<T> = T;
    const IS_INTERIOR_MUT: bool = false;
    
    fn new<T>(value: T) -> Self::Target<T> {
        value
    }

    fn into_exterior_mut<T>(target: Self::Target<T>) -> T {
        target
    }
}

impl MutFamily for UnsafeCellFamily {
    type Target<T> = core::cell::UnsafeCell<T>;
    const IS_INTERIOR_MUT: bool = true;
    
    fn new<T>(value: T) -> Self::Target<T> {
        core::cell::UnsafeCell::new(value)
    }

    fn into_exterior_mut<T>(target: Self::Target<T>) -> T {
        target.into_inner()
    }
}

impl MutFamily for CellFamily {
    type Target<T> = core::cell::Cell<T>;
    const IS_INTERIOR_MUT: bool = true;

    fn new<T>(value: T) -> Self::Target<T> {
        core::cell::Cell::new(value)
    }

    fn into_exterior_mut<T>(target: Self::Target<T>) -> T {
        target.into_inner()
    }
}

impl MutFamily for RefCellFamily {
    type Target<T> = core::cell::RefCell<T>;
    const IS_INTERIOR_MUT: bool = true;

    fn new<T>(value: T) -> Self::Target<T> {
        core::cell::RefCell::new(value)
    }

    fn into_exterior_mut<T>(target: Self::Target<T>) -> T {
        target.into_inner()
    }
}

Meta

rustc --version --verbose:

rustc 1.68.1 (8460ca823 2023-03-20)
binary: rustc
commit-hash: 8460ca823e8367a30dda430efda790588b8c84d3
commit-date: 2023-03-20
host: x86_64-pc-windows-msvc
release: 1.68.1
LLVM version: 15.0.6

Error output

compiler\rustc_infer\src\infer\region_constraints\mod.rs:568:17: cannot relate bound region: ReErased <= ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:42 ~ mut_family[c9ba]::MutFamily::as_ptr::'a), 'a) })
Backtrace

C:\Users\USER\Documents\github\mut_family>cargo check
    Checking mut_family v0.1.0 (C:\Users\USER\Documents\github\mut_family)
error: generic parameters may not be used in const operations
  --> src\lib.rs:32:69
   |
32 |     fn as_ptr<'a, T>(reference: RefCarrierTy<'a, Self::Target<T>, { Self::IS_INTERIOR_MUT }>::RefTy) -> *mut T;
   |                                                                     ^^^^^^^^^^^^^^^^^^^^^ cannot perform const operation using `Self`
   |
   = note: type parameters may not be used in const expressions

error: internal compiler error: compiler\rustc_infer\src\infer\region_constraints\mod.rs:568:17: cannot relate bound region: ReErased <= ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:42 ~ mut_family[c9ba]::MutFamily::as_ptr::'a), 'a) })

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/8460ca823e8367a30dda430efda790588b8c84d3\compiler\rustc_errors\src\lib.rs:987:33
stack backtrace:
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.68.1 (8460ca823 2023-03-20) running on x86_64-pc-windows-msvc

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:
#0 [fn_sig] computing function signature of `MutFamily::as_ptr`
#1 [collect_mod_item_types] collecting item types in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `mut_family` due to previous error

C:\Users\USER\Documents\github\mut_family>set RUST_BACKTRACE=full

C:\Users\USER\Documents\github\mut_family>cargo check
    Checking mut_family v0.1.0 (C:\Users\USER\Documents\github\mut_family)
error: generic parameters may not be used in const operations
  --> src\lib.rs:32:69
   |
32 |     fn as_ptr<'a, T>(reference: RefCarrierTy<'a, Self::Target<T>, { Self::IS_INTERIOR_MUT }>::RefTy) -> *mut T;
   |                                                                     ^^^^^^^^^^^^^^^^^^^^^ cannot perform const operation using `Self`
   |
   = note: type parameters may not be used in const expressions

error: internal compiler error: compiler\rustc_infer\src\infer\region_constraints\mod.rs:568:17: cannot relate bound region: ReErased <= ReLateBound(DebruijnIndex(0), BoundRegion { var: 0, kind: BrNamed(DefId(0:42 ~ mut_family[c9ba]::MutFamily::as_ptr::'a), 'a) })

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/8460ca823e8367a30dda430efda790588b8c84d3\compiler\rustc_errors\src\lib.rs:987:33
stack backtrace:
   0:     0x7fff53109d02 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h24420960574ebc1c
   1:     0x7fff5314570b - core::fmt::write::h26edb44d1c5a6228
   2:     0x7fff530fcdfa - <std::io::IoSlice as core::fmt::Debug>::fmt::h3ff7218cf0d77c3d
   3:     0x7fff53109a4b - std::sys::common::alloc::realloc_fallback::hc95eb280a5e906e1
   4:     0x7fff5310d3f9 - std::panicking::default_hook::h0e3996dde5e60121
   5:     0x7fff5310d07b - std::panicking::default_hook::h0e3996dde5e60121
   6:     0x7fff1da568d5 - rustc_driver[9a81db59c34cf3a5]::describe_lints
   7:     0x7fff5310dd5f - std::panicking::rust_panic_with_hook::hf3035ce96f91938a
   8:     0x7fff1fd16493 - <<rustc_infer[4a5594bed6e23f7a]::infer::error_reporting::TypeErrCtxt>::construct_generic_bound_failure::SubOrigin as core[88a2d7387c40f712]::fmt::Debug>::fmt
   9:     0x7fff1fd149a9 - <<rustc_infer[4a5594bed6e23f7a]::infer::error_reporting::TypeErrCtxt>::construct_generic_bound_failure::SubOrigin as core[88a2d7387c40f712]::fmt::Debug>::fmt
  10:     0x7fff1fd14619 - <<rustc_infer[4a5594bed6e23f7a]::infer::error_reporting::TypeErrCtxt>::construct_generic_bound_failure::SubOrigin as core[88a2d7387c40f712]::fmt::Debug>::fmt
  11:     0x7fff1fd14609 - <<rustc_infer[4a5594bed6e23f7a]::infer::error_reporting::TypeErrCtxt>::construct_generic_bound_failure::SubOrigin as core[88a2d7387c40f712]::fmt::Debug>::fmt
  12:     0x7fff1fd13fb0 - <<rustc_infer[4a5594bed6e23f7a]::infer::error_reporting::TypeErrCtxt>::construct_generic_bound_failure::SubOrigin as core[88a2d7387c40f712]::fmt::Debug>::fmt
  13:     0x7fff1fd13e09 - <<rustc_infer[4a5594bed6e23f7a]::infer::error_reporting::TypeErrCtxt>::construct_generic_bound_failure::SubOrigin as core[88a2d7387c40f712]::fmt::Debug>::fmt
  14:     0x7fff1fd1c259 - <rustc_infer[4a5594bed6e23f7a]::infer::opaque_types::table::OpaqueTypeStorage as core[88a2d7387c40f712]::fmt::Debug>::fmt
  15:     0x7fff1fd1c2bd - <rustc_infer[4a5594bed6e23f7a]::infer::opaque_types::table::OpaqueTypeStorage as core[88a2d7387c40f712]::fmt::Debug>::fmt
  16:     0x7fff1fd1b47a - <rustc_infer[4a5594bed6e23f7a]::infer::opaque_types::table::OpaqueTypeStorage as core[88a2d7387c40f712]::fmt::Debug>::fmt
  17:     0x7fff1fd1b408 - <rustc_infer[4a5594bed6e23f7a]::infer::opaque_types::table::OpaqueTypeStorage as core[88a2d7387c40f712]::fmt::Debug>::fmt
  18:     0x7fff1fd1b3c6 - <rustc_infer[4a5594bed6e23f7a]::infer::opaque_types::table::OpaqueTypeStorage as core[88a2d7387c40f712]::fmt::Debug>::fmt
  19:     0x7fff1d884d1a - <rustc_infer[4a5594bed6e23f7a]::infer::combine::ConstInferUnifier as rustc_middle[348c050efaf3cf62]::ty::relate::TypeRelation>::consts
  20:     0x7fff1d88ccbc - <rustc_middle[348c050efaf3cf62]::ty::sty::AliasTy as rustc_infer[4a5594bed6e23f7a]::infer::at::ToTrace>::to_trace
  21:     0x7fff1d893840 - <rustc_middle[348c050efaf3cf62]::ty::sty::AliasTy as rustc_infer[4a5594bed6e23f7a]::infer::at::ToTrace>::to_trace
  22:     0x7fff1d84ee99 - <rustc_infer[4a5594bed6e23f7a]::infer::equate::Equate as rustc_middle[348c050efaf3cf62]::ty::relate::TypeRelation>::tys
  23:     0x7fff1cd2c582 - <rustc_hir_analysis[38f54a96453c487e]::check::wfcheck::check_where_clauses::{closure#2}::CountParams as rustc_middle[348c050efaf3cf62]::ty::visit::TypeVisitor>::visit_ty
  24:     0x7fff1ccef08a - rustc_hir_analysis[38f54a96453c487e]::collect::get_infer_ret_ty
  25:     0x7fff1efbd849 - <rustc_hir_analysis[38f54a96453c487e]::check::compare_impl_item::CheckImpliedWfMode as core[88a2d7387c40f712]::fmt::Debug>::fmt
  26:     0x7fff1ef9a3b9 - <rustc_hir_analysis[38f54a96453c487e]::check::check::check_opaque_for_inheriting_lifetimes::ProhibitOpaqueVisitor as rustc_hir[c9ded08e9c1a2081]::intravisit::Visitor>::visit_ty
  27:     0x7fff1efa76d1 - <rustc_hir_analysis[38f54a96453c487e]::collect::predicates_of::OnlySelfBounds as core[88a2d7387c40f712]::fmt::Debug>::fmt
  28:     0x7fff1ef5ff50 - <rustc_hir_analysis[38f54a96453c487e]::variance::terms::InferredIndex as core[88a2d7387c40f712]::fmt::Debug>::fmt
  29:     0x7fff1ef67d1b - <dyn rustc_hir_analysis[38f54a96453c487e]::astconv::AstConv>::associated_path_to_ty
  30:     0x7fff1efc0f26 - <rustc_hir_analysis[38f54a96453c487e]::check::region::Context as core[88a2d7387c40f712]::fmt::Debug>::fmt
  31:     0x7fff1efa74ac - <rustc_hir_analysis[38f54a96453c487e]::collect::predicates_of::OnlySelfBounds as core[88a2d7387c40f712]::fmt::Debug>::fmt
  32:     0x7fff1ef99d20 - <rustc_hir_analysis[38f54a96453c487e]::check::check::check_opaque_for_inheriting_lifetimes::ProhibitOpaqueVisitor as rustc_hir[c9ded08e9c1a2081]::intravisit::Visitor>::visit_ty
  33:     0x7fff1efd1941 - <rustc_hir_analysis[38f54a96453c487e]::collect::type_of::find_opaque_ty_constraints_for_tait::ConstraintLocator as rustc_hir[c9ded08e9c1a2081]::intravisit::Visitor>::visit_trait_item
  34:     0x7fff1cccf334 - <<dyn rustc_hir_analysis[38f54a96453c487e]::astconv::AstConv>::create_substs_for_ast_path::{closure#0}::SubstsForAstPathCtxt as rustc_hir_analysis[38f54a96453c487e]::astconv::CreateSubstsForGenericArgsCtxt>::provided_kind
  35:     0x7fff1ccd3e98 - <<dyn rustc_hir_analysis[38f54a96453c487e]::astconv::AstConv>::create_substs_for_ast_path::{closure#0}::SubstsForAstPathCtxt as rustc_hir_analysis[38f54a96453c487e]::astconv::CreateSubstsForGenericArgsCtxt>::provided_kind
  36:     0x7fff1ccd521c - <dyn rustc_hir_analysis[38f54a96453c487e]::astconv::AstConv>::ty_of_fn
  37:     0x7fff1ccee194 - rustc_hir_analysis[38f54a96453c487e]::collect::get_infer_ret_ty
  38:     0x7fff1bc3f6ec - <rustc_query_impl[7254303e48199d54]::on_disk_cache::CacheEncoder as rustc_type_ir[1f8388642b2bc09c]::codec::TyEncoder>::encode_alloc_id
  39:     0x7fff1bca7ab9 - <&[(rustc_middle[348c050efaf3cf62]::ty::Predicate, rustc_span[d3e736c3e38f3ea5]::span_encoding::Span)] as rustc_serialize[fb792d7000edb6]::serialize::Decodable<rustc_query_impl[7254303e48199d54]::on_disk_cache::CacheDecoder>>::decode
  40:     0x7fff1d42e334 - <&[(rustc_middle[348c050efaf3cf62]::ty::Clause, rustc_span[d3e736c3e38f3ea5]::span_encoding::Span)] as rustc_serialize[fb792d7000edb6]::serialize::Decodable<rustc_query_impl[7254303e48199d54]::on_disk_cache::CacheDecoder>>::decode
  41:     0x7fff1d306ad8 - <rustc_query_impl[7254303e48199d54]::Queries as rustc_middle[348c050efaf3cf62]::ty::query::QueryEngine>::as_any
  42:     0x7fff1b9624f4 - <rustc_hir_analysis[38f54a96453c487e]::collect::CollectItemTypesVisitor as rustc_hir[c9ded08e9c1a2081]::intravisit::Visitor>::visit_trait_item
  43:     0x7fff1ccd69a4 - <dyn rustc_hir_analysis[38f54a96453c487e]::astconv::AstConv>::ty_of_fn
  44:     0x7fff1b961fd1 - <rustc_hir_analysis[38f54a96453c487e]::collect::generics_of::AnonConstInParamTyDetector as rustc_hir[c9ded08e9c1a2081]::intravisit::Visitor>::visit_generic_param
  45:     0x7fff1bc3ddb9 - <rustc_query_impl[7254303e48199d54]::on_disk_cache::CacheEncoder as rustc_type_ir[1f8388642b2bc09c]::codec::TyEncoder>::encode_alloc_id
  46:     0x7fff1bca7425 - <&[(rustc_middle[348c050efaf3cf62]::ty::Predicate, rustc_span[d3e736c3e38f3ea5]::span_encoding::Span)] as rustc_serialize[fb792d7000edb6]::serialize::Decodable<rustc_query_impl[7254303e48199d54]::on_disk_cache::CacheDecoder>>::decode
  47:     0x7fff1bd56191 - <&[(rustc_middle[348c050efaf3cf62]::ty::Predicate, rustc_span[d3e736c3e38f3ea5]::span_encoding::Span)] as rustc_serialize[fb792d7000edb6]::serialize::Decodable<rustc_query_impl[7254303e48199d54]::on_disk_cache::CacheDecoder>>::decode
  48:     0x7fff1bc12cbf - <rustc_query_impl[7254303e48199d54]::Queries as rustc_middle[348c050efaf3cf62]::ty::query::QueryEngine>::try_mark_green
  49:     0x7fff1b94a975 - <<dyn rustc_hir_analysis[38f54a96453c487e]::astconv::AstConv>::create_substs_for_ast_path::{closure#0}::SubstsForAstPathCtxt as rustc_hir_analysis[38f54a96453c487e]::astconv::CreateSubstsForGenericArgsCtxt>::inferred_kind
  50:     0x7fff1b94208a - rustc_hir_analysis[38f54a96453c487e]::check_crate
  51:     0x7fff1b222275 - rustc_interface[80bde221feee50b9]::passes::analysis
  52:     0x7fff1bc40a4f - <rustc_query_impl[7254303e48199d54]::on_disk_cache::CacheEncoder as rustc_type_ir[1f8388642b2bc09c]::codec::TyEncoder>::encode_alloc_id
  53:     0x7fff1bcbfe69 - <&[(rustc_middle[348c050efaf3cf62]::ty::Predicate, rustc_span[d3e736c3e38f3ea5]::span_encoding::Span)] as rustc_serialize[fb792d7000edb6]::serialize::Decodable<rustc_query_impl[7254303e48199d54]::on_disk_cache::CacheDecoder>>::decode
  54:     0x7fff1bdac201 - <&[(rustc_middle[348c050efaf3cf62]::ty::Predicate, rustc_span[d3e736c3e38f3ea5]::span_encoding::Span)] as rustc_serialize[fb792d7000edb6]::serialize::Decodable<rustc_query_impl[7254303e48199d54]::on_disk_cache::CacheDecoder>>::decode
  55:     0x7fff1bc1056f - <rustc_query_impl[7254303e48199d54]::Queries as rustc_middle[348c050efaf3cf62]::ty::query::QueryEngine>::try_mark_green
  56:     0x7fff1b1cd1a9 - <rustc_middle[348c050efaf3cf62]::ty::SymbolName as core[88a2d7387c40f712]::fmt::Debug>::fmt
  57:     0x7fff1b1de7ba - rustc_driver[9a81db59c34cf3a5]::args::arg_expand_all
  58:     0x7fff1b1c2ac1 - <unknown>
  59:     0x7fff1b1ccacb - <rustc_middle[348c050efaf3cf62]::ty::SymbolName as core[88a2d7387c40f712]::fmt::Debug>::fmt
  60:     0x7fff1b1cc319 - <rustc_middle[348c050efaf3cf62]::ty::SymbolName as core[88a2d7387c40f712]::fmt::Debug>::fmt
  61:     0x7fff1b1c404d - <rustc_middle[348c050efaf3cf62]::ty::SymbolName as core[88a2d7387c40f712]::fmt::Debug>::fmt
  62:     0x7fff5312021c - std::sys::windows::thread::Thread::new::hd26bc42258b98de9
  63:     0x7fff9b847614 - BaseThreadInitThunk
  64:     0x7fff9be426a1 - RtlUserThreadStart

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.68.1 (8460ca823 2023-03-20) running on x86_64-pc-windows-msvc

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:
#0 [fn_sig] computing function signature of `MutFamily::as_ptr`
#1 [collect_mod_item_types] collecting item types in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `mut_family` due to previous error

@JohnScience JohnScience 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 Apr 5, 2023
@JohnScience
Copy link
Contributor Author

This isn't meant to compile in the first place because type parameters cannot be used in const expressions yet it's still an ICE.

@Noratrieb
Copy link
Member

Thanks for the report, but this is a duplicate of #109361 which is fixed on nightly and beta

@Noratrieb Noratrieb closed this as not planned Won't fix, can't repro, duplicate, stale Apr 5, 2023
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. 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

No branches or pull requests

2 participants