]> git.lizzy.rs Git - rust.git/commitdiff
Fix coherence for negative implementations
authorFlavio Percoco <flaper87@gmail.com>
Wed, 7 Jan 2015 18:27:01 +0000 (19:27 +0100)
committerFlavio Percoco <flaper87@gmail.com>
Fri, 16 Jan 2015 07:18:56 +0000 (08:18 +0100)
src/librustc_typeck/coherence/overlap.rs
src/test/compile-fail/coherence-conflicting-negative-trait-impl.rs [new file with mode: 0644]

index e0bf6f86571299d8573eded6b185f74b3efa65b9..97cb3c1213fb871712ba73f5a1f7a53f6a4bc115 100644 (file)
@@ -39,8 +39,13 @@ fn check_for_overlapping_impls(&self) {
         // check can populate this table further with impls from other
         // crates.
         let trait_def_ids: Vec<(ast::DefId, Vec<ast::DefId>)> =
-            self.tcx.trait_impls.borrow().iter().map(|(&k, v)|
-                                                     (k, v.borrow().clone())).collect();
+            self.tcx.trait_impls.borrow().iter().map(|(&k, v)| {
+                let mut impls = v.borrow().clone();
+                if let Some(neg_impls) = self.tcx.trait_negative_impls.borrow().get(&k) {
+                    impls.push_all(neg_impls.borrow().as_slice());
+                }
+                (k, impls)
+            }).collect();
 
         for &(trait_def_id, ref impls) in trait_def_ids.iter() {
             self.check_for_overlapping_impls_of_trait(trait_def_id, impls);
diff --git a/src/test/compile-fail/coherence-conflicting-negative-trait-impl.rs b/src/test/compile-fail/coherence-conflicting-negative-trait-impl.rs
new file mode 100644 (file)
index 0000000..36c7546
--- /dev/null
@@ -0,0 +1,20 @@
+// Copyright 2014 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(optin_builtin_traits)]
+
+struct TestType;
+
+unsafe impl Send for TestType {}
+//~^ ERROR conflicting implementations for trait `core::marker::Send`
+
+impl !Send for TestType {}
+
+fn main() {}