Skip to content

ICE: instantiate_value_path: (UFCS) Fail<T/#0> was a subtype of Fail<i32> but now is not? #126062

Closed

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

struct Fail<T>(Fail);
impl<T> Fail<i32> {
    const C: () = panic!();
}

fn f<T>() {
    if false {
        let _val = &Fail::<T>::C;
    }
}
original code

original:

//@revisions: noopt opt
//@ build-fail
//@[noopt] compile-flags: -Copt-level=0
//@[opt] compile-flags: -O
// (Not sure why optimizations lead to this being emitted twice, but as long as compilation
struct Fail<T>(Fail);
impl<T> Fail<i32> {
    const C: () = panic!(); //~ERROR evaluation of `Fail::<i32>::C` failed
    //[opt]~^ ERROR evaluation of `Fail::<T>::C` failed
    // (Not sure why optimizations lead to this being emitted twice, but as long as compilation
    // fails either way it's fine.)
}

#[panic(C)]
fn f<T>() {
    if false {
        // If promotion moved `C` from our required_consts to its own, without adding itself to
        // our required_consts, then we'd miss the const-eval failure here.
        let _val = &Fail::<T>::C;
    }
}

fn main() {
    if false {
        // If promotion moved `C` from our required_consts to its own, without adding itself to
        // our required_consts, then we'd miss the const-eval failure here.
        let _val = &Fail::<T>::C;
    }
}

Version information

rustc 1.80.0-nightly (72fdf913c 2024-06-05)
binary: rustc
commit-hash: 72fdf913c53dd0e75313ba83e4aa80df3f6e2871
commit-date: 2024-06-05
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

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

Program output

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.0hca098Ozkau/rustc_testrunner_tmpdir_reporting.urLT6Xgm3pBR/mvce.rs:10:2
   |
10 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.0hca098Ozkau/rustc_testrunner_tmpdir_reporting.urLT6Xgm3pBR/mvce.rs`

error[E0107]: missing generics for struct `Fail`
 --> /tmp/icemaker_global_tempdir.0hca098Ozkau/rustc_testrunner_tmpdir_reporting.urLT6Xgm3pBR/mvce.rs:1:16
  |
1 | struct Fail<T>(Fail);
  |                ^^^^ expected 1 generic argument
  |
note: struct defined here, with 1 generic parameter: `T`
 --> /tmp/icemaker_global_tempdir.0hca098Ozkau/rustc_testrunner_tmpdir_reporting.urLT6Xgm3pBR/mvce.rs:1:8
  |
1 | struct Fail<T>(Fail);
  |        ^^^^ -
help: add missing generic argument
  |
1 | struct Fail<T>(Fail<T>);
  |                    +++

error[E0072]: recursive type `Fail` has infinite size
 --> /tmp/icemaker_global_tempdir.0hca098Ozkau/rustc_testrunner_tmpdir_reporting.urLT6Xgm3pBR/mvce.rs:1:1
  |
1 | struct Fail<T>(Fail);
  | ^^^^^^^^^^^^^^ ---- recursive without indirection
  |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
  |
1 | struct Fail<T>(Box<Fail>);
  |                ++++    +

error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
 --> /tmp/icemaker_global_tempdir.0hca098Ozkau/rustc_testrunner_tmpdir_reporting.urLT6Xgm3pBR/mvce.rs:2:6
  |
2 | impl<T> Fail<i32> {
  |      ^ unconstrained type parameter

error: internal compiler error: instantiate_value_path: (UFCS) Fail<T/#0> was a subtype of Fail<i32> but now is not?
 --> /tmp/icemaker_global_tempdir.0hca098Ozkau/rustc_testrunner_tmpdir_reporting.urLT6Xgm3pBR/mvce.rs:8:21
  |
8 |         let _val = &Fail::<T>::C;
  |                     ^^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs:1419:32:
Box<dyn Any>
stack backtrace:
   0:     0x7ac91e1a6d45 - std::backtrace_rs::backtrace::libunwind::trace::hb2aae96f7a63ad27
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7ac91e1a6d45 - std::backtrace_rs::backtrace::trace_unsynchronized::h21f79cd140dff600
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ac91e1a6d45 - std::sys_common::backtrace::_print_fmt::hc8ebdc1b64ae52ee
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7ac91e1a6d45 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h7ba491a968dfae1d
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ac91e1f74eb - core::fmt::rt::Argument::fmt::he322040f856802e1
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/core/src/fmt/rt.rs:165:63
   5:     0x7ac91e1f74eb - core::fmt::write::hb4f7da2a314ef133
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/core/src/fmt/mod.rs:1168:21
   6:     0x7ac91e19ba1f - std::io::Write::write_fmt::h9e79d11af9b4686b
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/io/mod.rs:1835:15
   7:     0x7ac91e1a6b1e - std::sys_common::backtrace::_print::h9276d72631ea2ebd
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7ac91e1a6b1e - std::sys_common::backtrace::print::h301edb80f46c58f8
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7ac91e1a9559 - std::panicking::default_hook::{{closure}}::h08c68fc043d12d43
  10:     0x7ac91e1a92fa - std::panicking::default_hook::hdf65558cafad5039
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/panicking.rs:298:9
  11:     0x7ac91a97206f - std[6e8d71b68429f045]::panicking::update_hook::<alloc[5a6e81a1c85e3cc3]::boxed::Box<rustc_driver_impl[3b16240f18c6f62f]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7ac91e1a9c8b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h69f90a497fd344b0
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/alloc/src/boxed.rs:2077:9
  13:     0x7ac91e1a9c8b - std::panicking::rust_panic_with_hook::h9576f09a7a058c94
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/panicking.rs:799:13
  14:     0x7ac91a9a2bc4 - std[6e8d71b68429f045]::panicking::begin_panic::<rustc_errors[85e49f4302adcb2e]::ExplicitBug>::{closure#0}
  15:     0x7ac91a99f7c6 - std[6e8d71b68429f045]::sys_common::backtrace::__rust_end_short_backtrace::<std[6e8d71b68429f045]::panicking::begin_panic<rustc_errors[85e49f4302adcb2e]::ExplicitBug>::{closure#0}, !>
  16:     0x7ac91a99f4a6 - std[6e8d71b68429f045]::panicking::begin_panic::<rustc_errors[85e49f4302adcb2e]::ExplicitBug>
  17:     0x7ac91a9ac021 - <rustc_errors[85e49f4302adcb2e]::diagnostic::BugAbort as rustc_errors[85e49f4302adcb2e]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7ac91aaf9928 - <rustc_errors[85e49f4302adcb2e]::DiagCtxt>::span_bug::<rustc_span[94e0545083c6ac7f]::span_encoding::Span, alloc[5a6e81a1c85e3cc3]::string::String>
  19:     0x7ac91c106c8d - <rustc_hir_typeck[7d07483f08c89c92]::fn_ctxt::FnCtxt>::instantiate_value_path
  20:     0x7ac91c0fbf19 - <rustc_hir_typeck[7d07483f08c89c92]::fn_ctxt::FnCtxt>::check_expr_path
  21:     0x7ac91c84188e - <rustc_hir_typeck[7d07483f08c89c92]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  22:     0x7ac91c84436e - <rustc_hir_typeck[7d07483f08c89c92]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  23:     0x7ac91c83c86b - <rustc_hir_typeck[7d07483f08c89c92]::fn_ctxt::FnCtxt>::check_decl
  24:     0x7ac91c83f181 - <rustc_hir_typeck[7d07483f08c89c92]::fn_ctxt::FnCtxt>::check_block_with_expected
  25:     0x7ac91c843bf2 - <rustc_hir_typeck[7d07483f08c89c92]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  26:     0x7ac91c845c27 - <rustc_hir_typeck[7d07483f08c89c92]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  27:     0x7ac91c83e2cf - <rustc_hir_typeck[7d07483f08c89c92]::fn_ctxt::FnCtxt>::check_block_with_expected
  28:     0x7ac91c843bf2 - <rustc_hir_typeck[7d07483f08c89c92]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  29:     0x7ac91c12f417 - rustc_hir_typeck[7d07483f08c89c92]::check::check_fn
  30:     0x7ac91c125e89 - rustc_hir_typeck[7d07483f08c89c92]::typeck
  31:     0x7ac91c125907 - rustc_query_impl[1572c7dfdd517a64]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1572c7dfdd517a64]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[62e7a9badcda725c]::query::erase::Erased<[u8; 8usize]>>
  32:     0x7ac91c1cf2b1 - rustc_query_system[dd7ca378a021eaaf]::query::plumbing::try_execute_query::<rustc_query_impl[1572c7dfdd517a64]::DynamicConfig<rustc_query_system[dd7ca378a021eaaf]::query::caches::VecCache<rustc_span[94e0545083c6ac7f]::def_id::LocalDefId, rustc_middle[62e7a9badcda725c]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[1572c7dfdd517a64]::plumbing::QueryCtxt, false>
  33:     0x7ac91c1cdfd5 - rustc_query_impl[1572c7dfdd517a64]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7ac91c1cdc0b - <rustc_middle[62e7a9badcda725c]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[f003d1007c3f00fd]::check_crate::{closure#4}>::{closure#0}
  35:     0x7ac91c1cc6c7 - rustc_hir_analysis[f003d1007c3f00fd]::check_crate
  36:     0x7ac91c409c3e - rustc_interface[8fb37091e3fd3ade]::passes::analysis
  37:     0x7ac91c40979b - rustc_query_impl[1572c7dfdd517a64]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1572c7dfdd517a64]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[62e7a9badcda725c]::query::erase::Erased<[u8; 1usize]>>
  38:     0x7ac91cbaa725 - rustc_query_system[dd7ca378a021eaaf]::query::plumbing::try_execute_query::<rustc_query_impl[1572c7dfdd517a64]::DynamicConfig<rustc_query_system[dd7ca378a021eaaf]::query::caches::SingleCache<rustc_middle[62e7a9badcda725c]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[1572c7dfdd517a64]::plumbing::QueryCtxt, false>
  39:     0x7ac91cbaa48f - rustc_query_impl[1572c7dfdd517a64]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  40:     0x7ac91c9f1612 - rustc_interface[8fb37091e3fd3ade]::interface::run_compiler::<core[31c46ae728976beb]::result::Result<(), rustc_span[94e0545083c6ac7f]::ErrorGuaranteed>, rustc_driver_impl[3b16240f18c6f62f]::run_compiler::{closure#0}>::{closure#1}
  41:     0x7ac91c9cf489 - std[6e8d71b68429f045]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[8fb37091e3fd3ade]::util::run_in_thread_with_globals<rustc_interface[8fb37091e3fd3ade]::util::run_in_thread_pool_with_globals<rustc_interface[8fb37091e3fd3ade]::interface::run_compiler<core[31c46ae728976beb]::result::Result<(), rustc_span[94e0545083c6ac7f]::ErrorGuaranteed>, rustc_driver_impl[3b16240f18c6f62f]::run_compiler::{closure#0}>::{closure#1}, core[31c46ae728976beb]::result::Result<(), rustc_span[94e0545083c6ac7f]::ErrorGuaranteed>>::{closure#0}, core[31c46ae728976beb]::result::Result<(), rustc_span[94e0545083c6ac7f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[31c46ae728976beb]::result::Result<(), rustc_span[94e0545083c6ac7f]::ErrorGuaranteed>>
  42:     0x7ac91c9cf23c - <<std[6e8d71b68429f045]::thread::Builder>::spawn_unchecked_<rustc_interface[8fb37091e3fd3ade]::util::run_in_thread_with_globals<rustc_interface[8fb37091e3fd3ade]::util::run_in_thread_pool_with_globals<rustc_interface[8fb37091e3fd3ade]::interface::run_compiler<core[31c46ae728976beb]::result::Result<(), rustc_span[94e0545083c6ac7f]::ErrorGuaranteed>, rustc_driver_impl[3b16240f18c6f62f]::run_compiler::{closure#0}>::{closure#1}, core[31c46ae728976beb]::result::Result<(), rustc_span[94e0545083c6ac7f]::ErrorGuaranteed>>::{closure#0}, core[31c46ae728976beb]::result::Result<(), rustc_span[94e0545083c6ac7f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[31c46ae728976beb]::result::Result<(), rustc_span[94e0545083c6ac7f]::ErrorGuaranteed>>::{closure#2} as core[31c46ae728976beb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:     0x7ac91e1b3c7b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd9d8a12a4cec8653
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/alloc/src/boxed.rs:2063:9
  44:     0x7ac91e1b3c7b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc87e6ebe32d18c90
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/alloc/src/boxed.rs:2063:9
  45:     0x7ac91e1b3c7b - std::sys::pal::unix::thread::Thread::new::thread_start::h68df5163d04f9130
                               at /rustc/72fdf913c53dd0e75313ba83e4aa80df3f6e2871/library/std/src/sys/pal/unix/thread.rs:108:17
  46:     0x7ac9176a6ded - <unknown>
  47:     0x7ac91772a0dc - <unknown>
  48:                0x0 - <unknown>

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.80.0-nightly (72fdf913c 2024-06-05) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `f`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 5 previous errors

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

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 6, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jun 6, 2024
  3. matthiaskrgr commented on Jun 6, 2024

    @matthiaskrgr
    MemberAuthor

    This crashes since #125622 cc @oli-obk

  4. oli-obk commented on Jun 7, 2024

    @oli-obk
    Contributor

    Further reduced

    struct Fail<T>;
    impl Fail<i32> {
        const C: () = ();
    }
    
    fn main() {
        Fail::<()>::C
    }
  5. self-assigned this
    on Jun 7, 2024
  6. oli-obk commented on Jun 7, 2024

    @oli-obk
    Contributor

    lmao I had a suspicion this is variance related...

                 rustc_middle::ty::relate::structurally_relate_tys a=Fail<i32>, b=Fail<()>
                     0ms DEBUG rustc_infer::infer::relate::type_relating new ambient variance, self.ambient_variance=*
                     0ms TRACE rustc_middle::ty::relate return=Ok(Fail<i32>)
    
  7. compiler-errors commented on Jun 7, 2024

    @compiler-errors
    Contributor

    Yeah, but if that's bivariant then Fail<i32> being related to Fail<()> should succeed?

  8. oli-obk commented on Jun 7, 2024

    @oli-obk
    Contributor

    Because if we're invariant, we don't load the variance and just use invariant for all generic args. So subtyping will succeed and equating will fail

  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. added a commit that references this issue on Jun 14, 2024
    d2b076c
  11. added
    S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
    on Jun 17, 2024
  12. added a commit that references this issue on Jun 17, 2024
    9b584a6
  13. added a commit that references this issue on Jun 17, 2024
    ca70f3e
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.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.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