From b411994b3b9a571db486cb7de9ea06b071a22b6c Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 10 Jan 2019 16:56:05 -0500 Subject: [PATCH] new trait alias tests Co-authored-by: Alexander Regueiro --- src/test/ui/issues/issue-56488.rs | 13 +++++++ .../lint-incoherent-auto-trait-objects.rs | 21 ++++++++++ .../lint-incoherent-auto-trait-objects.stderr | 39 +++++++++++++++++++ src/test/ui/traits/auxiliary/trait_alias.rs | 3 ++ src/test/ui/traits/trait-alias-cross-crate.rs | 17 ++++++++ .../ui/traits/trait-alias-cross-crate.stderr | 29 ++++++++++++++ 6 files changed, 122 insertions(+) create mode 100644 src/test/ui/issues/issue-56488.rs create mode 100644 src/test/ui/lint/lint-incoherent-auto-trait-objects.rs create mode 100644 src/test/ui/lint/lint-incoherent-auto-trait-objects.stderr create mode 100644 src/test/ui/traits/auxiliary/trait_alias.rs create mode 100644 src/test/ui/traits/trait-alias-cross-crate.rs create mode 100644 src/test/ui/traits/trait-alias-cross-crate.stderr diff --git a/src/test/ui/issues/issue-56488.rs b/src/test/ui/issues/issue-56488.rs new file mode 100644 index 0000000000000..e2f3996927b7f --- /dev/null +++ b/src/test/ui/issues/issue-56488.rs @@ -0,0 +1,13 @@ +// run-pass + +#![feature(trait_alias)] + +mod alpha { + pub trait A {} + pub trait C = A; +} + +#[allow(unused_imports)] +use alpha::C; + +fn main() {} diff --git a/src/test/ui/lint/lint-incoherent-auto-trait-objects.rs b/src/test/ui/lint/lint-incoherent-auto-trait-objects.rs new file mode 100644 index 0000000000000..0d18965ee7338 --- /dev/null +++ b/src/test/ui/lint/lint-incoherent-auto-trait-objects.rs @@ -0,0 +1,21 @@ +// ignore-tidy-linelength + +trait Foo {} + +impl Foo for dyn Send {} + +impl Foo for dyn Send + Send {} +//~^ ERROR conflicting implementations +//~| hard error + +impl Foo for dyn Send + Sync {} + +impl Foo for dyn Sync + Send {} +//~^ ERROR conflicting implementations +//~| hard error + +impl Foo for dyn Send + Sync + Send {} +//~^ ERROR conflicting implementations +//~| hard error + +fn main() {} diff --git a/src/test/ui/lint/lint-incoherent-auto-trait-objects.stderr b/src/test/ui/lint/lint-incoherent-auto-trait-objects.stderr new file mode 100644 index 0000000000000..928c92ef91655 --- /dev/null +++ b/src/test/ui/lint/lint-incoherent-auto-trait-objects.stderr @@ -0,0 +1,39 @@ +error: conflicting implementations of trait `Foo` for type `(dyn std::marker::Send + 'static)`: (E0119) + --> $DIR/lint-incoherent-auto-trait-objects.rs:7:1 + | +LL | impl Foo for dyn Send {} + | --------------------- first implementation here +LL | +LL | impl Foo for dyn Send + Send {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + 'static)` + | + = note: #[deny(order_dependent_trait_objects)] on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #56484 + +error: conflicting implementations of trait `Foo` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119) + --> $DIR/lint-incoherent-auto-trait-objects.rs:13:1 + | +LL | impl Foo for dyn Send + Sync {} + | ---------------------------- first implementation here +LL | +LL | impl Foo for dyn Sync + Send {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #56484 + +error: conflicting implementations of trait `Foo` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119) + --> $DIR/lint-incoherent-auto-trait-objects.rs:17:1 + | +LL | impl Foo for dyn Sync + Send {} + | ---------------------------- first implementation here +... +LL | impl Foo for dyn Send + Sync + Send {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #56484 + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/traits/auxiliary/trait_alias.rs b/src/test/ui/traits/auxiliary/trait_alias.rs new file mode 100644 index 0000000000000..9e56b87e08813 --- /dev/null +++ b/src/test/ui/traits/auxiliary/trait_alias.rs @@ -0,0 +1,3 @@ +#![feature(trait_alias)] + +pub trait SendSync = Send + Sync; diff --git a/src/test/ui/traits/trait-alias-cross-crate.rs b/src/test/ui/traits/trait-alias-cross-crate.rs new file mode 100644 index 0000000000000..259fc4fa5d1ce --- /dev/null +++ b/src/test/ui/traits/trait-alias-cross-crate.rs @@ -0,0 +1,17 @@ +// aux-build:trait_alias.rs + +#![feature(trait_alias)] + +extern crate trait_alias; + +use std::rc::Rc; +use trait_alias::SendSync; + +fn use_alias() {} + +fn main() { + use_alias::(); + use_alias::>(); + //~^ ERROR `std::rc::Rc` cannot be sent between threads safely [E0277] + //~^^ ERROR `std::rc::Rc` cannot be shared between threads safely [E0277] +} diff --git a/src/test/ui/traits/trait-alias-cross-crate.stderr b/src/test/ui/traits/trait-alias-cross-crate.stderr new file mode 100644 index 0000000000000..972d213ac8f8f --- /dev/null +++ b/src/test/ui/traits/trait-alias-cross-crate.stderr @@ -0,0 +1,29 @@ +error[E0277]: `std::rc::Rc` cannot be sent between threads safely + --> $DIR/trait-alias-cross-crate.rs:14:5 + | +LL | use_alias::>(); + | ^^^^^^^^^^^^^^^^^^^^ `std::rc::Rc` cannot be sent between threads safely + | + = help: the trait `std::marker::Send` is not implemented for `std::rc::Rc` +note: required by `use_alias` + --> $DIR/trait-alias-cross-crate.rs:10:1 + | +LL | fn use_alias() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0277]: `std::rc::Rc` cannot be shared between threads safely + --> $DIR/trait-alias-cross-crate.rs:14:5 + | +LL | use_alias::>(); + | ^^^^^^^^^^^^^^^^^^^^ `std::rc::Rc` cannot be shared between threads safely + | + = help: the trait `std::marker::Sync` is not implemented for `std::rc::Rc` +note: required by `use_alias` + --> $DIR/trait-alias-cross-crate.rs:10:1 + | +LL | fn use_alias() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`.