Skip to content

Commit 753db88

Browse files
committed
allow negative impls for traits that have a default impl
1 parent d021c55 commit 753db88

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/librustc_typeck/check/wf.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,15 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
8383
}
8484
ast::ItemImpl(_, ast::ImplPolarity::Negative, _, Some(ref tref), _, _) => {
8585
let trait_ref = ty::node_id_to_trait_ref(ccx.tcx, tref.ref_id);
86+
ty::populate_implementations_for_trait_if_necessary(ccx.tcx, trait_ref.def_id);
8687
match ccx.tcx.lang_items.to_builtin_kind(trait_ref.def_id) {
8788
Some(ty::BoundSend) | Some(ty::BoundSync) => {}
8889
Some(_) | None => {
89-
span_err!(ccx.tcx.sess, item.span, E0192,
90-
"negative impls are currently \
91-
allowed just for `Send` and `Sync`")
90+
if !ty::trait_has_default_impl(ccx.tcx, trait_ref.def_id) {
91+
span_err!(ccx.tcx.sess, item.span, E0192,
92+
"negative impls are only allowed for traits with \
93+
default impls (e.g., `Send` and `Sync`)")
94+
}
9295
}
9396
}
9497
}

src/test/compile-fail/typeck-negative-impls-builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ trait TestTrait {
1717
}
1818

1919
impl !TestTrait for TestType {}
20-
//~^ ERROR negative impls are currently allowed just for `Send` and `Sync`
20+
//~^ ERROR negative impls are only allowed for traits with default impls (e.g., `Send` and `Sync`)
2121

2222
fn main() {}

0 commit comments

Comments
 (0)