rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.86k stars 12.67k forks source link

ice: `no type-dependent def for method` #116893

Closed matthiaskrgr closed 9 months ago

matthiaskrgr commented 1 year ago

File: /tmp/icemaker/AE153D8D5D57B27605224C96E644139B2BD809C19625E0FE2660FDA8A2906DF3.rs

auto-reduced (treereduce-rust):

struct X;
struct Y;
struct Z;

trait Foo<T> {
    type Ty;
    fn foo() -> Self::Ty;
}

impl Foo<Y> for X {
    type Ty = Z;
    fn foo() -> Self::Ty {
        unimplemented!()
    }
}

fn main() {
    let s = [(); {
        let mut n = 113383;
        while n != 0 {}
        n
    }];
    s.doit();
    X::foo();
}

original:

// check-pass

#![feature(inline_const_pat)]

const TLC: usize = 4;

trait Tr { fn doit(&self); }

impl Tr for [usize; TLC] {
    fn doit(&self) {
        println!("called 4");
    }
}

struct X;
struct Y;
struct Z;

trait Foo<T> {
    type Ty;
    fn foo() -> Self::Ty;
}

impl Foo<Y> for X {
    type Ty = Z;
    fn foo() -> Self::Ty {
        unimplemented!()
    }
}

enum E {
    A,
    B, //~ WARN variants `B` and `C` are never constructed
    C,
}

type F = E;

impl E {
    fn check(&self) -> bool {
        match self {
            Self::A => true,
            Self::B => false,
            F::C => false,
        }
    }
}

fn main() {
    let s = [(); { //~ ERROR failed to evaluate the given constant
        let mut n = 113383; // #20 in https://oeis.org/A006884
        while n != 0 {
            n = if n % 2 == 0 { n/2 } else { 3*n + 1 };
            //~^ ERROR evaluation of constant value failed
        }
        n
    }];
    s.doit();
    X::foo();
    E::A.check();
}

Version information

rustc 1.75.0-nightly (e1de04ad4 2023-10-18)
binary: rustc
commit-hash: e1de04ad4e32afc6c82080a0b46408fee31dce88
commit-date: 2023-10-18
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.3

Command: /home/matthias/.rustup/toolchains/master/bin/rustc

Program output

``` warning: the feature `inline_const_pat` is incomplete and may not be safe to use and/or cause compiler crashes --> /tmp/icemaker/AE153D8D5D57B27605224C96E644139B2BD809C19625E0FE2660FDA8A2906DF3.rs:3:12 | 3 | #![feature(inline_const_pat)] | ^^^^^^^^^^^^^^^^ | = note: see issue #76001 for more information = note: `#[warn(incomplete_features)]` on by default error: constant evaluation is taking a long time --> /tmp/icemaker/AE153D8D5D57B27605224C96E644139B2BD809C19625E0FE2660FDA8A2906DF3.rs:52:9 | 52 | / while n != 0 { 53 | | n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; 54 | | //~^ ERROR evaluation of constant value failed 55 | | } | |_________^ | = note: this lint makes sure the compiler doesn't get stuck due to infinite loops in const eval. If your compilation actually takes a long time, you can safely allow the lint. help: the constant being evaluated --> /tmp/icemaker/AE153D8D5D57B27605224C96E644139B2BD809C19625E0FE2660FDA8A2906DF3.rs:50:18 | 50 | let s = [(); { //~ ERROR failed to evaluate the given constant | __________________^ 51 | | let mut n = 113383; // #20 in https://oeis.org/A006884 52 | | while n != 0 { 53 | | n = if n % 2 == 0 { n/2 } else { 3*n + 1 }; ... | 56 | | n 57 | | }]; | |_____^ = note: `#[deny(long_running_const_eval)]` on by default error: internal compiler error: compiler/rustc_passes/src/dead.rs:131:13: no type-dependent def for method thread 'rustc' panicked at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/compiler/rustc_errors/src/lib.rs:1659:9: Box stack backtrace: 0: 0x7f8b8816922c - std::backtrace_rs::backtrace::libunwind::trace::h78b9e962e243ca8f at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7f8b8816922c - std::backtrace_rs::backtrace::trace_unsynchronized::h10b60b94f8e8e90f at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f8b8816922c - std::sys_common::backtrace::_print_fmt::heabe9f83d4e1fbf2 at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/std/src/sys_common/backtrace.rs:67:5 3: 0x7f8b8816922c - ::fmt::h81b76958dc64cc2e at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7f8b881cb1c0 - core::fmt::rt::Argument::fmt::h7f74343dbffe9183 at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/core/src/fmt/rt.rs:142:9 5: 0x7f8b881cb1c0 - core::fmt::write::hc2d1091c5ed1b3b7 at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/core/src/fmt/mod.rs:1117:17 6: 0x7f8b8815cf3f - std::io::Write::write_fmt::hb67a8f48bcfb1f4f at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/std/src/io/mod.rs:1762:15 7: 0x7f8b88169014 - std::sys_common::backtrace::_print::h67add1984c5a1838 at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7f8b88169014 - std::sys_common::backtrace::print::h404a822bd43d8000 at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/std/src/sys_common/backtrace.rs:34:9 9: 0x7f8b8816bca7 - std::panicking::default_hook::{{closure}}::h4e8ae7bcfd2c52aa 10: 0x7f8b8816ba0f - std::panicking::default_hook::h004c8707dedde48e at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/std/src/panicking.rs:292:9 11: 0x7f8b8aca0400 - std[7217ace3ed74fbee]::panicking::update_hook::>::{closure#0} 12: 0x7f8b8816c3e8 - as core::ops::function::Fn>::call::hbb7dfda09706e9c5 at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/alloc/src/boxed.rs:2021:9 13: 0x7f8b8816c3e8 - std::panicking::rust_panic_with_hook::h9ccb8adbf5a6f206 at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/std/src/panicking.rs:735:13 14: 0x7f8b8b059704 - std[7217ace3ed74fbee]::panicking::begin_panic::::{closure#0} 15: 0x7f8b8b051126 - std[7217ace3ed74fbee]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7f8b8b04b536 - std[7217ace3ed74fbee]::panicking::begin_panic:: 17: 0x7f8b8b033f24 - ::bug:: 18: 0x7f8b8b033ce4 - ::bug:: 19: 0x7f8b8b0d2a7d - rustc_middle[c3bb664540fd40fe]::util::bug::opt_span_bug_fmt::::{closure#0} 20: 0x7f8b8b0b9a2a - rustc_middle[c3bb664540fd40fe]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 21: 0x7f8b8b0b98c8 - rustc_middle[c3bb664540fd40fe]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 22: 0x7f8b891bfe70 - rustc_middle[c3bb664540fd40fe]::util::bug::bug_fmt 23: 0x7f8b89495d72 - ::visit_expr 24: 0x7f8b8c13b4c4 - ::visit_block 25: 0x7f8b8c139b6f - rustc_hir[d5ac411c7739f82b]::intravisit::walk_item:: 26: 0x7f8b8cc8236a - rustc_passes[fe3435d9db1f5a89]::dead::live_symbols_and_ignored_derived_traits 27: 0x7f8b8cc81856 - rustc_query_impl[1e4b497268a3bf63]::plumbing::__rust_begin_short_backtrace::> 28: 0x7f8b8cb147b3 - rustc_query_system[643e04207a7d8bda]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1e4b497268a3bf63]::plumbing::QueryCtxt, false> 29: 0x7f8b8cb13f06 - rustc_query_impl[1e4b497268a3bf63]::query_impl::live_symbols_and_ignored_derived_traits::get_query_non_incr::__rust_end_short_backtrace 30: 0x7f8b8c5ba402 - rustc_passes[fe3435d9db1f5a89]::dead::check_mod_deathness 31: 0x7f8b8c5ba307 - rustc_query_impl[1e4b497268a3bf63]::plumbing::__rust_begin_short_backtrace::> 32: 0x7f8b8c5c4234 - rustc_query_system[643e04207a7d8bda]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1e4b497268a3bf63]::plumbing::QueryCtxt, false> 33: 0x7f8b8c5c3a8b - rustc_query_impl[1e4b497268a3bf63]::query_impl::check_mod_deathness::get_query_non_incr::__rust_end_short_backtrace 34: 0x7f8b8c75a18f - rustc_interface[41ec36dc370840d6]::passes::analysis 35: 0x7f8b8c759121 - rustc_query_impl[1e4b497268a3bf63]::plumbing::__rust_begin_short_backtrace::> 36: 0x7f8b8c91e0a6 - rustc_query_system[643e04207a7d8bda]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[1e4b497268a3bf63]::plumbing::QueryCtxt, false> 37: 0x7f8b8c91ded5 - rustc_query_impl[1e4b497268a3bf63]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 38: 0x7f8b8cb2cc6a - std[7217ace3ed74fbee]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[f4c3d59f9c31edf1]::run_compiler::{closure#1}>::{closure#0}, core[1d18a34c428c8cbf]::result::Result<(), rustc_span[86ba460ec05b7c05]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1d18a34c428c8cbf]::result::Result<(), rustc_span[86ba460ec05b7c05]::ErrorGuaranteed>> 39: 0x7f8b8cb2bf73 - <::spawn_unchecked_, rustc_driver_impl[f4c3d59f9c31edf1]::run_compiler::{closure#1}>::{closure#0}, core[1d18a34c428c8cbf]::result::Result<(), rustc_span[86ba460ec05b7c05]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1d18a34c428c8cbf]::result::Result<(), rustc_span[86ba460ec05b7c05]::ErrorGuaranteed>>::{closure#1} as core[1d18a34c428c8cbf]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 40: 0x7f8b88176f05 - as core::ops::function::FnOnce>::call_once::h2ccd842889ca1510 at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/alloc/src/boxed.rs:2007:9 41: 0x7f8b88176f05 - as core::ops::function::FnOnce>::call_once::h0b4e82b761ce431b at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/alloc/src/boxed.rs:2007:9 42: 0x7f8b88176f05 - std::sys::unix::thread::Thread::new::thread_start::hd80c9211641b110c at /rustc/e1de04ad4e32afc6c82080a0b46408fee31dce88/library/std/src/sys/unix/thread.rs:108:17 43: 0x7f8b87f409eb - 44: 0x7f8b87fc47cc - 45: 0x0 - 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 (e1de04ad4 2023-10-18) running on x86_64-unknown-linux-gnu query stack during panic: #0 [live_symbols_and_ignored_derived_traits] finding live symbols in crate #1 [check_mod_deathness] checking deathness of variables in top-level module #2 [analysis] running analysis passes on this crate end of query stack error: aborting due to 2 previous errors; 1 warning emitted ```

matthiaskrgr commented 1 year ago

Regression in nightly-2023-06-02 Regression in 23f93a1266e0530445db590c15e0bb5c1c624eb6 https://github.com/rust-lang/rust/pull/103877 cc @oli-obk