From 753db889149db712598ff2a1ee34885d7b9680cc Mon Sep 17 00:00:00 2001 From: Flavio Percoco Date: Sat, 21 Feb 2015 01:01:48 +0100 Subject: [PATCH] allow negative impls for traits that have a default impl --- src/librustc_typeck/check/wf.rs | 9 ++++++--- src/test/compile-fail/typeck-negative-impls-builtin.rs | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/librustc_typeck/check/wf.rs b/src/librustc_typeck/check/wf.rs index 2601c4d27529..c6fafb7a77ae 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 557fb2f4f883..57a394dc7f1e 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() {}