about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGeorg Semmler <georg_semmler_05@web.de>2018-11-21 21:35:56 +0100
committerGeorg Semmler <georg_semmler_05@web.de>2019-01-03 22:26:44 +0100
commitbcd7acfe046356e8107a4f2df2c5f06bc0abd219 (patch)
treed1f74844dd4ca01eb8c7e6647d08819595295aa6 /src
parent757d7ba9c9e66320f8ff22d435ad30d6048585e1 (diff)
downloadrust-bcd7acfe046356e8107a4f2df2c5f06bc0abd219.tar.gz
rust-bcd7acfe046356e8107a4f2df2c5f06bc0abd219.zip
Add some tests
This copies and adjusts the existing coherence tests to ensure that
they continue to work using the new implementation.
Diffstat (limited to 'src')
-rw-r--r--src/test/run-pass/re_rebalance_coherence/auxiliary/coherence_copy_like_lib.rs20
-rw-r--r--src/test/run-pass/re_rebalance_coherence/auxiliary/coherence_lib.rs25
-rw-r--r--src/test/run-pass/re_rebalance_coherence/auxiliary/re_rebalance_coherence_lib.rs23
-rw-r--r--src/test/run-pass/re_rebalance_coherence/coherence-bigint-int.rs25
-rw-r--r--src/test/run-pass/re_rebalance_coherence/coherence-bigint-vecint.rs25
-rw-r--r--src/test/run-pass/re_rebalance_coherence/coherence-blanket.rs27
-rw-r--r--src/test/run-pass/re_rebalance_coherence/coherence-covered-type-parameter.rs25
-rw-r--r--src/test/run-pass/re_rebalance_coherence/coherence-impl-in-fn.rs25
-rw-r--r--src/test/run-pass/re_rebalance_coherence/coherence-iterator-vec-any-elem.rs25
-rw-r--r--src/test/run-pass/re_rebalance_coherence/coherence-iterator-vec.rs25
-rw-r--r--src/test/run-pass/re_rebalance_coherence/coherence-multidispatch-tuple.rs35
-rw-r--r--src/test/run-pass/re_rebalance_coherence/coherence-negative-impls-safe.rs24
-rw-r--r--src/test/run-pass/re_rebalance_coherence/coherence-rfc447-constrained.rs34
-rw-r--r--src/test/run-pass/re_rebalance_coherence/coherence-subtyping.rs51
-rw-r--r--src/test/run-pass/re_rebalance_coherence/coherence-where-clause.rs49
-rw-r--r--src/test/run-pass/re_rebalance_coherence/coherence_copy_like.rs31
-rw-r--r--src/test/run-pass/re_rebalance_coherence/re-rebalance-coherence.rs13
-rw-r--r--src/test/ui/feature-gates/auxiliary/re_rebalance_coherence_lib.rs23
-rw-r--r--src/test/ui/feature-gates/feature-gate-re-rebalance-coherence.rs13
-rw-r--r--src/test/ui/feature-gates/feature-gate-re-rebalance-coherence.stderr11
-rw-r--r--src/test/ui/re_rebalance_coherence/auxiliary/coherence_copy_like_lib.rs20
-rw-r--r--src/test/ui/re_rebalance_coherence/auxiliary/coherence_inherent_cc_lib.rs21
-rw-r--r--src/test/ui/re_rebalance_coherence/auxiliary/coherence_lib.rs25
-rw-r--r--src/test/ui/re_rebalance_coherence/auxiliary/coherence_orphan_lib.rs13
-rw-r--r--src/test/ui/re_rebalance_coherence/auxiliary/go_trait.rs53
-rw-r--r--src/test/ui/re_rebalance_coherence/auxiliary/trait_impl_conflict.rs16
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-all-remote.rs21
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-all-remote.stderr11
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-bigint-param.rs23
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-bigint-param.stderr11
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-implemented.rs40
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-implemented.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-unimplemented.rs36
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-unimplemented.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-cross-crate.rs31
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-cross-crate.stderr13
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-multidispatch.rs38
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-multidispatch.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-trait.rs40
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-trait.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific.rs35
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-conflicting-negative-trait-impl.rs29
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-conflicting-negative-trait-impl.stderr21
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-cow.a.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-cow.b.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-cow.c.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-cow.rs37
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-cross-crate-conflict.rs26
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-cross-crate-conflict.stderr21
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-default-trait-impl.rs26
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-default-trait-impl.stderr16
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-error-suppression.rs27
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-error-suppression.stderr9
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait-object-safe.rs21
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait-object-safe.stderr11
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait.rs29
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait.stderr21
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-impls-copy.rs54
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-impls-copy.stderr87
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-impls-send.rs41
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-impls-send.stderr37
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-impls-sized.rs47
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-impls-sized.stderr67
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-inherited-assoc-ty-cycle-err.rs35
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-inherited-assoc-ty-cycle-err.stderr16
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-lone-type-parameter.rs21
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-lone-type-parameter.stderr11
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-negative-impls-safe.rs21
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-negative-impls-safe.stderr9
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-no-direct-lifetime-dispatch.rs20
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-no-direct-lifetime-dispatch.stderr11
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-orphan.rs32
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-orphan.stderr21
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-all-t-and-tuple.rs31
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-all-t-and-tuple.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-downstream-inherent.rs29
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-downstream-inherent.stderr23
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-downstream.rs29
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-downstream.stderr21
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516-inherent.rs25
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516-inherent.stderr14
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516.rs23
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516.stderr13
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-messages.rs34
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-messages.stderr44
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-upstream-inherent.rs27
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-upstream-inherent.stderr14
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-upstream.rs27
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlap-upstream.stderr13
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlapping-pairs.rs23
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-overlapping-pairs.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered-1.rs25
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered-1.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered.rs23
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-projection-conflict-orphan.rs29
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-projection-conflict-orphan.stderr14
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-projection-conflict-ty-param.rs24
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-projection-conflict-ty-param.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-projection-conflict.rs29
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-projection-conflict.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-projection-ok-orphan.rs30
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-projection-ok.rs30
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-tuple-conflict.rs31
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-tuple-conflict.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-vec-local-2.rs25
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-vec-local-2.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-vec-local.rs25
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence-vec-local.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct.rs35
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_ref.rs35
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_tuple.rs32
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_tuple.stderr14
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_copy_like_err_struct.rs33
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_copy_like_err_struct.stderr14
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_copy_like_err_tuple.rs32
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_copy_like_err_tuple.stderr14
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_inherent.rs47
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_inherent.stderr13
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_inherent_cc.rs39
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_inherent_cc.stderr13
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_local.rs34
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_local_err_struct.rs29
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_local_err_struct.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_local_err_tuple.rs29
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_local_err_tuple.stderr12
-rw-r--r--src/test/ui/re_rebalance_coherence/coherence_local_ref.rs28
128 files changed, 3144 insertions, 0 deletions
diff --git a/src/test/run-pass/re_rebalance_coherence/auxiliary/coherence_copy_like_lib.rs b/src/test/run-pass/re_rebalance_coherence/auxiliary/coherence_copy_like_lib.rs
new file mode 100644
index 00000000000..d3d389c6a8b
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/auxiliary/coherence_copy_like_lib.rs
@@ -0,0 +1,20 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type = "rlib"]
+#![feature(fundamental)]
+
+pub trait MyCopy { }
+impl MyCopy for i32 { }
+
+pub struct MyStruct<T>(T);
+
+#[fundamental]
+pub struct MyFundamentalStruct<T>(T);
diff --git a/src/test/run-pass/re_rebalance_coherence/auxiliary/coherence_lib.rs b/src/test/run-pass/re_rebalance_coherence/auxiliary/coherence_lib.rs
new file mode 100644
index 00000000000..daa123849e4
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/auxiliary/coherence_lib.rs
@@ -0,0 +1,25 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type="lib"]
+
+pub trait Remote {
+    fn foo(&self) { }
+}
+
+pub trait Remote1<T> {
+    fn foo(&self, t: T) { }
+}
+
+pub trait Remote2<T, U> {
+    fn foo(&self, t: T, u: U) { }
+}
+
+pub struct Pair<T,U>(T,U);
diff --git a/src/test/run-pass/re_rebalance_coherence/auxiliary/re_rebalance_coherence_lib.rs b/src/test/run-pass/re_rebalance_coherence/auxiliary/re_rebalance_coherence_lib.rs
new file mode 100644
index 00000000000..c8d027b25c7
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/auxiliary/re_rebalance_coherence_lib.rs
@@ -0,0 +1,23 @@
+
+pub trait Backend{}
+pub trait SupportsDefaultKeyword {}
+
+impl SupportsDefaultKeyword for Postgres {}
+
+pub struct Postgres;
+
+impl Backend for Postgres {}
+
+pub struct AstPass<DB>(::std::marker::PhantomData<DB>);
+
+pub trait QueryFragment<DB: Backend> {}
+
+
+#[derive(Debug, Clone, Copy)]
+pub struct BatchInsert<'a, T: 'a, Tab> {
+    _marker: ::std::marker::PhantomData<(&'a T, Tab)>,
+}
+
+impl<'a, T:'a, Tab, DB> QueryFragment<DB> for BatchInsert<'a, T, Tab>
+where DB: SupportsDefaultKeyword + Backend,
+{}
diff --git a/src/test/run-pass/re_rebalance_coherence/coherence-bigint-int.rs b/src/test/run-pass/re_rebalance_coherence/coherence-bigint-int.rs
new file mode 100644
index 00000000000..c436901a34f
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/coherence-bigint-int.rs
@@ -0,0 +1,25 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// run-pass
+// aux-build:coherence_lib.rs
+
+// pretty-expanded FIXME #23616
+
+extern crate coherence_lib as lib;
+use lib::Remote1;
+
+pub struct BigInt;
+
+impl Remote1<BigInt> for isize { }
+
+fn main() { }
diff --git a/src/test/run-pass/re_rebalance_coherence/coherence-bigint-vecint.rs b/src/test/run-pass/re_rebalance_coherence/coherence-bigint-vecint.rs
new file mode 100644
index 00000000000..67fb9d1d335
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/coherence-bigint-vecint.rs
@@ -0,0 +1,25 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// run-pass
+// aux-build:coherence_lib.rs
+
+// pretty-expanded FIXME #23616
+
+extern crate coherence_lib as lib;
+use lib::Remote1;
+
+pub struct BigInt;
+
+impl Remote1<BigInt> for Vec<isize> { }
+
+fn main() { }
diff --git a/src/test/run-pass/re_rebalance_coherence/coherence-blanket.rs b/src/test/run-pass/re_rebalance_coherence/coherence-blanket.rs
new file mode 100644
index 00000000000..7f8f27f39b1
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/coherence-blanket.rs
@@ -0,0 +1,27 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-pass
+#![allow(unused_imports)]
+#![feature(re_rebalance_coherence)]
+// aux-build:coherence_lib.rs
+
+// pretty-expanded FIXME #23616
+
+extern crate coherence_lib as lib;
+use lib::Remote1;
+
+pub trait Local {
+    fn foo(&self) { }
+}
+
+impl<T> Local for T { }
+
+fn main() { }
diff --git a/src/test/run-pass/re_rebalance_coherence/coherence-covered-type-parameter.rs b/src/test/run-pass/re_rebalance_coherence/coherence-covered-type-parameter.rs
new file mode 100644
index 00000000000..5e0d61884f9
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/coherence-covered-type-parameter.rs
@@ -0,0 +1,25 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-pass
+#![allow(dead_code)]
+#![feature(re_rebalance_coherence)]
+// aux-build:coherence_lib.rs
+
+// pretty-expanded FIXME #23616
+
+extern crate coherence_lib as lib;
+use lib::Remote;
+
+struct Foo<T>(T);
+
+impl<T> Remote for Foo<T> { }
+
+fn main() { }
diff --git a/src/test/run-pass/re_rebalance_coherence/coherence-impl-in-fn.rs b/src/test/run-pass/re_rebalance_coherence/coherence-impl-in-fn.rs
new file mode 100644
index 00000000000..2f8cbc032f2
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/coherence-impl-in-fn.rs
@@ -0,0 +1,25 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-pass
+#![allow(dead_code)]
+#![allow(non_camel_case_types)]
+#![feature(re_rebalance_coherence)]
+
+pub fn main() {
+    #[derive(Copy, Clone)]
+    enum x { foo }
+    impl ::std::cmp::PartialEq for x {
+        fn eq(&self, other: &x) -> bool {
+            (*self) as isize == (*other) as isize
+        }
+        fn ne(&self, other: &x) -> bool { !(*self).eq(other) }
+    }
+}
diff --git a/src/test/run-pass/re_rebalance_coherence/coherence-iterator-vec-any-elem.rs b/src/test/run-pass/re_rebalance_coherence/coherence-iterator-vec-any-elem.rs
new file mode 100644
index 00000000000..b19bede7441
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/coherence-iterator-vec-any-elem.rs
@@ -0,0 +1,25 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-pass
+#![allow(dead_code)]
+#![feature(re_rebalance_coherence)]
+// aux-build:coherence_lib.rs
+
+// pretty-expanded FIXME #23616
+
+extern crate coherence_lib as lib;
+use lib::Remote1;
+
+struct Foo<T>(T);
+
+impl<T,U> Remote1<U> for Foo<T> { }
+
+fn main() { }
diff --git a/src/test/run-pass/re_rebalance_coherence/coherence-iterator-vec.rs b/src/test/run-pass/re_rebalance_coherence/coherence-iterator-vec.rs
new file mode 100644
index 00000000000..5ce71f5d422
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/coherence-iterator-vec.rs
@@ -0,0 +1,25 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-pass
+#![allow(dead_code)]
+#![feature(re_rebalance_coherence)]
+// aux-build:coherence_lib.rs
+
+// pretty-expanded FIXME #23616
+
+extern crate coherence_lib as lib;
+use lib::Remote1;
+
+struct Foo<T>(T);
+
+impl<T> Remote1<T> for Foo<T> { }
+
+fn main() { }
diff --git a/src/test/run-pass/re_rebalance_coherence/coherence-multidispatch-tuple.rs b/src/test/run-pass/re_rebalance_coherence/coherence-multidispatch-tuple.rs
new file mode 100644
index 00000000000..6dc1da3376b
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/coherence-multidispatch-tuple.rs
@@ -0,0 +1,35 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-pass
+#![allow(unused_imports)]
+#![feature(re_rebalance_coherence)]
+// pretty-expanded FIXME #23616
+
+use std::fmt::Debug;
+use std::default::Default;
+
+// Test that an impl for homogeneous pairs does not conflict with a
+// heterogeneous pair.
+
+trait MyTrait {
+    fn get(&self) -> usize;
+}
+
+impl<T> MyTrait for (T,T) {
+    fn get(&self) -> usize { 0 }
+}
+
+impl MyTrait for (usize,isize) {
+    fn get(&self) -> usize { 0 }
+}
+
+fn main() {
+}
diff --git a/src/test/run-pass/re_rebalance_coherence/coherence-negative-impls-safe.rs b/src/test/run-pass/re_rebalance_coherence/coherence-negative-impls-safe.rs
new file mode 100644
index 00000000000..5e1a0e39e23
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/coherence-negative-impls-safe.rs
@@ -0,0 +1,24 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-pass
+#![allow(dead_code)]
+// pretty-expanded FIXME #23616
+
+#![feature(optin_builtin_traits)]
+#![feature(re_rebalance_coherence)]
+
+use std::marker::Send;
+
+struct TestType;
+
+impl !Send for TestType {}
+
+fn main() {}
diff --git a/src/test/run-pass/re_rebalance_coherence/coherence-rfc447-constrained.rs b/src/test/run-pass/re_rebalance_coherence/coherence-rfc447-constrained.rs
new file mode 100644
index 00000000000..651e595bde1
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/coherence-rfc447-constrained.rs
@@ -0,0 +1,34 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// run-pass
+// check that trait matching can handle impls whose types are only
+// constrained by a projection.
+
+trait IsU32 {}
+impl IsU32 for u32 {}
+
+trait Mirror { type Image: ?Sized; }
+impl<T: ?Sized> Mirror for T { type Image = T; }
+
+trait Bar {}
+impl<U: Mirror, V: Mirror<Image=L>, L: Mirror<Image=U>> Bar for V
+    where U::Image: IsU32 {}
+
+trait Foo { fn name() -> &'static str; }
+impl Foo for u64 { fn name() -> &'static str { "u64" } }
+impl<T: Bar> Foo for T { fn name() -> &'static str { "Bar" }}
+
+fn main() {
+    assert_eq!(<u64 as Foo>::name(), "u64");
+    assert_eq!(<u32 as Foo>::name(), "Bar");
+}
diff --git a/src/test/run-pass/re_rebalance_coherence/coherence-subtyping.rs b/src/test/run-pass/re_rebalance_coherence/coherence-subtyping.rs
new file mode 100644
index 00000000000..d9a9f580cfa
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/coherence-subtyping.rs
@@ -0,0 +1,51 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// run-pass
+// Test that two distinct impls which match subtypes of one another
+// yield coherence errors (or not) depending on the variance.
+
+trait Contravariant {
+    fn foo(&self) { }
+}
+
+impl Contravariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
+}
+
+impl Contravariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
+}
+
+///////////////////////////////////////////////////////////////////////////
+
+trait Covariant {
+    fn foo(&self) { }
+}
+
+impl Covariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
+}
+
+impl Covariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
+}
+
+///////////////////////////////////////////////////////////////////////////
+
+trait Invariant {
+    fn foo(&self) { }
+}
+
+impl Invariant for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
+}
+
+impl Invariant for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
+}
+
+fn main() { }
diff --git a/src/test/run-pass/re_rebalance_coherence/coherence-where-clause.rs b/src/test/run-pass/re_rebalance_coherence/coherence-where-clause.rs
new file mode 100644
index 00000000000..a7d3602a3cc
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/coherence-where-clause.rs
@@ -0,0 +1,49 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// run-pass
+use std::fmt::Debug;
+use std::default::Default;
+
+trait MyTrait {
+    fn get(&self) -> Self;
+}
+
+impl<T> MyTrait for T
+    where T : Default
+{
+    fn get(&self) -> T {
+        Default::default()
+    }
+}
+
+#[derive(Clone, Copy, Debug, PartialEq)]
+struct MyType {
+    dummy: usize
+}
+
+impl MyTrait for MyType {
+    fn get(&self) -> MyType { (*self).clone() }
+}
+
+fn test_eq<M>(m: M, n: M)
+where M : MyTrait + Debug + PartialEq
+{
+    assert_eq!(m.get(), n);
+}
+
+pub fn main() {
+    test_eq(0_usize, 0_usize);
+
+    let value = MyType { dummy: 256 + 22 };
+    test_eq(value, value);
+}
diff --git a/src/test/run-pass/re_rebalance_coherence/coherence_copy_like.rs b/src/test/run-pass/re_rebalance_coherence/coherence_copy_like.rs
new file mode 100644
index 00000000000..221095b148e
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/coherence_copy_like.rs
@@ -0,0 +1,31 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// run-pass
+#![allow(dead_code)]
+#![feature(re_rebalance_coherence)]
+
+// Test that we are able to introduce a negative constraint that
+// `MyType: !MyTrait` along with other "fundamental" wrappers.
+
+// aux-build:coherence_copy_like_lib.rs
+
+extern crate coherence_copy_like_lib as lib;
+
+struct MyType { x: i32 }
+
+trait MyTrait { }
+impl<T: lib::MyCopy> MyTrait for T { }
+impl MyTrait for MyType { }
+impl<'a> MyTrait for &'a MyType { }
+impl MyTrait for Box<MyType> { }
+impl<'a> MyTrait for &'a Box<MyType> { }
+
+fn main() { }
diff --git a/src/test/run-pass/re_rebalance_coherence/re-rebalance-coherence.rs b/src/test/run-pass/re_rebalance_coherence/re-rebalance-coherence.rs
new file mode 100644
index 00000000000..33ad4e97536
--- /dev/null
+++ b/src/test/run-pass/re_rebalance_coherence/re-rebalance-coherence.rs
@@ -0,0 +1,13 @@
+#![feature(re_rebalance_coherence)]
+
+// run-pass
+// aux-build:re_rebalance_coherence_lib.rs
+
+extern crate re_rebalance_coherence_lib as lib;
+use lib::*;
+
+struct Oracle;
+impl Backend for Oracle {}
+impl<'a, T:'a, Tab> QueryFragment<Oracle> for BatchInsert<'a, T, Tab> {}
+
+fn main() {}
diff --git a/src/test/ui/feature-gates/auxiliary/re_rebalance_coherence_lib.rs b/src/test/ui/feature-gates/auxiliary/re_rebalance_coherence_lib.rs
new file mode 100644
index 00000000000..c8d027b25c7
--- /dev/null
+++ b/src/test/ui/feature-gates/auxiliary/re_rebalance_coherence_lib.rs
@@ -0,0 +1,23 @@
+
+pub trait Backend{}
+pub trait SupportsDefaultKeyword {}
+
+impl SupportsDefaultKeyword for Postgres {}
+
+pub struct Postgres;
+
+impl Backend for Postgres {}
+
+pub struct AstPass<DB>(::std::marker::PhantomData<DB>);
+
+pub trait QueryFragment<DB: Backend> {}
+
+
+#[derive(Debug, Clone, Copy)]
+pub struct BatchInsert<'a, T: 'a, Tab> {
+    _marker: ::std::marker::PhantomData<(&'a T, Tab)>,
+}
+
+impl<'a, T:'a, Tab, DB> QueryFragment<DB> for BatchInsert<'a, T, Tab>
+where DB: SupportsDefaultKeyword + Backend,
+{}
diff --git a/src/test/ui/feature-gates/feature-gate-re-rebalance-coherence.rs b/src/test/ui/feature-gates/feature-gate-re-rebalance-coherence.rs
new file mode 100644
index 00000000000..7031e6061ed
--- /dev/null
+++ b/src/test/ui/feature-gates/feature-gate-re-rebalance-coherence.rs
@@ -0,0 +1,13 @@
+// Test that the use of the box syntax is gated by `box_syntax` feature gate.
+
+// aux-build:re_rebalance_coherence_lib.rs
+
+extern crate re_rebalance_coherence_lib as lib;
+use lib::*;
+
+struct Oracle;
+impl Backend for Oracle {}
+impl<'a, T:'a, Tab> QueryFragment<Oracle> for BatchInsert<'a, T, Tab> {}
+// ~^ ERROR E0210
+
+fn main() {}
diff --git a/src/test/ui/feature-gates/feature-gate-re-rebalance-coherence.stderr b/src/test/ui/feature-gates/feature-gate-re-rebalance-coherence.stderr
new file mode 100644
index 00000000000..7a79d0b1f2a
--- /dev/null
+++ b/src/test/ui/feature-gates/feature-gate-re-rebalance-coherence.stderr
@@ -0,0 +1,11 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g. `MyStruct<T>`)
+  --> $DIR/feature-gate-re-rebalance-coherence.rs:10:1
+   |
+LL | impl<'a, T:'a, Tab> QueryFragment<Oracle> for BatchInsert<'a, T, Tab> {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/re_rebalance_coherence/auxiliary/coherence_copy_like_lib.rs b/src/test/ui/re_rebalance_coherence/auxiliary/coherence_copy_like_lib.rs
new file mode 100644
index 00000000000..d3d389c6a8b
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/auxiliary/coherence_copy_like_lib.rs
@@ -0,0 +1,20 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type = "rlib"]
+#![feature(fundamental)]
+
+pub trait MyCopy { }
+impl MyCopy for i32 { }
+
+pub struct MyStruct<T>(T);
+
+#[fundamental]
+pub struct MyFundamentalStruct<T>(T);
diff --git a/src/test/ui/re_rebalance_coherence/auxiliary/coherence_inherent_cc_lib.rs b/src/test/ui/re_rebalance_coherence/auxiliary/coherence_inherent_cc_lib.rs
new file mode 100644
index 00000000000..0458636a401
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/auxiliary/coherence_inherent_cc_lib.rs
@@ -0,0 +1,21 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// See coherence_inherent_cc.rs
+
+pub trait TheTrait {
+    fn the_fn(&self);
+}
+
+pub struct TheStruct;
+
+impl TheTrait for TheStruct {
+    fn the_fn(&self) {}
+}
diff --git a/src/test/ui/re_rebalance_coherence/auxiliary/coherence_lib.rs b/src/test/ui/re_rebalance_coherence/auxiliary/coherence_lib.rs
new file mode 100644
index 00000000000..daa123849e4
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/auxiliary/coherence_lib.rs
@@ -0,0 +1,25 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_type="lib"]
+
+pub trait Remote {
+    fn foo(&self) { }
+}
+
+pub trait Remote1<T> {
+    fn foo(&self, t: T) { }
+}
+
+pub trait Remote2<T, U> {
+    fn foo(&self, t: T, u: U) { }
+}
+
+pub struct Pair<T,U>(T,U);
diff --git a/src/test/ui/re_rebalance_coherence/auxiliary/coherence_orphan_lib.rs b/src/test/ui/re_rebalance_coherence/auxiliary/coherence_orphan_lib.rs
new file mode 100644
index 00000000000..b22d12300c7
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/auxiliary/coherence_orphan_lib.rs
@@ -0,0 +1,13 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub trait TheTrait<T> {
+    fn the_fn(&self);
+}
diff --git a/src/test/ui/re_rebalance_coherence/auxiliary/go_trait.rs b/src/test/ui/re_rebalance_coherence/auxiliary/go_trait.rs
new file mode 100644
index 00000000000..044bb606b40
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/auxiliary/go_trait.rs
@@ -0,0 +1,53 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(specialization)]
+
+// Common code used for tests that model the Fn/FnMut/FnOnce hierarchy.
+
+pub trait Go {
+    fn go(&self, arg: isize);
+}
+
+pub fn go<G:Go>(this: &G, arg: isize) {
+    this.go(arg)
+}
+
+pub trait GoMut {
+    fn go_mut(&mut self, arg: isize);
+}
+
+pub fn go_mut<G:GoMut>(this: &mut G, arg: isize) {
+    this.go_mut(arg)
+}
+
+pub trait GoOnce {
+    fn go_once(self, arg: isize);
+}
+
+pub fn go_once<G:GoOnce>(this: G, arg: isize) {
+    this.go_once(arg)
+}
+
+impl<G> GoMut for G
+    where G : Go
+{
+    default fn go_mut(&mut self, arg: isize) {
+        go(&*self, arg)
+    }
+}
+
+impl<G> GoOnce for G
+    where G : GoMut
+{
+    default fn go_once(mut self, arg: isize) {
+        go_mut(&mut self, arg)
+    }
+}
diff --git a/src/test/ui/re_rebalance_coherence/auxiliary/trait_impl_conflict.rs b/src/test/ui/re_rebalance_coherence/auxiliary/trait_impl_conflict.rs
new file mode 100644
index 00000000000..3190ce430ad
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/auxiliary/trait_impl_conflict.rs
@@ -0,0 +1,16 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub trait Foo {
+    fn foo() {}
+}
+
+impl Foo for isize {
+}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-all-remote.rs b/src/test/ui/re_rebalance_coherence/coherence-all-remote.rs
new file mode 100644
index 00000000000..0769518b36b
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-all-remote.rs
@@ -0,0 +1,21 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:coherence_lib.rs
+
+#![feature(re_rebalance_coherence)]
+
+extern crate coherence_lib as lib;
+use lib::Remote1;
+
+impl<T> Remote1<T> for isize { }
+//~^ ERROR E0210
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-all-remote.stderr b/src/test/ui/re_rebalance_coherence/coherence-all-remote.stderr
new file mode 100644
index 00000000000..a6d5105cdc0
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-all-remote.stderr
@@ -0,0 +1,11 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g. `MyStruct<T>`)
+  --> $DIR/coherence-all-remote.rs:18:1
+   |
+LL | impl<T> Remote1<T> for isize { }
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-bigint-param.rs b/src/test/ui/re_rebalance_coherence/coherence-bigint-param.rs
new file mode 100644
index 00000000000..712fe9bdb4c
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-bigint-param.rs
@@ -0,0 +1,23 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::Remote1;
+
+pub struct BigInt;
+
+impl<T> Remote1<BigInt> for T { }
+//~^ ERROR type parameter `T` must be used as the type parameter for some local type
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-bigint-param.stderr b/src/test/ui/re_rebalance_coherence/coherence-bigint-param.stderr
new file mode 100644
index 00000000000..ed1540a303e
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-bigint-param.stderr
@@ -0,0 +1,11 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g. `MyStruct<T>`)
+  --> $DIR/coherence-bigint-param.rs:20:1
+   |
+LL | impl<T> Remote1<BigInt> for T { }
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-implemented.rs b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-implemented.rs
new file mode 100644
index 00000000000..da0221c3e0a
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-implemented.rs
@@ -0,0 +1,40 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+use std::fmt::Debug;
+use std::default::Default;
+
+// Test that two blanket impls conflict (at least without negative
+// bounds).  After all, some other crate could implement Even or Odd
+// for the same type (though this crate doesn't).
+
+trait MyTrait {
+    fn get(&self) -> usize;
+}
+
+trait Even { }
+
+trait Odd { }
+
+impl Even for isize { }
+
+impl Odd for usize { }
+
+impl<T:Even> MyTrait for T {
+    fn get(&self) -> usize { 0 }
+}
+
+impl<T:Odd> MyTrait for T { //~ ERROR E0119
+    fn get(&self) -> usize { 0 }
+}
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-implemented.stderr b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-implemented.stderr
new file mode 100644
index 00000000000..8d5d4787780
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-implemented.stderr
@@ -0,0 +1,12 @@
+error[E0119]: conflicting implementations of trait `MyTrait`:
+  --> $DIR/coherence-blanket-conflicts-with-blanket-implemented.rs:36:1
+   |
+LL | impl<T:Even> MyTrait for T {
+   | -------------------------- first implementation here
+...
+LL | impl<T:Odd> MyTrait for T { //~ ERROR E0119
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-unimplemented.rs b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-unimplemented.rs
new file mode 100644
index 00000000000..5e407588e2a
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-unimplemented.rs
@@ -0,0 +1,36 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+use std::fmt::Debug;
+use std::default::Default;
+
+// Test that two blanket impls conflict (at least without negative
+// bounds).  After all, some other crate could implement Even or Odd
+// for the same type (though this crate doesn't implement them at all).
+
+trait MyTrait {
+    fn get(&self) -> usize;
+}
+
+trait Even {}
+
+trait Odd {}
+
+impl<T:Even> MyTrait for T {
+    fn get(&self) -> usize { 0 }
+}
+
+impl<T:Odd> MyTrait for T { //~ ERROR E0119
+    fn get(&self) -> usize { 0 }
+}
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-unimplemented.stderr b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-unimplemented.stderr
new file mode 100644
index 00000000000..6e7df5e6ed3
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-unimplemented.stderr
@@ -0,0 +1,12 @@
+error[E0119]: conflicting implementations of trait `MyTrait`:
+  --> $DIR/coherence-blanket-conflicts-with-blanket-unimplemented.rs:32:1
+   |
+LL | impl<T:Even> MyTrait for T {
+   | -------------------------- first implementation here
+...
+LL | impl<T:Odd> MyTrait for T { //~ ERROR E0119
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-cross-crate.rs b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-cross-crate.rs
new file mode 100644
index 00000000000..9d1caf92922
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-cross-crate.rs
@@ -0,0 +1,31 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// aux-build:go_trait.rs
+
+extern crate go_trait;
+
+use go_trait::{Go,GoMut};
+use std::fmt::Debug;
+use std::default::Default;
+
+struct MyThingy;
+
+impl Go for MyThingy {
+    fn go(&self, arg: isize) { }
+}
+
+impl GoMut for MyThingy { //~ ERROR conflicting implementations
+    fn go_mut(&mut self, arg: isize) { }
+}
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-cross-crate.stderr b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-cross-crate.stderr
new file mode 100644
index 00000000000..30656fa41b4
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-cross-crate.stderr
@@ -0,0 +1,13 @@
+error[E0119]: conflicting implementations of trait `go_trait::GoMut` for type `MyThingy`:
+  --> $DIR/coherence-blanket-conflicts-with-specific-cross-crate.rs:27:1
+   |
+LL | impl GoMut for MyThingy { //~ ERROR conflicting implementations
+   | ^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: conflicting implementation in crate `go_trait`:
+           - impl<G> go_trait::GoMut for G
+             where G: go_trait::Go;
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-multidispatch.rs b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-multidispatch.rs
new file mode 100644
index 00000000000..f866465bd08
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-multidispatch.rs
@@ -0,0 +1,38 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+use std::fmt::Debug;
+use std::default::Default;
+
+// Test that a blank impl for all T conflicts with an impl for some
+// specific T, even when there are multiple type parameters involved.
+
+trait MyTrait<T> {
+    fn get(&self) -> T;
+}
+
+impl<T> MyTrait<T> for T {
+    fn get(&self) -> T {
+        panic!()
+    }
+}
+
+#[derive(Clone)]
+struct MyType {
+    dummy: usize
+}
+
+impl MyTrait<MyType> for MyType { //~ ERROR E0119
+    fn get(&self) -> usize { (*self).clone() }
+}
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-multidispatch.stderr b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-multidispatch.stderr
new file mode 100644
index 00000000000..f68e1fd94f0
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-multidispatch.stderr
@@ -0,0 +1,12 @@
+error[E0119]: conflicting implementations of trait `MyTrait<MyType>` for type `MyType`:
+  --> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:34:1
+   |
+LL | impl<T> MyTrait<T> for T {
+   | ------------------------ first implementation here
+...
+LL | impl MyTrait<MyType> for MyType { //~ ERROR E0119
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyType`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-trait.rs b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-trait.rs
new file mode 100644
index 00000000000..74b458b838e
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-trait.rs
@@ -0,0 +1,40 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Test that a blank impl for all T:PartialEq conflicts with an impl for some
+// specific T when T:PartialEq.
+
+trait OtherTrait {
+    fn noop(&self);
+}
+
+trait MyTrait {
+    fn get(&self) -> usize;
+}
+
+impl<T:OtherTrait> MyTrait for T {
+    fn get(&self) -> usize { 0 }
+}
+
+struct MyType {
+    dummy: usize
+}
+
+impl MyTrait for MyType { //~ ERROR E0119
+    fn get(&self) -> usize { self.dummy }
+}
+
+impl OtherTrait for MyType {
+    fn noop(&self) { }
+}
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-trait.stderr b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-trait.stderr
new file mode 100644
index 00000000000..bafeadcfcbe
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-trait.stderr
@@ -0,0 +1,12 @@
+error[E0119]: conflicting implementations of trait `MyTrait` for type `MyType`:
+  --> $DIR/coherence-blanket-conflicts-with-specific-trait.rs:32:1
+   |
+LL | impl<T:OtherTrait> MyTrait for T {
+   | -------------------------------- first implementation here
+...
+LL | impl MyTrait for MyType { //~ ERROR E0119
+   | ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyType`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific.rs b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific.rs
new file mode 100644
index 00000000000..51de0e33034
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific.rs
@@ -0,0 +1,35 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+use std::fmt::Debug;
+use std::default::Default;
+
+// Test that a blank impl for all T conflicts with an impl for some
+// specific T.
+
+trait MyTrait {
+    fn get(&self) -> usize;
+}
+
+impl<T> MyTrait for T {
+    fn get(&self) -> usize { 0 }
+}
+
+struct MyType {
+    dummy: usize
+}
+
+impl MyTrait for MyType { //~ ERROR E0119
+    fn get(&self) -> usize { self.dummy }
+}
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific.stderr b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific.stderr
new file mode 100644
index 00000000000..efc32d12364
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific.stderr
@@ -0,0 +1,12 @@
+error[E0119]: conflicting implementations of trait `MyTrait` for type `MyType`:
+  --> $DIR/coherence-blanket-conflicts-with-specific.rs:31:1
+   |
+LL | impl<T> MyTrait for T {
+   | --------------------- first implementation here
+...
+LL | impl MyTrait for MyType { //~ ERROR E0119
+   | ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyType`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-conflicting-negative-trait-impl.rs b/src/test/ui/re_rebalance_coherence/coherence-conflicting-negative-trait-impl.rs
new file mode 100644
index 00000000000..c2db97c68e8
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-conflicting-negative-trait-impl.rs
@@ -0,0 +1,29 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(optin_builtin_traits)]
+#![feature(overlapping_marker_traits)]
+#![feature(re_rebalance_coherence)]
+
+trait MyTrait {}
+
+struct TestType<T>(::std::marker::PhantomData<T>);
+
+unsafe impl<T: MyTrait+'static> Send for TestType<T> {}
+
+impl<T: MyTrait> !Send for TestType<T> {}
+//~^ ERROR conflicting implementations of trait `std::marker::Send`
+
+unsafe impl<T:'static> Send for TestType<T> {}
+
+impl !Send for TestType<i32> {}
+//~^ ERROR conflicting implementations of trait `std::marker::Send`
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-conflicting-negative-trait-impl.stderr b/src/test/ui/re_rebalance_coherence/coherence-conflicting-negative-trait-impl.stderr
new file mode 100644
index 00000000000..7555e9996cf
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-conflicting-negative-trait-impl.stderr
@@ -0,0 +1,21 @@
+error[E0119]: conflicting implementations of trait `std::marker::Send` for type `TestType<_>`:
+  --> $DIR/coherence-conflicting-negative-trait-impl.rs:21:1
+   |
+LL | unsafe impl<T: MyTrait+'static> Send for TestType<T> {}
+   | ---------------------------------------------------- first implementation here
+LL | 
+LL | impl<T: MyTrait> !Send for TestType<T> {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>`
+
+error[E0119]: conflicting implementations of trait `std::marker::Send` for type `TestType<i32>`:
+  --> $DIR/coherence-conflicting-negative-trait-impl.rs:26:1
+   |
+LL | unsafe impl<T:'static> Send for TestType<T> {}
+   | ------------------------------------------- first implementation here
+LL | 
+LL | impl !Send for TestType<i32> {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<i32>`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-cow.a.stderr b/src/test/ui/re_rebalance_coherence/coherence-cow.a.stderr
new file mode 100644
index 00000000000..09cc9801c14
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-cow.a.stderr
@@ -0,0 +1,12 @@
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-cow.rs:28:1
+   |
+LL | impl<T> Remote for Pair<T,Cover<T>> { } //[a]~ ERROR E0117
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0117`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-cow.b.stderr b/src/test/ui/re_rebalance_coherence/coherence-cow.b.stderr
new file mode 100644
index 00000000000..7bb8378ee4b
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-cow.b.stderr
@@ -0,0 +1,12 @@
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-cow.rs:31:1
+   |
+LL | impl<T> Remote for Pair<Cover<T>,T> { } //[b]~ ERROR E0117
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0117`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-cow.c.stderr b/src/test/ui/re_rebalance_coherence/coherence-cow.c.stderr
new file mode 100644
index 00000000000..6dbf0a44f02
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-cow.c.stderr
@@ -0,0 +1,12 @@
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-cow.rs:34:1
+   |
+LL | impl<T,U> Remote for Pair<Cover<T>,U> { }
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0117`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-cow.rs b/src/test/ui/re_rebalance_coherence/coherence-cow.rs
new file mode 100644
index 00000000000..da69d56a25a
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-cow.rs
@@ -0,0 +1,37 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// revisions: a b c
+
+// aux-build:coherence_lib.rs
+
+// Test that the `Pair` type reports an error if it contains type
+// parameters, even when they are covered by local types. This test
+// was originally intended to test the opposite, but the rules changed
+// with RFC 1023 and this became illegal.
+
+extern crate coherence_lib as lib;
+use lib::{Remote,Pair};
+
+pub struct Cover<T>(T);
+
+#[cfg(a)]
+impl<T> Remote for Pair<T,Cover<T>> { } //[a]~ ERROR E0117
+
+#[cfg(b)]
+impl<T> Remote for Pair<Cover<T>,T> { } //[b]~ ERROR E0117
+
+#[cfg(c)]
+impl<T,U> Remote for Pair<Cover<T>,U> { }
+//[c]~^ ERROR E0117
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-cross-crate-conflict.rs b/src/test/ui/re_rebalance_coherence/coherence-cross-crate-conflict.rs
new file mode 100644
index 00000000000..02624c70dc9
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-cross-crate-conflict.rs
@@ -0,0 +1,26 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// The error here is strictly due to orphan rules; the impl here
+// generalizes the one upstream
+
+// aux-build:trait_impl_conflict.rs
+extern crate trait_impl_conflict;
+use trait_impl_conflict::Foo;
+
+impl<A> Foo for A {
+    //~^ ERROR type parameter `A` must be used as the type parameter for some local type
+    //~| ERROR conflicting implementations of trait `trait_impl_conflict::Foo` for type `isize`
+}
+
+fn main() {
+}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-cross-crate-conflict.stderr b/src/test/ui/re_rebalance_coherence/coherence-cross-crate-conflict.stderr
new file mode 100644
index 00000000000..e4f8ba9868e
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-cross-crate-conflict.stderr
@@ -0,0 +1,21 @@
+error[E0119]: conflicting implementations of trait `trait_impl_conflict::Foo` for type `isize`:
+  --> $DIR/coherence-cross-crate-conflict.rs:20:1
+   |
+LL | impl<A> Foo for A {
+   | ^^^^^^^^^^^^^^^^^
+   |
+   = note: conflicting implementation in crate `trait_impl_conflict`:
+           - impl trait_impl_conflict::Foo for isize;
+
+error[E0210]: type parameter `A` must be used as the type parameter for some local type (e.g. `MyStruct<A>`)
+  --> $DIR/coherence-cross-crate-conflict.rs:20:1
+   |
+LL | impl<A> Foo for A {
+   | ^^^^^^^^^^^^^^^^^ type parameter `A` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to 2 previous errors
+
+Some errors occurred: E0119, E0210.
+For more information about an error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-default-trait-impl.rs b/src/test/ui/re_rebalance_coherence/coherence-default-trait-impl.rs
new file mode 100644
index 00000000000..86dd0e4f74f
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-default-trait-impl.rs
@@ -0,0 +1,26 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(optin_builtin_traits)]
+#![feature(re_rebalance_coherence)]
+
+auto trait MySafeTrait {}
+
+struct Foo;
+
+unsafe impl MySafeTrait for Foo {}
+//~^ ERROR implementing the trait `MySafeTrait` is not unsafe
+
+unsafe auto trait MyUnsafeTrait {}
+
+impl MyUnsafeTrait for Foo {}
+//~^ ERROR the trait `MyUnsafeTrait` requires an `unsafe impl` declaration
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-default-trait-impl.stderr b/src/test/ui/re_rebalance_coherence/coherence-default-trait-impl.stderr
new file mode 100644
index 00000000000..6c3d79cf53c
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-default-trait-impl.stderr
@@ -0,0 +1,16 @@
+error[E0199]: implementing the trait `MySafeTrait` is not unsafe
+  --> $DIR/coherence-default-trait-impl.rs:18:1
+   |
+LL | unsafe impl MySafeTrait for Foo {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0200]: the trait `MyUnsafeTrait` requires an `unsafe impl` declaration
+  --> $DIR/coherence-default-trait-impl.rs:23:1
+   |
+LL | impl MyUnsafeTrait for Foo {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+Some errors occurred: E0199, E0200.
+For more information about an error, try `rustc --explain E0199`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-error-suppression.rs b/src/test/ui/re_rebalance_coherence/coherence-error-suppression.rs
new file mode 100644
index 00000000000..24df1a1ee01
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-error-suppression.rs
@@ -0,0 +1,27 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// check that error types in coherence do not cause error cascades.
+
+trait Foo {}
+
+impl Foo for i8 {}
+impl Foo for i16 {}
+impl Foo for i32 {}
+impl Foo for i64 {}
+impl Foo for DoesNotExist {} //~ ERROR cannot find type `DoesNotExist` in this scope
+impl Foo for u8 {}
+impl Foo for u16 {}
+impl Foo for u32 {}
+impl Foo for u64 {}
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-error-suppression.stderr b/src/test/ui/re_rebalance_coherence/coherence-error-suppression.stderr
new file mode 100644
index 00000000000..97ed46c71bd
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-error-suppression.stderr
@@ -0,0 +1,9 @@
+error[E0412]: cannot find type `DoesNotExist` in this scope
+  --> $DIR/coherence-error-suppression.rs:21:14
+   |
+LL | impl Foo for DoesNotExist {} //~ ERROR cannot find type `DoesNotExist` in this scope
+   |              ^^^^^^^^^^^^ not found in this scope
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0412`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait-object-safe.rs b/src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait-object-safe.rs
new file mode 100644
index 00000000000..9e9a00af903
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait-object-safe.rs
@@ -0,0 +1,21 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Test that we give suitable error messages when the user attempts to
+// impl a trait `Trait` for its own object type.
+
+// If the trait is not object-safe, we give a more tailored message
+// because we're such schnuckels:
+trait NotObjectSafe { fn eq(&self, other: Self); }
+impl NotObjectSafe for NotObjectSafe { } //~ ERROR E0038
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait-object-safe.stderr b/src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait-object-safe.stderr
new file mode 100644
index 00000000000..0f4f33e4eb9
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait-object-safe.stderr
@@ -0,0 +1,11 @@
+error[E0038]: the trait `NotObjectSafe` cannot be made into an object
+  --> $DIR/coherence-impl-trait-for-trait-object-safe.rs:19:6
+   |
+LL | impl NotObjectSafe for NotObjectSafe { } //~ ERROR E0038
+   |      ^^^^^^^^^^^^^ the trait `NotObjectSafe` cannot be made into an object
+   |
+   = note: method `eq` references the `Self` type in its arguments or return type
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0038`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait.rs b/src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait.rs
new file mode 100644
index 00000000000..0ed88058f1f
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait.rs
@@ -0,0 +1,29 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Test that we give suitable error messages when the user attempts to
+// impl a trait `Trait` for its own object type.
+
+trait Foo { fn dummy(&self) { } }
+trait Bar: Foo { }
+trait Baz: Bar { }
+
+// Supertraits of Baz are not legal:
+impl Foo for Baz { }   //~ ERROR E0371
+impl Bar for Baz { }   //~ ERROR E0371
+impl Baz for Baz { }   //~ ERROR E0371
+
+// But other random traits are:
+trait Other { }
+impl Other for Baz { } // OK, Other not a supertrait of Baz
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait.stderr b/src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait.stderr
new file mode 100644
index 00000000000..d529e86f8fc
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait.stderr
@@ -0,0 +1,21 @@
+error[E0371]: the object type `(dyn Baz + 'static)` automatically implements the trait `Foo`
+  --> $DIR/coherence-impl-trait-for-trait.rs:21:1
+   |
+LL | impl Foo for Baz { }   //~ ERROR E0371
+   | ^^^^^^^^^^^^^^^^ `(dyn Baz + 'static)` automatically implements trait `Foo`
+
+error[E0371]: the object type `(dyn Baz + 'static)` automatically implements the trait `Bar`
+  --> $DIR/coherence-impl-trait-for-trait.rs:22:1
+   |
+LL | impl Bar for Baz { }   //~ ERROR E0371
+   | ^^^^^^^^^^^^^^^^ `(dyn Baz + 'static)` automatically implements trait `Bar`
+
+error[E0371]: the object type `(dyn Baz + 'static)` automatically implements the trait `Baz`
+  --> $DIR/coherence-impl-trait-for-trait.rs:23:1
+   |
+LL | impl Baz for Baz { }   //~ ERROR E0371
+   | ^^^^^^^^^^^^^^^^ `(dyn Baz + 'static)` automatically implements trait `Baz`
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0371`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-impls-copy.rs b/src/test/ui/re_rebalance_coherence/coherence-impls-copy.rs
new file mode 100644
index 00000000000..9f58d13efc2
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-impls-copy.rs
@@ -0,0 +1,54 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(optin_builtin_traits)]
+#![feature(re_rebalance_coherence)]
+
+use std::marker::Copy;
+
+impl Copy for i32 {}
+//~^ ERROR conflicting implementations of trait `std::marker::Copy` for type `i32`:
+//~| ERROR only traits defined in the current crate can be implemented for arbitrary types
+
+enum TestE {
+  A
+}
+
+struct MyType;
+
+struct NotSync;
+impl !Sync for NotSync {}
+
+impl Copy for TestE {}
+impl Clone for TestE { fn clone(&self) -> Self { *self } }
+
+impl Copy for MyType {}
+
+impl Copy for &'static mut MyType {}
+//~^ ERROR the trait `Copy` may not be implemented for this type
+impl Clone for MyType { fn clone(&self) -> Self { *self } }
+
+impl Copy for (MyType, MyType) {}
+//~^ ERROR the trait `Copy` may not be implemented for this type
+//~| ERROR only traits defined in the current crate can be implemented for arbitrary types
+
+impl Copy for &'static NotSync {}
+//~^ ERROR conflicting implementations of trait `std::marker::Copy` for type `&NotSync`:
+
+impl Copy for [MyType] {}
+//~^ ERROR the trait `Copy` may not be implemented for this type
+//~| ERROR only traits defined in the current crate can be implemented for arbitrary types
+
+impl Copy for &'static [NotSync] {}
+//~^ ERROR conflicting implementations of trait `std::marker::Copy` for type `&[NotSync]`:
+//~| ERROR only traits defined in the current crate can be implemented for arbitrary types
+
+fn main() {
+}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-impls-copy.stderr b/src/test/ui/re_rebalance_coherence/coherence-impls-copy.stderr
new file mode 100644
index 00000000000..80e2d203aaa
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-impls-copy.stderr
@@ -0,0 +1,87 @@
+error[E0119]: conflicting implementations of trait `std::marker::Copy` for type `i32`:
+  --> $DIR/coherence-impls-copy.rs:16:1
+   |
+LL | impl Copy for i32 {}
+   | ^^^^^^^^^^^^^^^^^
+   |
+   = note: conflicting implementation in crate `core`:
+           - impl std::marker::Copy for i32;
+
+error[E0119]: conflicting implementations of trait `std::marker::Copy` for type `&NotSync`:
+  --> $DIR/coherence-impls-copy.rs:42:1
+   |
+LL | impl Copy for &'static NotSync {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: conflicting implementation in crate `core`:
+           - impl<T> std::marker::Copy for &T
+             where T: ?Sized;
+
+error[E0119]: conflicting implementations of trait `std::marker::Copy` for type `&[NotSync]`:
+  --> $DIR/coherence-impls-copy.rs:49:1
+   |
+LL | impl Copy for &'static [NotSync] {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: conflicting implementation in crate `core`:
+           - impl<T> std::marker::Copy for &T
+             where T: ?Sized;
+
+error[E0206]: the trait `Copy` may not be implemented for this type
+  --> $DIR/coherence-impls-copy.rs:34:15
+   |
+LL | impl Copy for &'static mut MyType {}
+   |               ^^^^^^^^^^^^^^^^^^^ type is not a structure or enumeration
+
+error[E0206]: the trait `Copy` may not be implemented for this type
+  --> $DIR/coherence-impls-copy.rs:38:15
+   |
+LL | impl Copy for (MyType, MyType) {}
+   |               ^^^^^^^^^^^^^^^^ type is not a structure or enumeration
+
+error[E0206]: the trait `Copy` may not be implemented for this type
+  --> $DIR/coherence-impls-copy.rs:45:15
+   |
+LL | impl Copy for [MyType] {}
+   |               ^^^^^^^^ type is not a structure or enumeration
+
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-impls-copy.rs:16:1
+   |
+LL | impl Copy for i32 {}
+   | ^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-impls-copy.rs:38:1
+   |
+LL | impl Copy for (MyType, MyType) {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-impls-copy.rs:45:1
+   |
+LL | impl Copy for [MyType] {}
+   | ^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-impls-copy.rs:49:1
+   |
+LL | impl Copy for &'static [NotSync] {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to 10 previous errors
+
+Some errors occurred: E0117, E0119, E0206.
+For more information about an error, try `rustc --explain E0117`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-impls-send.rs b/src/test/ui/re_rebalance_coherence/coherence-impls-send.rs
new file mode 100644
index 00000000000..11b92d5254c
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-impls-send.rs
@@ -0,0 +1,41 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(optin_builtin_traits)]
+#![feature(overlapping_marker_traits)]
+#![feature(re_rebalance_coherence)]
+
+use std::marker::Copy;
+
+enum TestE {
+  A
+}
+
+struct MyType;
+
+struct NotSync;
+impl !Sync for NotSync {}
+
+unsafe impl Send for TestE {}
+unsafe impl Send for MyType {}
+unsafe impl Send for (MyType, MyType) {}
+//~^ ERROR E0117
+
+unsafe impl Send for &'static NotSync {}
+//~^ ERROR E0321
+
+unsafe impl Send for [MyType] {}
+//~^ ERROR E0117
+
+unsafe impl Send for &'static [NotSync] {}
+//~^ ERROR E0117
+
+fn main() {
+}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-impls-send.stderr b/src/test/ui/re_rebalance_coherence/coherence-impls-send.stderr
new file mode 100644
index 00000000000..8f09deeeb93
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-impls-send.stderr
@@ -0,0 +1,37 @@
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-impls-send.rs:28:1
+   |
+LL | unsafe impl Send for (MyType, MyType) {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error[E0321]: cross-crate traits with a default impl, like `std::marker::Send`, can only be implemented for a struct/enum type, not `&'static NotSync`
+  --> $DIR/coherence-impls-send.rs:31:1
+   |
+LL | unsafe impl Send for &'static NotSync {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type
+
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-impls-send.rs:34:1
+   |
+LL | unsafe impl Send for [MyType] {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-impls-send.rs:37:1
+   |
+LL | unsafe impl Send for &'static [NotSync] {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to 4 previous errors
+
+Some errors occurred: E0117, E0321.
+For more information about an error, try `rustc --explain E0117`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-impls-sized.rs b/src/test/ui/re_rebalance_coherence/coherence-impls-sized.rs
new file mode 100644
index 00000000000..3f7970f34fc
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-impls-sized.rs
@@ -0,0 +1,47 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(optin_builtin_traits)]
+#![feature(re_rebalance_coherence)]
+
+use std::marker::Copy;
+
+enum TestE {
+  A
+}
+
+struct MyType;
+
+struct NotSync;
+impl !Sync for NotSync {}
+
+impl Sized for TestE {} //~ ERROR E0322
+//~^ impl of 'Sized' not allowed
+
+impl Sized for MyType {} //~ ERROR E0322
+//~^ impl of 'Sized' not allowed
+
+impl Sized for (MyType, MyType) {} //~ ERROR E0322
+//~^ impl of 'Sized' not allowed
+//~| ERROR E0117
+
+impl Sized for &'static NotSync {} //~ ERROR E0322
+//~^ impl of 'Sized' not allowed
+
+impl Sized for [MyType] {} //~ ERROR E0322
+//~^ impl of 'Sized' not allowed
+//~| ERROR E0117
+
+impl Sized for &'static [NotSync] {} //~ ERROR E0322
+//~^ impl of 'Sized' not allowed
+//~| ERROR E0117
+
+fn main() {
+}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-impls-sized.stderr b/src/test/ui/re_rebalance_coherence/coherence-impls-sized.stderr
new file mode 100644
index 00000000000..92b165bdc3b
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-impls-sized.stderr
@@ -0,0 +1,67 @@
+error[E0322]: explicit impls for the `Sized` trait are not permitted
+  --> $DIR/coherence-impls-sized.rs:25:1
+   |
+LL | impl Sized for TestE {} //~ ERROR E0322
+   | ^^^^^^^^^^^^^^^^^^^^ impl of 'Sized' not allowed
+
+error[E0322]: explicit impls for the `Sized` trait are not permitted
+  --> $DIR/coherence-impls-sized.rs:28:1
+   |
+LL | impl Sized for MyType {} //~ ERROR E0322
+   | ^^^^^^^^^^^^^^^^^^^^^ impl of 'Sized' not allowed
+
+error[E0322]: explicit impls for the `Sized` trait are not permitted
+  --> $DIR/coherence-impls-sized.rs:31:1
+   |
+LL | impl Sized for (MyType, MyType) {} //~ ERROR E0322
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of 'Sized' not allowed
+
+error[E0322]: explicit impls for the `Sized` trait are not permitted
+  --> $DIR/coherence-impls-sized.rs:35:1
+   |
+LL | impl Sized for &'static NotSync {} //~ ERROR E0322
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of 'Sized' not allowed
+
+error[E0322]: explicit impls for the `Sized` trait are not permitted
+  --> $DIR/coherence-impls-sized.rs:38:1
+   |
+LL | impl Sized for [MyType] {} //~ ERROR E0322
+   | ^^^^^^^^^^^^^^^^^^^^^^^ impl of 'Sized' not allowed
+
+error[E0322]: explicit impls for the `Sized` trait are not permitted
+  --> $DIR/coherence-impls-sized.rs:42:1
+   |
+LL | impl Sized for &'static [NotSync] {} //~ ERROR E0322
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of 'Sized' not allowed
+
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-impls-sized.rs:31:1
+   |
+LL | impl Sized for (MyType, MyType) {} //~ ERROR E0322
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-impls-sized.rs:38:1
+   |
+LL | impl Sized for [MyType] {} //~ ERROR E0322
+   | ^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-impls-sized.rs:42:1
+   |
+LL | impl Sized for &'static [NotSync] {} //~ ERROR E0322
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to 9 previous errors
+
+Some errors occurred: E0117, E0322.
+For more information about an error, try `rustc --explain E0117`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-inherited-assoc-ty-cycle-err.rs b/src/test/ui/re_rebalance_coherence/coherence-inherited-assoc-ty-cycle-err.rs
new file mode 100644
index 00000000000..a2cfb11fdc2
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-inherited-assoc-ty-cycle-err.rs
@@ -0,0 +1,35 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Formerly this ICEd with the following message:
+// Tried to project an inherited associated type during coherence checking,
+// which is currently not supported.
+//
+// No we expect to run into a more user-friendly cycle error instead.
+
+#![feature(specialization)]
+#![feature(re_rebalance_coherence)]
+
+trait Trait<T> { type Assoc; }
+//~^ cycle detected
+
+impl<T> Trait<T> for Vec<T> {
+    type Assoc = ();
+}
+
+impl Trait<u8> for Vec<u8> {}
+
+impl<T> Trait<T> for String {
+    type Assoc = ();
+}
+
+impl Trait<<Vec<u8> as Trait<u8>>::Assoc> for String {}
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-inherited-assoc-ty-cycle-err.stderr b/src/test/ui/re_rebalance_coherence/coherence-inherited-assoc-ty-cycle-err.stderr
new file mode 100644
index 00000000000..aca2d64b623
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-inherited-assoc-ty-cycle-err.stderr
@@ -0,0 +1,16 @@
+error[E0391]: cycle detected when processing `Trait`
+  --> $DIR/coherence-inherited-assoc-ty-cycle-err.rs:20:1
+   |
+LL | trait Trait<T> { type Assoc; }
+   | ^^^^^^^^^^^^^^
+   |
+   = note: ...which again requires processing `Trait`, completing the cycle
+note: cycle used when coherence checking all impls of trait `Trait`
+  --> $DIR/coherence-inherited-assoc-ty-cycle-err.rs:20:1
+   |
+LL | trait Trait<T> { type Assoc; }
+   | ^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0391`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-lone-type-parameter.rs b/src/test/ui/re_rebalance_coherence/coherence-lone-type-parameter.rs
new file mode 100644
index 00000000000..8d3551beb5f
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-lone-type-parameter.rs
@@ -0,0 +1,21 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::Remote;
+
+impl<T> Remote for T { }
+//~^ ERROR type parameter `T` must be used as the type parameter for some local type
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-lone-type-parameter.stderr b/src/test/ui/re_rebalance_coherence/coherence-lone-type-parameter.stderr
new file mode 100644
index 00000000000..60ec7fb67de
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-lone-type-parameter.stderr
@@ -0,0 +1,11 @@
+error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g. `MyStruct<T>`)
+  --> $DIR/coherence-lone-type-parameter.rs:18:1
+   |
+LL | impl<T> Remote for T { }
+   | ^^^^^^^^^^^^^^^^^^^^ type parameter `T` must be used as the type parameter for some local type
+   |
+   = note: only traits defined in the current crate can be implemented for a type parameter
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0210`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-negative-impls-safe.rs b/src/test/ui/re_rebalance_coherence/coherence-negative-impls-safe.rs
new file mode 100644
index 00000000000..40f7ebfd250
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-negative-impls-safe.rs
@@ -0,0 +1,21 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(optin_builtin_traits)]
+#![feature(re_rebalance_coherence)]
+
+use std::marker::Send;
+
+struct TestType;
+
+unsafe impl !Send for TestType {}
+//~^ ERROR negative impls cannot be unsafe
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-negative-impls-safe.stderr b/src/test/ui/re_rebalance_coherence/coherence-negative-impls-safe.stderr
new file mode 100644
index 00000000000..70a879efa27
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-negative-impls-safe.stderr
@@ -0,0 +1,9 @@
+error[E0198]: negative impls cannot be unsafe
+  --> $DIR/coherence-negative-impls-safe.rs:18:1
+   |
+LL | unsafe impl !Send for TestType {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0198`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-no-direct-lifetime-dispatch.rs b/src/test/ui/re_rebalance_coherence/coherence-no-direct-lifetime-dispatch.rs
new file mode 100644
index 00000000000..838bc71d3af
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-no-direct-lifetime-dispatch.rs
@@ -0,0 +1,20 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Test that you cannot *directly* dispatch on lifetime requirements
+
+trait MyTrait { fn foo() {} }
+
+impl<T> MyTrait for T {}
+impl<T: 'static> MyTrait for T {} //~ ERROR E0119
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-no-direct-lifetime-dispatch.stderr b/src/test/ui/re_rebalance_coherence/coherence-no-direct-lifetime-dispatch.stderr
new file mode 100644
index 00000000000..aa6427ba24f
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-no-direct-lifetime-dispatch.stderr
@@ -0,0 +1,11 @@
+error[E0119]: conflicting implementations of trait `MyTrait`:
+  --> $DIR/coherence-no-direct-lifetime-dispatch.rs:18:1
+   |
+LL | impl<T> MyTrait for T {}
+   | --------------------- first implementation here
+LL | impl<T: 'static> MyTrait for T {} //~ ERROR E0119
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-orphan.rs b/src/test/ui/re_rebalance_coherence/coherence-orphan.rs
new file mode 100644
index 00000000000..dbe26a8898d
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-orphan.rs
@@ -0,0 +1,32 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// aux-build:coherence_orphan_lib.rs
+
+#![feature(optin_builtin_traits)]
+#![feature(re_rebalance_coherence)]
+
+extern crate coherence_orphan_lib as lib;
+
+use lib::TheTrait;
+
+struct TheType;
+
+impl TheTrait<usize> for isize { }
+//~^ ERROR E0117
+
+impl TheTrait<TheType> for isize { }
+
+impl TheTrait<isize> for TheType { }
+
+impl !Send for Vec<isize> { }
+//~^ ERROR E0117
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-orphan.stderr b/src/test/ui/re_rebalance_coherence/coherence-orphan.stderr
new file mode 100644
index 00000000000..6e5e734401f
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-orphan.stderr
@@ -0,0 +1,21 @@
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-orphan.rs:22:1
+   |
+LL | impl TheTrait<usize> for isize { }
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-orphan.rs:29:1
+   |
+LL | impl !Send for Vec<isize> { }
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0117`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-all-t-and-tuple.rs b/src/test/ui/re_rebalance_coherence/coherence-overlap-all-t-and-tuple.rs
new file mode 100644
index 00000000000..13604d9e495
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-all-t-and-tuple.rs
@@ -0,0 +1,31 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Check that we detect an overlap here in the case where:
+//
+//    for some type X:
+//      T = (X,)
+//      T11 = X, U11 = X
+//
+// Seems pretty basic, but then there was issue #24241. :)
+
+trait From<U> {
+    fn foo() {}
+}
+
+impl <T> From<T> for T {
+}
+
+impl <T11, U11> From<(U11,)> for (T11,) { //~ ERROR E0119
+}
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-all-t-and-tuple.stderr b/src/test/ui/re_rebalance_coherence/coherence-overlap-all-t-and-tuple.stderr
new file mode 100644
index 00000000000..dc052931ed1
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-all-t-and-tuple.stderr
@@ -0,0 +1,12 @@
+error[E0119]: conflicting implementations of trait `From<(_,)>` for type `(_,)`:
+  --> $DIR/coherence-overlap-all-t-and-tuple.rs:28:1
+   |
+LL | impl <T> From<T> for T {
+   | ---------------------- first implementation here
+...
+LL | impl <T11, U11> From<(U11,)> for (T11,) { //~ ERROR E0119
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(_,)`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-downstream-inherent.rs b/src/test/ui/re_rebalance_coherence/coherence-overlap-downstream-inherent.rs
new file mode 100644
index 00000000000..1f0ca50b60f
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-downstream-inherent.rs
@@ -0,0 +1,29 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Tests that we consider `T: Sugar + Fruit` to be ambiguous, even
+// though no impls are found.
+
+struct Sweet<X>(X);
+pub trait Sugar {}
+pub trait Fruit {}
+impl<T:Sugar> Sweet<T> { fn dummy(&self) { } }
+//~^ ERROR E0592
+impl<T:Fruit> Sweet<T> { fn dummy(&self) { } }
+
+trait Bar<X> {}
+struct A<T, X>(T, X);
+impl<X, T> A<T, X> where T: Bar<X> { fn f(&self) {} }
+//~^ ERROR E0592
+impl<X> A<i32, X> { fn f(&self) {} }
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-downstream-inherent.stderr b/src/test/ui/re_rebalance_coherence/coherence-overlap-downstream-inherent.stderr
new file mode 100644
index 00000000000..8a817fcb440
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-downstream-inherent.stderr
@@ -0,0 +1,23 @@
+error[E0592]: duplicate definitions with name `dummy`
+  --> $DIR/coherence-overlap-downstream-inherent.rs:19:26
+   |
+LL | impl<T:Sugar> Sweet<T> { fn dummy(&self) { } }
+   |                          ^^^^^^^^^^^^^^^^^^^ duplicate definitions for `dummy`
+LL | //~^ ERROR E0592
+LL | impl<T:Fruit> Sweet<T> { fn dummy(&self) { } }
+   |                          ------------------- other definition for `dummy`
+
+error[E0592]: duplicate definitions with name `f`
+  --> $DIR/coherence-overlap-downstream-inherent.rs:25:38
+   |
+LL | impl<X, T> A<T, X> where T: Bar<X> { fn f(&self) {} }
+   |                                      ^^^^^^^^^^^^^^ duplicate definitions for `f`
+LL | //~^ ERROR E0592
+LL | impl<X> A<i32, X> { fn f(&self) {} }
+   |                     -------------- other definition for `f`
+   |
+   = note: downstream crates may implement trait `Bar<_>` for type `i32`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0592`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-downstream.rs b/src/test/ui/re_rebalance_coherence/coherence-overlap-downstream.rs
new file mode 100644
index 00000000000..7a2b28f49b5
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-downstream.rs
@@ -0,0 +1,29 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Tests that we consider `T: Sugar + Fruit` to be ambiguous, even
+// though no impls are found.
+
+pub trait Sugar {}
+pub trait Fruit {}
+pub trait Sweet {}
+impl<T:Sugar> Sweet for T { }
+impl<T:Fruit> Sweet for T { }
+//~^ ERROR E0119
+
+pub trait Foo<X> {}
+pub trait Bar<X> {}
+impl<X, T> Foo<X> for T where T: Bar<X> {}
+impl<X> Foo<X> for i32 {}
+//~^ ERROR E0119
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-downstream.stderr b/src/test/ui/re_rebalance_coherence/coherence-overlap-downstream.stderr
new file mode 100644
index 00000000000..ce08ae15df1
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-downstream.stderr
@@ -0,0 +1,21 @@
+error[E0119]: conflicting implementations of trait `Sweet`:
+  --> $DIR/coherence-overlap-downstream.rs:20:1
+   |
+LL | impl<T:Sugar> Sweet for T { }
+   | ------------------------- first implementation here
+LL | impl<T:Fruit> Sweet for T { }
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
+
+error[E0119]: conflicting implementations of trait `Foo<_>` for type `i32`:
+  --> $DIR/coherence-overlap-downstream.rs:26:1
+   |
+LL | impl<X, T> Foo<X> for T where T: Bar<X> {}
+   | --------------------------------------- first implementation here
+LL | impl<X> Foo<X> for i32 {}
+   | ^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `i32`
+   |
+   = note: downstream crates may implement trait `Bar<_>` for type `i32`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516-inherent.rs b/src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516-inherent.rs
new file mode 100644
index 00000000000..ff6af49dfb2
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516-inherent.rs
@@ -0,0 +1,25 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Tests that we consider `Box<U>: !Sugar` to be ambiguous, even
+// though we see no impl of `Sugar` for `Box`. Therefore, an overlap
+// error is reported for the following pair of impls (#23516).
+
+pub trait Sugar {}
+
+struct Cake<X>(X);
+
+impl<T:Sugar> Cake<T> { fn dummy(&self) { } }
+//~^ ERROR E0592
+impl<U:Sugar> Cake<Box<U>> { fn dummy(&self) { } }
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516-inherent.stderr b/src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516-inherent.stderr
new file mode 100644
index 00000000000..26b59fbe71b
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516-inherent.stderr
@@ -0,0 +1,14 @@
+error[E0592]: duplicate definitions with name `dummy`
+  --> $DIR/coherence-overlap-issue-23516-inherent.rs:21:25
+   |
+LL | impl<T:Sugar> Cake<T> { fn dummy(&self) { } }
+   |                         ^^^^^^^^^^^^^^^^^^^ duplicate definitions for `dummy`
+LL | //~^ ERROR E0592
+LL | impl<U:Sugar> Cake<Box<U>> { fn dummy(&self) { } }
+   |                              ------------------- other definition for `dummy`
+   |
+   = note: downstream crates may implement trait `Sugar` for type `std::boxed::Box<_>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0592`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516.rs b/src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516.rs
new file mode 100644
index 00000000000..2e45572e4ec
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516.rs
@@ -0,0 +1,23 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Tests that we consider `Box<U>: !Sugar` to be ambiguous, even
+// though we see no impl of `Sugar` for `Box`. Therefore, an overlap
+// error is reported for the following pair of impls (#23516).
+
+pub trait Sugar { fn dummy(&self) { } }
+pub trait Sweet { fn dummy(&self) { } }
+impl<T:Sugar> Sweet for T { }
+impl<U:Sugar> Sweet for Box<U> { }
+//~^ ERROR E0119
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516.stderr b/src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516.stderr
new file mode 100644
index 00000000000..9d3d564b8a9
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516.stderr
@@ -0,0 +1,13 @@
+error[E0119]: conflicting implementations of trait `Sweet` for type `std::boxed::Box<_>`:
+  --> $DIR/coherence-overlap-issue-23516.rs:20:1
+   |
+LL | impl<T:Sugar> Sweet for T { }
+   | ------------------------- first implementation here
+LL | impl<U:Sugar> Sweet for Box<U> { }
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `std::boxed::Box<_>`
+   |
+   = note: downstream crates may implement trait `Sugar` for type `std::boxed::Box<_>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-messages.rs b/src/test/ui/re_rebalance_coherence/coherence-overlap-messages.rs
new file mode 100644
index 00000000000..1474fbd700c
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-messages.rs
@@ -0,0 +1,34 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+trait Foo { fn foo() {} }
+
+impl<T> Foo for T {}
+impl<U> Foo for U {} //~ ERROR conflicting implementations of trait `Foo`:
+
+trait Bar { fn bar() {} }
+
+impl<T> Bar for (T, u8) {}
+impl<T> Bar for (u8, T) {} //~ ERROR conflicting implementations of trait `Bar` for type `(u8, u8)`:
+
+trait Baz<T> { fn baz() {} }
+
+impl<T> Baz<u8> for T {}
+impl<T> Baz<T> for u8 {} //~ ERROR conflicting implementations of trait `Baz<u8>` for type `u8`:
+
+trait Quux<U, V> { fn quux() {} }
+
+impl<T, U, V> Quux<U, V> for T {}
+impl<T, U> Quux<U, U> for T {} //~ ERROR conflicting implementations of trait `Quux<_, _>`:
+impl<T, V> Quux<T, V> for T {} //~ ERROR conflicting implementations of trait `Quux<_, _>`:
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-messages.stderr b/src/test/ui/re_rebalance_coherence/coherence-overlap-messages.stderr
new file mode 100644
index 00000000000..c7b24e7bf6d
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-messages.stderr
@@ -0,0 +1,44 @@
+error[E0119]: conflicting implementations of trait `Foo`:
+  --> $DIR/coherence-overlap-messages.rs:16:1
+   |
+LL | impl<T> Foo for T {}
+   | ----------------- first implementation here
+LL | impl<U> Foo for U {} //~ ERROR conflicting implementations of trait `Foo`:
+   | ^^^^^^^^^^^^^^^^^ conflicting implementation
+
+error[E0119]: conflicting implementations of trait `Bar` for type `(u8, u8)`:
+  --> $DIR/coherence-overlap-messages.rs:21:1
+   |
+LL | impl<T> Bar for (T, u8) {}
+   | ----------------------- first implementation here
+LL | impl<T> Bar for (u8, T) {} //~ ERROR conflicting implementations of trait `Bar` for type `(u8, u8)`:
+   | ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(u8, u8)`
+
+error[E0119]: conflicting implementations of trait `Baz<u8>` for type `u8`:
+  --> $DIR/coherence-overlap-messages.rs:26:1
+   |
+LL | impl<T> Baz<u8> for T {}
+   | --------------------- first implementation here
+LL | impl<T> Baz<T> for u8 {} //~ ERROR conflicting implementations of trait `Baz<u8>` for type `u8`:
+   | ^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `u8`
+
+error[E0119]: conflicting implementations of trait `Quux<_, _>`:
+  --> $DIR/coherence-overlap-messages.rs:31:1
+   |
+LL | impl<T, U, V> Quux<U, V> for T {}
+   | ------------------------------ first implementation here
+LL | impl<T, U> Quux<U, U> for T {} //~ ERROR conflicting implementations of trait `Quux<_, _>`:
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
+
+error[E0119]: conflicting implementations of trait `Quux<_, _>`:
+  --> $DIR/coherence-overlap-messages.rs:32:1
+   |
+LL | impl<T, U, V> Quux<U, V> for T {}
+   | ------------------------------ first implementation here
+LL | impl<T, U> Quux<U, U> for T {} //~ ERROR conflicting implementations of trait `Quux<_, _>`:
+LL | impl<T, V> Quux<T, V> for T {} //~ ERROR conflicting implementations of trait `Quux<_, _>`:
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-upstream-inherent.rs b/src/test/ui/re_rebalance_coherence/coherence-overlap-upstream-inherent.rs
new file mode 100644
index 00000000000..e802c0113ad
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-upstream-inherent.rs
@@ -0,0 +1,27 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Tests that we consider `i16: Remote` to be ambiguous, even
+// though the upstream crate doesn't implement it for now.
+
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib;
+
+use coherence_lib::Remote;
+
+struct A<X>(X);
+impl<T> A<T> where T: Remote { fn dummy(&self) { } }
+//~^ ERROR E0592
+impl A<i16> { fn dummy(&self) { } }
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-upstream-inherent.stderr b/src/test/ui/re_rebalance_coherence/coherence-overlap-upstream-inherent.stderr
new file mode 100644
index 00000000000..70b19ddb429
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-upstream-inherent.stderr
@@ -0,0 +1,14 @@
+error[E0592]: duplicate definitions with name `dummy`
+  --> $DIR/coherence-overlap-upstream-inherent.rs:23:32
+   |
+LL | impl<T> A<T> where T: Remote { fn dummy(&self) { } }
+   |                                ^^^^^^^^^^^^^^^^^^^ duplicate definitions for `dummy`
+LL | //~^ ERROR E0592
+LL | impl A<i16> { fn dummy(&self) { } }
+   |               ------------------- other definition for `dummy`
+   |
+   = note: upstream crates may add new impl of trait `coherence_lib::Remote` for type `i16` in future versions
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0592`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-upstream.rs b/src/test/ui/re_rebalance_coherence/coherence-overlap-upstream.rs
new file mode 100644
index 00000000000..afbc69cac33
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-upstream.rs
@@ -0,0 +1,27 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Tests that we consider `i16: Remote` to be ambiguous, even
+// though the upstream crate doesn't implement it for now.
+
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib;
+
+use coherence_lib::Remote;
+
+trait Foo {}
+impl<T> Foo for T where T: Remote {}
+impl Foo for i16 {}
+//~^ ERROR E0119
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlap-upstream.stderr b/src/test/ui/re_rebalance_coherence/coherence-overlap-upstream.stderr
new file mode 100644
index 00000000000..88bea02b348
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlap-upstream.stderr
@@ -0,0 +1,13 @@
+error[E0119]: conflicting implementations of trait `Foo` for type `i16`:
+  --> $DIR/coherence-overlap-upstream.rs:24:1
+   |
+LL | impl<T> Foo for T where T: Remote {}
+   | --------------------------------- first implementation here
+LL | impl Foo for i16 {}
+   | ^^^^^^^^^^^^^^^^ conflicting implementation for `i16`
+   |
+   = note: upstream crates may add new impl of trait `coherence_lib::Remote` for type `i16` in future versions
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlapping-pairs.rs b/src/test/ui/re_rebalance_coherence/coherence-overlapping-pairs.rs
new file mode 100644
index 00000000000..25d8e3197f4
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlapping-pairs.rs
@@ -0,0 +1,23 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::Remote;
+
+struct Foo;
+
+impl<T> Remote for lib::Pair<T,Foo> { }
+//~^ ERROR E0117
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-overlapping-pairs.stderr b/src/test/ui/re_rebalance_coherence/coherence-overlapping-pairs.stderr
new file mode 100644
index 00000000000..2629a017b79
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-overlapping-pairs.stderr
@@ -0,0 +1,12 @@
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-overlapping-pairs.rs:20:1
+   |
+LL | impl<T> Remote for lib::Pair<T,Foo> { }
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0117`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered-1.rs b/src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered-1.rs
new file mode 100644
index 00000000000..4edfd5e1227
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered-1.rs
@@ -0,0 +1,25 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Test that the same coverage rules apply even if the local type appears in the
+// list of type parameters, not the self type.
+
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::{Remote1, Pair};
+
+pub struct Local<T>(T);
+
+impl<T, U> Remote1<Pair<T, Local<U>>> for i32 { }
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered-1.stderr b/src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered-1.stderr
new file mode 100644
index 00000000000..197056746b9
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered-1.stderr
@@ -0,0 +1,12 @@
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-pair-covered-uncovered-1.rs:23:1
+   |
+LL | impl<T, U> Remote1<Pair<T, Local<U>>> for i32 { }
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0117`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered.rs b/src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered.rs
new file mode 100644
index 00000000000..9b0d7177ffc
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered.rs
@@ -0,0 +1,23 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::{Remote, Pair};
+
+struct Local<T>(T);
+
+impl<T,U> Remote for Pair<T,Local<U>> { }
+//~^ ERROR E0117
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered.stderr b/src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered.stderr
new file mode 100644
index 00000000000..b9e2eced94b
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered.stderr
@@ -0,0 +1,12 @@
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-pair-covered-uncovered.rs:20:1
+   |
+LL | impl<T,U> Remote for Pair<T,Local<U>> { }
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0117`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-projection-conflict-orphan.rs b/src/test/ui/re_rebalance_coherence/coherence-projection-conflict-orphan.rs
new file mode 100644
index 00000000000..e3f945504fe
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-projection-conflict-orphan.rs
@@ -0,0 +1,29 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(rustc_attrs)]
+#![feature(re_rebalance_coherence)]
+
+// Here we expect a coherence conflict because, even though `i32` does
+// not implement `Iterator`, we cannot rely on that negative reasoning
+// due to the orphan rules. Therefore, `A::Item` may yet turn out to
+// be `i32`.
+
+pub trait Foo<P> { fn foo() {} }
+
+pub trait Bar {
+    type Output: 'static;
+}
+
+impl Foo<i32> for i32 { }
+
+impl<A:Iterator> Foo<A::Item> for A { }  //~ ERROR E0119
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-projection-conflict-orphan.stderr b/src/test/ui/re_rebalance_coherence/coherence-projection-conflict-orphan.stderr
new file mode 100644
index 00000000000..81b13438373
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-projection-conflict-orphan.stderr
@@ -0,0 +1,14 @@
+error[E0119]: conflicting implementations of trait `Foo<i32>` for type `i32`:
+  --> $DIR/coherence-projection-conflict-orphan.rs:27:1
+   |
+LL | impl Foo<i32> for i32 { }
+   | --------------------- first implementation here
+LL | 
+LL | impl<A:Iterator> Foo<A::Item> for A { }  //~ ERROR E0119
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `i32`
+   |
+   = note: upstream crates may add new impl of trait `std::iter::Iterator` for type `i32` in future versions
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-projection-conflict-ty-param.rs b/src/test/ui/re_rebalance_coherence/coherence-projection-conflict-ty-param.rs
new file mode 100644
index 00000000000..cb5c94a18a7
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-projection-conflict-ty-param.rs
@@ -0,0 +1,24 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Coherence error results because we do not know whether `T: Foo<P>` or not
+// for the second impl.
+
+use std::marker::PhantomData;
+
+pub trait Foo<P> { fn foo() {} }
+
+impl <P, T: Foo<P>> Foo<P> for Option<T> {}
+
+impl<T, U> Foo<T> for Option<U> { } //~ ERROR E0119
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-projection-conflict-ty-param.stderr b/src/test/ui/re_rebalance_coherence/coherence-projection-conflict-ty-param.stderr
new file mode 100644
index 00000000000..fe5a66ef9ea
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-projection-conflict-ty-param.stderr
@@ -0,0 +1,12 @@
+error[E0119]: conflicting implementations of trait `Foo<_>` for type `std::option::Option<_>`:
+  --> $DIR/coherence-projection-conflict-ty-param.rs:22:1
+   |
+LL | impl <P, T: Foo<P>> Foo<P> for Option<T> {}
+   | ---------------------------------------- first implementation here
+LL | 
+LL | impl<T, U> Foo<T> for Option<U> { } //~ ERROR E0119
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `std::option::Option<_>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-projection-conflict.rs b/src/test/ui/re_rebalance_coherence/coherence-projection-conflict.rs
new file mode 100644
index 00000000000..73adba0819e
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-projection-conflict.rs
@@ -0,0 +1,29 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+use std::marker::PhantomData;
+
+pub trait Foo<P> { fn foo() {} }
+
+pub trait Bar {
+    type Output: 'static;
+}
+
+impl Foo<i32> for i32 { }
+
+impl<A:Bar> Foo<A::Output> for A { } //~ ERROR E0119
+
+impl Bar for i32 {
+    type Output = i32;
+}
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-projection-conflict.stderr b/src/test/ui/re_rebalance_coherence/coherence-projection-conflict.stderr
new file mode 100644
index 00000000000..7f5ff3de178
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-projection-conflict.stderr
@@ -0,0 +1,12 @@
+error[E0119]: conflicting implementations of trait `Foo<i32>` for type `i32`:
+  --> $DIR/coherence-projection-conflict.rs:23:1
+   |
+LL | impl Foo<i32> for i32 { }
+   | --------------------- first implementation here
+LL | 
+LL | impl<A:Bar> Foo<A::Output> for A { } //~ ERROR E0119
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `i32`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-projection-ok-orphan.rs b/src/test/ui/re_rebalance_coherence/coherence-projection-ok-orphan.rs
new file mode 100644
index 00000000000..b02289dc68e
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-projection-ok-orphan.rs
@@ -0,0 +1,30 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-pass
+// skip-codegen
+#![allow(dead_code)]
+#![feature(re_rebalance_coherence)]
+// Here we do not get a coherence conflict because `Baz: Iterator`
+// does not hold and (due to the orphan rules), we can rely on that.
+
+pub trait Foo<P> {}
+
+pub trait Bar {
+    type Output: 'static;
+}
+
+struct Baz;
+impl Foo<i32> for Baz { }
+
+impl<A:Iterator> Foo<A::Item> for A { }
+
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-projection-ok.rs b/src/test/ui/re_rebalance_coherence/coherence-projection-ok.rs
new file mode 100644
index 00000000000..9c797b61a43
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-projection-ok.rs
@@ -0,0 +1,30 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// compile-pass
+// skip-codegen
+pub trait Foo<P> {}
+
+pub trait Bar {
+    type Output: 'static;
+}
+
+impl Foo<i32> for i32 { }
+
+impl<A:Bar> Foo<A::Output> for A { }
+
+impl Bar for i32 {
+    type Output = u32;
+}
+
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence-tuple-conflict.rs b/src/test/ui/re_rebalance_coherence/coherence-tuple-conflict.rs
new file mode 100644
index 00000000000..c6dda7f2773
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-tuple-conflict.rs
@@ -0,0 +1,31 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+use std::fmt::Debug;
+use std::default::Default;
+
+// Test that a blank impl for all T conflicts with an impl for some
+// specific T.
+
+trait MyTrait {
+    fn get(&self) -> usize;
+}
+
+impl<T> MyTrait for (T,T) {
+    fn get(&self) -> usize { 0 }
+}
+
+impl<A,B> MyTrait for (A,B) { //~ ERROR E0119
+    fn get(&self) -> usize { self.dummy }
+}
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-tuple-conflict.stderr b/src/test/ui/re_rebalance_coherence/coherence-tuple-conflict.stderr
new file mode 100644
index 00000000000..bd4f2908cdf
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-tuple-conflict.stderr
@@ -0,0 +1,12 @@
+error[E0119]: conflicting implementations of trait `MyTrait` for type `(_, _)`:
+  --> $DIR/coherence-tuple-conflict.rs:27:1
+   |
+LL | impl<T> MyTrait for (T,T) {
+   | ------------------------- first implementation here
+...
+LL | impl<A,B> MyTrait for (A,B) { //~ ERROR E0119
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(_, _)`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-vec-local-2.rs b/src/test/ui/re_rebalance_coherence/coherence-vec-local-2.rs
new file mode 100644
index 00000000000..6849f004c63
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-vec-local-2.rs
@@ -0,0 +1,25 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Test that a local, generic type appearing within a
+// *non-fundamental* remote type like `Vec` is not considered local.
+
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::Remote;
+
+struct Local<T>(T);
+
+impl<T> Remote for Vec<Local<T>> { } //~ ERROR E0117
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-vec-local-2.stderr b/src/test/ui/re_rebalance_coherence/coherence-vec-local-2.stderr
new file mode 100644
index 00000000000..d507edbb0bd
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-vec-local-2.stderr
@@ -0,0 +1,12 @@
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-vec-local-2.rs:23:1
+   |
+LL | impl<T> Remote for Vec<Local<T>> { } //~ ERROR E0117
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0117`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence-vec-local.rs b/src/test/ui/re_rebalance_coherence/coherence-vec-local.rs
new file mode 100644
index 00000000000..24a00febfd8
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-vec-local.rs
@@ -0,0 +1,25 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Test that a local type (with no type parameters) appearing within a
+// *non-fundamental* remote type like `Vec` is not considered local.
+
+// aux-build:coherence_lib.rs
+
+extern crate coherence_lib as lib;
+use lib::Remote;
+
+struct Local;
+
+impl Remote for Vec<Local> { } //~ ERROR E0117
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence-vec-local.stderr b/src/test/ui/re_rebalance_coherence/coherence-vec-local.stderr
new file mode 100644
index 00000000000..fc400da7115
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence-vec-local.stderr
@@ -0,0 +1,12 @@
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence-vec-local.rs:23:1
+   |
+LL | impl Remote for Vec<Local> { } //~ ERROR E0117
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0117`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct.rs b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct.rs
new file mode 100644
index 00000000000..5e09cf69a61
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct.rs
@@ -0,0 +1,35 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test that we are able to introduce a negative constraint that
+// `MyType: !MyTrait` along with other "fundamental" wrappers.
+
+// aux-build:coherence_copy_like_lib.rs
+// compile-pass
+// skip-codgen
+#![allow(dead_code)]
+#![feature(re_rebalance_coherence)]
+
+extern crate coherence_copy_like_lib as lib;
+
+struct MyType { x: i32 }
+
+trait MyTrait { fn foo() {} }
+impl<T: lib::MyCopy> MyTrait for T { }
+
+// `MyFundamentalStruct` is declared fundamental, so we can test that
+//
+//    MyFundamentalStruct<MyTrait>: !MyTrait
+//
+// Huzzah.
+impl MyTrait for lib::MyFundamentalStruct<MyType> { }
+
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_ref.rs b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_ref.rs
new file mode 100644
index 00000000000..8e5d2bf4cf7
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_ref.rs
@@ -0,0 +1,35 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test that we are able to introduce a negative constraint that
+// `MyType: !MyTrait` along with other "fundamental" wrappers.
+
+// aux-build:coherence_copy_like_lib.rs
+// compile-pass
+// skip-codegen
+#![allow(dead_code)]
+#![feature(re_rebalance_coherence)]
+
+extern crate coherence_copy_like_lib as lib;
+
+struct MyType { x: i32 }
+
+trait MyTrait { fn foo() {} }
+impl<T: lib::MyCopy> MyTrait for T { }
+
+// `MyFundamentalStruct` is declared fundamental, so we can test that
+//
+//    MyFundamentalStruct<&MyTrait>: !MyTrait
+//
+// Huzzah.
+impl<'a> MyTrait for lib::MyFundamentalStruct<&'a MyType> { }
+
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_tuple.rs b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_tuple.rs
new file mode 100644
index 00000000000..e7a8edbd221
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_tuple.rs
@@ -0,0 +1,32 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Test that we are able to introduce a negative constraint that
+// `MyType: !MyTrait` along with other "fundamental" wrappers.
+
+// aux-build:coherence_copy_like_lib.rs
+
+
+
+extern crate coherence_copy_like_lib as lib;
+
+struct MyType { x: i32 }
+
+trait MyTrait { fn foo() {} }
+
+impl<T: lib::MyCopy> MyTrait for T { }
+
+// Tuples are not fundamental.
+impl MyTrait for lib::MyFundamentalStruct<(MyType,)> { } //~ ERROR E0119
+
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_tuple.stderr b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_tuple.stderr
new file mode 100644
index 00000000000..e6adc08c28c
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_tuple.stderr
@@ -0,0 +1,14 @@
+error[E0119]: conflicting implementations of trait `MyTrait` for type `lib::MyFundamentalStruct<(MyType,)>`:
+  --> $DIR/coherence_copy_like_err_fundamental_struct_tuple.rs:29:1
+   |
+LL | impl<T: lib::MyCopy> MyTrait for T { }
+   | ---------------------------------- first implementation here
+...
+LL | impl MyTrait for lib::MyFundamentalStruct<(MyType,)> { } //~ ERROR E0119
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyFundamentalStruct<(MyType,)>`
+   |
+   = note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyFundamentalStruct<(MyType,)>` in future versions
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_struct.rs b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_struct.rs
new file mode 100644
index 00000000000..3f91750104b
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_struct.rs
@@ -0,0 +1,33 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// aux-build:coherence_copy_like_lib.rs
+
+// Test that we are able to introduce a negative constraint that
+// `MyType: !MyTrait` along with other "fundamental" wrappers.
+
+extern crate coherence_copy_like_lib as lib;
+
+struct MyType { x: i32 }
+
+trait MyTrait { fn foo() {} }
+impl<T: lib::MyCopy> MyTrait for T { }
+
+// `MyStruct` is not declared fundamental, therefore this would
+// require that
+//
+//     MyStruct<MyType>: !MyTrait
+//
+// which we cannot approve.
+impl MyTrait for lib::MyStruct<MyType> { } //~ ERROR E0119
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_struct.stderr b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_struct.stderr
new file mode 100644
index 00000000000..a40ae4fc448
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_struct.stderr
@@ -0,0 +1,14 @@
+error[E0119]: conflicting implementations of trait `MyTrait` for type `lib::MyStruct<MyType>`:
+  --> $DIR/coherence_copy_like_err_struct.rs:31:1
+   |
+LL | impl<T: lib::MyCopy> MyTrait for T { }
+   | ---------------------------------- first implementation here
+...
+LL | impl MyTrait for lib::MyStruct<MyType> { } //~ ERROR E0119
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyStruct<MyType>`
+   |
+   = note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyStruct<MyType>` in future versions
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_tuple.rs b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_tuple.rs
new file mode 100644
index 00000000000..0e7eef6fe6d
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_tuple.rs
@@ -0,0 +1,32 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Test that we are able to introduce a negative constraint that
+// `MyType: !MyTrait` along with other "fundamental" wrappers.
+
+// aux-build:coherence_copy_like_lib.rs
+
+extern crate coherence_copy_like_lib as lib;
+
+struct MyType { x: i32 }
+
+trait MyTrait { fn foo() {} }
+impl<T: lib::MyCopy> MyTrait for T { }
+
+// Tuples are not fundamental, therefore this would require that
+//
+//     (MyType,): !MyTrait
+//
+// which we cannot approve.
+impl MyTrait for (MyType,) { } //~ ERROR E0119
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_tuple.stderr b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_tuple.stderr
new file mode 100644
index 00000000000..82e43f6d721
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_copy_like_err_tuple.stderr
@@ -0,0 +1,14 @@
+error[E0119]: conflicting implementations of trait `MyTrait` for type `(MyType,)`:
+  --> $DIR/coherence_copy_like_err_tuple.rs:30:1
+   |
+LL | impl<T: lib::MyCopy> MyTrait for T { }
+   | ---------------------------------- first implementation here
+...
+LL | impl MyTrait for (MyType,) { } //~ ERROR E0119
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(MyType,)`
+   |
+   = note: upstream crates may add new impl of trait `lib::MyCopy` for type `(MyType,)` in future versions
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0119`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence_inherent.rs b/src/test/ui/re_rebalance_coherence/coherence_inherent.rs
new file mode 100644
index 00000000000..d4d29326e4f
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_inherent.rs
@@ -0,0 +1,47 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// Tests that methods that implement a trait cannot be invoked
+// unless the trait is imported.
+
+mod Lib {
+    pub trait TheTrait {
+        fn the_fn(&self);
+    }
+
+    pub struct TheStruct;
+
+    impl TheTrait for TheStruct {
+        fn the_fn(&self) {}
+    }
+}
+
+mod Import {
+    // Trait is in scope here:
+    use Lib::TheStruct;
+    use Lib::TheTrait;
+
+    fn call_the_fn(s: &TheStruct) {
+        s.the_fn();
+    }
+}
+
+mod NoImport {
+    // Trait is not in scope here:
+    use Lib::TheStruct;
+
+    fn call_the_fn(s: &TheStruct) {
+        s.the_fn(); //~ ERROR no method named `the_fn` found
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence_inherent.stderr b/src/test/ui/re_rebalance_coherence/coherence_inherent.stderr
new file mode 100644
index 00000000000..9294899bfee
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_inherent.stderr
@@ -0,0 +1,13 @@
+error[E0599]: no method named `the_fn` found for type `&Lib::TheStruct` in the current scope
+  --> $DIR/coherence_inherent.rs:43:11
+   |
+LL |         s.the_fn(); //~ ERROR no method named `the_fn` found
+   |           ^^^^^^
+   |
+   = help: items from traits can only be used if the trait is in scope
+   = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
+           `use Lib::TheTrait;`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence_inherent_cc.rs b/src/test/ui/re_rebalance_coherence/coherence_inherent_cc.rs
new file mode 100644
index 00000000000..beb60f57a2a
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_inherent_cc.rs
@@ -0,0 +1,39 @@
+// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(re_rebalance_coherence)]
+
+// aux-build:coherence_inherent_cc_lib.rs
+
+// Tests that methods that implement a trait cannot be invoked
+// unless the trait is imported.
+
+extern crate coherence_inherent_cc_lib;
+
+mod Import {
+    // Trait is in scope here:
+    use coherence_inherent_cc_lib::TheStruct;
+    use coherence_inherent_cc_lib::TheTrait;
+
+    fn call_the_fn(s: &TheStruct) {
+        s.the_fn();
+    }
+}
+
+mod NoImport {
+    // Trait is not in scope here:
+    use coherence_inherent_cc_lib::TheStruct;
+
+    fn call_the_fn(s: &TheStruct) {
+        s.the_fn(); //~ ERROR no method named `the_fn` found
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/re_rebalance_coherence/coherence_inherent_cc.stderr b/src/test/ui/re_rebalance_coherence/coherence_inherent_cc.stderr
new file mode 100644
index 00000000000..bf67313879b
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_inherent_cc.stderr
@@ -0,0 +1,13 @@
+error[E0599]: no method named `the_fn` found for type `&coherence_inherent_cc_lib::TheStruct` in the current scope
+  --> $DIR/coherence_inherent_cc.rs:35:11
+   |
+LL |         s.the_fn(); //~ ERROR no method named `the_fn` found
+   |           ^^^^^^
+   |
+   = help: items from traits can only be used if the trait is in scope
+   = note: the following trait is implemented but not in scope, perhaps add a `use` for it:
+           `use coherence_inherent_cc_lib::TheTrait;`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence_local.rs b/src/test/ui/re_rebalance_coherence/coherence_local.rs
new file mode 100644
index 00000000000..7f72ff7af88
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_local.rs
@@ -0,0 +1,34 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test that we are able to introduce a negative constraint that
+// `MyType: !MyTrait` along with other "fundamental" wrappers.
+
+// aux-build:coherence_copy_like_lib.rs
+// compile-pass
+// skip-codegen
+#![allow(dead_code)]
+#![feature(re_rebalance_coherence)]
+
+extern crate coherence_copy_like_lib as lib;
+
+struct MyType { x: i32 }
+
+// These are all legal because they are all fundamental types:
+
+impl lib::MyCopy for MyType { }
+impl<'a> lib::MyCopy for &'a MyType { }
+impl<'a> lib::MyCopy for &'a Box<MyType> { }
+impl lib::MyCopy for Box<MyType> { }
+impl lib::MyCopy for lib::MyFundamentalStruct<MyType> { }
+impl lib::MyCopy for lib::MyFundamentalStruct<Box<MyType>> { }
+
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence_local_err_struct.rs b/src/test/ui/re_rebalance_coherence/coherence_local_err_struct.rs
new file mode 100644
index 00000000000..3d7145e489d
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_local_err_struct.rs
@@ -0,0 +1,29 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test that we are able to introduce a negative constraint that
+// `MyType: !MyTrait` along with other "fundamental" wrappers.
+
+// aux-build:coherence_copy_like_lib.rs
+
+#![feature(re_rebalance_coherence)]
+#![allow(dead_code)]
+
+extern crate coherence_copy_like_lib as lib;
+
+struct MyType { x: i32 }
+
+// These are all legal because they are all fundamental types:
+
+// MyStruct is not fundamental.
+impl lib::MyCopy for lib::MyStruct<MyType> { } //~ ERROR E0117
+
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence_local_err_struct.stderr b/src/test/ui/re_rebalance_coherence/coherence_local_err_struct.stderr
new file mode 100644
index 00000000000..c35e95040de
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_local_err_struct.stderr
@@ -0,0 +1,12 @@
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence_local_err_struct.rs:26:1
+   |
+LL | impl lib::MyCopy for lib::MyStruct<MyType> { } //~ ERROR E0117
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0117`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence_local_err_tuple.rs b/src/test/ui/re_rebalance_coherence/coherence_local_err_tuple.rs
new file mode 100644
index 00000000000..f2c9008dd8c
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_local_err_tuple.rs
@@ -0,0 +1,29 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test that we are able to introduce a negative constraint that
+// `MyType: !MyTrait` along with other "fundamental" wrappers.
+
+// aux-build:coherence_copy_like_lib.rs
+
+#![feature(re_rebalance_coherence)]
+#![allow(dead_code)]
+
+extern crate coherence_copy_like_lib as lib;
+
+struct MyType { x: i32 }
+
+// These are all legal because they are all fundamental types:
+
+// Tuples are not fundamental, so this is not a local impl.
+impl lib::MyCopy for (MyType,) { } //~ ERROR E0117
+
+
+fn main() { }
diff --git a/src/test/ui/re_rebalance_coherence/coherence_local_err_tuple.stderr b/src/test/ui/re_rebalance_coherence/coherence_local_err_tuple.stderr
new file mode 100644
index 00000000000..a3f9f2d32b8
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_local_err_tuple.stderr
@@ -0,0 +1,12 @@
+error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
+  --> $DIR/coherence_local_err_tuple.rs:26:1
+   |
+LL | impl lib::MyCopy for (MyType,) { } //~ ERROR E0117
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl doesn't use types inside crate
+   |
+   = note: the impl does not reference any types defined in this crate
+   = note: define and implement a trait or new type instead
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0117`.
diff --git a/src/test/ui/re_rebalance_coherence/coherence_local_ref.rs b/src/test/ui/re_rebalance_coherence/coherence_local_ref.rs
new file mode 100644
index 00000000000..b15a5cc245b
--- /dev/null
+++ b/src/test/ui/re_rebalance_coherence/coherence_local_ref.rs
@@ -0,0 +1,28 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test that we are able to introduce a negative constraint that
+// `MyType: !MyTrait` along with other "fundamental" wrappers.
+
+// aux-build:coherence_copy_like_lib.rs
+// compile-pass
+// skip-codegen
+#![allow(dead_code)]
+#![feature(re_rebalance_coherence)]
+
+extern crate coherence_copy_like_lib as lib;
+
+struct MyType { x: i32 }
+
+// naturally, legal
+impl lib::MyCopy for MyType { }
+
+
+fn main() { }