@@ -53,7 +53,7 @@ use syntax::{abi, ast};
5353use syntax:: ast_util:: { self , is_shift_binop, local_def} ;
5454use syntax:: attr:: { self , AttrMetaMethods } ;
5555use syntax:: codemap:: { self , Span } ;
56- use syntax:: feature_gate:: { KNOWN_ATTRIBUTES , AttributeType } ;
56+ use syntax:: feature_gate:: { KNOWN_ATTRIBUTES , AttributeType , emit_feature_err } ;
5757use syntax:: parse:: token;
5858use syntax:: ast:: { TyIs , TyUs , TyI8 , TyU8 , TyI16 , TyU16 , TyI32 , TyU32 , TyI64 , TyU64 } ;
5959use syntax:: ptr:: P ;
@@ -88,12 +88,6 @@ impl LintPass for WhileTrue {
8888 }
8989}
9090
91- declare_lint ! {
92- UNSIGNED_NEGATION ,
93- Warn ,
94- "using an unary minus operator on unsigned type"
95- }
96-
9791declare_lint ! {
9892 UNUSED_COMPARISONS ,
9993 Warn ,
@@ -128,8 +122,7 @@ impl TypeLimits {
128122
129123impl LintPass for TypeLimits {
130124 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 )
133126 }
134127
135128 fn check_expr ( & mut self , cx : & Context , e : & ast:: Expr ) {
@@ -139,9 +132,12 @@ impl LintPass for TypeLimits {
139132 ast:: ExprLit ( ref lit) => {
140133 match lit. node {
141134 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+ }
145141 } ,
146142 _ => ( )
147143 }
@@ -150,9 +146,7 @@ impl LintPass for TypeLimits {
150146 let t = cx. tcx . expr_ty ( & * * expr) ;
151147 match t. sty {
152148 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 ) ;
156150 } ,
157151 _ => ( )
158152 }
@@ -385,6 +379,16 @@ impl LintPass for TypeLimits {
385379 _ => false
386380 }
387381 }
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+ }
388392 }
389393}
390394
0 commit comments