@@ -30,7 +30,7 @@ struct UnsafetyChecker<'cx, 'tcx:'cx> {
30
30
impl < ' cx , ' tcx , ' v > visit:: Visitor < ' v > for UnsafetyChecker < ' cx , ' tcx > {
31
31
fn visit_item ( & mut self , item : & ' v ast:: Item ) {
32
32
match item. node {
33
- ast:: ItemImpl ( unsafety, _ , _, _, _, _) => {
33
+ ast:: ItemImpl ( unsafety, polarity , _, _, _, _) => {
34
34
match ty:: impl_trait_ref ( self . tcx , ast_util:: local_def ( item. id ) ) {
35
35
None => {
36
36
// Inherent impl.
@@ -46,23 +46,34 @@ impl<'cx, 'tcx,'v> visit::Visitor<'v> for UnsafetyChecker<'cx, 'tcx> {
46
46
47
47
Some ( trait_ref) => {
48
48
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 , _) => {
51
58
self . tcx . sess . span_err (
52
59
item. span ,
53
60
format ! ( "implementing the trait `{}` is not unsafe" ,
54
61
trait_ref. user_string( self . tcx) ) . as_slice ( ) ) ;
55
62
}
56
63
57
- ( ast:: Unsafety :: Unsafe , ast:: Unsafety :: Normal ) => {
64
+ ( ast:: Unsafety :: Unsafe ,
65
+ ast:: Unsafety :: Normal , ast:: ImplPolarity :: Positive ) => {
58
66
self . tcx . sess . span_err (
59
67
item. span ,
60
68
format ! ( "the trait `{}` requires an `unsafe impl` declaration" ,
61
69
trait_ref. user_string( self . tcx) ) . as_slice ( ) ) ;
62
70
}
63
71
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 , _) => {
66
77
/* OK */
67
78
}
68
79
}
0 commit comments