@@ -53,7 +53,7 @@ use syntax::{abi, ast};
53
53
use syntax:: ast_util:: { self , is_shift_binop, local_def} ;
54
54
use syntax:: attr:: { self , AttrMetaMethods } ;
55
55
use syntax:: codemap:: { self , Span } ;
56
- use syntax:: feature_gate:: { KNOWN_ATTRIBUTES , AttributeType } ;
56
+ use syntax:: feature_gate:: { KNOWN_ATTRIBUTES , AttributeType , emit_feature_err } ;
57
57
use syntax:: parse:: token;
58
58
use syntax:: ast:: { TyIs , TyUs , TyI8 , TyU8 , TyI16 , TyU16 , TyI32 , TyU32 , TyI64 , TyU64 } ;
59
59
use syntax:: ptr:: P ;
@@ -88,12 +88,6 @@ impl LintPass for WhileTrue {
88
88
}
89
89
}
90
90
91
- declare_lint ! {
92
- UNSIGNED_NEGATION ,
93
- Warn ,
94
- "using an unary minus operator on unsigned type"
95
- }
96
-
97
91
declare_lint ! {
98
92
UNUSED_COMPARISONS ,
99
93
Warn ,
@@ -128,8 +122,7 @@ impl TypeLimits {
128
122
129
123
impl LintPass for TypeLimits {
130
124
fn get_lints ( & self ) -> LintArray {
131
- lint_array ! ( UNSIGNED_NEGATION , UNUSED_COMPARISONS , OVERFLOWING_LITERALS ,
132
- EXCEEDING_BITSHIFTS )
125
+ lint_array ! ( UNUSED_COMPARISONS , OVERFLOWING_LITERALS , EXCEEDING_BITSHIFTS )
133
126
}
134
127
135
128
fn check_expr ( & mut self , cx : & Context , e : & ast:: Expr ) {
@@ -139,9 +132,12 @@ impl LintPass for TypeLimits {
139
132
ast:: ExprLit ( ref lit) => {
140
133
match lit. node {
141
134
ast:: LitInt ( _, ast:: UnsignedIntLit ( _) ) => {
142
- cx. span_lint ( UNSIGNED_NEGATION , e. span ,
143
- "negation of unsigned int literal may \
144
- be unintentional") ;
135
+ check_unsigned_negation_feature ( cx, e. span ) ;
136
+ } ,
137
+ ast:: LitInt ( _, ast:: UnsuffixedIntLit ( _) ) => {
138
+ if let ty:: TyUint ( _) = cx. tcx . expr_ty ( e) . sty {
139
+ check_unsigned_negation_feature ( cx, e. span ) ;
140
+ }
145
141
} ,
146
142
_ => ( )
147
143
}
@@ -150,9 +146,7 @@ impl LintPass for TypeLimits {
150
146
let t = cx. tcx . expr_ty ( & * * expr) ;
151
147
match t. sty {
152
148
ty:: TyUint ( _) => {
153
- cx. span_lint ( UNSIGNED_NEGATION , e. span ,
154
- "negation of unsigned int variable may \
155
- be unintentional") ;
149
+ check_unsigned_negation_feature ( cx, e. span ) ;
156
150
} ,
157
151
_ => ( )
158
152
}
@@ -385,6 +379,16 @@ impl LintPass for TypeLimits {
385
379
_ => false
386
380
}
387
381
}
382
+
383
+ fn check_unsigned_negation_feature ( cx : & Context , span : Span ) {
384
+ if !cx. sess ( ) . features . borrow ( ) . negate_unsigned {
385
+ emit_feature_err (
386
+ & cx. sess ( ) . parse_sess . span_diagnostic ,
387
+ "negate_unsigned" ,
388
+ span,
389
+ "unary negation of unsigned integers may be removed in the future" ) ;
390
+ }
391
+ }
388
392
}
389
393
}
390
394
0 commit comments