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

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

Closed
tirr-c opened this issue Aug 19, 2018 · 3 comments · Fixed by #60721
Closed

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

tirr-c opened this issue Aug 19, 2018 · 3 comments · Fixed by #60721
Labels
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.

Comments

@tirr-c
Copy link
Contributor

tirr-c commented Aug 19, 2018

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>
@Centril Centril added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Aug 19, 2018
@Centril
Copy link
Contributor

Centril commented Aug 19, 2018

@tirr-c
Copy link
Contributor Author

tirr-c commented Aug 23, 2018

Interesting point: in this code, Foo<A> doesn't have method foobar but the compiler reports that it exists but is private.

pub mod test {
    pub struct A;
    pub struct B;
    pub struct Foo<T>(T);

    impl Foo<A> {
        fn foo() {}
    }

    impl Foo<B> {
        fn foobar() {}
    }
}

fn foo() {
    test::Foo::<test::A>::foobar();
}
error[E0624]: method `foobar` is private
  --> src/lib.rs:16:5
   |
16 |     test::Foo::<test::A>::foobar();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

However, with pub fn foobar(), the compiler reports error correctly.

error[E0599]: no function or associated item named `foobar` found for type `test::Foo<test::A>` in the current scope
  --> src/lib.rs:16:5
   |
4  |     pub struct Foo<T>(T);
   |     --------------------- function or associated item `foobar` not found for this
...
16 |     test::Foo::<test::A>::foobar();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `test::Foo<test::A>`

@estebank
Copy link
Contributor

CC #59406, #39124.

@estebank estebank added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 26, 2019
bors added a commit that referenced this issue May 11, 2019
Avoid ICE by using delay_span_bug

Fix #59406, fix #53498.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants