From ded177a06a1cde44ab64dcd09c63f6c2b815a9fe Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Sat, 30 Nov 2019 07:44:01 +0100 Subject: [PATCH] derive(Default) for Features --- src/librustc_feature/active.rs | 14 ++------------ src/librustc_parse/config.rs | 2 +- src/libsyntax/feature_gate/check.rs | 2 +- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/librustc_feature/active.rs b/src/librustc_feature/active.rs index fc1f770e226..7c0d39965fc 100644 --- a/src/librustc_feature/active.rs +++ b/src/librustc_feature/active.rs @@ -36,7 +36,7 @@ macro_rules! declare_features { ),+]; /// A set of features to be used by later passes. - #[derive(Clone)] + #[derive(Clone, Default)] pub struct Features { /// `#![feature]` attrs for language features, for error reporting. pub declared_lang_features: Vec<(Symbol, Span, Option)>, @@ -49,17 +49,7 @@ pub struct Features { } impl Features { - pub fn new() -> Features { - Features { - declared_lang_features: Vec::new(), - declared_lib_features: Vec::new(), - $($feature: false),+ - } - } - - pub fn walk_feature_fields(&self, mut f: F) - where F: FnMut(&str, bool) - { + pub fn walk_feature_fields(&self, mut f: impl FnMut(&str, bool)) { $(f(stringify!($feature), self.$feature);)+ } } diff --git a/src/librustc_parse/config.rs b/src/librustc_parse/config.rs index 6293858ed4e..26e51e83d62 100644 --- a/src/librustc_parse/config.rs +++ b/src/librustc_parse/config.rs @@ -47,7 +47,7 @@ pub fn features(mut krate: ast::Crate, sess: &ParseSess, edition: Edition, } else { // the entire crate is unconfigured krate.attrs = Vec::new(); krate.module.items = Vec::new(); - return (krate, Features::new()); + return (krate, Features::default()); } features = get_features(&sess.span_diagnostic, &krate.attrs, edition, allow_features); diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index c90f4c6f19f..3d2c3b1d4f9 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -641,7 +641,7 @@ fn feature_removed(span_handler: &Handler, span: Span, reason: Option<&str>) { err.emit(); } - let mut features = Features::new(); + let mut features = Features::default(); let mut edition_enabled_features = FxHashMap::default(); for &edition in ALL_EDITIONS { -- 2.44.0