Skip to content

Commit 19878fe

Browse files
committedDec 3, 2019
Auto merge of #66945 - Centril:de-macro-gating, r=<try>
de-macro-ize feature gate checking This PR removes the usage of macros in feature gating preferring to take in symbols instead. The aim is to make feature gating more understandable overall while also reducing some duplication. To check whether a feature gate is active, `tcx.features().on(sym::my_feature)` can be used. Inside `PostExpansionVisitor` it's however better to use `self.gate(...)` which provides a nicer API atop of that. Outside of the visitor, if `gate_feature` can be used, it should be preferred over `feature_err`. As a follow-up, and once #66878 is merged, it might be a good idea to add a method to `Session` for more convenient access to `gate_feature` and `feature_err` respectively. Originally I intended to go for a `HashSet` representation, but this felt like a smaller change to just expand to a `match` on the symbol => field pairs. r? @oli-obk
2 parents f577b0e + 359de34 commit 19878fe

File tree

52 files changed

+478
-528
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+478
-528
lines changed
 

‎src/librustc/hir/lowering.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ impl<'a> LoweringContext<'a> {
834834
return;
835835
}
836836

837-
if !self.sess.features_untracked().in_band_lifetimes {
837+
if !self.sess.features_untracked().on(sym::in_band_lifetimes) {
838838
return;
839839
}
840840

@@ -1394,7 +1394,7 @@ impl<'a> LoweringContext<'a> {
13941394
}
13951395
ImplTraitContext::Disallowed(pos) => {
13961396
let allowed_in = if self.sess.features_untracked()
1397-
.impl_trait_in_bindings {
1397+
.on(sym::impl_trait_in_bindings) {
13981398
"bindings or function and inherent method return types"
13991399
} else {
14001400
"function and inherent method return types"
@@ -2118,7 +2118,7 @@ impl<'a> LoweringContext<'a> {
21182118

21192119
fn lower_local(&mut self, l: &Local) -> (hir::Local, SmallVec<[NodeId; 1]>) {
21202120
let mut ids = SmallVec::<[NodeId; 1]>::new();
2121-
if self.sess.features_untracked().impl_trait_in_bindings {
2121+
if self.sess.features_untracked().on(sym::impl_trait_in_bindings) {
21222122
if let Some(ref ty) = l.ty {
21232123
let mut visitor = ImplTraitTypeIdVisitor { ids: &mut ids };
21242124
visitor.visit_ty(ty);
@@ -2130,7 +2130,7 @@ impl<'a> LoweringContext<'a> {
21302130
ty: l.ty
21312131
.as_ref()
21322132
.map(|t| self.lower_ty(t,
2133-
if self.sess.features_untracked().impl_trait_in_bindings {
2133+
if self.sess.features_untracked().on(sym::impl_trait_in_bindings) {
21342134
ImplTraitContext::OpaqueTy(Some(parent_def_id))
21352135
} else {
21362136
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)

‎src/librustc/hir/lowering/item.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,15 @@ impl LoweringContext<'_> {
181181
ItemKind::Impl(.., None, _, _) => smallvec![i.id],
182182
ItemKind::Static(ref ty, ..) => {
183183
let mut ids = smallvec![i.id];
184-
if self.sess.features_untracked().impl_trait_in_bindings {
184+
if self.sess.features_untracked().on(sym::impl_trait_in_bindings) {
185185
let mut visitor = ImplTraitTypeIdVisitor { ids: &mut ids };
186186
visitor.visit_ty(ty);
187187
}
188188
ids
189189
},
190190
ItemKind::Const(ref ty, ..) => {
191191
let mut ids = smallvec![i.id];
192-
if self.sess.features_untracked().impl_trait_in_bindings {
192+
if self.sess.features_untracked().on(sym::impl_trait_in_bindings) {
193193
let mut visitor = ImplTraitTypeIdVisitor { ids: &mut ids };
194194
visitor.visit_ty(ty);
195195
}
@@ -285,7 +285,7 @@ impl LoweringContext<'_> {
285285
hir::ItemKind::Static(
286286
self.lower_ty(
287287
t,
288-
if self.sess.features_untracked().impl_trait_in_bindings {
288+
if self.sess.features_untracked().on(sym::impl_trait_in_bindings) {
289289
ImplTraitContext::OpaqueTy(None)
290290
} else {
291291
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
@@ -299,7 +299,7 @@ impl LoweringContext<'_> {
299299
hir::ItemKind::Const(
300300
self.lower_ty(
301301
t,
302-
if self.sess.features_untracked().impl_trait_in_bindings {
302+
if self.sess.features_untracked().on(sym::impl_trait_in_bindings) {
303303
ImplTraitContext::OpaqueTy(None)
304304
} else {
305305
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)

0 commit comments

Comments
 (0)