impl<'cx, 'tcx,'v> visit::Visitor<'v> for UnsafetyChecker<'cx, 'tcx> {
fn visit_item(&mut self, item: &'v ast::Item) {
match item.node {
- ast::ItemImpl(unsafety, _, _, _, _, _) => {
+ ast::ItemImpl(unsafety, polarity, _, _, _, _) => {
match ty::impl_trait_ref(self.tcx, ast_util::local_def(item.id)) {
None => {
// Inherent impl.
Some(trait_ref) => {
let trait_def = ty::lookup_trait_def(self.tcx, trait_ref.def_id);
- match (trait_def.unsafety, unsafety) {
- (ast::Unsafety::Normal, ast::Unsafety::Unsafe) => {
+ match (trait_def.unsafety, unsafety, polarity) {
+ (ast::Unsafety::Unsafe,
+ ast::Unsafety::Unsafe, ast::ImplPolarity::Negative) => {
+ self.tcx.sess.span_err(
+ item.span,
+ format!("negative implementations are not unsafe").as_slice());
+ }
+
+ (ast::Unsafety::Normal, ast::Unsafety::Unsafe, _) => {
self.tcx.sess.span_err(
item.span,
format!("implementing the trait `{}` is not unsafe",
trait_ref.user_string(self.tcx)).as_slice());
}
- (ast::Unsafety::Unsafe, ast::Unsafety::Normal) => {
+ (ast::Unsafety::Unsafe,
+ ast::Unsafety::Normal, ast::ImplPolarity::Positive) => {
self.tcx.sess.span_err(
item.span,
format!("the trait `{}` requires an `unsafe impl` declaration",
trait_ref.user_string(self.tcx)).as_slice());
}
- (ast::Unsafety::Unsafe, ast::Unsafety::Unsafe) |
- (ast::Unsafety::Normal, ast::Unsafety::Normal) => {
+ (ast::Unsafety::Unsafe,
+ ast::Unsafety::Normal, ast::ImplPolarity::Negative) |
+ (ast::Unsafety::Unsafe,
+ ast::Unsafety::Unsafe, ast::ImplPolarity::Positive) |
+ (ast::Unsafety::Normal, ast::Unsafety::Normal, _) => {
/* OK */
}
}
--- /dev/null
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(optin_builtin_traits)]
+
+use std::marker::Send;
+
+struct TestType;
+
+unsafe impl !Send for TestType {}
+//~^ ERROR negative implementations are not unsafe
+
+fn main() {}
--- /dev/null
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(optin_builtin_traits)]
+
+use std::marker::Send;
+
+struct TestType;
+
+unsafe impl Send for TestType {}
+
+impl !Send for TestType {}
+
+fn main() {}