Skip to content

Panic implementing Hash using using impl Trait in argument positions #50286

Closed
@nsmaciej

Description

@nsmaciej

When implementing the Hash trait using impl Trait in argument positions the compiler panics.

use std::hash::{Hash, Hasher};

struct Foo;

impl Hash for Foo {
    fn hash(&self, s: &mut impl Hasher) { }
}

The excepted error is:

error[E0643]: method `zots` has incompatible signature for trait
  --> src/main.rs:10:28
   |
6  |     fn zots<B: Barer>(&self, s: &mut B);
   |             - annotation in trait
...
10 |     fn zots(&self, s: &mut impl Barer) { }   
   |                            ^^^^^^^^^^ annotation in impl

which can be reproduced using:

struct Foo;

trait Barer { }

trait Bar {
    fn zots<B: Barer>(&self, s: &mut B);
}

impl Bar for Foo {
    fn zots(&self, s: &mut impl Barer) { }   
}

I tried to reproducing it outside of the Hash trait but to no avail. I'm using the latest (as of writing) nightly.

Compiler Version

rustc 1.27.0-nightly (7f3444e1b 2018-04-26)
binary: rustc
commit-hash: 7f3444e1baf0d335b4bf379f845dbc28cdd0509c
commit-date: 2018-04-26
host: x86_64-apple-darwin
release: 1.27.0-nightly
LLVM version: 6.0

Backtrace

thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:335:21
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic_fmt
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::panicking::panic
  10: rustc_typeck::check::compare_method::compare_impl_method
  11: rustc_typeck::check::check_item_type
  12: rustc::hir::Crate::visit_all_item_likes
  13: rustc::util::common::time
  14: rustc_typeck::check_crate
  15: rustc::ty::context::tls::enter_context
  16: <std::thread::local::LocalKey<T>>::with
  17: rustc::ty::context::TyCtxt::create_and_enter
  18: rustc_driver::driver::compile_input
  19: rustc_driver::run_compiler_impl
  20: syntax::with_globals
  21: rustc_driver::run
  22: rustc_driver::main
  23: std::rt::lang_start::{{closure}}
  24: std::panicking::try::do_call
  25: __rust_maybe_catch_panic
  26: std::rt::lang_start_internal
  27: main
query stack during panic:
end of query stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions