From 8f3021bd2cc49eda82ae01ac2e769a7e0fd0aa36 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Tue, 10 Dec 2019 12:41:27 -0800 Subject: [PATCH] Get active features dynamically by their `Symbol` --- src/librustc_feature/active.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/librustc_feature/active.rs b/src/librustc_feature/active.rs index 363621b3ca4..8794d830961 100644 --- a/src/librustc_feature/active.rs +++ b/src/librustc_feature/active.rs @@ -53,6 +53,18 @@ macro_rules! declare_features { $(f(stringify!($feature), self.$feature);)+ } } + + impl std::ops::Index for Features { + type Output = bool; + + fn index(&self, feature: Symbol) -> &Self::Output { + match feature { + $( sym::$feature => &self.$feature, )* + + _ => panic!("{} was not defined in `declare_features`", feature), + } + } + } }; }