Skip to content

Commit d8da75a

Browse files
committed
---
yaml --- r: 182243 b: refs/heads/beta c: 39fe05f h: refs/heads/master i: 182241: bb1f3b1 182239: a99eb81 v: v3
1 parent ad9c63f commit d8da75a

File tree

4 files changed

+59
-7
lines changed

4 files changed

+59
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3131
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2
3232
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3333
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
34-
refs/heads/beta: e644ca0d6a61f243c8a3cb9708bae6da216bc5de
34+
refs/heads/beta: 39fe05f58c5d7d805580826ce202d9a801813cb2
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3737
refs/heads/tmp: eb836bf767aa1d8d4cba488a9091cde3c0ab4b2f

branches/beta/src/librustc_typeck/coherence/unsafety.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct UnsafetyChecker<'cx, 'tcx:'cx> {
3030
impl<'cx, 'tcx,'v> visit::Visitor<'v> for UnsafetyChecker<'cx, 'tcx> {
3131
fn visit_item(&mut self, item: &'v ast::Item) {
3232
match item.node {
33-
ast::ItemImpl(unsafety, _, _, _, _, _) => {
33+
ast::ItemImpl(unsafety, polarity, _, _, _, _) => {
3434
match ty::impl_trait_ref(self.tcx, ast_util::local_def(item.id)) {
3535
None => {
3636
// Inherent impl.
@@ -46,23 +46,34 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for UnsafetyChecker<'cx, 'tcx> {
4646

4747
Some(trait_ref) => {
4848
let trait_def = ty::lookup_trait_def(self.tcx, trait_ref.def_id);
49-
match (trait_def.unsafety, unsafety) {
50-
(ast::Unsafety::Normal, ast::Unsafety::Unsafe) => {
49+
match (trait_def.unsafety, unsafety, polarity) {
50+
(ast::Unsafety::Unsafe,
51+
ast::Unsafety::Unsafe, ast::ImplPolarity::Negative) => {
52+
self.tcx.sess.span_err(
53+
item.span,
54+
format!("negative implementations are not unsafe").as_slice());
55+
}
56+
57+
(ast::Unsafety::Normal, ast::Unsafety::Unsafe, _) => {
5158
self.tcx.sess.span_err(
5259
item.span,
5360
format!("implementing the trait `{}` is not unsafe",
5461
trait_ref.user_string(self.tcx)).as_slice());
5562
}
5663

57-
(ast::Unsafety::Unsafe, ast::Unsafety::Normal) => {
64+
(ast::Unsafety::Unsafe,
65+
ast::Unsafety::Normal, ast::ImplPolarity::Positive) => {
5866
self.tcx.sess.span_err(
5967
item.span,
6068
format!("the trait `{}` requires an `unsafe impl` declaration",
6169
trait_ref.user_string(self.tcx)).as_slice());
6270
}
6371

64-
(ast::Unsafety::Unsafe, ast::Unsafety::Unsafe) |
65-
(ast::Unsafety::Normal, ast::Unsafety::Normal) => {
72+
(ast::Unsafety::Unsafe,
73+
ast::Unsafety::Normal, ast::ImplPolarity::Negative) |
74+
(ast::Unsafety::Unsafe,
75+
ast::Unsafety::Unsafe, ast::ImplPolarity::Positive) |
76+
(ast::Unsafety::Normal, ast::Unsafety::Normal, _) => {
6677
/* OK */
6778
}
6879
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(optin_builtin_traits)]
12+
13+
use std::marker::Send;
14+
15+
struct TestType;
16+
17+
unsafe impl !Send for TestType {}
18+
//~^ ERROR negative implementations are not unsafe
19+
20+
fn main() {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(optin_builtin_traits)]
12+
13+
use std::marker::Send;
14+
15+
struct TestType;
16+
17+
unsafe impl Send for TestType {}
18+
19+
impl !Send for TestType {}
20+
21+
fn main() {}

0 commit comments

Comments
 (0)