Skip to content

ICE: None in compiler/rustc_middle/src/ty/sty.rs #126378

Closed

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

struct A();

impl const Drop for A {}

#![feature(effects)]

original:

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

struct A();

impl const Drop for A {
    fn main() {
    let _: &'static A = &A(); //~ ERROR temporary value dropped while borrowed
    let _: &'static [A] = &[C]; //~ ERROR temporary value dropped while borrowed
}
}

const const_trait_impl: A = A();

fn main() {
    let _: &'static A = &A(); //~ ERROR temporary value dropped while borrowed
    let _: &'static [A] = &[C]; //~ ERROR temporary value dropped while borrowed
}

Version information

rustc 1.81.0-nightly (8cf5101d7 2024-06-12)
binary: rustc
commit-hash: 8cf5101d77cd9eeb12751c563d8098aba2c604d0
commit-date: 2024-06-12
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

Command:
/home/gh-matthiaskrgr/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(effects)

Program output

error[E0658]: const trait impls are experimental
 --> /tmp/icemaker_global_tempdir.qucPmmmLlnXC/rustc_testrunner_tmpdir_reporting.BE4likY1WzZ7/mvce.rs:3:6
  |
3 | impl const Drop for A {}
  |      ^^^^^
  |
  = note: see issue #67792 <https://github.com/rust-lang/rust/issues/67792> for more information
  = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable
  = note: this compiler was built on 2024-06-12; consider upgrading it if it is out of date

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.qucPmmmLlnXC/rustc_testrunner_tmpdir_reporting.BE4likY1WzZ7/mvce.rs:3:25
  |
3 | impl const Drop for A {}
  |                         ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.qucPmmmLlnXC/rustc_testrunner_tmpdir_reporting.BE4likY1WzZ7/mvce.rs`

error: const `impl` for trait `Drop` which is not marked with `#[const_trait]`
 --> /tmp/icemaker_global_tempdir.qucPmmmLlnXC/rustc_testrunner_tmpdir_reporting.BE4likY1WzZ7/mvce.rs:3:12
  |
3 | impl const Drop for A {}
  |            ^^^^
  |
  = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
  = note: adding a non-const method body in the future would be a breaking change

thread 'rustc' panicked at compiler/rustc_middle/src/ty/sty.rs:360:36:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x72429878aae5 - std::backtrace_rs::backtrace::libunwind::trace::h1eae5369495be94c
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x72429878aae5 - std::backtrace_rs::backtrace::trace_unsynchronized::hb9ff15614ae80516
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x72429878aae5 - std::sys_common::backtrace::_print_fmt::h715013f8db9fa836
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x72429878aae5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb2525cfb3de001ec
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7242987db77b - core::fmt::rt::Argument::fmt::h313d6a20d718e675
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/core/src/fmt/rt.rs:165:63
   5:     0x7242987db77b - core::fmt::write::h34b41f02f735d6be
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/core/src/fmt/mod.rs:1168:21
   6:     0x72429877f76f - std::io::Write::write_fmt::h3163bf1024b30f9d
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/std/src/io/mod.rs:1835:15
   7:     0x72429878a8be - std::sys_common::backtrace::_print::h3cf8718ea70ad379
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x72429878a8be - std::sys_common::backtrace::print::hb2023c867b337d63
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x72429878d2f9 - std::panicking::default_hook::{{closure}}::h077ef55df06e466d
  10:     0x72429878d09c - std::panicking::default_hook::hfd347bda164b89a9
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/std/src/panicking.rs:292:9
  11:     0x72429bab5ed0 - std[1b0e87a7881e3f2e]::panicking::update_hook::<alloc[256686a2906c29a0]::boxed::Box<rustc_driver_impl[935dcf8ae4c858c0]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x72429878dbff - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::he8ea12bfb8de16b1
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/alloc/src/boxed.rs:2076:9
  13:     0x72429878dbff - std::panicking::rust_panic_with_hook::h77a553aef83cdbaf
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/std/src/panicking.rs:801:13
  14:     0x72429878d7f3 - std::panicking::begin_panic_handler::{{closure}}::h5b05d7e6508b1742
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/std/src/panicking.rs:660:13
  15:     0x72429878afa9 - std::sys_common::backtrace::__rust_end_short_backtrace::h5c68199ef3e35ced
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x72429878d4d4 - rust_begin_unwind
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/std/src/panicking.rs:658:5
  17:     0x7242987d7d33 - core::panicking::panic_fmt::h2a691adfa40775d5
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/core/src/panicking.rs:74:14
  18:     0x7242987d7dbc - core::panicking::panic::h5482279ace8e11cf
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/core/src/panicking.rs:148:5
  19:     0x7242987d7b29 - core::option::unwrap_failed::hf7e2b68d8b2b7d2b
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/core/src/option.rs:1985:5
  20:     0x72429e76dcbc - <rustc_middle[ca7f0dc9254b8975]::ty::sty::ParamConst>::find_ty_from_env.cold
  21:     0x724299bb1e32 - <rustc_trait_selection[61b62075c2ac6296]::traits::fulfill::FulfillProcessor as rustc_data_structures[75e680cad15e3340]::obligation_forest::ObligationProcessor>::process_obligation
  22:     0x72429cef8907 - <rustc_data_structures[75e680cad15e3340]::obligation_forest::ObligationForest<rustc_trait_selection[61b62075c2ac6296]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[61b62075c2ac6296]::traits::fulfill::FulfillProcessor>
  23:     0x72429cefa943 - <rustc_trait_selection[61b62075c2ac6296]::traits::fulfill::FulfillmentContext<rustc_trait_selection[61b62075c2ac6296]::traits::FulfillmentError> as rustc_infer[b02e37160fc9aec]::traits::engine::TraitEngine<rustc_trait_selection[61b62075c2ac6296]::traits::FulfillmentError>>::select_all_or_error
  24:     0x72429daaec8f - rustc_hir_analysis[5d45d15212514940]::check::dropck::check_drop_impl
  25:     0x72429daae746 - <rustc_middle[ca7f0dc9254b8975]::ty::context::TyCtxt>::calculate_dtor::<rustc_hir_analysis[5d45d15212514940]::check::dropck::check_drop_impl>::{closure#0}
  26:     0x72429d90e862 - rustc_hir_analysis[5d45d15212514940]::check::adt_destructor
  27:     0x72429d90ea72 - rustc_query_impl[74ded2e9ca83132e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[74ded2e9ca83132e]::query_impl::adt_destructor::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ca7f0dc9254b8975]::query::erase::Erased<[u8; 12usize]>>
  28:     0x72429d4089ad - rustc_query_system[32db906e1bbe7f36]::query::plumbing::try_execute_query::<rustc_query_impl[74ded2e9ca83132e]::DynamicConfig<rustc_query_system[32db906e1bbe7f36]::query::caches::DefIdCache<rustc_middle[ca7f0dc9254b8975]::query::erase::Erased<[u8; 12usize]>>, false, false, false>, rustc_query_impl[74ded2e9ca83132e]::plumbing::QueryCtxt, false>
  29:     0x72429d40828f - rustc_query_impl[74ded2e9ca83132e]::query_impl::adt_destructor::get_query_non_incr::__rust_end_short_backtrace
  30:     0x72429d70b372 - <rustc_middle[ca7f0dc9254b8975]::ty::adt::AdtDef>::destructor
  31:     0x72429978a44a - rustc_hir_analysis[5d45d15212514940]::check::check::check_item_type
  32:     0x72429a78ad4c - rustc_hir_analysis[5d45d15212514940]::check::wfcheck::check_well_formed
  33:     0x72429d0f19a9 - rustc_query_impl[74ded2e9ca83132e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[74ded2e9ca83132e]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ca7f0dc9254b8975]::query::erase::Erased<[u8; 1usize]>>
  34:     0x72429d0f1c2a - rustc_query_system[32db906e1bbe7f36]::query::plumbing::try_execute_query::<rustc_query_impl[74ded2e9ca83132e]::DynamicConfig<rustc_query_system[32db906e1bbe7f36]::query::caches::VecCache<rustc_hir[c2711ee5d901482]::hir_id::OwnerId, rustc_middle[ca7f0dc9254b8975]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[74ded2e9ca83132e]::plumbing::QueryCtxt, false>
  35:     0x72429d0f1986 - rustc_query_impl[74ded2e9ca83132e]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  36:     0x72429d0f270f - rustc_hir_analysis[5d45d15212514940]::check::wfcheck::check_mod_type_wf
  37:     0x72429d0f2555 - rustc_query_impl[74ded2e9ca83132e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[74ded2e9ca83132e]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ca7f0dc9254b8975]::query::erase::Erased<[u8; 1usize]>>
  38:     0x72429d8aaab0 - rustc_query_system[32db906e1bbe7f36]::query::plumbing::try_execute_query::<rustc_query_impl[74ded2e9ca83132e]::DynamicConfig<rustc_query_system[32db906e1bbe7f36]::query::caches::DefaultCache<rustc_span[504087e652f64f62]::def_id::LocalModDefId, rustc_middle[ca7f0dc9254b8975]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[74ded2e9ca83132e]::plumbing::QueryCtxt, false>
  39:     0x72429d8aa859 - rustc_query_impl[74ded2e9ca83132e]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  40:     0x72429d10428c - rustc_hir_analysis[5d45d15212514940]::check_crate
  41:     0x72429d8452fe - rustc_interface[30a5feafe5a08242]::passes::analysis
  42:     0x72429d844e47 - rustc_query_impl[74ded2e9ca83132e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[74ded2e9ca83132e]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ca7f0dc9254b8975]::query::erase::Erased<[u8; 1usize]>>
  43:     0x72429dc31f65 - rustc_query_system[32db906e1bbe7f36]::query::plumbing::try_execute_query::<rustc_query_impl[74ded2e9ca83132e]::DynamicConfig<rustc_query_system[32db906e1bbe7f36]::query::caches::SingleCache<rustc_middle[ca7f0dc9254b8975]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[74ded2e9ca83132e]::plumbing::QueryCtxt, false>
  44:     0x72429dc31ccf - rustc_query_impl[74ded2e9ca83132e]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  45:     0x72429dac8f12 - rustc_interface[30a5feafe5a08242]::interface::run_compiler::<core[1ccefa92ed8426b9]::result::Result<(), rustc_span[504087e652f64f62]::ErrorGuaranteed>, rustc_driver_impl[935dcf8ae4c858c0]::run_compiler::{closure#0}>::{closure#1}
  46:     0x72429dae7949 - std[1b0e87a7881e3f2e]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[30a5feafe5a08242]::util::run_in_thread_with_globals<rustc_interface[30a5feafe5a08242]::util::run_in_thread_pool_with_globals<rustc_interface[30a5feafe5a08242]::interface::run_compiler<core[1ccefa92ed8426b9]::result::Result<(), rustc_span[504087e652f64f62]::ErrorGuaranteed>, rustc_driver_impl[935dcf8ae4c858c0]::run_compiler::{closure#0}>::{closure#1}, core[1ccefa92ed8426b9]::result::Result<(), rustc_span[504087e652f64f62]::ErrorGuaranteed>>::{closure#0}, core[1ccefa92ed8426b9]::result::Result<(), rustc_span[504087e652f64f62]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1ccefa92ed8426b9]::result::Result<(), rustc_span[504087e652f64f62]::ErrorGuaranteed>>
  47:     0x72429dae76fa - <<std[1b0e87a7881e3f2e]::thread::Builder>::spawn_unchecked_<rustc_interface[30a5feafe5a08242]::util::run_in_thread_with_globals<rustc_interface[30a5feafe5a08242]::util::run_in_thread_pool_with_globals<rustc_interface[30a5feafe5a08242]::interface::run_compiler<core[1ccefa92ed8426b9]::result::Result<(), rustc_span[504087e652f64f62]::ErrorGuaranteed>, rustc_driver_impl[935dcf8ae4c858c0]::run_compiler::{closure#0}>::{closure#1}, core[1ccefa92ed8426b9]::result::Result<(), rustc_span[504087e652f64f62]::ErrorGuaranteed>>::{closure#0}, core[1ccefa92ed8426b9]::result::Result<(), rustc_span[504087e652f64f62]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1ccefa92ed8426b9]::result::Result<(), rustc_span[504087e652f64f62]::ErrorGuaranteed>>::{closure#2} as core[1ccefa92ed8426b9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  48:     0x724298797a7b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hbaa641b300aece5a
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/alloc/src/boxed.rs:2062:9
  49:     0x724298797a7b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h67b521bf367d14d7
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/alloc/src/boxed.rs:2062:9
  50:     0x724298797a7b - std::sys::pal::unix::thread::Thread::new::thread_start::hc86a294633ed1c1b
                               at /rustc/8cf5101d77cd9eeb12751c563d8098aba2c604d0/library/std/src/sys/pal/unix/thread.rs:108:17
  51:     0x724298494ac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  52:     0x724298526850 - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  53:                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 make sure that you have updated to the latest nightly

note: rustc 1.81.0-nightly (8cf5101d7 2024-06-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(effects) -Z dump-mir-dir=dir

query stack during panic:
#0 [adt_destructor] computing `Drop` impl for `A`
#1 [check_well_formed] checking that `A` is well-formed
end of query stack
error[E0207]: the const parameter `host` is not constrained by the impl trait, self type, or predicates
 --> /tmp/icemaker_global_tempdir.qucPmmmLlnXC/rustc_testrunner_tmpdir_reporting.BE4likY1WzZ7/mvce.rs:3:6
  |
3 | impl const Drop for A {}
  |      ^^^^^ 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 4 previous errors

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

@rustbot label +F-const_trait_impl +F-const_trait_impl +F-effects

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Jun 13, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    F-effects`#![feature(effects)]`
    on Jun 13, 2024
  3. changed the title [-]ICE: `None` in `compiler/rustc_middle/src/ty/sty.rs:[/-] [+]ICE: `None` in `compiler/rustc_middle/src/ty/sty.rs`[/+] on Jun 13, 2024
  4. BoxyUwU commented on Jun 13, 2024

    @BoxyUwU
    Member

    This is a dupe of #126147, it doesnt ICE on nightly

  5. matthiaskrgr commented on Jun 13, 2024

    @matthiaskrgr
    Author
  6. oli-obk commented on Jun 13, 2024

    @oli-obk
    Contributor

    The playground does not reproduce this issue

  7. matthiaskrgr commented on Jun 13, 2024

    @matthiaskrgr
    MemberAuthor

    with rustc master 56e112a I can still reproduce this.
    this is also what the report was generated with

  8. matthiaskrgr commented on Jun 13, 2024

    @matthiaskrgr
    MemberAuthor

    ah nevermind, I think I was inside a repo with a rustc-toolchain which downgraded the rustc to nightly again without me noticing xD

  9. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 13, 2024
  10. matthiaskrgr commented on Jun 13, 2024

    @matthiaskrgr
    MemberAuthor

    After all, I stand correct that the

    struct A();
    impl const Drop for A {}

    snippet with effects was never fixed:

    #126147 (comment) fixed
    #126147 (comment) fixed
    #126147 (comment) fixed

    never fixed: #126147 (comment)

    playground repro ICE long https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=4f5758a90a2ae608d4a7ebcb768ce68b

    playground repro ICE short
    https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=489f57bd378a68a1be8c7a5b1623eb2c

  11. matthiaskrgr commented on Jun 13, 2024

    @matthiaskrgr
    MemberAuthor

    rustc does not like having the feature standalone, so

    struct A();
    
    impl const Drop for A {}
    
    #![feature(effects)]

    does not ICE; but this is only generated because people wanted to have the feature gets inside the repro (I forgot to manually fix it and copy it to the top):

    so

    #![feature(effects)]
    struct A();
    impl const Drop for A {}

    as well as

    struct A();
    impl const Drop for A {}

    with -Zcrate-attr=feature(effects) should still ICE on nightly / master

  12. BoxyUwU commented on Jun 13, 2024

    @BoxyUwU
    Member

    Likely caused by the ConstArgHasType predicates we generate in predicates_of being based off the hir generics instead of generics_of.

  13. self-assigned this
    on Jun 13, 2024
  14. BoxyUwU commented on Jun 13, 2024

    @BoxyUwU
    Member

    Actually no, while that's something we should fix, the ICE here is actually caused by the fact that we prove the impl predicates in the env of the adt which.... ConstArgHasType(HostParam, bool) does not hold in

  15. added a commit that references this issue on Jul 25, 2024
    29314e4
  16. added a commit that references this issue on Jul 26, 2024
    d93ed60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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) ❄️T-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