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

Compiler Error while trying to prototype a workaround for const methods in traits #116599

Closed
gammelalf opened this issue Oct 10, 2023 · 2 comments · Fixed by #122988
Closed

Compiler Error while trying to prototype a workaround for const methods in traits #116599

gammelalf opened this issue Oct 10, 2023 · 2 comments · Fixed by #122988
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@gammelalf
Copy link

Code

pub trait EvaluateConstMethods {
    type Trait: TraitWithConstMethods;

    /// **This block breaks**
    const DATA_3: Data3 = {
        <<<Self::Trait as TraitWithConstMethods>::Method2 as ConstFn<_, _>>::Body<
            <<Self::Trait as TraitWithConstMethods>::Method1 as ConstFn<_, _>>::Body<ContainsData1>,
        > as Contains<_>>::ITEM
    };
}

pub trait TraitWithConstMethods {
    /// "const trait method" of signature `fn(Data1) -> Data2`
    type Method1: ConstFn<Data1, Data2>;

    /// "const trait method" of signature `fn(Data2) -> Data3`
    type Method2: ConstFn<Data2, Data3>;
}

/// A trait which tries to implement const methods in traits
pub trait ConstFn<Arg, Ret> {
    type Body<T: Contains<Arg>>: Contains<Ret>;
}

/// A ZST which represents / "contains" a const value which can be pass to a [`ConstFn`]
pub trait Contains<T> {
    const ITEM: T;
}

pub struct ContainsData1;
impl Contains<Data1> for ContainsData1 {
    const ITEM: Data1 = Data1 {};
}

// Arbitrary data
pub struct Data1 {}
pub struct Data2 {}
pub struct Data3 {}

Meta

rustc --version --verbose:

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

Also reproduced on the rust playground

Error output

error: internal compiler error: /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/compiler/rustc_infer/src/infer/nll_relate/mod.rs:483:21: unexpected inference var _

[...]

query stack during panic:
#0 [mir_borrowck] borrow-checking `EvaluateConstMethods::DATA_3`
#1 [analysis] running analysis passes on this crate
end of query stack
Backtrace

error: internal compiler error: /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/compiler/rustc_infer/src/infer/nll_relate/mod.rs:483:21: unexpected inference var _

thread 'rustc' panicked at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/compiler/rustc_errors/src/lib.rs:1635:9:
Box<dyn Any>
stack backtrace:
   0:     0x7f15ecee749c - std::backtrace_rs::backtrace::libunwind::trace::he43a6a3949163f8c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f15ecee749c - std::backtrace_rs::backtrace::trace_unsynchronized::h50db52ca99f692e7
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f15ecee749c - std::sys_common::backtrace::_print_fmt::hd37d595f2ceb2d3c
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f15ecee749c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h678bbcf9da6d7d75
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f15ecf4d3fc - core::fmt::rt::Argument::fmt::h3a159adc080a6fc9
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/rt.rs:138:9
   5:     0x7f15ecf4d3fc - core::fmt::write::hb8eaf5a8e45a738e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f15eceda12e - std::io::Write::write_fmt::h9663fe36b2ee08f9
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/io/mod.rs:1714:15
   7:     0x7f15ecee7284 - std::sys_common::backtrace::_print::hcd4834796ee88ad2
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f15ecee7284 - std::sys_common::backtrace::print::h1360e9450e4f922a
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f15eceea193 - std::panicking::default_hook::{{closure}}::h2609fa95cd5ab1f4
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:270:22
  10:     0x7f15ecee9eac - std::panicking::default_hook::h6d75f5747cab6e8d
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:290:9
  11:     0x7f15ebd30a3e - <alloc[98253621d83cbf53]::boxed::Box<rustc_driver_impl[566d207f92c3d9d2]::install_ice_hook::{closure#0}> as core[d28c4e8d9c4eebaa]::ops::function::Fn<(&dyn for<'a, 'b> core[d28c4e8d9c4eebaa]::ops::function::Fn<(&'a core[d28c4e8d9c4eebaa]::panic::panic_info::PanicInfo<'b>,), Output = ()>   core[d28c4e8d9c4eebaa]::marker::Sync   core[d28c4e8d9c4eebaa]::marker::Send, &core[d28c4e8d9c4eebaa]::panic::panic_info::PanicInfo)>>::call
  12:     0x7f15eceea9be - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h05249de742e1768e
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2021:9
  13:     0x7f15eceea9be - std::panicking::rust_panic_with_hook::h57e78470c47c84de
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:711:13
  14:     0x7f15ec281521 - std[3759e478f3a6c4f2]::panicking::begin_panic::<rustc_errors[f3962fbeb8edb247]::ExplicitBug>::{closure#0}
  15:     0x7f15ec27d206 - std[3759e478f3a6c4f2]::sys_common::backtrace::__rust_end_short_backtrace::<std[3759e478f3a6c4f2]::panicking::begin_panic<rustc_errors[f3962fbeb8edb247]::ExplicitBug>::{closure#0}, !>
  16:     0x7f15ec2476c6 - std[3759e478f3a6c4f2]::panicking::begin_panic::<rustc_errors[f3962fbeb8edb247]::ExplicitBug>
  17:     0x7f15ec254134 - <rustc_errors[f3962fbeb8edb247]::HandlerInner>::bug::<alloc[98253621d83cbf53]::string::String>
  18:     0x7f15ec253fc6 - <rustc_errors[f3962fbeb8edb247]::Handler>::bug::<alloc[98253621d83cbf53]::string::String>
  19:     0x7f15ec2fb5ac - rustc_middle[5935fdd60c99b3fe]::util::bug::opt_span_bug_fmt::<rustc_span[4c9f011e8b033119]::span_encoding::Span>::{closure#0}
  20:     0x7f15ec2f9c5a - rustc_middle[5935fdd60c99b3fe]::ty::context::tls::with_opt::<rustc_middle[5935fdd60c99b3fe]::util::bug::opt_span_bug_fmt<rustc_span[4c9f011e8b033119]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f15ec2f9c28 - rustc_middle[5935fdd60c99b3fe]::ty::context::tls::with_context_opt::<rustc_middle[5935fdd60c99b3fe]::ty::context::tls::with_opt<rustc_middle[5935fdd60c99b3fe]::util::bug::opt_span_bug_fmt<rustc_span[4c9f011e8b033119]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f15ea5fd1b0 - rustc_middle[5935fdd60c99b3fe]::util::bug::bug_fmt
  23:     0x7f15eab04dd0 - <rustc_infer[2448fd35ed713fff]::infer::InferCtxt>::instantiate_nll_query_response_and_region_obligations::<()>
  24:     0x7f15eaab5755 - <rustc_middle[5935fdd60c99b3fe]::ty::ParamEnvAnd<rustc_middle[5935fdd60c99b3fe]::traits::query::type_op::AscribeUserType> as rustc_trait_selection[48b7f7e13fbddf35]::traits::query::type_op::TypeOp>::fully_perform
  25:     0x7f15eaab4f2a - <rustc_borrowck[29a4cdfbf3f92543]::type_check::TypeChecker>::ascribe_user_type
  26:     0x7f15eaab1b16 - rustc_borrowck[29a4cdfbf3f92543]::type_check::type_check
  27:     0x7f15eaa9ae2b - rustc_borrowck[29a4cdfbf3f92543]::nll::compute_regions
  28:     0x7f15eaa82cff - rustc_borrowck[29a4cdfbf3f92543]::do_mir_borrowck
  29:     0x7f15eaa81055 - rustc_borrowck[29a4cdfbf3f92543]::mir_borrowck
  30:     0x7f15e9e53aae - rustc_query_impl[778daaabc67f3fff]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[778daaabc67f3fff]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5935fdd60c99b3fe]::query::erase::Erased<[u8; 8usize]>>
  31:     0x7f15e9e53a7e - <rustc_query_impl[778daaabc67f3fff]::query_impl::mir_borrowck::dynamic_query::{closure#2} as core[d28c4e8d9c4eebaa]::ops::function::FnOnce<(rustc_middle[5935fdd60c99b3fe]::ty::context::TyCtxt, rustc_span[4c9f011e8b033119]::def_id::LocalDefId)>>::call_once
  32:     0x7f15ea3b71bf - rustc_query_system[e0e328d29a6e1c80]::query::plumbing::try_execute_query::<rustc_query_impl[778daaabc67f3fff]::DynamicConfig<rustc_query_system[e0e328d29a6e1c80]::query::caches::VecCache<rustc_span[4c9f011e8b033119]::def_id::LocalDefId, rustc_middle[5935fdd60c99b3fe]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[778daaabc67f3fff]::plumbing::QueryCtxt, true>
  33:     0x7f15eb6a4dfe - rustc_query_impl[778daaabc67f3fff]::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace
  34:     0x7f15eaeef031 - rustc_data_structures[29929b1a5d4d6700]::sync::par_for_each_in::<&[rustc_span[4c9f011e8b033119]::def_id::LocalDefId], <rustc_middle[5935fdd60c99b3fe]::hir::map::Map>::par_body_owners<rustc_interface[5bdd18de9f5858d8]::passes::analysis::{closure#1}::{closure#0}>::{closure#0}>
  35:     0x7f15eaeeed4d - <rustc_session[f1e1083633086c54]::session::Session>::time::<(), rustc_interface[5bdd18de9f5858d8]::passes::analysis::{closure#1}>
  36:     0x7f15eaeee4be - rustc_interface[5bdd18de9f5858d8]::passes::analysis
  37:     0x7f15eb23670a - rustc_query_impl[778daaabc67f3fff]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[778daaabc67f3fff]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5935fdd60c99b3fe]::query::erase::Erased<[u8; 1usize]>>
  38:     0x7f15eb2366f9 - <rustc_query_impl[778daaabc67f3fff]::query_impl::analysis::dynamic_query::{closure#2} as core[d28c4e8d9c4eebaa]::ops::function::FnOnce<(rustc_middle[5935fdd60c99b3fe]::ty::context::TyCtxt, ())>>::call_once
  39:     0x7f15eb51d898 - rustc_query_system[e0e328d29a6e1c80]::query::plumbing::try_execute_query::<rustc_query_impl[778daaabc67f3fff]::DynamicConfig<rustc_query_system[e0e328d29a6e1c80]::query::caches::SingleCache<rustc_middle[5935fdd60c99b3fe]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[778daaabc67f3fff]::plumbing::QueryCtxt, true>
  40:     0x7f15eb51d3f4 - rustc_query_impl[778daaabc67f3fff]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  41:     0x7f15eafe2973 - <rustc_interface[5bdd18de9f5858d8]::queries::QueryResult<&rustc_middle[5935fdd60c99b3fe]::ty::context::GlobalCtxt>>::enter::<core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>, rustc_driver_impl[566d207f92c3d9d2]::run_compiler::{closure#1}::{closure#2}::{closure#6}>
  42:     0x7f15eafe194a - <rustc_interface[5bdd18de9f5858d8]::interface::Compiler>::enter::<rustc_driver_impl[566d207f92c3d9d2]::run_compiler::{closure#1}::{closure#2}, core[d28c4e8d9c4eebaa]::result::Result<core[d28c4e8d9c4eebaa]::option::Option<rustc_interface[5bdd18de9f5858d8]::queries::Linker>, rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>
  43:     0x7f15eafdec68 - std[3759e478f3a6c4f2]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[5bdd18de9f5858d8]::util::run_in_thread_pool_with_globals<rustc_interface[5bdd18de9f5858d8]::interface::run_compiler<core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>, rustc_driver_impl[566d207f92c3d9d2]::run_compiler::{closure#1}>::{closure#0}, core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>
  44:     0x7f15eafde3ee - <<std[3759e478f3a6c4f2]::thread::Builder>::spawn_unchecked_<rustc_interface[5bdd18de9f5858d8]::util::run_in_thread_pool_with_globals<rustc_interface[5bdd18de9f5858d8]::interface::run_compiler<core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>, rustc_driver_impl[566d207f92c3d9d2]::run_compiler::{closure#1}>::{closure#0}, core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d28c4e8d9c4eebaa]::result::Result<(), rustc_span[4c9f011e8b033119]::ErrorGuaranteed>>::{closure#1} as core[d28c4e8d9c4eebaa]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  45:     0x7f15ecef5295 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::haadd4e5af2ab0d62
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
  46:     0x7f15ecef5295 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::he4ba1fb09c16d807
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/alloc/src/boxed.rs:2007:9
  47:     0x7f15ecef5295 - std::sys::unix::thread::Thread::new::thread_start::he524ecf4b47bee95
                               at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/sys/unix/thread.rs:108:17
  48:     0x7f15e8aaa9eb - <unknown>
  49:     0x7f15e8b2e7cc - <unknown>
  50:                0x0 - <unknown>

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug, I-ICE, T-compiler&template=ice.md

note: rustc 1.73.0 (cc66ad468 2023-10-03) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_borrowck] borrow-checking `EvaluateConstMethods::DATA_3`
#1 [analysis] running analysis passes on this crate
end of query stack

@gammelalf gammelalf added C-bug Category: This is a bug. 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. labels Oct 10, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 10, 2023
@matthiaskrgr
Copy link
Member

Regression in nightly-2023-03-10

fetching (via local git) commits from 900c354 to 39f2657
opening existing repository at "rust.git"
Found origin remote under name origin
refreshing repository at "rust.git"
looking up first commit
looking up second commit
checking that commits are by bors and thus have ci artifacts...
finding bors merge commits
found 4 bors merge commits in the specified range
commit[0] 2023-03-08: Auto merge of #108665 - weihanglo:update-cargo, r=weihanglo
commit[1] 2023-03-08: Auto merge of #108919 - matthiaskrgr:rollup-g271pm2, r=matthiaskrgr
commit[2] 2023-03-09: Auto merge of #108178 - cjgillot:ssa-deref, r=oli-obk
commit[3] 2023-03-09: Auto merge of #108920 - matthiaskrgr:rollup-qrr9a0u, r=matthiaskrgr
ERROR: no CI builds available between 900c354 and 39f2657 within last 167 days

@saethlin saethlin added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 22, 2023
@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jan 17, 2024

This compiles now

maybe #120019 ? dunno

@matthiaskrgr matthiaskrgr added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jan 17, 2024
@bors bors closed this as completed in db68dc2 Mar 25, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 25, 2024
Rollup merge of rust-lang#122988 - matthiaskrgr:icetests, r=petrochenkov

add even more tests!

Fixes rust-lang#109869
Fixes rust-lang#110453
Fixes rust-lang#109020
Fixes rust-lang#108580
Fixes rust-lang#108220
Fixes rust-lang#113045
Fixes rust-lang#113133
Fixes rust-lang#114464
Fixes rust-lang#116599
Fixes rust-lang#119731
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. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.

4 participants