added unary_negate feature gate.
This commit is contained in:
parent
d528aa9960
commit
d8e309320d
|
@ -120,6 +120,7 @@ use syntax::attr::AttrMetaMethods;
|
|||
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_expr_with_unifier<'a, 'tcx, F>(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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,6 +150,9 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
|
|||
|
||||
// #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 @@ impl 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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue