Skip to content

Commit 002287d

Browse files
committed
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`
2 parents c9290dc + 302f8c9 commit 002287d

15 files changed

+52
-109
lines changed

src/librustc/arena.rs

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ arena_types!(declare_arena, [], 'tcx);
216216

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

219+
#[marker]
219220
pub trait ArenaAllocatable {}
220221

221222
impl<T: Copy> ArenaAllocatable for T {}

src/librustc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#![feature(drain_filter)]
3737
#![feature(never_type)]
3838
#![feature(exhaustive_patterns)]
39-
#![feature(overlapping_marker_traits)]
39+
#![feature(marker_trait_attr)]
4040
#![feature(extern_types)]
4141
#![feature(nll)]
4242
#![feature(optin_builtin_traits)]

src/librustc/ty/mod.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -2647,9 +2647,7 @@ impl<'tcx> ::std::ops::Deref for Attributes<'tcx> {
26472647
pub enum ImplOverlapKind {
26482648
/// These impls are always allowed to overlap.
26492649
Permitted {
2650-
/// Whether or not the impl is permitted due to the trait being
2651-
/// a marker trait (a trait with #[marker], or a trait with
2652-
/// no associated items and #![feature(overlapping_marker_traits)] enabled)
2650+
/// Whether or not the impl is permitted due to the trait being a `#[marker]` trait
26532651
marker: bool,
26542652
},
26552653
/// These impls are allowed to overlap, but that raises
@@ -2796,15 +2794,7 @@ impl<'tcx> TyCtxt<'tcx> {
27962794
| (ImplPolarity::Negative, ImplPolarity::Negative) => {}
27972795
};
27982796

2799-
let is_marker_overlap = if self.features().overlapping_marker_traits {
2800-
let trait1_is_empty = self.impl_trait_ref(def_id1).map_or(false, |trait_ref| {
2801-
self.associated_item_def_ids(trait_ref.def_id).is_empty()
2802-
});
2803-
let trait2_is_empty = self.impl_trait_ref(def_id2).map_or(false, |trait_ref| {
2804-
self.associated_item_def_ids(trait_ref.def_id).is_empty()
2805-
});
2806-
trait1_is_empty && trait2_is_empty
2807-
} else {
2797+
let is_marker_overlap = {
28082798
let is_marker_impl = |def_id: DefId| -> bool {
28092799
let trait_ref = self.impl_trait_ref(def_id);
28102800
trait_ref.map_or(false, |tr| self.trait_def(tr.def_id).is_marker)

src/librustc_feature/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,6 @@ declare_features! (
344344
/// Allows `extern "x86-interrupt" fn()`.
345345
(active, abi_x86_interrupt, "1.17.0", Some(40180), None),
346346

347-
/// Allows overlapping impls of marker traits.
348-
(active, overlapping_marker_traits, "1.18.0", Some(29864), None),
349-
350347
/// Allows a test to fail without failing the whole suite.
351348
(active, allow_fail, "1.19.0", Some(46488), None),
352349

src/librustc_feature/removed.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ declare_features! (
108108
/// Allows using `#[on_unimplemented(..)]` on traits.
109109
/// (Moved to `rustc_attrs`.)
110110
(removed, on_unimplemented, "1.40.0", None, None, None),
111-
111+
/// Allows overlapping impls of marker traits.
112+
(removed, overlapping_marker_traits, "1.42.0", Some(29864), None,
113+
Some("removed in favor of `#![feature(marker_trait_attr)]`")),
112114
// -------------------------------------------------------------------------
113115
// feature-group-end: removed features
114116
// -------------------------------------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
#![feature(optin_builtin_traits)]
2-
#![feature(overlapping_marker_traits)]
2+
#![feature(marker_trait_attr)]
33

4+
#[marker]
45
trait MyTrait {}
56

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

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

1011
impl<T: MyTrait> !Send for TestType<T> {}
11-
//~^ ERROR E0119
12+
//~^ ERROR conflicting implementations
1213

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

1517
impl !Send for TestType<i32> {}
16-
//~^ ERROR E0119
1718

1819
fn main() {}

src/test/ui/coherence/coherence-conflicting-negative-trait-impl.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
error[E0119]: conflicting implementations of trait `std::marker::Send` for type `TestType<_>`:
2-
--> $DIR/coherence-conflicting-negative-trait-impl.rs:10:1
2+
--> $DIR/coherence-conflicting-negative-trait-impl.rs:11:1
33
|
44
LL | unsafe impl<T: MyTrait+'static> Send for TestType<T> {}
55
| ---------------------------------------------------- first implementation here
66
LL |
77
LL | impl<T: MyTrait> !Send for TestType<T> {}
88
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>`
99

10-
error[E0119]: conflicting implementations of trait `std::marker::Send` for type `TestType<i32>`:
11-
--> $DIR/coherence-conflicting-negative-trait-impl.rs:15:1
10+
error[E0119]: conflicting implementations of trait `std::marker::Send` for type `TestType<_>`:
11+
--> $DIR/coherence-conflicting-negative-trait-impl.rs:14:1
1212
|
13+
LL | unsafe impl<T: MyTrait+'static> Send for TestType<T> {}
14+
| ---------------------------------------------------- first implementation here
15+
...
1316
LL | unsafe impl<T:'static> Send for TestType<T> {}
14-
| ------------------------------------------- first implementation here
15-
LL |
16-
LL | impl !Send for TestType<i32> {}
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<i32>`
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>`
1818

1919
error: aborting due to 2 previous errors
2020

src/test/ui/coherence/coherence-impls-send.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(optin_builtin_traits)]
2-
#![feature(overlapping_marker_traits)]
32

43
use std::marker::Copy;
54

@@ -24,7 +23,8 @@ unsafe impl Send for [MyType] {}
2423
//~^ ERROR E0117
2524

2625
unsafe impl Send for &'static [NotSync] {}
27-
//~^ ERROR E0117
26+
//~^ ERROR conflicting implementations of trait
27+
//~| ERROR only traits defined in the current crate
2828

2929
fn main() {
3030
}

src/test/ui/coherence/coherence-impls-send.stderr

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
error[E0119]: conflicting implementations of trait `std::marker::Send` for type `&[NotSync]`:
2+
--> $DIR/coherence-impls-send.rs:25:1
3+
|
4+
LL | unsafe impl Send for &'static [NotSync] {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: conflicting implementation in crate `core`:
8+
- impl<T> std::marker::Send for &T
9+
where T: std::marker::Sync, T: ?Sized;
10+
= note: upstream crates may add a new impl of trait `std::marker::Sync` for type `[NotSync]` in future versions
11+
112
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
2-
--> $DIR/coherence-impls-send.rs:17:1
13+
--> $DIR/coherence-impls-send.rs:16:1
314
|
415
LL | unsafe impl Send for (MyType, MyType) {}
516
| ^^^^^^^^^^^^^^^^^^^^^----------------
@@ -10,13 +21,13 @@ LL | unsafe impl Send for (MyType, MyType) {}
1021
= note: define and implement a trait or new type instead
1122

1223
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`
13-
--> $DIR/coherence-impls-send.rs:20:1
24+
--> $DIR/coherence-impls-send.rs:19:1
1425
|
1526
LL | unsafe impl Send for &'static NotSync {}
1627
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type
1728

1829
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
19-
--> $DIR/coherence-impls-send.rs:23:1
30+
--> $DIR/coherence-impls-send.rs:22:1
2031
|
2132
LL | unsafe impl Send for [MyType] {}
2233
| ^^^^^^^^^^^^^^^^^^^^^--------
@@ -27,7 +38,7 @@ LL | unsafe impl Send for [MyType] {}
2738
= note: define and implement a trait or new type instead
2839

2940
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
30-
--> $DIR/coherence-impls-send.rs:26:1
41+
--> $DIR/coherence-impls-send.rs:25:1
3142
|
3243
LL | unsafe impl Send for &'static [NotSync] {}
3344
| ^^^^^^^^^^^^^^^^^^^^^------------------
@@ -37,7 +48,7 @@ LL | unsafe impl Send for &'static [NotSync] {}
3748
|
3849
= note: define and implement a trait or new type instead
3950

40-
error: aborting due to 4 previous errors
51+
error: aborting due to 5 previous errors
4152

42-
Some errors have detailed explanations: E0117, E0321.
53+
Some errors have detailed explanations: E0117, E0119, E0321.
4354
For more information about an error, try `rustc --explain E0117`.

src/test/ui/overlap-doesnt-conflict-with-specialization.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// run-pass
22

3-
#![feature(overlapping_marker_traits)]
3+
#![feature(marker_trait_attr)]
44
#![feature(specialization)]
55

6+
#[marker]
67
trait MyMarker {}
78

89
impl<T> MyMarker for T {}

src/test/ui/overlap-marker-trait.rs

-31
This file was deleted.

src/test/ui/overlap-marker-trait.stderr

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
// run-pass
21
#![allow(dead_code)]
3-
#![feature(overlapping_marker_traits)]
42
#![feature(optin_builtin_traits)]
53

6-
// Overlapping negative impls for `MyStruct` are permitted:
4+
// Overlapping negative impls for `MyStruct` are not permitted:
75
struct MyStruct;
86
impl !Send for MyStruct {}
97
impl !Send for MyStruct {}
8+
//~^ ERROR conflicting implementations of trait
109

1110
fn main() {
1211
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0119]: conflicting implementations of trait `std::marker::Send` for type `MyStruct`:
2+
--> $DIR/overlap-not-permitted-for-builtin-trait.rs:7:1
3+
|
4+
LL | impl !Send for MyStruct {}
5+
| ----------------------- first implementation here
6+
LL | impl !Send for MyStruct {}
7+
| ^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `MyStruct`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0119`.

src/test/ui/traits/overlap-permitted-for-marker-traits.rs

-27
This file was deleted.

0 commit comments

Comments
 (0)