From 80581be2c00ae9c9b24dea1c5a1465f6863564f3 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Wed, 11 Dec 2019 10:24:40 -0800 Subject: [PATCH] Replace `Index` impl with `enabled` method --- src/librustc_feature/active.rs | 8 ++------ src/librustc_passes/check_const.rs | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/librustc_feature/active.rs b/src/librustc_feature/active.rs index 123188944b2..a4099187762 100644 --- a/src/librustc_feature/active.rs +++ b/src/librustc_feature/active.rs @@ -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 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), } diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index 713dd3a7c83..e382d76f120 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -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() {