allow negative impls for traits that have a default impl

This commit is contained in:
Flavio Percoco 2015-02-21 01:01:48 +01:00
parent d021c55fb9
commit 753db88914
2 changed files with 7 additions and 4 deletions

View file

@ -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`)")
}
}
}
}

View file

@ -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() {}