Auto merge of #68544 - Aaron1011:remove-overlapping-traits, r=estebank
Remove the `overlapping_marker_traits` feature See #29864 This has been replaced by `#[feature(marker_trait_attr)]` A few notes: * Due to PR #68057 not yet being in the bootstrap compiler, it's necessary to continue using `#![feature(overlapping_marker_traits)]` under `#[cfg(bootstrap)]` to work around type inference issues. * I've updated tests that used `overlapping_marker_traits` to now use `marker_trait_attr` where applicable The test `src/test/ui/overlap-marker-trait.rs` doesn't make any sense now that `overlapping_marker_traits`, so I removed it. The test `src/test/ui/traits/overlap-permitted-for-marker-traits-neg.rs` now fails, since it's no longer possible to have multiple overlapping negative impls of `Send`. I believe that this is the behavior we want (assuming that `Send` is not going to become a `#[marker]` trait, so I renamed the test to `overlap-permitted-for-marker-traits-neg`
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#![feature(optin_builtin_traits)]
|
||||
#![feature(overlapping_marker_traits)]
|
||||
#![feature(marker_trait_attr)]
|
||||
|
||||
#[marker]
|
||||
trait MyTrait {}
|
||||
|
||||
struct TestType<T>(::std::marker::PhantomData<T>);
|
||||
@@ -8,11 +9,11 @@ struct TestType<T>(::std::marker::PhantomData<T>);
|
||||
unsafe impl<T: MyTrait+'static> Send for TestType<T> {}
|
||||
|
||||
impl<T: MyTrait> !Send for TestType<T> {}
|
||||
//~^ ERROR E0119
|
||||
//~^ ERROR conflicting implementations
|
||||
|
||||
unsafe impl<T:'static> Send for TestType<T> {}
|
||||
//~^ ERROR conflicting implementations
|
||||
|
||||
impl !Send for TestType<i32> {}
|
||||
//~^ ERROR E0119
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
error[E0119]: conflicting implementations of trait `std::marker::Send` for type `TestType<_>`:
|
||||
--> $DIR/coherence-conflicting-negative-trait-impl.rs:10:1
|
||||
--> $DIR/coherence-conflicting-negative-trait-impl.rs:11:1
|
||||
|
|
||||
LL | unsafe impl<T: MyTrait+'static> Send for TestType<T> {}
|
||||
| ---------------------------------------------------- first implementation here
|
||||
@@ -7,14 +7,14 @@ LL |
|
||||
LL | impl<T: MyTrait> !Send for TestType<T> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>`
|
||||
|
||||
error[E0119]: conflicting implementations of trait `std::marker::Send` for type `TestType<i32>`:
|
||||
--> $DIR/coherence-conflicting-negative-trait-impl.rs:15:1
|
||||
error[E0119]: conflicting implementations of trait `std::marker::Send` for type `TestType<_>`:
|
||||
--> $DIR/coherence-conflicting-negative-trait-impl.rs:14:1
|
||||
|
|
||||
LL | unsafe impl<T: MyTrait+'static> Send for TestType<T> {}
|
||||
| ---------------------------------------------------- first implementation here
|
||||
...
|
||||
LL | unsafe impl<T:'static> Send for TestType<T> {}
|
||||
| ------------------------------------------- first implementation here
|
||||
LL |
|
||||
LL | impl !Send for TestType<i32> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<i32>`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#![feature(optin_builtin_traits)]
|
||||
#![feature(overlapping_marker_traits)]
|
||||
|
||||
use std::marker::Copy;
|
||||
|
||||
@@ -24,7 +23,8 @@ unsafe impl Send for [MyType] {}
|
||||
//~^ ERROR E0117
|
||||
|
||||
unsafe impl Send for &'static [NotSync] {}
|
||||
//~^ ERROR E0117
|
||||
//~^ ERROR conflicting implementations of trait
|
||||
//~| ERROR only traits defined in the current crate
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
error[E0119]: conflicting implementations of trait `std::marker::Send` for type `&[NotSync]`:
|
||||
--> $DIR/coherence-impls-send.rs:25:1
|
||||
|
|
||||
LL | unsafe impl Send for &'static [NotSync] {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: conflicting implementation in crate `core`:
|
||||
- impl<T> std::marker::Send for &T
|
||||
where T: std::marker::Sync, T: ?Sized;
|
||||
= note: upstream crates may add a new impl of trait `std::marker::Sync` for type `[NotSync]` in future versions
|
||||
|
||||
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
|
||||
--> $DIR/coherence-impls-send.rs:17:1
|
||||
--> $DIR/coherence-impls-send.rs:16:1
|
||||
|
|
||||
LL | unsafe impl Send for (MyType, MyType) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^----------------
|
||||
@@ -10,13 +21,13 @@ LL | unsafe impl Send for (MyType, MyType) {}
|
||||
= 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:20:1
|
||||
--> $DIR/coherence-impls-send.rs:19: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:23:1
|
||||
--> $DIR/coherence-impls-send.rs:22:1
|
||||
|
|
||||
LL | unsafe impl Send for [MyType] {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^--------
|
||||
@@ -27,7 +38,7 @@ LL | unsafe impl Send for [MyType] {}
|
||||
= 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:26:1
|
||||
--> $DIR/coherence-impls-send.rs:25:1
|
||||
|
|
||||
LL | unsafe impl Send for &'static [NotSync] {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^------------------
|
||||
@@ -37,7 +48,7 @@ LL | unsafe impl Send for &'static [NotSync] {}
|
||||
|
|
||||
= note: define and implement a trait or new type instead
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0117, E0321.
|
||||
Some errors have detailed explanations: E0117, E0119, E0321.
|
||||
For more information about an error, try `rustc --explain E0117`.
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// run-pass
|
||||
|
||||
#![feature(overlapping_marker_traits)]
|
||||
#![feature(marker_trait_attr)]
|
||||
#![feature(specialization)]
|
||||
|
||||
#[marker]
|
||||
trait MyMarker {}
|
||||
|
||||
impl<T> MyMarker for T {}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
// Test for RFC 1268: we allow overlapping impls of marker traits,
|
||||
// that is, traits without items. In this case, a type `T` is
|
||||
// `MyMarker` if it is either `Debug` or `Display`. This test just
|
||||
// checks that we don't consider **all** types to be `MyMarker`. See
|
||||
// also the companion test in
|
||||
// `run-pass/overlap-permitted-for-marker-traits.rs`.
|
||||
|
||||
#![feature(overlapping_marker_traits)]
|
||||
#![feature(optin_builtin_traits)]
|
||||
|
||||
use std::fmt::{Debug, Display};
|
||||
|
||||
trait Marker {}
|
||||
|
||||
impl<T: Debug> Marker for T {}
|
||||
impl<T: Display> Marker for T {}
|
||||
|
||||
fn is_marker<T: Marker>() { }
|
||||
|
||||
struct NotDebugOrDisplay;
|
||||
|
||||
fn main() {
|
||||
// Debug && Display:
|
||||
is_marker::<i32>();
|
||||
|
||||
// Debug && !Display:
|
||||
is_marker::<Vec<i32>>();
|
||||
|
||||
// !Debug && !Display
|
||||
is_marker::<NotDebugOrDisplay>(); //~ ERROR
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
error[E0277]: the trait bound `NotDebugOrDisplay: Marker` is not satisfied
|
||||
--> $DIR/overlap-marker-trait.rs:30:17
|
||||
|
|
||||
LL | fn is_marker<T: Marker>() { }
|
||||
| --------- ------ required by this bound in `is_marker`
|
||||
...
|
||||
LL | is_marker::<NotDebugOrDisplay>();
|
||||
| ^^^^^^^^^^^^^^^^^ the trait `Marker` is not implemented for `NotDebugOrDisplay`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
@@ -1,12 +1,11 @@
|
||||
// run-pass
|
||||
#![allow(dead_code)]
|
||||
#![feature(overlapping_marker_traits)]
|
||||
#![feature(optin_builtin_traits)]
|
||||
|
||||
// Overlapping negative impls for `MyStruct` are permitted:
|
||||
// Overlapping negative impls for `MyStruct` are not permitted:
|
||||
struct MyStruct;
|
||||
impl !Send for MyStruct {}
|
||||
impl !Send for MyStruct {}
|
||||
//~^ ERROR conflicting implementations of trait
|
||||
|
||||
fn main() {
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
error[E0119]: conflicting implementations of trait `std::marker::Send` for type `MyStruct`:
|
||||
--> $DIR/overlap-not-permitted-for-builtin-trait.rs:7:1
|
||||
|
|
||||
LL | impl !Send for MyStruct {}
|
||||
| ----------------------- first implementation here
|
||||
LL | impl !Send for MyStruct {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyStruct`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0119`.
|
||||
@@ -1,27 +0,0 @@
|
||||
// run-pass
|
||||
// Tests for RFC 1268: we allow overlapping impls of marker traits,
|
||||
// that is, traits without items. In this case, a type `T` is
|
||||
// `MyMarker` if it is either `Debug` or `Display`.
|
||||
|
||||
#![feature(overlapping_marker_traits)]
|
||||
#![feature(optin_builtin_traits)]
|
||||
|
||||
use std::fmt::{Debug, Display};
|
||||
|
||||
trait MyMarker {}
|
||||
|
||||
impl<T: Debug> MyMarker for T {}
|
||||
impl<T: Display> MyMarker for T {}
|
||||
|
||||
fn foo<T: MyMarker>(t: T) -> T {
|
||||
t
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Debug && Display:
|
||||
assert_eq!(1, foo(1));
|
||||
assert_eq!(2.0, foo(2.0));
|
||||
|
||||
// Debug && !Display:
|
||||
assert_eq!(vec![1], foo(vec![1]));
|
||||
}
|
||||
Reference in New Issue
Block a user