Skip to content

internal compiler error: coherence failed to report ambiguit #23853

Closed
@max6cn

Description

@max6cn

I am trying the example from http://ironframework.io and got the following error:

/Users/max6/.cargo/registry/src/github.com-1ecc6299db9ec823/plugin-0.2.2/src/lib.rs:75:45: 75:59
error: internal compiler error: coherence failed to report ambiguity:
cannot locate the impl of the trait `core::any::Any` for the type `<P as typemap::Key>::Value`

Steps to reproduce this error:

  1. create new project
cargo new webex1  --bin
  1. edit main.rs as following

    extern crate iron;
    
    use iron::prelude::*;
    use iron::status;
    
    fn main() {
        fn hello_world(_: &mut Request) -> IronResult<Response> {
            Ok(Response::with((status::Ok, "Hello World!")))
        }
    
        Iron::new(hello_world).http("localhost:3000").unwrap();
        println!("On 3000");
    }

    add following lines to Cargo.toml

    [dependencies]
    iron = "*"
  2. RUST_BACKTRACE=1 cargo run

Output

Compiling conduit-mime-types v0.7.3
Compiling time v0.1.22
Compiling openssl-sys v0.5.3
Compiling num_cpus v0.1.0
Compiling url v0.2.28
Compiling mime v0.0.10
Compiling plugin v0.2.2
/Users/max6/.cargo/registry/src/github.com-1ecc6299db9ec823/plugin-0.2.2/src/lib.rs:75:45: 75:59 error: internal compiler error: coherence failed to report ambiguity: cannot locate the impl of the trait `core::any::Any` for the type `<P as typemap::Key>::Value`
/Users/max6/.cargo/registry/src/github.com-1ecc6299db9ec823/plugin-0.2.2/src/lib.rs:75             return Ok(self.extensions_mut().get_mut::<P>().unwrap());
^~~~~~~~~~~~~~
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libsyntax/diagnostic.rs:130


Related Source file

cat /Users/max6/.cargo/registry/src/github.com-1ecc6299db9ec823/plugin-0.2.2/src/lib.rs

#![feature(core)]
#![deny(missing_docs, warnings)]

//! Lazily-Evaluated, Order-Independent Plugins for Extensible Types.

extern crate typemap;
use typemap::{TypeMap, Key};

/// Implementers of this trait can act as plugins for other types, via `OtherType::get<P>()`.
///
/// To create a plugin, implement this trait and provide an empty implementation
/// of `Key` to associate the plugin with its return type, `Key::Value`.
pub trait Plugin<E: ?Sized>: Key {
  /// The error type associated with this plugin.
  type Error;

  /// Create the plugin from an instance of the extended type.
  ///
  /// While `eval` is given a mutable reference to the extended
  /// type, it is important for implementers to remember that
  /// the result of `eval` is usually cached, so care should
  /// be taken when doing mutation on the extended type.
  fn eval(&mut E) -> Result<Self::Value, Self::Error>;
}

/// Defines an interface that extensible types must implement.
///
/// Extensible types must contain a TypeMap.
pub trait Extensible {
  /// Get a reference to the type's extension storage.
  fn extensions(&self) -> &TypeMap;

  /// Get a mutable reference to the type's extension storage.
  fn extensions_mut(&mut self) -> &mut TypeMap;
}

/// An interface for plugins that cache values between calls.
///
/// `R` is the type of the plugin's return value, which must be cloneable.
pub trait Pluggable {
  /// Return a copy of the plugin's produced value.
  ///
  /// The plugin will be created if it doesn't exist already.
  /// If plugin creation fails, an error is returned.
  ///
  /// `P` is the plugin type.
  fn get<P: Plugin<Self>>(&mut self) -> Result<P::Value, P::Error>
  where P::Value: Clone + 'static, Self: Extensible, P::Error: Clone {
    self.get_ref::<P>().map(|v| v.clone())
  }

  /// Return a reference to the plugin's produced value.
  ///
  /// The plugin will be created if it doesn't exist already.
  /// If plugin creation fails an error is returned.
  ///
  /// `P` is the plugin type.
  fn get_ref<P: Plugin<Self>>(&mut self) -> Result<&P::Value, P::Error>
  where P::Value: 'static, Self: Extensible {
    self.get_mut::<P>().map(|mutref| &*mutref)
  }

  /// Return a mutable reference to the plugin's produced value.
  ///
  /// The plugin will be created if it doesn't exist already.
  /// If plugin creation fail an error is returned.
  ///
  /// `P` is the plugin type.
  fn get_mut<P: Plugin<Self>>(&mut self) -> Result<&mut P::Value, P::Error>
  where P::Value: 'static, Self: Extensible {
    use typemap::Entry::{Occupied, Vacant};
    use std::intrinsics::unreachable;

    if self.extensions().contains::<P>() {
      return Ok(self.extensions_mut().get_mut::<P>().unwrap());
    }

    <P as Plugin<Self>>::eval(self).map(move |data| {
      match self.extensions_mut().entry::<P>() {
        Vacant(entry) => entry.insert(data),
        Occupied(..) => unsafe { unreachable() }
      }
      })
    }

    /// Create and evaluate a once-off instance of a plugin.
    fn compute<P: Plugin<Self>>(&mut self) -> Result<P::Value, P::Error> {
      <P as Plugin<Self>>::eval(self)
    }
  }

  #[cfg(test)]
  mod test {
    extern crate void;

    use test::void::{Void, VoidExtensions};

    use typemap::{TypeMap, Key};
    use super::{Extensible, Plugin, Pluggable};

    struct Extended {
      map: TypeMap
    }

    impl Extended {
      fn new() -> Extended {
        Extended { map: TypeMap::new() }
      }
    }

    impl Extensible for Extended {
      fn extensions(&self) -> &TypeMap { &self.map }
      fn extensions_mut(&mut self) -> &mut TypeMap { &mut self.map }
    }

    impl Pluggable for Extended {}

      macro_rules! generate_simple_plugin (
        ($t:ty, $v:ident, $v2:expr) => {
          #[derive(PartialEq, Debug, Clone)]
          struct $v(i32);

          impl Key for $t { type Value = $t; }

          impl Plugin<Extended> for $t {
            type Error = Void;

            fn eval(_: &mut Extended) -> Result<$t, Void> {
              Ok($v($v2))
            }
          }
        }
        );

        generate_simple_plugin!(One, One, 1);
        generate_simple_plugin!(Two, Two, 2);
        generate_simple_plugin!(Three, Three, 3);
        generate_simple_plugin!(Four, Four, 4);
        generate_simple_plugin!(Five, Five, 5);
        generate_simple_plugin!(Six, Six, 6);
        generate_simple_plugin!(Seven, Seven, 7);
        generate_simple_plugin!(Eight, Eight, 8);
        generate_simple_plugin!(Nine, Nine, 9);
        generate_simple_plugin!(Ten, Ten, 10);

        #[test] fn test_simple() {
          let mut extended = Extended::new();
          assert_eq!(extended.get::<One>(),   Ok(One(1)));
          assert_eq!(extended.get::<Two>(),   Ok(Two(2)));
          assert_eq!(extended.get::<Three>(), Ok(Three(3)));
        }

        #[test] fn test_resize() {
          let mut extended = Extended::new();
          extended.get::<One>().void_unwrap();
          extended.get::<Two>().void_unwrap();
          extended.get::<Three>().void_unwrap();
          extended.get::<Four>().void_unwrap();
          extended.get::<Five>().void_unwrap();
          extended.get::<Six>().void_unwrap();
          extended.get::<Seven>().void_unwrap();
          extended.get::<Eight>().void_unwrap();
          extended.get::<Nine>().void_unwrap();
          extended.get::<Ten>().void_unwrap();
          assert_eq!(extended.get_ref::<One>(), Ok(&One(1)))
        }

        #[test] fn test_custom_return_type() {
          let mut extended = Extended::new();

          // Define a struct.
          struct IntPlugin;

          // Map it onto an `i32` value.
          impl Key for IntPlugin { type Value = i32; }

          // Define the plugin evaluation function.
          impl Plugin<Extended> for IntPlugin {
            type Error = Void;

            fn eval(_: &mut Extended) -> Result<i32, Void> {
              Ok(0i32)
            }
          }
          assert_eq!(extended.get::<IntPlugin>().void_unwrap(), 0i32);
        }
      }

Backtrace and version information

rustc --version --verbose:

rustc --version --verbose
rustc 1.0.0-nightly (27901849e 2015-03-25) (built 2015-03-26)
binary: rustc
commit-hash: 27901849e07558639b8decc03707e0317ae8280e
commit-date: 2015-03-25
build-date: 2015-03-26
host: x86_64-apple-darwin
release: 1.0.0-nightly

Backtrace:

stack backtrace:
1:        0x11145dae4 - sys::backtrace::write::h60a4d01122ac4cc2OjD
2:        0x111488c38 - panicking::on_panic::h71bf3930cf08a95dY9I
3:        0x1113a687e - rt::unwind::begin_unwind_inner::h8510ec4880ca5ddc8RI
4:        0x110ba4c1e - rt::unwind::begin_unwind::h11428392113330414505
5:        0x110ba4bcb - diagnostic::SpanHandler::span_bug::h51d3c08c25edd395taB
6:        0x10e53c241 - middle::traits::error_reporting::report_fulfillment_errors::h5d246675425c9d4bhwM
7:        0x10dadd912 - check::vtable::select_all_fcx_obligations_or_error::h25f1bd2bc40df770k2b
8:        0x10db8e6fa - check::check_bare_fn::hef1e97f4f82ddc463nn
9:        0x10db93d2f - check::check_method_body::hbbb7de48d1cfdabeTVn
10:        0x10db8a0c4 - check::check_item::h25c21617996c325dOGn
11:        0x10dc5fed6 - check_crate::closure.36000
12:        0x10dc5ad9a - check_crate::hd293b9d434113177OmC
13:        0x10d996627 - driver::phase_3_run_analysis_passes::h4f2a12d60051e411rGa
14:        0x10d97c667 - driver::compile_input::h16042e7910f69e15Rba
15:        0x10da36173 - run_compiler::ha385e70672e841abs2b
16:        0x10da33d05 - thunk::F.Invoke<A, R>::invoke::h16437619201372565195
17:        0x10da330c7 - rt::unwind::try::try_fn::h3771335316142457703
18:        0x11150f1e8 - rust_try_inner
19:        0x11150f1d5 - rust_try
20:        0x10da33465 - thunk::F.Invoke<A, R>::invoke::h15947769794543045347
21:        0x111473bcd - sys::thread::create::thread_start::hbb06c6fdb1ad3e1eYPH
22:     0x7fff83b6b267 - _pthread_body
23:     0x7fff83b6b1e4 - _pthread_start

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