Skip to content

Commit dd923b3

Browse files
committed
---
yaml --- r: 173903 b: refs/heads/auto c: 39fe05f h: refs/heads/master i: 173901: 6d99038 173899: 2a87ce2 173895: a28c45a 173887: dc9739a v: v3
1 parent 6375228 commit dd923b3

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
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: e644ca0d6a61f243c8a3cb9708bae6da216bc5de
13+
refs/heads/auto: 39fe05f58c5d7d805580826ce202d9a801813cb2
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/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)