Skip to content

Commit b411994

Browse files
nikomatsakisAlexander Regueiro
and
Alexander Regueiro
committed
new trait alias tests
Co-authored-by: Alexander Regueiro <[email protected]>
1 parent 1336b8e commit b411994

6 files changed

+122
-0
lines changed

src/test/ui/issues/issue-56488.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// run-pass
2+
3+
#![feature(trait_alias)]
4+
5+
mod alpha {
6+
pub trait A {}
7+
pub trait C = A;
8+
}
9+
10+
#[allow(unused_imports)]
11+
use alpha::C;
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// ignore-tidy-linelength
2+
3+
trait Foo {}
4+
5+
impl Foo for dyn Send {}
6+
7+
impl Foo for dyn Send + Send {}
8+
//~^ ERROR conflicting implementations
9+
//~| hard error
10+
11+
impl Foo for dyn Send + Sync {}
12+
13+
impl Foo for dyn Sync + Send {}
14+
//~^ ERROR conflicting implementations
15+
//~| hard error
16+
17+
impl Foo for dyn Send + Sync + Send {}
18+
//~^ ERROR conflicting implementations
19+
//~| hard error
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error: conflicting implementations of trait `Foo` for type `(dyn std::marker::Send + 'static)`: (E0119)
2+
--> $DIR/lint-incoherent-auto-trait-objects.rs:7:1
3+
|
4+
LL | impl Foo for dyn Send {}
5+
| --------------------- first implementation here
6+
LL |
7+
LL | impl Foo for dyn Send + Send {}
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + 'static)`
9+
|
10+
= note: #[deny(order_dependent_trait_objects)] on by default
11+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
12+
= note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
13+
14+
error: conflicting implementations of trait `Foo` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119)
15+
--> $DIR/lint-incoherent-auto-trait-objects.rs:13:1
16+
|
17+
LL | impl Foo for dyn Send + Sync {}
18+
| ---------------------------- first implementation here
19+
LL |
20+
LL | impl Foo for dyn Sync + Send {}
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)`
22+
|
23+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
24+
= note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
25+
26+
error: conflicting implementations of trait `Foo` for type `(dyn std::marker::Send + std::marker::Sync + 'static)`: (E0119)
27+
--> $DIR/lint-incoherent-auto-trait-objects.rs:17:1
28+
|
29+
LL | impl Foo for dyn Sync + Send {}
30+
| ---------------------------- first implementation here
31+
...
32+
LL | impl Foo for dyn Send + Sync + Send {}
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `(dyn std::marker::Send + std::marker::Sync + 'static)`
34+
|
35+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
36+
= note: for more information, see issue #56484 <https://github.com/rust-lang/rust/issues/56484>
37+
38+
error: aborting due to 3 previous errors
39+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![feature(trait_alias)]
2+
3+
pub trait SendSync = Send + Sync;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// aux-build:trait_alias.rs
2+
3+
#![feature(trait_alias)]
4+
5+
extern crate trait_alias;
6+
7+
use std::rc::Rc;
8+
use trait_alias::SendSync;
9+
10+
fn use_alias<T: SendSync>() {}
11+
12+
fn main() {
13+
use_alias::<u32>();
14+
use_alias::<Rc<u32>>();
15+
//~^ ERROR `std::rc::Rc<u32>` cannot be sent between threads safely [E0277]
16+
//~^^ ERROR `std::rc::Rc<u32>` cannot be shared between threads safely [E0277]
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0277]: `std::rc::Rc<u32>` cannot be sent between threads safely
2+
--> $DIR/trait-alias-cross-crate.rs:14:5
3+
|
4+
LL | use_alias::<Rc<u32>>();
5+
| ^^^^^^^^^^^^^^^^^^^^ `std::rc::Rc<u32>` cannot be sent between threads safely
6+
|
7+
= help: the trait `std::marker::Send` is not implemented for `std::rc::Rc<u32>`
8+
note: required by `use_alias`
9+
--> $DIR/trait-alias-cross-crate.rs:10:1
10+
|
11+
LL | fn use_alias<T: SendSync>() {}
12+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
13+
14+
error[E0277]: `std::rc::Rc<u32>` cannot be shared between threads safely
15+
--> $DIR/trait-alias-cross-crate.rs:14:5
16+
|
17+
LL | use_alias::<Rc<u32>>();
18+
| ^^^^^^^^^^^^^^^^^^^^ `std::rc::Rc<u32>` cannot be shared between threads safely
19+
|
20+
= help: the trait `std::marker::Sync` is not implemented for `std::rc::Rc<u32>`
21+
note: required by `use_alias`
22+
--> $DIR/trait-alias-cross-crate.rs:10:1
23+
|
24+
LL | fn use_alias<T: SendSync>() {}
25+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
26+
27+
error: aborting due to 2 previous errors
28+
29+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)