Skip to content

Commit ec1a85a

Browse files
committed
rollup merge of #23211: FlaPer87/oibit-send-and-friends
Fixes #23225 r? @nikomatsakis
2 parents ad41e7c + 04d5772 commit ec1a85a

File tree

6 files changed

+76
-45
lines changed

6 files changed

+76
-45
lines changed

src/libcore/marker.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub unsafe trait Send : MarkerTrait {
3939
// empty.
4040
}
4141

42+
unsafe impl Send for .. { }
43+
4244
impl<T> !Send for *const T { }
4345
impl<T> !Send for *mut T { }
4446
impl !Send for Managed { }
@@ -203,6 +205,8 @@ pub unsafe trait Sync : MarkerTrait {
203205
// Empty
204206
}
205207

208+
unsafe impl Sync for .. { }
209+
206210
impl<T> !Sync for *const T { }
207211
impl<T> !Sync for *mut T { }
208212
impl !Sync for Managed { }

src/librustc/middle/ty.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5989,10 +5989,7 @@ pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc<ItemVariances> {
59895989

59905990
pub fn trait_has_default_impl(tcx: &ctxt, trait_def_id: DefId) -> bool {
59915991
populate_implementations_for_trait_if_necessary(tcx, trait_def_id);
5992-
match tcx.lang_items.to_builtin_kind(trait_def_id) {
5993-
Some(BoundSend) | Some(BoundSync) => true,
5994-
_ => tcx.traits_with_default_impls.borrow().contains_key(&trait_def_id),
5995-
}
5992+
tcx.traits_with_default_impls.borrow().contains_key(&trait_def_id)
59965993
}
59975994

59985995
/// Records a trait-to-implementation mapping.

src/librustc_typeck/coherence/unsafety.rs

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,55 +27,66 @@ struct UnsafetyChecker<'cx, 'tcx:'cx> {
2727
tcx: &'cx ty::ctxt<'tcx>
2828
}
2929

30-
impl<'cx, 'tcx,'v> visit::Visitor<'v> for UnsafetyChecker<'cx, 'tcx> {
31-
fn visit_item(&mut self, item: &'v ast::Item) {
32-
match item.node {
33-
ast::ItemImpl(unsafety, polarity, _, _, _, _) => {
34-
match ty::impl_trait_ref(self.tcx, ast_util::local_def(item.id)) {
35-
None => {
36-
// Inherent impl.
37-
match unsafety {
38-
ast::Unsafety::Normal => { /* OK */ }
39-
ast::Unsafety::Unsafe => {
40-
span_err!(self.tcx.sess, item.span, E0197,
41-
"inherent impls cannot be declared as unsafe");
42-
}
43-
}
30+
impl<'cx, 'tcx, 'v> UnsafetyChecker<'cx, 'tcx> {
31+
fn check_unsafety_coherence(&mut self, item: &'v ast::Item,
32+
unsafety: ast::Unsafety,
33+
polarity: ast::ImplPolarity) {
34+
match ty::impl_trait_ref(self.tcx, ast_util::local_def(item.id)) {
35+
None => {
36+
// Inherent impl.
37+
match unsafety {
38+
ast::Unsafety::Normal => { /* OK */ }
39+
ast::Unsafety::Unsafe => {
40+
span_err!(self.tcx.sess, item.span, E0197,
41+
"inherent impls cannot be declared as unsafe");
4442
}
43+
}
44+
}
4545

46-
Some(trait_ref) => {
47-
let trait_def = ty::lookup_trait_def(self.tcx, trait_ref.def_id);
48-
match (trait_def.unsafety, unsafety, polarity) {
49-
(ast::Unsafety::Unsafe,
50-
ast::Unsafety::Unsafe, ast::ImplPolarity::Negative) => {
51-
span_err!(self.tcx.sess, item.span, E0198,
52-
"negative implementations are not unsafe");
53-
}
46+
Some(trait_ref) => {
47+
let trait_def = ty::lookup_trait_def(self.tcx, trait_ref.def_id);
48+
match (trait_def.unsafety, unsafety, polarity) {
49+
(ast::Unsafety::Unsafe,
50+
ast::Unsafety::Unsafe, ast::ImplPolarity::Negative) => {
51+
span_err!(self.tcx.sess, item.span, E0198,
52+
"negative implementations are not unsafe");
53+
}
5454

55-
(ast::Unsafety::Normal, ast::Unsafety::Unsafe, _) => {
56-
span_err!(self.tcx.sess, item.span, E0199,
57-
"implementing the trait `{}` is not unsafe",
58-
trait_ref.user_string(self.tcx));
59-
}
55+
(ast::Unsafety::Normal, ast::Unsafety::Unsafe, _) => {
56+
span_err!(self.tcx.sess, item.span, E0199,
57+
"implementing the trait `{}` is not unsafe",
58+
trait_ref.user_string(self.tcx));
59+
}
6060

61-
(ast::Unsafety::Unsafe,
62-
ast::Unsafety::Normal, ast::ImplPolarity::Positive) => {
63-
span_err!(self.tcx.sess, item.span, E0200,
64-
"the trait `{}` requires an `unsafe impl` declaration",
65-
trait_ref.user_string(self.tcx));
66-
}
61+
(ast::Unsafety::Unsafe,
62+
ast::Unsafety::Normal, ast::ImplPolarity::Positive) => {
63+
span_err!(self.tcx.sess, item.span, E0200,
64+
"the trait `{}` requires an `unsafe impl` declaration",
65+
trait_ref.user_string(self.tcx));
66+
}
6767

68-
(ast::Unsafety::Unsafe,
69-
ast::Unsafety::Normal, ast::ImplPolarity::Negative) |
70-
(ast::Unsafety::Unsafe,
71-
ast::Unsafety::Unsafe, ast::ImplPolarity::Positive) |
72-
(ast::Unsafety::Normal, ast::Unsafety::Normal, _) => {
73-
/* OK */
74-
}
75-
}
68+
(ast::Unsafety::Unsafe,
69+
ast::Unsafety::Normal, ast::ImplPolarity::Negative) |
70+
(ast::Unsafety::Unsafe,
71+
ast::Unsafety::Unsafe, ast::ImplPolarity::Positive) |
72+
(ast::Unsafety::Normal, ast::Unsafety::Normal, _) => {
73+
/* OK */
7674
}
7775
}
7876
}
77+
}
78+
}
79+
}
80+
81+
impl<'cx, 'tcx,'v> visit::Visitor<'v> for UnsafetyChecker<'cx, 'tcx> {
82+
fn visit_item(&mut self, item: &'v ast::Item) {
83+
match item.node {
84+
ast::ItemDefaultImpl(unsafety, _) => {
85+
self.check_unsafety_coherence(item, unsafety, ast::ImplPolarity::Positive);
86+
}
87+
ast::ItemImpl(unsafety, polarity, _, _, _, _) => {
88+
self.check_unsafety_coherence(item, unsafety, polarity);
89+
}
7990
_ => { }
8091
}
8192

src/libsyntax/feature_gate.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,13 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
563563
}
564564
}
565565

566+
ast::ItemDefaultImpl(..) => {
567+
self.gate_feature("optin_builtin_traits",
568+
i.span,
569+
"default trait implementations are experimental \
570+
and possibly buggy");
571+
}
572+
566573
ast::ItemImpl(_, polarity, _, _, _, _) => {
567574
match polarity {
568575
ast::ImplPolarity::Negative => {

src/test/compile-fail/coherence-default-trait-impl.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ impl MyTrait for .. {}
2121
impl MyTrait for .. {}
2222
//~^ ERROR conflicting implementations for trait `MyTrait`
2323

24+
trait MySafeTrait: MarkerTrait {}
25+
26+
unsafe impl MySafeTrait for .. {}
27+
//~^ ERROR implementing the trait `MySafeTrait` is not unsafe
28+
29+
unsafe trait MyUnsafeTrait: MarkerTrait {}
30+
31+
impl MyUnsafeTrait for .. {}
32+
//~^ ERROR the trait `MyUnsafeTrait` requires an `unsafe impl` declaration
33+
2434
fn main() {}

src/test/run-make/rustdoc-default-impl/foo.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(optin_builtin_traits)]
12+
1113
pub mod bar {
1214
use std::marker;
1315

0 commit comments

Comments
 (0)