]> git.lizzy.rs Git - rust.git/commitdiff
Put overlapping impls behind feature gate, add tests
authorSean Griffin <sean@seantheprogrammer.com>
Fri, 17 Mar 2017 18:16:29 +0000 (14:16 -0400)
committerCorey Farwell <coreyf@rwell.org>
Sat, 15 Apr 2017 02:05:11 +0000 (22:05 -0400)
I've added some explicit tests that negative impls are allowed to
overlap, and also to make sure that the feature doesn't interfere with
specialization. I've not added an explicit test for positive overlapping
with negative, as that's already tested elsewhere.

src/librustc/ty/mod.rs
src/libsyntax/feature_gate.rs
src/test/compile-fail/coherence-conflicting-negative-trait-impl.rs
src/test/compile-fail/coherence-impls-send.rs
src/test/compile-fail/overlapping-impls-requires-feature-gate.rs [new file with mode: 0644]
src/test/run-pass/overlap-doesnt-conflict-with-specialization.rs [new file with mode: 0644]
src/test/run-pass/overlap-permitted-for-marker-traits.rs

index 2ae77046a90ed776a8f4464172f6725905cc183e..3da9383762bc6c682889daef12a5be762b0215cc 100644 (file)
@@ -2230,6 +2230,9 @@ pub fn impl_trait_ref(self, id: DefId) -> Option<TraitRef<'gcx>> {
     /// Returns true if the impls are the same polarity and are implementing
     /// a trait which contains no items
     pub fn impls_are_allowed_to_overlap(self, def_id1: DefId, def_id2: DefId) -> bool {
+        if !self.sess.features.borrow().overlapping_marker_traits {
+            return false;
+        }
         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()
index 8b62416dcbdbd6e541f68b055ac8f8933dfc3a95..6e455234196d461d6430838a1e6c6bd10be46927 100644 (file)
@@ -349,6 +349,9 @@ pub fn new() -> Features {
 
     // Allows module-level inline assembly by way of global_asm!()
     (active, global_asm, "1.18.0", Some(35119)),
+
+    // Allows overlapping impls of marker traits
+    (active, overlapping_marker_traits, "1.18.0", Some(29864)),
 );
 
 declare_features! (
index d841e8c41d984e0b40fd2347d6a185621c4123ad..8e9d1eff34580575dc64b4ba6e43c77ae09c6f2c 100644 (file)
@@ -9,6 +9,7 @@
 // except according to those terms.
 
 #![feature(optin_builtin_traits)]
+#![feature(overlapping_marker_traits)]
 
 trait MyTrait {}
 
index d0e6bc6a1c699264b016d9acb994098f494f3cd8..9caaee41aeb1dba09b2ad576a83cba1a559d3143 100644 (file)
@@ -9,6 +9,7 @@
 // except according to those terms.
 
 #![feature(optin_builtin_traits)]
+#![feature(overlapping_marker_traits)]
 
 use std::marker::Copy;
 
diff --git a/src/test/compile-fail/overlapping-impls-requires-feature-gate.rs b/src/test/compile-fail/overlapping-impls-requires-feature-gate.rs
new file mode 100644 (file)
index 0000000..bf2b06d
--- /dev/null
@@ -0,0 +1,17 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+trait MyMarker {}
+
+impl<T> MyMarker for T {}
+impl<T> MyMarker for Vec<T> {}
+//~^ ERROR E0119
+
+fn main() {}
diff --git a/src/test/run-pass/overlap-doesnt-conflict-with-specialization.rs b/src/test/run-pass/overlap-doesnt-conflict-with-specialization.rs
new file mode 100644 (file)
index 0000000..ed45d81
--- /dev/null
@@ -0,0 +1,27 @@
+// 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 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(overlapping_marker_traits)]
+#![feature(specialization)]
+
+trait MyMarker {}
+
+impl<T> MyMarker for T {}
+impl<T> MyMarker for Vec<T> {}
+
+fn foo<T: MyMarker>(t: T) -> T {
+    t
+}
+
+fn main() {
+    assert_eq!(1, foo(1));
+    assert_eq!(2.0, foo(2.0));
+    assert_eq!(vec![1], foo(vec![1]));
+}
index b0b1930d274d69dd2b15ff93674b5ae1971e7eed..45085c093fc986b670fedf91a2b2f2c496b29990 100644 (file)
@@ -8,11 +8,18 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+#![feature(overlapping_marker_traits)]
+#![feature(optin_builtin_traits)]
+
 trait MyMarker {}
 
 impl<T: Copy> MyMarker for T {}
 impl<T: Eq> MyMarker for T {}
 
+struct MyStruct;
+impl !Send for MyStruct {}
+impl !Send for MyStruct {}
+
 fn foo<T: MyMarker>(t: T) -> T {
     t
 }