diff --git a/src/test/compile-fail/feature-gate-overlapping_marker_traits.rs b/src/test/compile-fail/feature-gate-overlapping_marker_traits.rs index bf2b06dd8ba0c..d2aa4e59b5ba9 100644 --- a/src/test/compile-fail/feature-gate-overlapping_marker_traits.rs +++ b/src/test/compile-fail/feature-gate-overlapping_marker_traits.rs @@ -8,10 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use std::fmt::{Debug, Display}; + trait MyMarker {} -impl MyMarker for T {} -impl MyMarker for Vec {} +impl MyMarker for T {} +impl MyMarker for T {} //~^ ERROR E0119 fn main() {} diff --git a/src/test/compile-fail/overlap-marker-trait.rs b/src/test/compile-fail/overlap-marker-trait.rs new file mode 100644 index 0000000000000..a649ae25f34ea --- /dev/null +++ b/src/test/compile-fail/overlap-marker-trait.rs @@ -0,0 +1,41 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// 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/run-pass/overlap-permitted-for-marker-traits-neg.rs b/src/test/run-pass/overlap-permitted-for-marker-traits-neg.rs new file mode 100644 index 0000000000000..740d5d22ab507 --- /dev/null +++ b/src/test/run-pass/overlap-permitted-for-marker-traits-neg.rs @@ -0,0 +1,20 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(overlapping_marker_traits)] +#![feature(optin_builtin_traits)] + +// Overlapping negative impls for `MyStruct` are permitted: +struct MyStruct; +impl !Send for MyStruct {} +impl !Send for MyStruct {} + +fn main() { +} diff --git a/src/test/run-pass/overlap-permitted-for-marker-traits.rs b/src/test/run-pass/overlap-permitted-for-marker-traits.rs index 45085c093fc98..11a46299d8c83 100644 --- a/src/test/run-pass/overlap-permitted-for-marker-traits.rs +++ b/src/test/run-pass/overlap-permitted-for-marker-traits.rs @@ -8,24 +8,29 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// 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)] -trait MyMarker {} +use std::fmt::{Debug, Display}; -impl MyMarker for T {} -impl MyMarker for T {} +trait MyMarker {} -struct MyStruct; -impl !Send for MyStruct {} -impl !Send for MyStruct {} +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])); }