added unary_negate feature gate.

This commit is contained in:
Felix S. Klock II 2015-04-01 01:32:41 +02:00
parent d528aa9960
commit d8e309320d
2 changed files with 16 additions and 0 deletions

View file

@ -120,6 +120,7 @@
use syntax::ast::{self, DefId, Visibility};
use syntax::ast_util::{self, local_def};
use syntax::codemap::{self, Span};
use syntax::feature_gate;
use syntax::owned_slice::OwnedSlice;
use syntax::parse::token;
use syntax::print::pprust;
@ -3258,6 +3259,15 @@ fn check_struct_fields_on_error<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>,
tcx.lang_items.neg_trait(),
expr, &**oprnd, oprnd_t, unop);
}
if let ty::ty_uint(_) = oprnd_t.sty {
if !tcx.sess.features.borrow().negate_unsigned {
feature_gate::emit_feature_err(
&tcx.sess.parse_sess.span_diagnostic,
"negate_unsigned",
expr.span,
"unary negation of unsigned integers may be removed in the future");
}
}
}
}
}

View file

@ -150,6 +150,9 @@
// #23121. Array patterns have some hazards yet.
("slice_patterns", "1.0.0", Active),
// Allows use of unary negate on unsigned integers, e.g. -e for e: u8
("negate_unsigned", "1.0.0", Active),
];
// (changing above list without updating src/doc/reference.md makes @cmr sad)
@ -319,6 +322,7 @@ pub struct Features {
pub allow_custom_derive: bool,
pub simd_ffi: bool,
pub unmarked_api: bool,
pub negate_unsigned: bool,
/// spans of #![feature] attrs for stable language features. for error reporting
pub declared_stable_lang_features: Vec<Span>,
/// #![feature] attrs for non-language (library) features
@ -340,6 +344,7 @@ pub fn new() -> Features {
allow_custom_derive: false,
simd_ffi: false,
unmarked_api: false,
negate_unsigned: false,
declared_stable_lang_features: Vec::new(),
declared_lib_features: Vec::new()
}
@ -712,6 +717,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,
allow_custom_derive: cx.has_feature("custom_derive"),
simd_ffi: cx.has_feature("simd_ffi"),
unmarked_api: cx.has_feature("unmarked_api"),
negate_unsigned: cx.has_feature("negate_unsigned"),
declared_stable_lang_features: accepted_features,
declared_lib_features: unknown_features
}