Skip to content

ice: internal error: entered unreachable code: encountered TraitItem(TraitItem .. #119942

Closed
@matthiaskrgr

Description

auto-reduced (treereduce-rust):

use std::ops::Deref;

trait PointerFamily {
    type Pointer<T>: Deref + Sized;
}

struct RcFamily;

impl PointerFamily for RcFamily {
    type Pointer<T> = Deref<Target = T>;
}

enum Node<T, P: PointerFamily> {
    Cons(T, P::Pointer<Node<T, P>>),
    Nil,
}

type RcNode<T> = Node<T, RcFamily>;

impl<T, P: PointerFamily> Node<T, P>
where
    P::Pointer<Node<T, P>>: Sized,
{
    fn new() -> P::Pointer<Self> {}
}

fn main() {
    let mut list: Pointer<i32> = RcNode::<i32>::new();
}
original code

original:

#![feature(generic_associated_types)]
use std::rc::Rc;
use std::ops::Deref;

trait PointerFamily {
    type Pointer<T>: Deref<Target=RcList> + Sized;

    fn new<T>(obj: T) -> Self::Pointer<T>;
}

#[derive(Debug)]
struct RcFamily;

impl PointerFamily for RcFamily {
    type Pointer<T> = Deref<Target=T>;

    fn new<T>(obj: T) -> Rc<T> {
        Rc::new(obj)
    }
}

#[derive(Debug)]
enum Node<T, P: PointerFamily> where P::Pointer<Node<T, P>>: Sized {
    Cons(T, P::Pointer<Node<T, P>>),
    Nil
}

type List<T, P> = <P as PointerFamily>::Pointer<Node<T, P>>;
type RcList<T> = List<T, RcFamily>;
type RcNode<T> = Node<T, RcFamily>;

impl<T, P: PointerFamily> Node<T, P> where P::Pointer<Node<T, P>>: Sized {
    fn new() -> P::Pointer<Self> {
        P::new(Self::Nil)
    }

    fn cons(head: T, head: T) -> P::Pointer<Self> {
        ops::new(Self::Cons(head, tail))
    }
}

fn main() {
    let mut list: Pointer<i32> = RcNode::<i32>::new();
    list = RcNode::<i32>::cons(1, list);
    //println!("{:?}", list);

}

Version information

rustc 1.77.0-nightly (1d8d7b16c 2024-01-13)
binary: rustc
commit-hash: 1d8d7b16cbcd048e98359cd0d42b03bc1710cca8
commit-date: 2024-01-13
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

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

Program output

error[E0412]: cannot find type `Pointer` in this scope
  --> /tmp/icemaker_global_tempdir.jjN8FIglpDL0/rustc_testrunner_tmpdir_reporting.PPvgEAUDyHb1/mvce.rs:28:19
   |
28 |     let mut list: Pointer<i32> = RcNode::<i32>::new();
   |                   ^^^^^^^ not found in this scope
   |
help: consider importing this trait
   |
1  + use std::fmt::Pointer;
   |

warning: trait objects without an explicit `dyn` are deprecated
  --> /tmp/icemaker_global_tempdir.jjN8FIglpDL0/rustc_testrunner_tmpdir_reporting.PPvgEAUDyHb1/mvce.rs:10:23
   |
10 |     type Pointer<T> = Deref<Target = T>;
   |                       ^^^^^^^^^^^^^^^^^
   |
   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
   = note: `#[warn(bare_trait_objects)]` on by default
help: use `dyn`
   |
10 |     type Pointer<T> = dyn Deref<Target = T>;
   |                       +++

error[E0277]: the size for values of type `(dyn Deref<Target = T> + 'static)` cannot be known at compilation time
  --> /tmp/icemaker_global_tempdir.jjN8FIglpDL0/rustc_testrunner_tmpdir_reporting.PPvgEAUDyHb1/mvce.rs:10:23
   |
10 |     type Pointer<T> = Deref<Target = T>;
   |                       ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   |
   = help: the trait `Sized` is not implemented for `(dyn Deref<Target = T> + 'static)`
note: required by a bound in `PointerFamily::Pointer`
  --> /tmp/icemaker_global_tempdir.jjN8FIglpDL0/rustc_testrunner_tmpdir_reporting.PPvgEAUDyHb1/mvce.rs:4:5
   |
4  |     type Pointer<T>: Deref + Sized;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `PointerFamily::Pointer`

error[E0308]: mismatched types
  --> /tmp/icemaker_global_tempdir.jjN8FIglpDL0/rustc_testrunner_tmpdir_reporting.PPvgEAUDyHb1/mvce.rs:24:17
   |
24 |     fn new() -> P::Pointer<Self> {}
   |        ---      ^^^^^^^^^^^^^^^^ expected associated type, found `()`
   |        |
   |        implicitly returns `()` as its body has no tail or `return` expression
   |
   = note: expected associated type `<P as PointerFamily>::Pointer<Node<T, P>>`
                    found unit type `()`
help: consider constraining the associated type `<P as PointerFamily>::Pointer<Node<T, P>>` to `()`
   |
20 | impl<T, P: PointerFamily<Pointer<Node<T, P>> = ()>> Node<T, P>
   |                         ++++++++++++++++++++++++++

thread 'rustc' panicked at compiler/rustc_hir_typeck/src/method/suggest.rs:843:35:
internal error: entered unreachable code: encountered `TraitItem(TraitItem { ident: Pointer#0, owner_id: DefId(0:5 ~ mvce[2bb9]::PointerFamily::Pointer), generics: Generics { params: [GenericParam { hir_id: HirId(DefId(0:5 ~ mvce[2bb9]::PointerFamily::Pointer).1), def_id: DefId(0:6 ~ mvce[2bb9]::PointerFamily::Pointer::T), name: Plain(T#0), span: /tmp/icemaker_global_tempdir.jjN8FIglpDL0/rustc_testrunner_tmpdir_reporting.PPvgEAUDyHb1/mvce.rs:4:18: 4:19 (#0), pure_wrt_drop: false, kind: Type { default: None, synthetic: false }, colon_span: None, source: Generics }], predicates: [], has_where_clause_predicates: false, where_clause_span: /tmp/icemaker_global_tempdir.jjN8FIglpDL0/rustc_testrunner_tmpdir_reporting.PPvgEAUDyHb1/mvce.rs:4:35: 4:35 (#0), span: /tmp/icemaker_global_tempdir.jjN8FIglpDL0/rustc_testrunner_tmpdir_reporting.PPvgEAUDyHb1/mvce.rs:4:17: 4:20 (#0) }, kind: Type([Trait(PolyTraitRef { bound_generic_params: [], trait_ref: TraitRef { path: Path { span: /tmp/icemaker_global_tempdir.jjN8FIglpDL0/rustc_testrunner_tmpdir_reporting.PPvgEAUDyHb1/mvce.rs:4:22: 4:27 (#0), res: Def(Trait, DefId(2:3099 ~ core[e512]::ops::deref::Deref)), segments: [PathSegment { ident: Deref#0, hir_id: HirId(DefId(0:5 ~ mvce[2bb9]::PointerFamily::Pointer).2), res: Def(Trait, DefId(2:3099 ~ core[e512]::ops::deref::Deref)), args: None, infer_args: false }] }, hir_ref_id: HirId(DefId(0:5 ~ mvce[2bb9]::PointerFamily::Pointer).3) }, span: /tmp/icemaker_global_tempdir.jjN8FIglpDL0/rustc_testrunner_tmpdir_reporting.PPvgEAUDyHb1/mvce.rs:4:22: 4:27 (#0) }, None), Trait(PolyTraitRef { bound_generic_params: [], trait_ref: TraitRef { path: Path { span: /tmp/icemaker_global_tempdir.jjN8FIglpDL0/rustc_testrunner_tmpdir_reporting.PPvgEAUDyHb1/mvce.rs:4:30: 4:35 (#0), res: Def(Trait, DefId(2:32446 ~ core[e512]::marker::Sized)), segments: [PathSegment { ident: Sized#0, hir_id: HirId(DefId(0:5 ~ mvce[2bb9]::PointerFamily::Pointer).4), res: Def(Trait, DefId(2:32446 ~ core[e512]::marker::Sized)), args: None, infer_args: false }] }, hir_ref_id: HirId(DefId(0:5 ~ mvce[2bb9]::PointerFamily::Pointer).5) }, span: /tmp/icemaker_global_tempdir.jjN8FIglpDL0/rustc_testrunner_tmpdir_reporting.PPvgEAUDyHb1/mvce.rs:4:30: 4:35 (#0) }, None)], None), span: /tmp/icemaker_global_tempdir.jjN8FIglpDL0/rustc_testrunner_tmpdir_reporting.PPvgEAUDyHb1/mvce.rs:4:5: 4:36 (#0), defaultness: Default { has_value: false } })`
stack backtrace:
   0:     0x7efd9ab8bad6 - std::backtrace_rs::backtrace::libunwind::trace::hafe4208b6c07c670
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7efd9ab8bad6 - std::backtrace_rs::backtrace::trace_unsynchronized::h73707f3e9c303fc3
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7efd9ab8bad6 - std::sys_common::backtrace::_print_fmt::h2632e46081e3482c
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7efd9ab8bad6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h47aeb79f6c12370e
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7efd9abde180 - core::fmt::rt::Argument::fmt::hf4ed74fd0ce2f365
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/core/src/fmt/rt.rs:142:9
   5:     0x7efd9abde180 - core::fmt::write::h3cb9c8aec8a606ac
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/core/src/fmt/mod.rs:1120:17
   6:     0x7efd9ab7f40f - std::io::Write::write_fmt::h06ac7f824eda4cc9
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/std/src/io/mod.rs:1810:15
   7:     0x7efd9ab8b8b4 - std::sys_common::backtrace::_print::h0711b9d959a6f708
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7efd9ab8b8b4 - std::sys_common::backtrace::print::h299d5e24840f6565
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7efd9ab8e647 - std::panicking::default_hook::{{closure}}::hae33a1db9d7bda73
  10:     0x7efd9ab8e3a9 - std::panicking::default_hook::h14076f5ecb82f2ad
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/std/src/panicking.rs:292:9
  11:     0x7efd9d96011c - std[ce45e49631e1cb35]::panicking::update_hook::<alloc[a43e71f630abdcc2]::boxed::Box<rustc_driver_impl[37f6d03016e0bdfe]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7efd9ab8ed96 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hffa6893bf823c735
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/alloc/src/boxed.rs:2030:9
  13:     0x7efd9ab8ed96 - std::panicking::rust_panic_with_hook::h6450b06268e3a1de
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/std/src/panicking.rs:785:13
  14:     0x7efd9ab8eae2 - std::panicking::begin_panic_handler::{{closure}}::h1d83a1644f0dd250
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/std/src/panicking.rs:659:13
  15:     0x7efd9ab8bfd6 - std::sys_common::backtrace::__rust_end_short_backtrace::h40ae9afcd5155a77
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7efd9ab8e840 - rust_begin_unwind
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/std/src/panicking.rs:647:5
  17:     0x7efd9abda885 - core::panicking::panic_fmt::h984a996b333d4995
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/core/src/panicking.rs:72:14
  18:     0x7efd9db5bc33 - <rustc_hir_typeck[a618237861171b5]::fn_ctxt::FnCtxt>::report_no_match_method_error
  19:     0x7efd9db7b0d1 - <rustc_hir_typeck[a618237861171b5]::fn_ctxt::FnCtxt>::report_method_error
  20:     0x7efd9f08bdfa - <rustc_hir_typeck[a618237861171b5]::fn_ctxt::FnCtxt>::check_expr_path
  21:     0x7efd9f356521 - <rustc_hir_typeck[a618237861171b5]::fn_ctxt::FnCtxt>::check_call
  22:     0x7efd9f6d3eb9 - <rustc_hir_typeck[a618237861171b5]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  23:     0x7efd9f55b9a0 - <rustc_hir_typeck[a618237861171b5]::fn_ctxt::FnCtxt>::check_decl
  24:     0x7efd9f559565 - <rustc_hir_typeck[a618237861171b5]::fn_ctxt::FnCtxt>::check_block_with_expected
  25:     0x7efd9f6d42c9 - <rustc_hir_typeck[a618237861171b5]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  26:     0x7efd9f262bc8 - rustc_hir_typeck[a618237861171b5]::check::check_fn
  27:     0x7efd9eed42f6 - rustc_hir_typeck[a618237861171b5]::typeck
  28:     0x7efd9eed3675 - rustc_query_impl[e4ce4d657abfabc5]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e4ce4d657abfabc5]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[384f37dc3ec43e81]::query::erase::Erased<[u8; 8usize]>>
  29:     0x7efd9f0da079 - rustc_query_system[f728052ad5099490]::query::plumbing::try_execute_query::<rustc_query_impl[e4ce4d657abfabc5]::DynamicConfig<rustc_query_system[f728052ad5099490]::query::caches::VecCache<rustc_span[e9265f3e0932590b]::def_id::LocalDefId, rustc_middle[384f37dc3ec43e81]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[e4ce4d657abfabc5]::plumbing::QueryCtxt, false>
  30:     0x7efd9f0d9d10 - rustc_query_impl[e4ce4d657abfabc5]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7efd9f0d958c - <rustc_middle[384f37dc3ec43e81]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[6f9a3fbaf16e07f7]::check_crate::{closure#6}>::{closure#0}
  32:     0x7efd9f0d7e84 - rustc_hir_analysis[6f9a3fbaf16e07f7]::check_crate
  33:     0x7efd9f858999 - rustc_interface[669531d91382febc]::passes::analysis
  34:     0x7efd9f8585df - rustc_query_impl[e4ce4d657abfabc5]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e4ce4d657abfabc5]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[384f37dc3ec43e81]::query::erase::Erased<[u8; 1usize]>>
  35:     0x7efd9fbc5240 - rustc_query_system[f728052ad5099490]::query::plumbing::try_execute_query::<rustc_query_impl[e4ce4d657abfabc5]::DynamicConfig<rustc_query_system[f728052ad5099490]::query::caches::SingleCache<rustc_middle[384f37dc3ec43e81]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[e4ce4d657abfabc5]::plumbing::QueryCtxt, false>
  36:     0x7efd9fbc5047 - rustc_query_impl[e4ce4d657abfabc5]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7efd9f94502d - rustc_interface[669531d91382febc]::interface::run_compiler::<core[e512b67a359c8dc0]::result::Result<(), rustc_span[e9265f3e0932590b]::ErrorGuaranteed>, rustc_driver_impl[37f6d03016e0bdfe]::run_compiler::{closure#0}>::{closure#0}
  38:     0x7efd9fbf3f86 - std[ce45e49631e1cb35]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[669531d91382febc]::util::run_in_thread_with_globals<rustc_interface[669531d91382febc]::util::run_in_thread_pool_with_globals<rustc_interface[669531d91382febc]::interface::run_compiler<core[e512b67a359c8dc0]::result::Result<(), rustc_span[e9265f3e0932590b]::ErrorGuaranteed>, rustc_driver_impl[37f6d03016e0bdfe]::run_compiler::{closure#0}>::{closure#0}, core[e512b67a359c8dc0]::result::Result<(), rustc_span[e9265f3e0932590b]::ErrorGuaranteed>>::{closure#0}, core[e512b67a359c8dc0]::result::Result<(), rustc_span[e9265f3e0932590b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e512b67a359c8dc0]::result::Result<(), rustc_span[e9265f3e0932590b]::ErrorGuaranteed>>
  39:     0x7efd9fbf3db3 - <<std[ce45e49631e1cb35]::thread::Builder>::spawn_unchecked_<rustc_interface[669531d91382febc]::util::run_in_thread_with_globals<rustc_interface[669531d91382febc]::util::run_in_thread_pool_with_globals<rustc_interface[669531d91382febc]::interface::run_compiler<core[e512b67a359c8dc0]::result::Result<(), rustc_span[e9265f3e0932590b]::ErrorGuaranteed>, rustc_driver_impl[37f6d03016e0bdfe]::run_compiler::{closure#0}>::{closure#0}, core[e512b67a359c8dc0]::result::Result<(), rustc_span[e9265f3e0932590b]::ErrorGuaranteed>>::{closure#0}, core[e512b67a359c8dc0]::result::Result<(), rustc_span[e9265f3e0932590b]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e512b67a359c8dc0]::result::Result<(), rustc_span[e9265f3e0932590b]::ErrorGuaranteed>>::{closure#1} as core[e512b67a359c8dc0]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  40:     0x7efd9ab98c95 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h268b96dcdfddeab3
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/alloc/src/boxed.rs:2016:9
  41:     0x7efd9ab98c95 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6c1442a7cc8857fa
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/alloc/src/boxed.rs:2016:9
  42:     0x7efd9ab98c95 - std::sys::pal::unix::thread::Thread::new::thread_start::h43a1ec9dc2556f56
                               at /rustc/1d8d7b16cbcd048e98359cd0d42b03bc1710cca8/library/std/src/sys/pal/unix/thread.rs:108:17
  43:     0x7efd9a9849eb - <unknown>
  44:     0x7efd9aa087cc - <unknown>
  45:                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.77.0-nightly (1d8d7b16c 2024-01-13) running on x86_64-unknown-linux-gnu

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

Some errors have detailed explanations: E0277, E0308, E0412.
For more information about an error, try `rustc --explain E0277`.

Activity

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

Metadata

Labels

C-bugCategory: This is a bug.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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions