Skip to content

ICE: None in compiler/rustc_middle/src/ty/sty.rs without feature(effects) #126889

Closed
@Naserume

Description

@Naserume

Code

Related issue is #126378. This ices without #![feature(effects)].

(reduced)

struct Foo {}

impl<const Ca: usize> Drop for Foo {}

fn main() {}

(original)

struct Foo {
    bar: Bar,
}

struct Bar {
    qux: i32,
}

// Issue 8142: Test that Drop impls cannot be specialized beyond the
// predicates attached to the type definition itself.
trait Bound { fn foo(&self) { } }
struct K<'l1,'l2> { x: &'l1 i8, y: &'l2 u8 }
struct L<'l1,'l2> { x: &'l1 i8, y: &'l2 u8 }
struct M<'m> { x: &'m i8 }
struct N<'n> { x: &'n i8 }
struct O<To> { x: *const To }
struct P<Tp> { x: *const Tp }
struct Q<Tq> { x: *const Tq }
struct R<Tr> { x: *const Tr }
struct S<Ts:Bound> { x: *const Ts }
struct T<'t,Ts:'t> { x: &'t Ts }
struct U;
struct V<Tva, Tvb> { x: *const Tva, y: *const Tvb }
struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }
struct X<const Ca: usize>;
struct Y<const Ca: usize, const Cb: usize>;

enum Enum<T> { Variant(T) }
struct TupleStruct<T>(T);
union Union<T: Copy> { f: T }

impl<'al,'adds_bnd:'al> Drop for K<'al,'adds_bnd> {                        // REJECT
    //~^ ERROR `Drop` impl requires `'adds_bnd: 'al`
    fn drop(&mut self) { } }

impl<'al,'adds_bnd>     Drop for L<'al,'adds_bnd> where 'adds_bnd:'al {    // REJECT
    //~^ ERROR `Drop` impl requires `'adds_bnd: 'al`
    fn drop(&mut self) { } }

impl<'ml>               Drop for M<'ml>         { fn drop(&mut self) { } } // ACCEPT

impl                    Drop for N<'static>     { fn drop(&mut self) { } } // REJECT
//~^ ERROR `Drop` impls cannot be specialized

impl<COkNoBound> Drop for O<COkNoBound> { fn drop(&mut self) { } } // ACCEPT

impl              Drop for P<i8>          { fn drop(&mut self) { } } // REJECT
//~^ ERROR `Drop` impls cannot be specialized

impl<AddsBnd:Bound> Drop for Q<AddsBnd> { fn drop(&mut self) { } } // REJECT
//~^ ERROR `Drop` impl requires `AddsBnd: Bound`

impl<'rbnd,AddsRBnd:'rbnd> Drop for R<AddsRBnd> { fn drop(&mut self) { } } // REJECT
//~^ ERROR `Drop` impl requires `AddsRBnd: 'rbnd`

impl<Bs:Bound>    Drop for S<Bs>          { fn drop(&mut self) { } } // ACCEPT

impl<'t,Bt:'t>    Drop for T<'t,Bt>       { fn drop(&mut self) { } } // ACCEPT

impl              Drop for U              { fn drop(&mut self) { } } // ACCEPT

impl<One>         Drop for V<One,One>     { fn drop(&mut self) { } } // REJECT
//~^ ERROR `Drop` impls cannot be specialized

impl<'lw>         Drop for W<'lw,'lw>     { fn drop(&mut self) { } } // REJECT
//~^ ERROR `Drop` impls cannot be specialized

impl              Drop for X<3>           { fn drop(&mut self) { } } // REJECT
//~^ ERROR `Drop` impls cannot be specialized

impl<const Ca: usize> Drop for Foo     { fn drop(&mut self) { } } // REJECT
//~^ ERROR `Drop` impls cannot be specialized

impl<AddsBnd:Bound> Drop for Enum<AddsBnd> { fn drop(&mut self) { } } // REJECT
//~^ ERROR `Drop` impl requires `AddsBnd: Bound`

impl<AddsBnd:Bound> Drop for TupleStruct<AddsBnd> { fn drop(&mut self) { } } // REJECT
//~^ ERROR `Drop` impl requires `AddsBnd: Bound`

impl<AddsBnd:Copy + Bound> Drop for Union<AddsBnd> { fn drop(&mut self) { } } // REJECT
//~^ ERROR `Drop` impl requires `AddsBnd: Bound`

pub fn main() { }

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (bcf94dec5 2024-06-23)
binary: rustc
commit-hash: bcf94dec5ba6838e435902120c0384c360126a26
commit-date: 2024-06-23
host: x86_64-apple-darwin
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

error[E0207]: the const parameter `Ca` is not constrained by the impl trait, self type, or predicates
 --> ./D2859.rs:4:6
  |
4 | impl<const Ca: usize> Drop for Foo {}
  |      ^^^^^^^^^^^^^^^ unconstrained const parameter
  |
  = note: expressions using a const parameter must map each value to a distinct output value
  = note: proving the result of expressions other than the parameter are unique is not supported

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0207`.
Backtrace

thread 'rustc' panicked at compiler/rustc_middle/src/ty/sty.rs:360:36:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:        0x106fe6b43 - <std::sys::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he71f7af0ddafc64d
   1:        0x10703225b - core::fmt::write::h30d0e266faff29b6
   2:        0x106fdcace - std::io::Write::write_fmt::he666ca78eb4b8406
   3:        0x106fe6931 - std::sys::backtrace::print::h22721f9ab9a2749a
   4:        0x106fe9709 - std::panicking::default_hook::{{closure}}::h145e29ed875d8021
   5:        0x106fe948a - std::panicking::default_hook::h5d437c7e6bf0e3b5
   6:        0x11028147c - std[8efa578c02603ef9]::panicking::update_hook::<alloc[135510a28be92df]::boxed::Box<rustc_driver_impl[63f2171535a6fe49]::install_ice_hook::{closure#0}>>::{closure#0}
   7:        0x106fea326 - std::panicking::rust_panic_with_hook::h6889093a56e48d04
   8:        0x106fe9b92 - std::panicking::begin_panic_handler::{{closure}}::hedafaff529964e0a
   9:        0x106fe7019 - std::sys::backtrace::__rust_end_short_backtrace::h15452907bf21f649
  10:        0x106fe989c - _rust_begin_unwind
  11:        0x10704d4aa - core::panicking::panic_fmt::hd76eb95c9d9ba8b3
  12:        0x10704d554 - core::panicking::panic::hb329c30fe2728c0f
  13:        0x10704d3f8 - core::option::unwrap_failed::hb04517061396b912
  14:        0x110f927e8 - <rustc_middle[4384e439927f71dd]::ty::sty::ParamConst>::find_ty_from_env
  15:        0x111f60d6c - <rustc_trait_selection[2bb3b73d2222b57e]::traits::fulfill::FulfillProcessor as rustc_data_structures[ff15d8e8c9f969c2]::obligation_forest::ObligationProcessor>::process_obligation
  16:        0x111d86a2b - <rustc_data_structures[ff15d8e8c9f969c2]::obligation_forest::ObligationForest<rustc_trait_selection[2bb3b73d2222b57e]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[2bb3b73d2222b57e]::traits::fulfill::FulfillProcessor>
  17:        0x111eca542 - <rustc_trait_selection[2bb3b73d2222b57e]::traits::fulfill::FulfillmentContext<rustc_trait_selection[2bb3b73d2222b57e]::traits::FulfillmentError> as rustc_infer[48e5f050b52d2ea4]::traits::engine::TraitEngine<rustc_trait_selection[2bb3b73d2222b57e]::traits::FulfillmentError>>::select_where_possible
  18:        0x111ea2b4f - <rustc_trait_selection[2bb3b73d2222b57e]::traits::fulfill::FulfillmentContext<rustc_trait_selection[2bb3b73d2222b57e]::traits::FulfillmentError> as rustc_infer[48e5f050b52d2ea4]::traits::engine::TraitEngine<rustc_trait_selection[2bb3b73d2222b57e]::traits::FulfillmentError>>::select_all_or_error
  19:        0x1105a599d - rustc_hir_analysis[8e62bc6471a04889]::check::dropck::check_drop_impl
  20:        0x1104f418b - <rustc_middle[4384e439927f71dd]::ty::context::TyCtxt>::calculate_dtor::<rustc_hir_analysis[8e62bc6471a04889]::check::dropck::check_drop_impl>::{closure#0}
  21:        0x1105ca1b0 - rustc_hir_analysis[8e62bc6471a04889]::check::adt_destructor
  22:        0x11191cac2 - rustc_query_impl[a24e9023943e74ab]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a24e9023943e74ab]::query_impl::adt_destructor::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 12usize]>>
  23:        0x1118b245e - <rustc_query_impl[a24e9023943e74ab]::query_impl::adt_destructor::dynamic_query::{closure#2} as core[9412a59d758dca42]::ops::function::FnOnce<(rustc_middle[4384e439927f71dd]::ty::context::TyCtxt, rustc_span[aed5394308446158]::def_id::DefId)>>::call_once
  24:        0x1116f9c4e - rustc_query_system[30bd0146b5104221]::query::plumbing::try_execute_query::<rustc_query_impl[a24e9023943e74ab]::DynamicConfig<rustc_query_system[30bd0146b5104221]::query::caches::DefIdCache<rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 12usize]>>, false, false, false>, rustc_query_impl[a24e9023943e74ab]::plumbing::QueryCtxt, false>
  25:        0x11193b2dd - rustc_query_impl[a24e9023943e74ab]::query_impl::adt_destructor::get_query_non_incr::__rust_end_short_backtrace
  26:        0x110fb35c0 - rustc_middle[4384e439927f71dd]::query::plumbing::query_get_at::<rustc_query_system[30bd0146b5104221]::query::caches::DefIdCache<rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 12usize]>>>
  27:        0x11057ca2a - rustc_hir_analysis[8e62bc6471a04889]::check::check::check_item_type
  28:        0x1105b64ae - rustc_hir_analysis[8e62bc6471a04889]::check::wfcheck::check_well_formed
  29:        0x11191e86c - rustc_query_impl[a24e9023943e74ab]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a24e9023943e74ab]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>
  30:        0x11179701f - rustc_query_system[30bd0146b5104221]::query::plumbing::try_execute_query::<rustc_query_impl[a24e9023943e74ab]::DynamicConfig<rustc_query_system[30bd0146b5104221]::query::caches::VecCache<rustc_hir[ae2456c39d7f6170]::hir_id::OwnerId, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a24e9023943e74ab]::plumbing::QueryCtxt, false>
  31:        0x111968280 - rustc_query_impl[a24e9023943e74ab]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  32:        0x1104acba2 - rustc_middle[4384e439927f71dd]::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system[30bd0146b5104221]::query::caches::VecCache<rustc_hir[ae2456c39d7f6170]::hir_id::OwnerId, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>, ()>
  33:        0x1105c4de1 - rustc_hir_analysis[8e62bc6471a04889]::check::wfcheck::check_mod_type_wf
  34:        0x11191e83c - rustc_query_impl[a24e9023943e74ab]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a24e9023943e74ab]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>
  35:        0x11174db79 - rustc_query_system[30bd0146b5104221]::query::plumbing::try_execute_query::<rustc_query_impl[a24e9023943e74ab]::DynamicConfig<rustc_query_system[30bd0146b5104221]::query::caches::DefaultCache<rustc_span[aed5394308446158]::def_id::LocalModDefId, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a24e9023943e74ab]::plumbing::QueryCtxt, false>
  36:        0x111944ed0 - rustc_query_impl[a24e9023943e74ab]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  37:        0x11064024c - rustc_hir_analysis[8e62bc6471a04889]::check_crate
  38:        0x110bda6cb - rustc_interface[73216d77aad0c3a5]::passes::run_required_analyses
  39:        0x110bdccb3 - rustc_interface[73216d77aad0c3a5]::passes::analysis
  40:        0x111922dec - rustc_query_impl[a24e9023943e74ab]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a24e9023943e74ab]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>
  41:        0x11170249e - rustc_query_system[30bd0146b5104221]::query::plumbing::try_execute_query::<rustc_query_impl[a24e9023943e74ab]::DynamicConfig<rustc_query_system[30bd0146b5104221]::query::caches::SingleCache<rustc_middle[4384e439927f71dd]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a24e9023943e74ab]::plumbing::QueryCtxt, false>
  42:        0x11192d307 - rustc_query_impl[a24e9023943e74ab]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  43:        0x1102258d7 - <rustc_interface[73216d77aad0c3a5]::queries::QueryResult<&rustc_middle[4384e439927f71dd]::ty::context::GlobalCtxt>>::enter::<core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>, rustc_driver_impl[63f2171535a6fe49]::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  44:        0x11027fc94 - rustc_interface[73216d77aad0c3a5]::interface::run_compiler::<core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>, rustc_driver_impl[63f2171535a6fe49]::run_compiler::{closure#0}>::{closure#1}
  45:        0x11026ec91 - std[8efa578c02603ef9]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[73216d77aad0c3a5]::util::run_in_thread_with_globals<rustc_interface[73216d77aad0c3a5]::util::run_in_thread_pool_with_globals<rustc_interface[73216d77aad0c3a5]::interface::run_compiler<core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>, rustc_driver_impl[63f2171535a6fe49]::run_compiler::{closure#0}>::{closure#1}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#0}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>
  46:        0x11028a3a6 - <<std[8efa578c02603ef9]::thread::Builder>::spawn_unchecked_<rustc_interface[73216d77aad0c3a5]::util::run_in_thread_with_globals<rustc_interface[73216d77aad0c3a5]::util::run_in_thread_pool_with_globals<rustc_interface[73216d77aad0c3a5]::interface::run_compiler<core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>, rustc_driver_impl[63f2171535a6fe49]::run_compiler::{closure#0}>::{closure#1}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#0}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9412a59d758dca42]::result::Result<(), rustc_span[aed5394308446158]::ErrorGuaranteed>>::{closure#2} as core[9412a59d758dca42]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  47:        0x106ff352b - std::sys::pal::unix::thread::Thread::new::thread_start::h68d49fa26efc1659
  48:     0x7ff801f5318b - __pthread_start

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

note: please attach the file at `/Users/Documents/2024-06-24-17224.txt` to your bug report

query stack during panic:
#0 [adt_destructor] computing `Drop` impl for `Foo`
#1 [check_well_formed] checking that `Foo` is well-formed
end of query stack

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions