From bcd7acfe046356e8107a4f2df2c5f06bc0abd219 Mon Sep 17 00:00:00 2001 From: Georg Semmler Date: Wed, 21 Nov 2018 21:35:56 +0100 Subject: [PATCH] Add some tests This copies and adjusts the existing coherence tests to ensure that they continue to work using the new implementation. --- .../auxiliary/coherence_copy_like_lib.rs | 20 +++++ .../auxiliary/coherence_lib.rs | 25 ++++++ .../auxiliary/re_rebalance_coherence_lib.rs | 23 +++++ .../coherence-bigint-int.rs | 25 ++++++ .../coherence-bigint-vecint.rs | 25 ++++++ .../coherence-blanket.rs | 27 ++++++ .../coherence-covered-type-parameter.rs | 25 ++++++ .../coherence-impl-in-fn.rs | 25 ++++++ .../coherence-iterator-vec-any-elem.rs | 25 ++++++ .../coherence-iterator-vec.rs | 25 ++++++ .../coherence-multidispatch-tuple.rs | 35 ++++++++ .../coherence-negative-impls-safe.rs | 24 +++++ .../coherence-rfc447-constrained.rs | 34 ++++++++ .../coherence-subtyping.rs | 51 +++++++++++ .../coherence-where-clause.rs | 49 +++++++++++ .../coherence_copy_like.rs | 31 +++++++ .../re-rebalance-coherence.rs | 13 +++ .../auxiliary/re_rebalance_coherence_lib.rs | 23 +++++ .../feature-gate-re-rebalance-coherence.rs | 13 +++ ...feature-gate-re-rebalance-coherence.stderr | 11 +++ .../auxiliary/coherence_copy_like_lib.rs | 20 +++++ .../auxiliary/coherence_inherent_cc_lib.rs | 21 +++++ .../auxiliary/coherence_lib.rs | 25 ++++++ .../auxiliary/coherence_orphan_lib.rs | 13 +++ .../auxiliary/go_trait.rs | 53 +++++++++++ .../auxiliary/trait_impl_conflict.rs | 16 ++++ .../coherence-all-remote.rs | 21 +++++ .../coherence-all-remote.stderr | 11 +++ .../coherence-bigint-param.rs | 23 +++++ .../coherence-bigint-param.stderr | 11 +++ ...nket-conflicts-with-blanket-implemented.rs | 40 +++++++++ ...-conflicts-with-blanket-implemented.stderr | 12 +++ ...et-conflicts-with-blanket-unimplemented.rs | 36 ++++++++ ...onflicts-with-blanket-unimplemented.stderr | 12 +++ ...ket-conflicts-with-specific-cross-crate.rs | 31 +++++++ ...conflicts-with-specific-cross-crate.stderr | 13 +++ ...t-conflicts-with-specific-multidispatch.rs | 38 ++++++++ ...nflicts-with-specific-multidispatch.stderr | 12 +++ ...e-blanket-conflicts-with-specific-trait.rs | 40 +++++++++ ...anket-conflicts-with-specific-trait.stderr | 12 +++ ...herence-blanket-conflicts-with-specific.rs | 35 ++++++++ ...nce-blanket-conflicts-with-specific.stderr | 12 +++ ...herence-conflicting-negative-trait-impl.rs | 29 +++++++ ...nce-conflicting-negative-trait-impl.stderr | 21 +++++ .../coherence-cow.a.stderr | 12 +++ .../coherence-cow.b.stderr | 12 +++ .../coherence-cow.c.stderr | 12 +++ .../re_rebalance_coherence/coherence-cow.rs | 37 ++++++++ .../coherence-cross-crate-conflict.rs | 26 ++++++ .../coherence-cross-crate-conflict.stderr | 21 +++++ .../coherence-default-trait-impl.rs | 26 ++++++ .../coherence-default-trait-impl.stderr | 16 ++++ .../coherence-error-suppression.rs | 27 ++++++ .../coherence-error-suppression.stderr | 9 ++ ...erence-impl-trait-for-trait-object-safe.rs | 21 +++++ ...ce-impl-trait-for-trait-object-safe.stderr | 11 +++ .../coherence-impl-trait-for-trait.rs | 29 +++++++ .../coherence-impl-trait-for-trait.stderr | 21 +++++ .../coherence-impls-copy.rs | 54 ++++++++++++ .../coherence-impls-copy.stderr | 87 +++++++++++++++++++ .../coherence-impls-send.rs | 41 +++++++++ .../coherence-impls-send.stderr | 37 ++++++++ .../coherence-impls-sized.rs | 47 ++++++++++ .../coherence-impls-sized.stderr | 67 ++++++++++++++ .../coherence-inherited-assoc-ty-cycle-err.rs | 35 ++++++++ ...erence-inherited-assoc-ty-cycle-err.stderr | 16 ++++ .../coherence-lone-type-parameter.rs | 21 +++++ .../coherence-lone-type-parameter.stderr | 11 +++ .../coherence-negative-impls-safe.rs | 21 +++++ .../coherence-negative-impls-safe.stderr | 9 ++ .../coherence-no-direct-lifetime-dispatch.rs | 20 +++++ ...herence-no-direct-lifetime-dispatch.stderr | 11 +++ .../coherence-orphan.rs | 32 +++++++ .../coherence-orphan.stderr | 21 +++++ .../coherence-overlap-all-t-and-tuple.rs | 31 +++++++ .../coherence-overlap-all-t-and-tuple.stderr | 12 +++ .../coherence-overlap-downstream-inherent.rs | 29 +++++++ ...herence-overlap-downstream-inherent.stderr | 23 +++++ .../coherence-overlap-downstream.rs | 29 +++++++ .../coherence-overlap-downstream.stderr | 21 +++++ .../coherence-overlap-issue-23516-inherent.rs | 25 ++++++ ...erence-overlap-issue-23516-inherent.stderr | 14 +++ .../coherence-overlap-issue-23516.rs | 23 +++++ .../coherence-overlap-issue-23516.stderr | 13 +++ .../coherence-overlap-messages.rs | 34 ++++++++ .../coherence-overlap-messages.stderr | 44 ++++++++++ .../coherence-overlap-upstream-inherent.rs | 27 ++++++ ...coherence-overlap-upstream-inherent.stderr | 14 +++ .../coherence-overlap-upstream.rs | 27 ++++++ .../coherence-overlap-upstream.stderr | 13 +++ .../coherence-overlapping-pairs.rs | 23 +++++ .../coherence-overlapping-pairs.stderr | 12 +++ .../coherence-pair-covered-uncovered-1.rs | 25 ++++++ .../coherence-pair-covered-uncovered-1.stderr | 12 +++ .../coherence-pair-covered-uncovered.rs | 23 +++++ .../coherence-pair-covered-uncovered.stderr | 12 +++ .../coherence-projection-conflict-orphan.rs | 29 +++++++ ...oherence-projection-conflict-orphan.stderr | 14 +++ .../coherence-projection-conflict-ty-param.rs | 24 +++++ ...erence-projection-conflict-ty-param.stderr | 12 +++ .../coherence-projection-conflict.rs | 29 +++++++ .../coherence-projection-conflict.stderr | 12 +++ .../coherence-projection-ok-orphan.rs | 30 +++++++ .../coherence-projection-ok.rs | 30 +++++++ .../coherence-tuple-conflict.rs | 31 +++++++ .../coherence-tuple-conflict.stderr | 12 +++ .../coherence-vec-local-2.rs | 25 ++++++ .../coherence-vec-local-2.stderr | 12 +++ .../coherence-vec-local.rs | 25 ++++++ .../coherence-vec-local.stderr | 12 +++ ...erence_copy_like_err_fundamental_struct.rs | 35 ++++++++ ...ce_copy_like_err_fundamental_struct_ref.rs | 35 ++++++++ ..._copy_like_err_fundamental_struct_tuple.rs | 32 +++++++ ...y_like_err_fundamental_struct_tuple.stderr | 14 +++ .../coherence_copy_like_err_struct.rs | 33 +++++++ .../coherence_copy_like_err_struct.stderr | 14 +++ .../coherence_copy_like_err_tuple.rs | 32 +++++++ .../coherence_copy_like_err_tuple.stderr | 14 +++ .../coherence_inherent.rs | 47 ++++++++++ .../coherence_inherent.stderr | 13 +++ .../coherence_inherent_cc.rs | 39 +++++++++ .../coherence_inherent_cc.stderr | 13 +++ .../re_rebalance_coherence/coherence_local.rs | 34 ++++++++ .../coherence_local_err_struct.rs | 29 +++++++ .../coherence_local_err_struct.stderr | 12 +++ .../coherence_local_err_tuple.rs | 29 +++++++ .../coherence_local_err_tuple.stderr | 12 +++ .../coherence_local_ref.rs | 28 ++++++ 128 files changed, 3144 insertions(+) create mode 100644 src/test/run-pass/re_rebalance_coherence/auxiliary/coherence_copy_like_lib.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/auxiliary/coherence_lib.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/auxiliary/re_rebalance_coherence_lib.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/coherence-bigint-int.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/coherence-bigint-vecint.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/coherence-blanket.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/coherence-covered-type-parameter.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/coherence-impl-in-fn.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/coherence-iterator-vec-any-elem.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/coherence-iterator-vec.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/coherence-multidispatch-tuple.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/coherence-negative-impls-safe.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/coherence-rfc447-constrained.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/coherence-subtyping.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/coherence-where-clause.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/coherence_copy_like.rs create mode 100644 src/test/run-pass/re_rebalance_coherence/re-rebalance-coherence.rs create mode 100644 src/test/ui/feature-gates/auxiliary/re_rebalance_coherence_lib.rs create mode 100644 src/test/ui/feature-gates/feature-gate-re-rebalance-coherence.rs create mode 100644 src/test/ui/feature-gates/feature-gate-re-rebalance-coherence.stderr create mode 100644 src/test/ui/re_rebalance_coherence/auxiliary/coherence_copy_like_lib.rs create mode 100644 src/test/ui/re_rebalance_coherence/auxiliary/coherence_inherent_cc_lib.rs create mode 100644 src/test/ui/re_rebalance_coherence/auxiliary/coherence_lib.rs create mode 100644 src/test/ui/re_rebalance_coherence/auxiliary/coherence_orphan_lib.rs create mode 100644 src/test/ui/re_rebalance_coherence/auxiliary/go_trait.rs create mode 100644 src/test/ui/re_rebalance_coherence/auxiliary/trait_impl_conflict.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-all-remote.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-all-remote.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-bigint-param.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-bigint-param.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-implemented.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-implemented.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-unimplemented.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-blanket-unimplemented.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-cross-crate.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-cross-crate.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-multidispatch.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-multidispatch.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-trait.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-trait.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-conflicting-negative-trait-impl.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-conflicting-negative-trait-impl.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-cow.a.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-cow.b.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-cow.c.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-cow.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-cross-crate-conflict.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-cross-crate-conflict.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-default-trait-impl.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-default-trait-impl.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-error-suppression.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-error-suppression.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait-object-safe.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait-object-safe.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-impl-trait-for-trait.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-impls-copy.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-impls-copy.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-impls-send.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-impls-send.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-impls-sized.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-impls-sized.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-inherited-assoc-ty-cycle-err.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-inherited-assoc-ty-cycle-err.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-lone-type-parameter.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-lone-type-parameter.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-negative-impls-safe.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-negative-impls-safe.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-no-direct-lifetime-dispatch.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-no-direct-lifetime-dispatch.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-orphan.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-orphan.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-all-t-and-tuple.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-all-t-and-tuple.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-downstream-inherent.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-downstream-inherent.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-downstream.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-downstream.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516-inherent.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516-inherent.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-issue-23516.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-messages.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-messages.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-upstream-inherent.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-upstream-inherent.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-upstream.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlap-upstream.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlapping-pairs.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-overlapping-pairs.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered-1.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered-1.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-pair-covered-uncovered.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-projection-conflict-orphan.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-projection-conflict-orphan.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-projection-conflict-ty-param.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-projection-conflict-ty-param.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-projection-conflict.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-projection-conflict.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-projection-ok-orphan.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-projection-ok.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-tuple-conflict.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-tuple-conflict.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-vec-local-2.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-vec-local-2.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence-vec-local.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence-vec-local.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_ref.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_tuple.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence_copy_like_err_fundamental_struct_tuple.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence_copy_like_err_struct.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence_copy_like_err_struct.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence_copy_like_err_tuple.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence_copy_like_err_tuple.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence_inherent.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence_inherent.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence_inherent_cc.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence_inherent_cc.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence_local.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence_local_err_struct.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence_local_err_struct.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence_local_err_tuple.rs create mode 100644 src/test/ui/re_rebalance_coherence/coherence_local_err_tuple.stderr create mode 100644 src/test/ui/re_rebalance_coherence/coherence_local_ref.rs 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 000000000000..d3d389c6a8bd --- /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 or the MIT license +// , 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); + +#[fundamental] +pub struct MyFundamentalStruct(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 000000000000..daa123849e4e --- /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 or the MIT license +// , 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 { + fn foo(&self, t: T) { } +} + +pub trait Remote2 { + fn foo(&self, t: T, u: U) { } +} + +pub struct Pair(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 000000000000..c8d027b25c74 --- /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(::std::marker::PhantomData); + +pub trait QueryFragment {} + + +#[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 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 000000000000..c436901a34f0 --- /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 or the MIT license +// , 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 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 000000000000..67fb9d1d335c --- /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 or the MIT license +// , 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 for Vec { } + +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 000000000000..7f8f27f39b1b --- /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 or the MIT license +// , 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 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 000000000000..5e0d61884f91 --- /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 or the MIT license +// , 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); + +impl Remote for Foo { } + +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 000000000000..2f8cbc032f2f --- /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 or the MIT license +// , 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 000000000000..b19bede74410 --- /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 or the MIT license +// , 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); + +impl Remote1 for Foo { } + +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 000000000000..5ce71f5d4227 --- /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 or the MIT license +// , 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); + +impl Remote1 for Foo { } + +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 000000000000..6dc1da3376b1 --- /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 or the MIT license +// , 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 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 000000000000..5e1a0e39e234 --- /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 or the MIT license +// , 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 000000000000..651e595bde12 --- /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 or the MIT license +// , 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 Mirror for T { type Image = T; } + +trait Bar {} +impl, L: Mirror> Bar for V + where U::Image: IsU32 {} + +trait Foo { fn name() -> &'static str; } +impl Foo for u64 { fn name() -> &'static str { "u64" } } +impl Foo for T { fn name() -> &'static str { "Bar" }} + +fn main() { + assert_eq!(::name(), "u64"); + assert_eq!(::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 000000000000..d9a9f580cfaf --- /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 or the MIT license +// , 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 000000000000..a7d3602a3cc6 --- /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 or the MIT license +// , 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 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, 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 000000000000..221095b148e0 --- /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 or the MIT license +// , 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 MyTrait for T { } +impl MyTrait for MyType { } +impl<'a> MyTrait for &'a MyType { } +impl MyTrait for Box { } +impl<'a> MyTrait for &'a Box { } + +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 000000000000..33ad4e975366 --- /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 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 000000000000..c8d027b25c74 --- /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(::std::marker::PhantomData); + +pub trait QueryFragment {} + + +#[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 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 000000000000..7031e6061edd --- /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 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 000000000000..7a79d0b1f2a6 --- /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`) + --> $DIR/feature-gate-re-rebalance-coherence.rs:10:1 + | +LL | impl<'a, T:'a, Tab> QueryFragment 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 000000000000..d3d389c6a8bd --- /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 or the MIT license +// , 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); + +#[fundamental] +pub struct MyFundamentalStruct(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 000000000000..0458636a401e --- /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 or the MIT license +// , 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 000000000000..daa123849e4e --- /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 or the MIT license +// , 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 { + fn foo(&self, t: T) { } +} + +pub trait Remote2 { + fn foo(&self, t: T, u: U) { } +} + +pub struct Pair(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 000000000000..b22d12300c7d --- /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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub trait TheTrait { + 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 000000000000..044bb606b40e --- /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 or the MIT license +// , 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(this: &G, arg: isize) { + this.go(arg) +} + +pub trait GoMut { + fn go_mut(&mut self, arg: isize); +} + +pub fn go_mut(this: &mut G, arg: isize) { + this.go_mut(arg) +} + +pub trait GoOnce { + fn go_once(self, arg: isize); +} + +pub fn go_once(this: G, arg: isize) { + this.go_once(arg) +} + +impl GoMut for G + where G : Go +{ + default fn go_mut(&mut self, arg: isize) { + go(&*self, arg) + } +} + +impl 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 000000000000..3190ce430ad6 --- /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 or the MIT license +// , 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 000000000000..0769518b36be --- /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 or the MIT license +// , 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 Remote1 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 000000000000..a6d5105cdc0e --- /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`) + --> $DIR/coherence-all-remote.rs:18:1 + | +LL | impl Remote1 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 000000000000..712fe9bdb4c7 --- /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 or the MIT license +// , 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 Remote1 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 000000000000..ed1540a303e6 --- /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`) + --> $DIR/coherence-bigint-param.rs:20:1 + | +LL | impl Remote1 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 000000000000..da0221c3e0af --- /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 or the MIT license +// , 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 MyTrait for T { + fn get(&self) -> usize { 0 } +} + +impl 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 000000000000..8d5d47877807 --- /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 MyTrait for T { + | -------------------------- first implementation here +... +LL | impl 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 000000000000..5e407588e2af --- /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 or the MIT license +// , 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 MyTrait for T { + fn get(&self) -> usize { 0 } +} + +impl 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 000000000000..6e7df5e6ed3b --- /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 MyTrait for T { + | -------------------------- first implementation here +... +LL | impl 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 000000000000..9d1caf929222 --- /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 or the MIT license +// , 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 000000000000..30656fa41b4f --- /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 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 000000000000..f866465bd081 --- /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 or the MIT license +// , 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 { + fn get(&self) -> T; +} + +impl MyTrait for T { + fn get(&self) -> T { + panic!() + } +} + +#[derive(Clone)] +struct MyType { + dummy: usize +} + +impl MyTrait 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 000000000000..f68e1fd94f0c --- /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` for type `MyType`: + --> $DIR/coherence-blanket-conflicts-with-specific-multidispatch.rs:34:1 + | +LL | impl 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-trait.rs b/src/test/ui/re_rebalance_coherence/coherence-blanket-conflicts-with-specific-trait.rs new file mode 100644 index 000000000000..74b458b838e0 --- /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 or the MIT license +// , 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 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 000000000000..bafeadcfcbef --- /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 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 000000000000..51de0e33034c --- /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 or the MIT license +// , 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 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 000000000000..efc32d123640 --- /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 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 000000000000..c2db97c68e8e --- /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 or the MIT license +// , 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(::std::marker::PhantomData); + +unsafe impl Send for TestType {} + +impl !Send for TestType {} +//~^ ERROR conflicting implementations of trait `std::marker::Send` + +unsafe impl Send for TestType {} + +impl !Send for TestType {} +//~^ 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 000000000000..7555e9996cf2 --- /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 Send for TestType {} + | ---------------------------------------------------- first implementation here +LL | +LL | impl !Send for TestType {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>` + +error[E0119]: conflicting implementations of trait `std::marker::Send` for type `TestType`: + --> $DIR/coherence-conflicting-negative-trait-impl.rs:26:1 + | +LL | unsafe impl Send for TestType {} + | ------------------------------------------- first implementation here +LL | +LL | impl !Send for TestType {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType` + +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 000000000000..09cc9801c14a --- /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 Remote for Pair> { } //[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 000000000000..7bb8378ee4ba --- /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 Remote for Pair,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 000000000000..6dbf0a44f02b --- /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 Remote for Pair,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 000000000000..da69d56a25a5 --- /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 or the MIT license +// , 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); + +#[cfg(a)] +impl Remote for Pair> { } //[a]~ ERROR E0117 + +#[cfg(b)] +impl Remote for Pair,T> { } //[b]~ ERROR E0117 + +#[cfg(c)] +impl Remote for Pair,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 000000000000..02624c70dc9d --- /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 or the MIT license +// , 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 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 000000000000..e4f8ba9868e4 --- /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 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`) + --> $DIR/coherence-cross-crate-conflict.rs:20:1 + | +LL | impl 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 000000000000..86dd0e4f74fb --- /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 or the MIT license +// , 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 000000000000..6c3d79cf53c1 --- /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 000000000000..24df1a1ee01f --- /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 or the MIT license +// , 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 000000000000..97ed46c71bd5 --- /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 000000000000..9e9a00af903d --- /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 or the MIT license +// , 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 000000000000..0f4f33e4eb9a --- /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 000000000000..0ed88058f1fb --- /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 or the MIT license +// , 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 000000000000..d529e86f8fc0 --- /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 000000000000..9f58d13efc2a --- /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 or the MIT license +// , 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 000000000000..80e2d203aaaa --- /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 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 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 000000000000..11b92d5254c4 --- /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 or the MIT license +// , 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 000000000000..8f09deeeb930 --- /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 000000000000..3f7970f34fc5 --- /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 or the MIT license +// , 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 000000000000..92b165bdc3b7 --- /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 000000000000..a2cfb11fdc23 --- /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 or the MIT license +// , 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 { type Assoc; } +//~^ cycle detected + +impl Trait for Vec { + type Assoc = (); +} + +impl Trait for Vec {} + +impl Trait for String { + type Assoc = (); +} + +impl Trait< as Trait>::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 000000000000..aca2d64b6231 --- /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 { 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 { 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 000000000000..8d3551beb5fc --- /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 or the MIT license +// , 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 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 000000000000..60ec7fb67def --- /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`) + --> $DIR/coherence-lone-type-parameter.rs:18:1 + | +LL | impl 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 000000000000..40f7ebfd2502 --- /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 or the MIT license +// , 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 000000000000..70a879efa27c --- /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 000000000000..838bc71d3afe --- /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 or the MIT license +// , 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 MyTrait for T {} +impl 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 000000000000..aa6427ba24f9 --- /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 MyTrait for T {} + | --------------------- first implementation here +LL | impl 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 000000000000..dbe26a8898d4 --- /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 or the MIT license +// , 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 for isize { } +//~^ ERROR E0117 + +impl TheTrait for isize { } + +impl TheTrait for TheType { } + +impl !Send for Vec { } +//~^ 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 000000000000..6e5e734401f4 --- /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 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 { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^ 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 000000000000..13604d9e4952 --- /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 or the MIT license +// , 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 { + fn foo() {} +} + +impl From for T { +} + +impl 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 000000000000..dc052931ed14 --- /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 From for T { + | ---------------------- first implementation here +... +LL | impl 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 000000000000..1f0ca50b60fc --- /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 or the MIT license +// , 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); +pub trait Sugar {} +pub trait Fruit {} +impl Sweet { fn dummy(&self) { } } +//~^ ERROR E0592 +impl Sweet { fn dummy(&self) { } } + +trait Bar {} +struct A(T, X); +impl A where T: Bar { fn f(&self) {} } +//~^ ERROR E0592 +impl A { 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 000000000000..8a817fcb4406 --- /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 Sweet { fn dummy(&self) { } } + | ^^^^^^^^^^^^^^^^^^^ duplicate definitions for `dummy` +LL | //~^ ERROR E0592 +LL | impl Sweet { fn dummy(&self) { } } + | ------------------- other definition for `dummy` + +error[E0592]: duplicate definitions with name `f` + --> $DIR/coherence-overlap-downstream-inherent.rs:25:38 + | +LL | impl A where T: Bar { fn f(&self) {} } + | ^^^^^^^^^^^^^^ duplicate definitions for `f` +LL | //~^ ERROR E0592 +LL | impl A { 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 000000000000..7a2b28f49b54 --- /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 or the MIT license +// , 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 Sweet for T { } +impl Sweet for T { } +//~^ ERROR E0119 + +pub trait Foo {} +pub trait Bar {} +impl Foo for T where T: Bar {} +impl Foo 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 000000000000..ce08ae15df13 --- /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 Sweet for T { } + | ------------------------- first implementation here +LL | impl Sweet for T { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation + +error[E0119]: conflicting implementations of trait `Foo<_>` for type `i32`: + --> $DIR/coherence-overlap-downstream.rs:26:1 + | +LL | impl Foo for T where T: Bar {} + | --------------------------------------- first implementation here +LL | impl Foo 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 000000000000..ff6af49dfb2e --- /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 or the MIT license +// , 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: !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); + +impl Cake { fn dummy(&self) { } } +//~^ ERROR E0592 +impl Cake> { 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 000000000000..26b59fbe71bd --- /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 Cake { fn dummy(&self) { } } + | ^^^^^^^^^^^^^^^^^^^ duplicate definitions for `dummy` +LL | //~^ ERROR E0592 +LL | impl Cake> { 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 000000000000..2e45572e4ecc --- /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 or the MIT license +// , 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: !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 Sweet for T { } +impl Sweet for Box { } +//~^ 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 000000000000..9d3d564b8a91 --- /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 Sweet for T { } + | ------------------------- first implementation here +LL | impl Sweet for Box { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 000000000000..1474fbd700c7 --- /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 or the MIT license +// , 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 Foo for T {} +impl Foo for U {} //~ ERROR conflicting implementations of trait `Foo`: + +trait Bar { fn bar() {} } + +impl Bar for (T, u8) {} +impl Bar for (u8, T) {} //~ ERROR conflicting implementations of trait `Bar` for type `(u8, u8)`: + +trait Baz { fn baz() {} } + +impl Baz for T {} +impl Baz for u8 {} //~ ERROR conflicting implementations of trait `Baz` for type `u8`: + +trait Quux { fn quux() {} } + +impl Quux for T {} +impl Quux for T {} //~ ERROR conflicting implementations of trait `Quux<_, _>`: +impl Quux 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 000000000000..c7b24e7bf6de --- /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 Foo for T {} + | ----------------- first implementation here +LL | impl 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 Bar for (T, u8) {} + | ----------------------- first implementation here +LL | impl 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` for type `u8`: + --> $DIR/coherence-overlap-messages.rs:26:1 + | +LL | impl Baz for T {} + | --------------------- first implementation here +LL | impl Baz for u8 {} //~ ERROR conflicting implementations of trait `Baz` for type `u8`: + | ^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `u8` + +error[E0119]: conflicting implementations of trait `Quux<_, _>`: + --> $DIR/coherence-overlap-messages.rs:31:1 + | +LL | impl Quux for T {} + | ------------------------------ first implementation here +LL | impl Quux 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 Quux for T {} + | ------------------------------ first implementation here +LL | impl Quux for T {} //~ ERROR conflicting implementations of trait `Quux<_, _>`: +LL | impl Quux 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 000000000000..e802c0113ad8 --- /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 or the MIT license +// , 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); +impl A where T: Remote { fn dummy(&self) { } } +//~^ ERROR E0592 +impl A { 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 000000000000..70b19ddb429a --- /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 A where T: Remote { fn dummy(&self) { } } + | ^^^^^^^^^^^^^^^^^^^ duplicate definitions for `dummy` +LL | //~^ ERROR E0592 +LL | impl A { 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 000000000000..afbc69cac330 --- /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 or the MIT license +// , 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 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 000000000000..88bea02b3481 --- /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 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 000000000000..25d8e3197f42 --- /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 or the MIT license +// , 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 Remote for lib::Pair { } +//~^ 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 000000000000..2629a017b793 --- /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 Remote for lib::Pair { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 000000000000..4edfd5e12270 --- /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 or the MIT license +// , 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); + +impl Remote1>> 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 000000000000..197056746b9c --- /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 Remote1>> 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 000000000000..9b0d7177ffcc --- /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 or the MIT license +// , 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); + +impl Remote for Pair> { } +//~^ 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 000000000000..b9e2eced94b1 --- /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 Remote for Pair> { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 000000000000..e3f945504feb --- /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 or the MIT license +// , 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

{ fn foo() {} } + +pub trait Bar { + type Output: 'static; +} + +impl Foo for i32 { } + +impl Foo 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 000000000000..81b134383734 --- /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` for type `i32`: + --> $DIR/coherence-projection-conflict-orphan.rs:27:1 + | +LL | impl Foo for i32 { } + | --------------------- first implementation here +LL | +LL | impl Foo 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 000000000000..cb5c94a18a72 --- /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 or the MIT license +// , 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

` or not +// for the second impl. + +use std::marker::PhantomData; + +pub trait Foo

{ fn foo() {} } + +impl > Foo

for Option {} + +impl Foo for Option { } //~ 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 000000000000..fe5a66ef9ea2 --- /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 > Foo

for Option {} + | ---------------------------------------- first implementation here +LL | +LL | impl Foo for Option { } //~ 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 000000000000..73adba0819e6 --- /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 or the MIT license +// , 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

{ fn foo() {} } + +pub trait Bar { + type Output: 'static; +} + +impl Foo for i32 { } + +impl Foo 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 000000000000..7f5ff3de1786 --- /dev/null +++ b/src/test/ui/re_rebalance_coherence/coherence-projection-conflict.stderr @@ -0,0 +1,12 @@ +error[E0119]: conflicting implementations of trait `Foo` for type `i32`: + --> $DIR/coherence-projection-conflict.rs:23:1 + | +LL | impl Foo for i32 { } + | --------------------- first implementation here +LL | +LL | impl Foo 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 000000000000..b02289dc68e5 --- /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 or the MIT license +// , 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

{} + +pub trait Bar { + type Output: 'static; +} + +struct Baz; +impl Foo for Baz { } + +impl Foo 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 000000000000..9c797b61a43b --- /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 or the MIT license +// , 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

{} + +pub trait Bar { + type Output: 'static; +} + +impl Foo for i32 { } + +impl Foo 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 000000000000..c6dda7f27731 --- /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 or the MIT license +// , 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 MyTrait for (T,T) { + fn get(&self) -> usize { 0 } +} + +impl 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 000000000000..bd4f2908cdfe --- /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 MyTrait for (T,T) { + | ------------------------- first implementation here +... +LL | impl 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 000000000000..6849f004c635 --- /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 or the MIT license +// , 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); + +impl Remote for Vec> { } //~ 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 000000000000..d507edbb0bde --- /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 Remote for Vec> { } //~ 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 000000000000..24a00febfd8f --- /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 or the MIT license +// , 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 { } //~ 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 000000000000..fc400da71155 --- /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 { } //~ 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 000000000000..5e09cf69a61a --- /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 or the MIT license +// , 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 MyTrait for T { } + +// `MyFundamentalStruct` is declared fundamental, so we can test that +// +// MyFundamentalStruct: !MyTrait +// +// Huzzah. +impl MyTrait for lib::MyFundamentalStruct { } + + +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 000000000000..8e5d2bf4cf7b --- /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 or the MIT license +// , 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 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 000000000000..e7a8edbd2214 --- /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 or the MIT license +// , 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 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 000000000000..e6adc08c28c3 --- /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 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 000000000000..3f91750104b9 --- /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 or the MIT license +// , 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 MyTrait for T { } + +// `MyStruct` is not declared fundamental, therefore this would +// require that +// +// MyStruct: !MyTrait +// +// which we cannot approve. +impl MyTrait for lib::MyStruct { } //~ 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 000000000000..a40ae4fc4488 --- /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`: + --> $DIR/coherence_copy_like_err_struct.rs:31:1 + | +LL | impl MyTrait for T { } + | ---------------------------------- first implementation here +... +LL | impl MyTrait for lib::MyStruct { } //~ ERROR E0119 + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `lib::MyStruct` + | + = note: upstream crates may add new impl of trait `lib::MyCopy` for type `lib::MyStruct` 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 000000000000..0e7eef6fe6de --- /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 or the MIT license +// , 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 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 000000000000..82e43f6d721e --- /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 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 000000000000..d4d29326e4f7 --- /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 or the MIT license +// , 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 000000000000..9294899bfee5 --- /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 000000000000..beb60f57a2a2 --- /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 or the MIT license +// , 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 000000000000..bf67313879b7 --- /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 000000000000..7f72ff7af888 --- /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 or the MIT license +// , 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 { } +impl lib::MyCopy for Box { } +impl lib::MyCopy for lib::MyFundamentalStruct { } +impl lib::MyCopy for lib::MyFundamentalStruct> { } + + +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 000000000000..3d7145e489d1 --- /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 or the MIT license +// , 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 { } //~ 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 000000000000..c35e95040de1 --- /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 { } //~ 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 000000000000..f2c9008dd8ca --- /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 or the MIT license +// , 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 000000000000..a3f9f2d32b8f --- /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 000000000000..b15a5cc245bf --- /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 or the MIT license +// , 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() { }