about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlavio Percoco <flaper87@gmail.com>2015-02-21 01:01:48 +0100
committerFlavio Percoco <flaper87@gmail.com>2015-02-22 02:14:27 +0100
commit753db889149db712598ff2a1ee34885d7b9680cc (patch)
treefe5405e844c8b4f9fc2ac50d8014128e9883d781
parentd021c55fb9a18b854cd70a3d67a260d4d71a14c3 (diff)
downloadrust-753db889149db712598ff2a1ee34885d7b9680cc.tar.gz
rust-753db889149db712598ff2a1ee34885d7b9680cc.zip
allow negative impls for traits that have a default impl
-rw-r--r--src/librustc_typeck/check/wf.rs9
-rw-r--r--src/test/compile-fail/typeck-negative-impls-builtin.rs2
2 files changed, 7 insertions, 4 deletions
diff --git a/src/librustc_typeck/check/wf.rs b/src/librustc_typeck/check/wf.rs
index 2601c4d2752..c6fafb7a77a 100644
--- a/src/librustc_typeck/check/wf.rs
+++ b/src/librustc_typeck/check/wf.rs
@@ -83,12 +83,15 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
             }
             ast::ItemImpl(_, ast::ImplPolarity::Negative, _, Some(ref tref), _, _) => {
                 let trait_ref = ty::node_id_to_trait_ref(ccx.tcx, tref.ref_id);
+                ty::populate_implementations_for_trait_if_necessary(ccx.tcx, trait_ref.def_id);
                 match ccx.tcx.lang_items.to_builtin_kind(trait_ref.def_id) {
                     Some(ty::BoundSend) | Some(ty::BoundSync) => {}
                     Some(_) | None => {
-                        span_err!(ccx.tcx.sess, item.span, E0192,
-                            "negative impls are currently \
-                                     allowed just for `Send` and `Sync`")
+                        if !ty::trait_has_default_impl(ccx.tcx, trait_ref.def_id) {
+                            span_err!(ccx.tcx.sess, item.span, E0192,
+                                      "negative impls are only allowed for traits with \
+                                       default impls (e.g., `Send` and `Sync`)")
+                        }
                     }
                 }
             }
diff --git a/src/test/compile-fail/typeck-negative-impls-builtin.rs b/src/test/compile-fail/typeck-negative-impls-builtin.rs
index 557fb2f4f88..57a394dc7f1 100644
--- a/src/test/compile-fail/typeck-negative-impls-builtin.rs
+++ b/src/test/compile-fail/typeck-negative-impls-builtin.rs
@@ -17,6 +17,6 @@ trait TestTrait {
 }
 
 impl !TestTrait for TestType {}
-//~^ ERROR  negative impls are currently allowed just for `Send` and `Sync`
+//~^ ERROR negative impls are only allowed for traits with default impls (e.g., `Send` and `Sync`)
 
 fn main() {}