Skip to content

Commit

Permalink
allow negative impls for traits that have a default impl
Browse files Browse the repository at this point in the history
  • Loading branch information
flaper87 committed Feb 22, 2015
1 parent d021c55 commit 753db88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/librustc_typeck/check/wf.rs
Expand Up @@ -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`)")
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/typeck-negative-impls-builtin.rs
Expand Up @@ -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() {}

0 comments on commit 753db88

Please sign in to comment.