Skip to content

ICE: struct impl with type parameter substituted with another type #53498

Closed
@tirr-c

Description

@tirr-c

I made a struct Foo<T>, and made two impl blocks for Foo<A> and Foo<B> (A and B are unit structs.) Each impl block has a method with same name but different argument count. I accidentally made those methods private.

pub mod test {
    pub struct A;
    pub struct B;
    pub struct Foo<T>(::std::marker::PhantomData<T>);

    impl Foo<A> {
        fn foo(a: usize) -> usize {
            a
        }
    }
    
    impl Foo<B> {
        fn foo(_a: usize, b: usize) -> usize {
            b
        }
    }
}

fn main() {
    test::Foo::<test::B>::foo(0, 0);
}

Link to the playground

I expected to get error about privacy, but with that, the compiler panicked.

error[E0624]: method `foo` is private
  --> src/main.rs:20:5
   |
20 |     test::Foo::<test::B>::foo(0, 0);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: librustc_typeck/check/mod.rs:4910: instantiate_value_path: (UFCS) test::Foo<test::B> was a subtype of test::Foo<test::A> but now is not?
  --> src/main.rs:20:5
   |
20 |     test::Foo::<test::B>::foo(0, 0);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:499:9

(... backtrace below ...)

query stack during panic:
#0 [typeck_tables_of] processing `main`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: aborting due to 2 previous errors

Meta

note: rustc 1.28.0 (9634041f0 2018-07-30) running on x86_64-unknown-linux-gnu
note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin
note: some of the compiler flags provided by cargo are hidden

Backtrace:

stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:515
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::span_bug
   8: rustc::session::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::session::opt_span_bug_fmt
  13: rustc::session::span_bug_fmt
  14: rustc_typeck::check::FnCtxt::instantiate_value_path
  15: rustc_typeck::check::FnCtxt::check_expr_kind
  16: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs
  17: rustc_typeck::check::FnCtxt::check_expr_kind
  18: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs
  19: rustc_typeck::check::FnCtxt::check_block_with_expected
  20: rustc_typeck::check::FnCtxt::check_expr_kind
  21: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs
  22: rustc_typeck::check::FnCtxt::check_return_expr
  23: rustc_typeck::check::check_fn
  24: rustc::ty::context::tls::with_related_context
  25: rustc::infer::InferCtxtBuilder::enter
  26: rustc_typeck::check::typeck_tables_of
  27: rustc::ty::query::__query_compute::typeck_tables_of
  28: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_tables_of<'tcx>>::compute
  29: rustc::dep_graph::graph::DepGraph::with_task_impl
  30: rustc::ty::context::tls::with_related_context
  31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  32: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
  34: rustc::session::Session::track_errors
  35: rustc_typeck::check::typeck_item_bodies
  36: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_item_bodies<'tcx>>::compute
  37: rustc::dep_graph::graph::DepGraph::with_task_impl
  38: rustc::ty::context::tls::with_related_context
  39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  40: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  41: rustc::util::common::time
  42: rustc_typeck::check_crate
  43: rustc::ty::context::tls::enter_context
  44: <std::thread::local::LocalKey<T>>::with
  45: rustc::ty::context::TyCtxt::create_and_enter
  46: rustc_driver::driver::compile_input
  47: rustc_driver::run_compiler_with_pool
  48: <scoped_tls::ScopedKey<T>>::set
  49: syntax::with_globals
  50: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  51: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  52: rustc_driver::run
  53: rustc_driver::main
  54: std::rt::lang_start::{{closure}}
  55: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  56: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  57: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  58: main
  59: __libc_start_main
  60: <unknown>

Metadata

Metadata

Assignees

No one assigned

    Labels

    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