Skip to content

Commit

Permalink
Auto merge of #68544 - Aaron1011:remove-overlapping-traits, r=estebank
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
bors committed Feb 4, 2020
2 parents c9290dc + 302f8c9 commit 002287d
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 109 deletions.
1 change: 1 addition & 0 deletions src/librustc/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ arena_types!(declare_arena, [], 'tcx);

arena_types!(impl_arena_allocatable, [], 'tcx);

#[marker]
pub trait ArenaAllocatable {}

impl<T: Copy> ArenaAllocatable for T {}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#![feature(drain_filter)]
#![feature(never_type)]
#![feature(exhaustive_patterns)]
#![feature(overlapping_marker_traits)]
#![feature(marker_trait_attr)]
#![feature(extern_types)]
#![feature(nll)]
#![feature(optin_builtin_traits)]
Expand Down
14 changes: 2 additions & 12 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2647,9 +2647,7 @@ impl<'tcx> ::std::ops::Deref for Attributes<'tcx> {
pub enum ImplOverlapKind {
/// These impls are always allowed to overlap.
Permitted {
/// Whether or not the impl is permitted due to the trait being
/// a marker trait (a trait with #[marker], or a trait with
/// no associated items and #![feature(overlapping_marker_traits)] enabled)
/// Whether or not the impl is permitted due to the trait being a `#[marker]` trait
marker: bool,
},
/// These impls are allowed to overlap, but that raises
Expand Down Expand Up @@ -2796,15 +2794,7 @@ impl<'tcx> TyCtxt<'tcx> {
| (ImplPolarity::Negative, ImplPolarity::Negative) => {}
};

let is_marker_overlap = if self.features().overlapping_marker_traits {
let trait1_is_empty = self.impl_trait_ref(def_id1).map_or(false, |trait_ref| {
self.associated_item_def_ids(trait_ref.def_id).is_empty()
});
let trait2_is_empty = self.impl_trait_ref(def_id2).map_or(false, |trait_ref| {
self.associated_item_def_ids(trait_ref.def_id).is_empty()
});
trait1_is_empty && trait2_is_empty
} else {
let is_marker_overlap = {
let is_marker_impl = |def_id: DefId| -> bool {
let trait_ref = self.impl_trait_ref(def_id);
trait_ref.map_or(false, |tr| self.trait_def(tr.def_id).is_marker)
Expand Down
3 changes: 0 additions & 3 deletions src/librustc_feature/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,6 @@ declare_features! (
/// Allows `extern "x86-interrupt" fn()`.
(active, abi_x86_interrupt, "1.17.0", Some(40180), None),

/// Allows overlapping impls of marker traits.
(active, overlapping_marker_traits, "1.18.0", Some(29864), None),

/// Allows a test to fail without failing the whole suite.
(active, allow_fail, "1.19.0", Some(46488), None),

Expand Down
4 changes: 3 additions & 1 deletion src/librustc_feature/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ declare_features! (
/// Allows using `#[on_unimplemented(..)]` on traits.
/// (Moved to `rustc_attrs`.)
(removed, on_unimplemented, "1.40.0", None, None, None),

/// Allows overlapping impls of marker traits.
(removed, overlapping_marker_traits, "1.42.0", Some(29864), None,
Some("removed in favor of `#![feature(marker_trait_attr)]`")),
// -------------------------------------------------------------------------
// feature-group-end: removed features
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#![feature(optin_builtin_traits)]
#![feature(overlapping_marker_traits)]
#![feature(marker_trait_attr)]

#[marker]
trait MyTrait {}

struct TestType<T>(::std::marker::PhantomData<T>);

unsafe impl<T: MyTrait+'static> Send for TestType<T> {}

impl<T: MyTrait> !Send for TestType<T> {}
//~^ ERROR E0119
//~^ ERROR conflicting implementations

unsafe impl<T:'static> Send for TestType<T> {}
//~^ ERROR conflicting implementations

impl !Send for TestType<i32> {}
//~^ ERROR E0119

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
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
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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/coherence/coherence-impls-send.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(optin_builtin_traits)]
#![feature(overlapping_marker_traits)]

use std::marker::Copy;

Expand All @@ -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() {
}
23 changes: 17 additions & 6 deletions src/test/ui/coherence/coherence-impls-send.stderr
Original file line number Diff line number Diff line change
@@ -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) {}
| ^^^^^^^^^^^^^^^^^^^^^----------------
Expand All @@ -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] {}
| ^^^^^^^^^^^^^^^^^^^^^--------
Expand All @@ -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] {}
| ^^^^^^^^^^^^^^^^^^^^^------------------
Expand All @@ -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`.
3 changes: 2 additions & 1 deletion src/test/ui/overlap-doesnt-conflict-with-specialization.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// run-pass

#![feature(overlapping_marker_traits)]
#![feature(marker_trait_attr)]
#![feature(specialization)]

#[marker]
trait MyMarker {}

impl<T> MyMarker for T {}
Expand Down
31 changes: 0 additions & 31 deletions src/test/ui/overlap-marker-trait.rs

This file was deleted.

12 changes: 0 additions & 12 deletions src/test/ui/overlap-marker-trait.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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() {
}
11 changes: 11 additions & 0 deletions src/test/ui/traits/overlap-not-permitted-for-builtin-trait.stderr
Original file line number Diff line number Diff line change
@@ -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`.
27 changes: 0 additions & 27 deletions src/test/ui/traits/overlap-permitted-for-marker-traits.rs

This file was deleted.

0 comments on commit 002287d

Please sign in to comment.