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: effects: assertion failed: constant / lifetime #117244

Closed
matthiaskrgr opened this issue Oct 26, 2023 · 6 comments · Fixed by #119072
Closed

ice: effects: assertion failed: constant / lifetime #117244

matthiaskrgr opened this issue Oct 26, 2023 · 6 comments · Fixed by #119072
Assignees
Labels
C-bug Category: This is a bug. 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

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Oct 26, 2023

auto-reduced (treereduce-rust):

#![feature(effects)]

use std::marker::Destruct;

const fn check<T: ~const Destruct>(_: T) {}

original:

// known-bug: #110395

// revisions: stock precise
#![feature(const_trait_impl)]
#![feature(const_mut_refs)]
#![cfg_attr(precise, feature(const_precise_live_drops))]
#![feature(effects)]

use std::marker::{Destruct, PhantomData};

pub struct Color<const WHITE: (fn(),)>;

impl Drop for NonTrivialDrop {
    fn drop(&mut self) {
        println!("Non trivial drop");
    }
}

struct ConstImplWithDropGlue(NonTrivialDrop);

impl const Drop for ConstImplWithDropGlue {
    fn drop(&mut self) {}
}

const fn check<T: ~const Destruct>(_: T) {}

macro_rules! check_all {
    ($($exp:expr),*$(,)?) => {$(
        const _: () = check($exp);
    )*};
}

check_all! {
    NonTrivialDrop,
    ConstImplWithDropGlue(NonTrivialDrop),
}

fn main() {}

Version information

rustc 1.75.0-nightly (698db856d 2023-10-26)
binary: rustc
commit-hash: 698db856de0b67313ddcb96b6599598058489ea9
commit-date: 2023-10-26
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.3

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

Program output

error[E0658]: const trait impls are experimental
 --> /tmp/icemaker_global_tempdir.zf1EZKgSPxgi/rustc_testrunner_tmpdir_reporting.ytGYsxhOGnyY/mvce.rs:3:19
  |
3 | const fn check<T: ~const Destruct>(_: T) {}
  |                   ^^^^^^
  |
  = 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

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.zf1EZKgSPxgi/rustc_testrunner_tmpdir_reporting.ytGYsxhOGnyY/mvce.rs:3:44
  |
3 | const fn check<T: ~const Destruct>(_: T) {}
  |                                            ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.zf1EZKgSPxgi/rustc_testrunner_tmpdir_reporting.ytGYsxhOGnyY/mvce.rs`

error[E0658]: use of unstable library feature 'const_trait_impl'
 --> /tmp/icemaker_global_tempdir.zf1EZKgSPxgi/rustc_testrunner_tmpdir_reporting.ytGYsxhOGnyY/mvce.rs:1:5
  |
1 | use std::marker::Destruct;
  |     ^^^^^^^^^^^^^^^^^^^^^
  |
  = 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

error[E0658]: use of unstable library feature 'const_trait_impl'
 --> /tmp/icemaker_global_tempdir.zf1EZKgSPxgi/rustc_testrunner_tmpdir_reporting.ytGYsxhOGnyY/mvce.rs:3:26
  |
3 | const fn check<T: ~const Destruct>(_: T) {}
  |                          ^^^^^^^^
  |
  = 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

thread 'rustc' panicked at compiler/rustc_hir_analysis/src/astconv/generics.rs:352:25:
assertion `left == right` failed
  left: "constant"
 right: "lifetime"
stack backtrace:
   0:     0x7fa1bac17e0c - std::backtrace_rs::backtrace::libunwind::trace::h26f9c796037cce52
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fa1bac17e0c - std::backtrace_rs::backtrace::trace_unsynchronized::hee359840b9dafeac
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fa1bac17e0c - std::sys_common::backtrace::_print_fmt::h9bb6ca31bc75c5d0
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7fa1bac17e0c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h1232efd9e71af7ee
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fa1bac7a070 - core::fmt::rt::Argument::fmt::hf0a8fd66ca5e69d7
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/core/src/fmt/rt.rs:142:9
   5:     0x7fa1bac7a070 - core::fmt::write::haad2ec2532166927
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/core/src/fmt/mod.rs:1117:17
   6:     0x7fa1bac0bc9f - std::io::Write::write_fmt::ha23c136682b46710
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/std/src/io/mod.rs:1762:15
   7:     0x7fa1bac17bf4 - std::sys_common::backtrace::_print::h95f3c84329b5c92d
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fa1bac17bf4 - std::sys_common::backtrace::print::h20e8e2976e5bbe94
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fa1bac1a887 - std::panicking::default_hook::{{closure}}::h1eae7995acc746d3
  10:     0x7fa1bac1a5ef - std::panicking::default_hook::h4d5fabf853e7ef7b
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/std/src/panicking.rs:292:9
  11:     0x7fa1b7cce120 - std[460b5be3558c375d]::panicking::update_hook::<alloc[693971052a9e8422]::boxed::Box<rustc_driver_impl[e72fe5bfa41da330]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fa1bac1afc8 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h843de2e1901f057d
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/alloc/src/boxed.rs:2021:9
  13:     0x7fa1bac1afc8 - std::panicking::rust_panic_with_hook::hd10c46bdf894a0ee
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/std/src/panicking.rs:735:13
  14:     0x7fa1bac1ad1e - std::panicking::begin_panic_handler::{{closure}}::h45eb8defe1b35d80
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/std/src/panicking.rs:609:13
  15:     0x7fa1bac182d6 - std::sys_common::backtrace::__rust_end_short_backtrace::h3ddbcc723f81873e
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7fa1bac1aa82 - rust_begin_unwind
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/std/src/panicking.rs:597:5
  17:     0x7fa1bac76795 - core::panicking::panic_fmt::h48abbd5c08ea998c
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/core/src/panicking.rs:72:14
  18:     0x7fa1bac76d0b - core::panicking::assert_failed_inner::h9f251a4ea4c836b7
  19:     0x7fa1b7d7f55b - core[2a54af29626ba4c5]::panicking::assert_failed::<&str, &str>
  20:     0x7fa1b968db22 - <dyn rustc_hir_analysis[4ab1543de9c19fcd]::astconv::AstConv>::instantiate_poly_trait_ref_inner
  21:     0x7fa1b9688c5d - <dyn rustc_hir_analysis[4ab1543de9c19fcd]::astconv::AstConv>::instantiate_poly_trait_ref
  22:     0x7fa1b904eaea - rustc_hir_analysis[4ab1543de9c19fcd]::collect::predicates_of::gather_explicit_predicates_of
  23:     0x7fa1b904bf5e - rustc_query_impl[b93e503e69ee3f1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b93e503e69ee3f1]::query_impl::explicit_predicates_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[405ee4a693ef0c6a]::query::erase::Erased<[u8; 24usize]>>
  24:     0x7fa1b904afe2 - rustc_query_system[58175847c4e3ea34]::query::plumbing::try_execute_query::<rustc_query_impl[b93e503e69ee3f1]::DynamicConfig<rustc_query_system[58175847c4e3ea34]::query::caches::DefaultCache<rustc_span[2a5b7a2a8d495c3a]::def_id::DefId, rustc_middle[405ee4a693ef0c6a]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[b93e503e69ee3f1]::plumbing::QueryCtxt, false>
  25:     0x7fa1b904ace0 - rustc_query_impl[b93e503e69ee3f1]::query_impl::explicit_predicates_of::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7fa1b904b6a3 - rustc_hir_analysis[4ab1543de9c19fcd]::collect::predicates_defined_on
  27:     0x7fa1b904b593 - rustc_query_impl[b93e503e69ee3f1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b93e503e69ee3f1]::query_impl::predicates_defined_on::dynamic_query::{closure#2}::{closure#0}, rustc_middle[405ee4a693ef0c6a]::query::erase::Erased<[u8; 24usize]>>
  28:     0x7fa1b904afb7 - rustc_query_system[58175847c4e3ea34]::query::plumbing::try_execute_query::<rustc_query_impl[b93e503e69ee3f1]::DynamicConfig<rustc_query_system[58175847c4e3ea34]::query::caches::DefaultCache<rustc_span[2a5b7a2a8d495c3a]::def_id::DefId, rustc_middle[405ee4a693ef0c6a]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[b93e503e69ee3f1]::plumbing::QueryCtxt, false>
  29:     0x7fa1b904ab20 - rustc_query_impl[b93e503e69ee3f1]::query_impl::predicates_defined_on::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7fa1b9049be9 - rustc_hir_analysis[4ab1543de9c19fcd]::collect::predicates_of::predicates_of
  31:     0x7fa1b9049ad3 - rustc_query_impl[b93e503e69ee3f1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b93e503e69ee3f1]::query_impl::predicates_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[405ee4a693ef0c6a]::query::erase::Erased<[u8; 24usize]>>
  32:     0x7fa1b904af8a - rustc_query_system[58175847c4e3ea34]::query::plumbing::try_execute_query::<rustc_query_impl[b93e503e69ee3f1]::DynamicConfig<rustc_query_system[58175847c4e3ea34]::query::caches::DefaultCache<rustc_span[2a5b7a2a8d495c3a]::def_id::DefId, rustc_middle[405ee4a693ef0c6a]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[b93e503e69ee3f1]::plumbing::QueryCtxt, false>
  33:     0x7fa1b904abfe - rustc_query_impl[b93e503e69ee3f1]::query_impl::predicates_of::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7fa1b92de086 - <rustc_hir_analysis[4ab1543de9c19fcd]::collect::CollectItemTypesVisitor as rustc_hir[2e6132ac8cc970b0]::intravisit::Visitor>::visit_item
  35:     0x7fa1b92dc4e8 - rustc_hir_analysis[4ab1543de9c19fcd]::collect::collect_mod_item_types
  36:     0x7fa1b92dc47d - rustc_query_impl[b93e503e69ee3f1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b93e503e69ee3f1]::query_impl::collect_mod_item_types::dynamic_query::{closure#2}::{closure#0}, rustc_middle[405ee4a693ef0c6a]::query::erase::Erased<[u8; 0usize]>>
  37:     0x7fa1b96f2734 - rustc_query_system[58175847c4e3ea34]::query::plumbing::try_execute_query::<rustc_query_impl[b93e503e69ee3f1]::DynamicConfig<rustc_query_system[58175847c4e3ea34]::query::caches::DefaultCache<rustc_span[2a5b7a2a8d495c3a]::def_id::LocalModDefId, rustc_middle[405ee4a693ef0c6a]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[b93e503e69ee3f1]::plumbing::QueryCtxt, false>
  38:     0x7fa1b96f2203 - rustc_query_impl[b93e503e69ee3f1]::query_impl::collect_mod_item_types::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7fa1b921fe26 - rustc_hir_analysis[4ab1543de9c19fcd]::check_crate
  40:     0x7fa1b96385d6 - rustc_interface[f97d1d56abeae6a6]::passes::analysis
  41:     0x7fa1b9637ff5 - rustc_query_impl[b93e503e69ee3f1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b93e503e69ee3f1]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[405ee4a693ef0c6a]::query::erase::Erased<[u8; 1usize]>>
  42:     0x7fa1b991d266 - rustc_query_system[58175847c4e3ea34]::query::plumbing::try_execute_query::<rustc_query_impl[b93e503e69ee3f1]::DynamicConfig<rustc_query_system[58175847c4e3ea34]::query::caches::SingleCache<rustc_middle[405ee4a693ef0c6a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[b93e503e69ee3f1]::plumbing::QueryCtxt, false>
  43:     0x7fa1b991d095 - rustc_query_impl[b93e503e69ee3f1]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  44:     0x7fa1b9b022cd - std[460b5be3558c375d]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[f97d1d56abeae6a6]::util::run_in_thread_with_globals<rustc_interface[f97d1d56abeae6a6]::interface::run_compiler<core[2a54af29626ba4c5]::result::Result<(), rustc_span[2a5b7a2a8d495c3a]::ErrorGuaranteed>, rustc_driver_impl[e72fe5bfa41da330]::run_compiler::{closure#1}>::{closure#0}, core[2a54af29626ba4c5]::result::Result<(), rustc_span[2a5b7a2a8d495c3a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[2a54af29626ba4c5]::result::Result<(), rustc_span[2a5b7a2a8d495c3a]::ErrorGuaranteed>>
  45:     0x7fa1b9b015b3 - <<std[460b5be3558c375d]::thread::Builder>::spawn_unchecked_<rustc_interface[f97d1d56abeae6a6]::util::run_in_thread_with_globals<rustc_interface[f97d1d56abeae6a6]::interface::run_compiler<core[2a54af29626ba4c5]::result::Result<(), rustc_span[2a5b7a2a8d495c3a]::ErrorGuaranteed>, rustc_driver_impl[e72fe5bfa41da330]::run_compiler::{closure#1}>::{closure#0}, core[2a54af29626ba4c5]::result::Result<(), rustc_span[2a5b7a2a8d495c3a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[2a54af29626ba4c5]::result::Result<(), rustc_span[2a5b7a2a8d495c3a]::ErrorGuaranteed>>::{closure#1} as core[2a54af29626ba4c5]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  46:     0x7fa1bac25d95 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h685ade75afd0fa00
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/alloc/src/boxed.rs:2007:9
  47:     0x7fa1bac25d95 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7f8eddf0418f773b
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/alloc/src/boxed.rs:2007:9
  48:     0x7fa1bac25d95 - std::sys::unix::thread::Thread::new::thread_start::hd2a483094951da8e
                               at /rustc/698db856de0b67313ddcb96b6599598058489ea9/library/std/src/sys/unix/thread.rs:108:17
  49:     0x7fa1b50aa9eb - <unknown>
  50:     0x7fa1b512e7cc - <unknown>
  51:                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: rustc 1.75.0-nightly (698db856d 2023-10-26) 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 [explicit_predicates_of] computing explicit predicates of `check`
#1 [predicates_defined_on] computing predicates of `check`
#2 [predicates_of] computing predicates of `check`
#3 [collect_mod_item_types] collecting item types in top-level module
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

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

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

#117171 cc @fee1-dead ^^

@compiler-errors
Copy link
Member

compiler-errors commented Oct 26, 2023

Would be nice if you uplifted the -Zcrate-attr=feature(effects) into the minimal repro, I think I've mentioned this before but it's easy to miss :)

@matthiaskrgr
Copy link
Member Author

@compiler-errors flags are added now, at the bottom though as to not shift all the lines around which would get the mvce/error output out of sync and might cause other problems I suspect (iirc specifying a flag multiple times via file AND cmdline arg still breaks things)
matthiaskrgr/icemaker@a982242

@compiler-errors
Copy link
Member

I don't see any flags added so I've added them myself.

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 28, 2023
@jruderman
Copy link
Contributor

Further reduced:

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

trait Foo {}

const fn check<T: ~const Foo>() {}

fn main() {}

@matthiaskrgr
Copy link
Member Author

#![feature(derive_const)]
#![feature(const_trait_impl, effects)]

#[derive_const(PartialEq, Eq)]
pub struct Reverse<T>(T);

const fn foo(a: Reverse<i32>, b: Reverse<i32>) -> bool {
    a == b
}

fn main() {}

@fmease fmease self-assigned this Dec 18, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 23, 2023
…=compiler-errors

Clean up `check_consts` and misc fixes

1. Remove most of the logic around erroring with trait methods. I have kept the part resolving it to a concrete impl, as that is used for const stability checks.
2. Turning on `effects` causes ICE with generic args, due to `~const Tr` when `Tr` is not `#[const_trait]` tripping up expectation in code that handles generic args, more specifically here:
https://github.com/rust-lang/rust/blob/8681e077b8afa99d60acf8f8470a012a3ce709a5/compiler/rustc_hir_analysis/src/astconv/generics.rs#L377

We set `arg_count.correct` to `Err` to correctly signal that an error has already been reported.

3. UI test blesses.

Edit(fmease): Fixes rust-lang#117244 (UI test is in rust-lang#119099 for now).

r? compiler-errors
@bors bors closed this as completed in edcbcc7 Dec 23, 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. 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.

7 participants