Skip to content

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

Closed

Description

auto-reduced (treereduce-rust):

#![feature(effects)]
struct D;

impl const Drop for D {}
original code

original:

#![warn(clippy::missing_const_for_fn)]
#![allow(incomplete_features, clippy::let_and_return, clippy::missing_transmute_annotations)]
#![feature(const_mut_refs)]
#![feature(const_trait_impl)]

use std::mem::transmute;

struct Game {
    guess: i32,
}

impl Game {
    // Could be const
    pub fn new() -> Self {
        //~^ ERROR: this could be a `const fn`
        //~| NOTE: `-D clippy::missing-const-for-fn` implied by `-D warnings`
        Self { guess: 42 }
    }

    fn const_generic_params<'a, T, const N: usize>(&self, b: &'a [T; N]) -> &'a [T; N] {
        //~^ ERROR: this could be a `const fn`
        b
    }
}

// Could be const
fn one() -> i32 {
    //~^ ERROR: this could be a `const fn`
    1
}

// Could also be const
fn two() -> i32 {
    //~^ ERROR: this could be a `const fn`
    let abc = 2;
    abc
}

// Could be const (since Rust 1.39)
fn string() -> String {
    //~^ ERROR: this could be a `const fn`
    String::new()
}

// Could be const
unsafe fn four() -> i32 {
    //~^ ERROR: this could be a `const fn`
    4
}

// Could also be const
fn generic<T>(t: T) -> T {
    //~^ ERROR: this could be a `const fn`
    t
}

fn sub(x: u32) -> usize {
    unsafe { transmute(&x) }
}

fn generic_arr<T: Copy>(t: [T; 1]) -> T {
    //~^ ERROR: this could be a `const fn`
    t[0]
}

mod with_drop {
    pub struct A;
    pub struct B;
    impl Drop for A {
        fn drop(&mut self) {}
    }

    impl B {
        // This can be const, because `a` is passed by reference
        pub fn b(self, a: &A) -> B {
            //~^ ERROR: this could be a `const fn`
            B
        }
    }
}

#[clippy::msrv = "1.47.0"]
mod const_fn_stabilized_before_msrv {
    // This could be const because `u8::is_ascii_digit` is a stable const function in 1.47.
    fn const_fn_stabilized_before_msrv(byte: u8) {
        //~^ ERROR: this could be a `const fn`
        byte.is_ascii_digit();
    }
}

#[clippy::msrv = "1.45"]
fn msrv_1_45() -> i32 {
    45
}

#[clippy::msrv = "1.46"]
fn msrv_1_46() -> i32 {
    //~^ ERROR: this could be a `const fn`
    46
}

// Should not be const
fn main() {}

struct D;

impl const Drop for D {
    fn drop(&mut self) {
        todo!();
    }
}

// Lint this, since it can be dropped in const contexts
// FIXME(effects)
fn d(this: D) {}

mod msrv {
    struct Foo(*const u8, &'static u8);

    impl Foo {
        #[clippy::msrv = "1.58"]
        fn deref_ptr_can_be_const(self) -> usize {
            //~^ ERROR: this could be a `const fn`
            unsafe { *self.0 as usize }
        }

        fn deref_copied_val(self) -> usize {
            //~^ ERROR: this could be a `const fn`
            *self.1 as usize
        }
    }

    union Bar {
        val: u8,
    }

    #[clippy::msrv = "1.56"]
    fn union_access_can_be_const() {
        //~^ ERROR: this could be a `const fn`
        let bar = Bar { val: 1 };
        let _ = unsafe { bar.val };
    }
}

Version information

rustc 1.81.0-nightly (ff014f5de 2024-06-08)
binary: rustc
commit-hash: ff014f5de0c4d9a53e2d80b53e1faaca96964314
commit-date: 2024-06-08
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

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.C4ybMM9sNamb/rustc_testrunner_tmpdir_reporting.NHR7pTsdHpyq/mvce.rs:3:6
  |
3 | impl const Drop for D {}
  |      ^^^^^
  |
  = 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-08; consider upgrading it if it is out of date

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

error: const `impl` for trait `Drop` which is not marked with `#[const_trait]`
 --> /tmp/icemaker_global_tempdir.C4ybMM9sNamb/rustc_testrunner_tmpdir_reporting.NHR7pTsdHpyq/mvce.rs:3:12
  |
3 | impl const Drop for D {}
  |            ^^^^
  |
  = 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:     0x768b1c3e8f15 - std::backtrace_rs::backtrace::libunwind::trace::h391c84fc4ecc1dec
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x768b1c3e8f15 - std::backtrace_rs::backtrace::trace_unsynchronized::h3e92edc77e0c5c4e
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x768b1c3e8f15 - std::sys_common::backtrace::_print_fmt::h87ef60a1873724a8
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x768b1c3e8f15 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb8e68420de9fbe34
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x768b1c439c5b - core::fmt::rt::Argument::fmt::h988688d3b6b43938
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/core/src/fmt/rt.rs:165:63
   5:     0x768b1c439c5b - core::fmt::write::h26bacab22040c630
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/core/src/fmt/mod.rs:1168:21
   6:     0x768b1c3ddbef - std::io::Write::write_fmt::h6eccb8f4340b2875
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/std/src/io/mod.rs:1835:15
   7:     0x768b1c3e8cee - std::sys_common::backtrace::_print::h4e05c7347d93fefc
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x768b1c3e8cee - std::sys_common::backtrace::print::h0d1ce927f3656a2b
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x768b1c3eb729 - std::panicking::default_hook::{{closure}}::hf913f37399eebbd3
  10:     0x768b1c3eb4ca - std::panicking::default_hook::h824adac0153bd182
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/std/src/panicking.rs:298:9
  11:     0x768b18bd91af - std[41894142a3d00c]::panicking::update_hook::<alloc[4f88e964462652ad]::boxed::Box<rustc_driver_impl[1c61470bbdda786f]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x768b1c3ebe5b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h6bc7f7783dfea44c
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/alloc/src/boxed.rs:2077:9
  13:     0x768b1c3ebe5b - std::panicking::rust_panic_with_hook::hb16889bb52fcfe7b
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/std/src/panicking.rs:799:13
  14:     0x768b1c3ebb9b - std::panicking::begin_panic_handler::{{closure}}::h293d942456e2c1a2
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/std/src/panicking.rs:656:13
  15:     0x768b1c3e93d9 - std::sys_common::backtrace::__rust_end_short_backtrace::h8c11736cc445b2bc
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x768b1c3eb907 - rust_begin_unwind
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/std/src/panicking.rs:652:5
  17:     0x768b1c4361f3 - core::panicking::panic_fmt::hce91f8f9dbd92639
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/core/src/panicking.rs:72:14
  18:     0x768b1c43629c - core::panicking::panic::had919c47d11dcbea
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/core/src/panicking.rs:146:5
  19:     0x768b1c435f39 - core::option::unwrap_failed::hb4b0fa43b674aeb3
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/core/src/option.rs:1985:5
  20:     0x768b1b8a3c2a - <rustc_middle[c314043e2f18fb75]::ty::sty::ParamConst>::find_ty_from_env.cold
  21:     0x768b16d2e0e3 - <rustc_trait_selection[34e35e16a7935b19]::traits::fulfill::FulfillProcessor as rustc_data_structures[b62e5bdcfef69737]::obligation_forest::ObligationProcessor>::process_obligation
  22:     0x768b1a10c7c7 - <rustc_data_structures[b62e5bdcfef69737]::obligation_forest::ObligationForest<rustc_trait_selection[34e35e16a7935b19]::traits::fulfill::PendingPredicateObligation>>::process_obligations::<rustc_trait_selection[34e35e16a7935b19]::traits::fulfill::FulfillProcessor>
  23:     0x768b1a10e76d - <rustc_trait_selection[34e35e16a7935b19]::traits::fulfill::FulfillmentContext<rustc_trait_selection[34e35e16a7935b19]::traits::FulfillmentError> as rustc_infer[f4f36518e97505c8]::traits::engine::TraitEngine<rustc_trait_selection[34e35e16a7935b19]::traits::FulfillmentError>>::select_all_or_error
  24:     0x768b1ac3720f - rustc_hir_analysis[53542630c6369c29]::check::dropck::check_drop_impl
  25:     0x768b1ac36cc6 - <rustc_middle[c314043e2f18fb75]::ty::context::TyCtxt>::calculate_dtor::<rustc_hir_analysis[53542630c6369c29]::check::dropck::check_drop_impl>::{closure#0}
  26:     0x768b1a6b7aea - rustc_hir_analysis[53542630c6369c29]::check::adt_destructor
  27:     0x768b1a7f3f88 - rustc_query_impl[31633fcbb427b4dc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[31633fcbb427b4dc]::query_impl::adt_destructor::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c314043e2f18fb75]::query::erase::Erased<[u8; 12usize]>>
  28:     0x768b1a81a8dc - rustc_query_system[4bc92dc28279729a]::query::plumbing::try_execute_query::<rustc_query_impl[31633fcbb427b4dc]::DynamicConfig<rustc_query_system[4bc92dc28279729a]::query::caches::DefIdCache<rustc_middle[c314043e2f18fb75]::query::erase::Erased<[u8; 12usize]>>, false, false, false>, rustc_query_impl[31633fcbb427b4dc]::plumbing::QueryCtxt, false>
  29:     0x768b1a81a1d3 - rustc_query_impl[31633fcbb427b4dc]::query_impl::adt_destructor::get_query_non_incr::__rust_end_short_backtrace
  30:     0x768b1a840b0e - <rustc_middle[c314043e2f18fb75]::ty::adt::AdtDef>::destructor
  31:     0x768b16972a49 - rustc_hir_analysis[53542630c6369c29]::check::check::check_item_type
  32:     0x768b17b32b77 - rustc_hir_analysis[53542630c6369c29]::check::wfcheck::check_well_formed
  33:     0x768b1a5ae7a9 - rustc_query_impl[31633fcbb427b4dc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[31633fcbb427b4dc]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c314043e2f18fb75]::query::erase::Erased<[u8; 1usize]>>
  34:     0x768b1a5aea26 - rustc_query_system[4bc92dc28279729a]::query::plumbing::try_execute_query::<rustc_query_impl[31633fcbb427b4dc]::DynamicConfig<rustc_query_system[4bc92dc28279729a]::query::caches::VecCache<rustc_hir[41bca576c253e1bc]::hir_id::OwnerId, rustc_middle[c314043e2f18fb75]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[31633fcbb427b4dc]::plumbing::QueryCtxt, false>
  35:     0x768b1a5ae786 - rustc_query_impl[31633fcbb427b4dc]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  36:     0x768b1a5af4f7 - rustc_hir_analysis[53542630c6369c29]::check::wfcheck::check_mod_type_wf
  37:     0x768b1a5af33b - rustc_query_impl[31633fcbb427b4dc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[31633fcbb427b4dc]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c314043e2f18fb75]::query::erase::Erased<[u8; 1usize]>>
  38:     0x768b1aadc9f0 - rustc_query_system[4bc92dc28279729a]::query::plumbing::try_execute_query::<rustc_query_impl[31633fcbb427b4dc]::DynamicConfig<rustc_query_system[4bc92dc28279729a]::query::caches::DefaultCache<rustc_span[fc6a22b319982284]::def_id::LocalModDefId, rustc_middle[c314043e2f18fb75]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[31633fcbb427b4dc]::plumbing::QueryCtxt, false>
  39:     0x768b1aadc799 - rustc_query_impl[31633fcbb427b4dc]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  40:     0x768b1a41e5ea - rustc_hir_analysis[53542630c6369c29]::check_crate
  41:     0x768b1a5a3dbe - rustc_interface[c8f1c8b6dfa33e5d]::passes::analysis
  42:     0x768b1a5a391b - rustc_query_impl[31633fcbb427b4dc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[31633fcbb427b4dc]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c314043e2f18fb75]::query::erase::Erased<[u8; 1usize]>>
  43:     0x768b1adf4ce5 - rustc_query_system[4bc92dc28279729a]::query::plumbing::try_execute_query::<rustc_query_impl[31633fcbb427b4dc]::DynamicConfig<rustc_query_system[4bc92dc28279729a]::query::caches::SingleCache<rustc_middle[c314043e2f18fb75]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[31633fcbb427b4dc]::plumbing::QueryCtxt, false>
  44:     0x768b1adf4a4f - rustc_query_impl[31633fcbb427b4dc]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  45:     0x768b1ac758d2 - rustc_interface[c8f1c8b6dfa33e5d]::interface::run_compiler::<core[3b0a81cff9e78d23]::result::Result<(), rustc_span[fc6a22b319982284]::ErrorGuaranteed>, rustc_driver_impl[1c61470bbdda786f]::run_compiler::{closure#0}>::{closure#1}
  46:     0x768b1ac28f09 - std[41894142a3d00c]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c8f1c8b6dfa33e5d]::util::run_in_thread_with_globals<rustc_interface[c8f1c8b6dfa33e5d]::util::run_in_thread_pool_with_globals<rustc_interface[c8f1c8b6dfa33e5d]::interface::run_compiler<core[3b0a81cff9e78d23]::result::Result<(), rustc_span[fc6a22b319982284]::ErrorGuaranteed>, rustc_driver_impl[1c61470bbdda786f]::run_compiler::{closure#0}>::{closure#1}, core[3b0a81cff9e78d23]::result::Result<(), rustc_span[fc6a22b319982284]::ErrorGuaranteed>>::{closure#0}, core[3b0a81cff9e78d23]::result::Result<(), rustc_span[fc6a22b319982284]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3b0a81cff9e78d23]::result::Result<(), rustc_span[fc6a22b319982284]::ErrorGuaranteed>>
  47:     0x768b1ac28cc0 - <<std[41894142a3d00c]::thread::Builder>::spawn_unchecked_<rustc_interface[c8f1c8b6dfa33e5d]::util::run_in_thread_with_globals<rustc_interface[c8f1c8b6dfa33e5d]::util::run_in_thread_pool_with_globals<rustc_interface[c8f1c8b6dfa33e5d]::interface::run_compiler<core[3b0a81cff9e78d23]::result::Result<(), rustc_span[fc6a22b319982284]::ErrorGuaranteed>, rustc_driver_impl[1c61470bbdda786f]::run_compiler::{closure#0}>::{closure#1}, core[3b0a81cff9e78d23]::result::Result<(), rustc_span[fc6a22b319982284]::ErrorGuaranteed>>::{closure#0}, core[3b0a81cff9e78d23]::result::Result<(), rustc_span[fc6a22b319982284]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3b0a81cff9e78d23]::result::Result<(), rustc_span[fc6a22b319982284]::ErrorGuaranteed>>::{closure#2} as core[3b0a81cff9e78d23]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  48:     0x768b1c3f5e4b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7880e98e31b6901f
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/alloc/src/boxed.rs:2063:9
  49:     0x768b1c3f5e4b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h947e9b0d87d30ce7
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/alloc/src/boxed.rs:2063:9
  50:     0x768b1c3f5e4b - std::sys::pal::unix::thread::Thread::new::thread_start::hb9f9757f270b060b
                               at /rustc/ff014f5de0c4d9a53e2d80b53e1faaca96964314/library/std/src/sys/pal/unix/thread.rs:108:17
  51:     0x768b158a6ded - <unknown>
  52:     0x768b1592a0dc - <unknown>
  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 (ff014f5de 2024-06-08) 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 `D`
#1 [check_well_formed] checking that `D` 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.C4ybMM9sNamb/rustc_testrunner_tmpdir_reporting.NHR7pTsdHpyq/mvce.rs:3:6
  |
3 | impl const Drop for D {}
  |      ^^^^^ 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_mut_refs +F-const_trait_impl +F-effects

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions