Skip to content

Commit d8e3093

Browse files
committed
added unary_negate feature gate.
1 parent d528aa9 commit d8e3093

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/librustc_typeck/check/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ use syntax::attr::AttrMetaMethods;
120120
use syntax::ast::{self, DefId, Visibility};
121121
use syntax::ast_util::{self, local_def};
122122
use syntax::codemap::{self, Span};
123+
use syntax::feature_gate;
123124
use syntax::owned_slice::OwnedSlice;
124125
use syntax::parse::token;
125126
use syntax::print::pprust;
@@ -3258,6 +3259,15 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
32583259
tcx.lang_items.neg_trait(),
32593260
expr, &**oprnd, oprnd_t, unop);
32603261
}
3262+
if let ty::ty_uint(_) = oprnd_t.sty {
3263+
if !tcx.sess.features.borrow().negate_unsigned {
3264+
feature_gate::emit_feature_err(
3265+
&tcx.sess.parse_sess.span_diagnostic,
3266+
"negate_unsigned",
3267+
expr.span,
3268+
"unary negation of unsigned integers may be removed in the future");
3269+
}
3270+
}
32613271
}
32623272
}
32633273
}

src/libsyntax/feature_gate.rs

+6
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
150150

151151
// #23121. Array patterns have some hazards yet.
152152
("slice_patterns", "1.0.0", Active),
153+
154+
// Allows use of unary negate on unsigned integers, e.g. -e for e: u8
155+
("negate_unsigned", "1.0.0", Active),
153156
];
154157
// (changing above list without updating src/doc/reference.md makes @cmr sad)
155158

@@ -319,6 +322,7 @@ pub struct Features {
319322
pub allow_custom_derive: bool,
320323
pub simd_ffi: bool,
321324
pub unmarked_api: bool,
325+
pub negate_unsigned: bool,
322326
/// spans of #![feature] attrs for stable language features. for error reporting
323327
pub declared_stable_lang_features: Vec<Span>,
324328
/// #![feature] attrs for non-language (library) features
@@ -340,6 +344,7 @@ impl Features {
340344
allow_custom_derive: false,
341345
simd_ffi: false,
342346
unmarked_api: false,
347+
negate_unsigned: false,
343348
declared_stable_lang_features: Vec::new(),
344349
declared_lib_features: Vec::new()
345350
}
@@ -712,6 +717,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,
712717
allow_custom_derive: cx.has_feature("custom_derive"),
713718
simd_ffi: cx.has_feature("simd_ffi"),
714719
unmarked_api: cx.has_feature("unmarked_api"),
720+
negate_unsigned: cx.has_feature("negate_unsigned"),
715721
declared_stable_lang_features: accepted_features,
716722
declared_lib_features: unknown_features
717723
}

0 commit comments

Comments
 (0)