Replace Index impl with enabled method

This commit is contained in:
Dylan MacKenzie 2019-12-11 10:24:40 -08:00
parent 2b5ae1cb06
commit 80581be2c0
2 changed files with 4 additions and 8 deletions

View File

@ -52,14 +52,10 @@ macro_rules! declare_features {
pub fn walk_feature_fields(&self, mut f: impl FnMut(&str, bool)) {
$(f(stringify!($feature), self.$feature);)+
}
}
impl std::ops::Index<Symbol> for Features {
type Output = bool;
fn index(&self, feature: Symbol) -> &Self::Output {
pub fn enabled(&self, feature: Symbol) -> bool {
match feature {
$( sym::$feature => &self.$feature, )*
$( sym::$feature => self.$feature, )*
_ => panic!("`{}` was not listed in `declare_features`", feature),
}

View File

@ -137,7 +137,7 @@ impl<'tcx> CheckConstVisitor<'tcx> {
let gates = expr.required_feature_gates();
match gates {
// Don't emit an error if the user has enabled the requisite feature gates.
Some(gates) if gates.iter().all(|&g| features[g]) => return,
Some(gates) if gates.iter().all(|&g| features.enabled(g)) => return,
// `-Zunleash-the-miri-inside-of-you` only works for expressions that don't have a
// corresponding feature gate. This encourages nightly users to use feature gates when
@ -158,7 +158,7 @@ impl<'tcx> CheckConstVisitor<'tcx> {
let missing_gates: Vec<_> = gates
.iter()
.copied()
.filter(|&g| !features[g])
.filter(|&g| !features.enabled(g))
.collect();
match missing_gates.as_slice() {