diff --git a/src/librustc/arena.rs b/src/librustc/arena.rs index 15e92d8d84219..92f5bf87535e6 100644 --- a/src/librustc/arena.rs +++ b/src/librustc/arena.rs @@ -216,6 +216,7 @@ arena_types!(declare_arena, [], 'tcx); arena_types!(impl_arena_allocatable, [], 'tcx); +#[marker] pub trait ArenaAllocatable {} impl ArenaAllocatable for T {} diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 744ee1a65e154..2f77792f7a198 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -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)] diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 0781feee84541..fe25f451a3a1e 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -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 @@ -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) diff --git a/src/librustc_feature/active.rs b/src/librustc_feature/active.rs index 0252d88e73889..4ae79f9ccaa6c 100644 --- a/src/librustc_feature/active.rs +++ b/src/librustc_feature/active.rs @@ -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), diff --git a/src/librustc_feature/removed.rs b/src/librustc_feature/removed.rs index d5b6fe81c7be8..e6ea093fe89c7 100644 --- a/src/librustc_feature/removed.rs +++ b/src/librustc_feature/removed.rs @@ -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 // ------------------------------------------------------------------------- diff --git a/src/test/ui/coherence/coherence-conflicting-negative-trait-impl.rs b/src/test/ui/coherence/coherence-conflicting-negative-trait-impl.rs index 66d0958e4c9a4..b4f5f9ef56bb1 100644 --- a/src/test/ui/coherence/coherence-conflicting-negative-trait-impl.rs +++ b/src/test/ui/coherence/coherence-conflicting-negative-trait-impl.rs @@ -1,6 +1,7 @@ #![feature(optin_builtin_traits)] -#![feature(overlapping_marker_traits)] +#![feature(marker_trait_attr)] +#[marker] trait MyTrait {} struct TestType(::std::marker::PhantomData); @@ -8,11 +9,11 @@ struct TestType(::std::marker::PhantomData); unsafe impl Send for TestType {} impl !Send for TestType {} -//~^ ERROR E0119 +//~^ ERROR conflicting implementations unsafe impl Send for TestType {} +//~^ ERROR conflicting implementations impl !Send for TestType {} -//~^ ERROR E0119 fn main() {} diff --git a/src/test/ui/coherence/coherence-conflicting-negative-trait-impl.stderr b/src/test/ui/coherence/coherence-conflicting-negative-trait-impl.stderr index 0a8bbc4bc50a8..25d3d3ee997a5 100644 --- a/src/test/ui/coherence/coherence-conflicting-negative-trait-impl.stderr +++ b/src/test/ui/coherence/coherence-conflicting-negative-trait-impl.stderr @@ -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 Send for TestType {} | ---------------------------------------------------- first implementation here @@ -7,14 +7,14 @@ LL | LL | impl !Send for TestType {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>` -error[E0119]: conflicting implementations of trait `std::marker::Send` for type `TestType`: - --> $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 Send for TestType {} + | ---------------------------------------------------- first implementation here +... LL | unsafe impl Send for TestType {} - | ------------------------------------------- first implementation here -LL | -LL | impl !Send for TestType {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `TestType<_>` error: aborting due to 2 previous errors diff --git a/src/test/ui/coherence/coherence-impls-send.rs b/src/test/ui/coherence/coherence-impls-send.rs index b2a9c5be65843..7898dc9831da2 100644 --- a/src/test/ui/coherence/coherence-impls-send.rs +++ b/src/test/ui/coherence/coherence-impls-send.rs @@ -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() { } diff --git a/src/test/ui/coherence/coherence-impls-send.stderr b/src/test/ui/coherence/coherence-impls-send.stderr index a5b3c7657bdfe..dbfc968332c5c 100644 --- a/src/test/ui/coherence/coherence-impls-send.stderr +++ b/src/test/ui/coherence/coherence-impls-send.stderr @@ -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 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`. diff --git a/src/test/ui/overlap-doesnt-conflict-with-specialization.rs b/src/test/ui/overlap-doesnt-conflict-with-specialization.rs index 3d4069f368d2a..dd09d68367ec3 100644 --- a/src/test/ui/overlap-doesnt-conflict-with-specialization.rs +++ b/src/test/ui/overlap-doesnt-conflict-with-specialization.rs @@ -1,8 +1,9 @@ // run-pass -#![feature(overlapping_marker_traits)] +#![feature(marker_trait_attr)] #![feature(specialization)] +#[marker] trait MyMarker {} impl MyMarker for T {} diff --git a/src/test/ui/overlap-marker-trait.rs b/src/test/ui/overlap-marker-trait.rs deleted file mode 100644 index bf39d9c903f80..0000000000000 --- a/src/test/ui/overlap-marker-trait.rs +++ /dev/null @@ -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 Marker for T {} -impl Marker for T {} - -fn is_marker() { } - -struct NotDebugOrDisplay; - -fn main() { - // Debug && Display: - is_marker::(); - - // Debug && !Display: - is_marker::>(); - - // !Debug && !Display - is_marker::(); //~ ERROR -} diff --git a/src/test/ui/overlap-marker-trait.stderr b/src/test/ui/overlap-marker-trait.stderr deleted file mode 100644 index 15ebcd17b0dbc..0000000000000 --- a/src/test/ui/overlap-marker-trait.stderr +++ /dev/null @@ -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() { } - | --------- ------ required by this bound in `is_marker` -... -LL | is_marker::(); - | ^^^^^^^^^^^^^^^^^ the trait `Marker` is not implemented for `NotDebugOrDisplay` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/traits/overlap-permitted-for-marker-traits-neg.rs b/src/test/ui/traits/overlap-not-permitted-for-builtin-trait.rs similarity index 55% rename from src/test/ui/traits/overlap-permitted-for-marker-traits-neg.rs rename to src/test/ui/traits/overlap-not-permitted-for-builtin-trait.rs index bc8dc8dbd05b5..86029473b513b 100644 --- a/src/test/ui/traits/overlap-permitted-for-marker-traits-neg.rs +++ b/src/test/ui/traits/overlap-not-permitted-for-builtin-trait.rs @@ -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() { } diff --git a/src/test/ui/traits/overlap-not-permitted-for-builtin-trait.stderr b/src/test/ui/traits/overlap-not-permitted-for-builtin-trait.stderr new file mode 100644 index 0000000000000..94a0c287f4a32 --- /dev/null +++ b/src/test/ui/traits/overlap-not-permitted-for-builtin-trait.stderr @@ -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`. diff --git a/src/test/ui/traits/overlap-permitted-for-marker-traits.rs b/src/test/ui/traits/overlap-permitted-for-marker-traits.rs deleted file mode 100644 index 59ec9d5689d8c..0000000000000 --- a/src/test/ui/traits/overlap-permitted-for-marker-traits.rs +++ /dev/null @@ -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 MyMarker for T {} -impl MyMarker for T {} - -fn foo(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])); -}