Skip to content

Commit 359de34

Browse files
committed
de-macro-ize feature gate checking
1 parent f577b0e commit 359de34

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)

src/librustc/infer/error_reporting/need_type_info.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::infer::InferCtxt;
55
use crate::infer::type_variable::TypeVariableOriginKind;
66
use crate::ty::{self, Ty, Infer, TyVar};
77
use crate::ty::print::Print;
8-
use syntax::source_map::DesugaringKind;
9-
use syntax_pos::Span;
8+
use syntax_pos::source_map::DesugaringKind;
9+
use syntax_pos::{Span, symbol::sym};
1010
use errors::{Applicability, DiagnosticBuilder};
1111

1212
use rustc_error_codes::*;
@@ -217,7 +217,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
217217
let is_named_and_not_impl_trait = |ty: Ty<'_>| {
218218
&ty.to_string() != "_" &&
219219
// FIXME: Remove this check after `impl_trait_in_bindings` is stabilized. #63527
220-
(!ty.is_impl_trait() || self.tcx.features().impl_trait_in_bindings)
220+
(!ty.is_impl_trait() || self.tcx.features().on(sym::impl_trait_in_bindings))
221221
};
222222

223223
let ty_msg = match local_visitor.found_ty {

src/librustc/infer/opaque_types/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use errors::DiagnosticBuilder;
1313
use rustc::session::config::nightly_options;
1414
use rustc_data_structures::fx::FxHashMap;
1515
use rustc_data_structures::sync::Lrc;
16-
use syntax_pos::Span;
16+
use syntax_pos::{Span, symbol::sym};
1717

1818
use rustc_error_codes::*;
1919

@@ -488,7 +488,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
488488
conflict2: ty::Region<'tcx>,
489489
) -> bool {
490490
// If we have `#![feature(member_constraints)]`, no problems.
491-
if self.tcx.features().member_constraints {
491+
if self.tcx.features().on(sym::member_constraints) {
492492
return false;
493493
}
494494

src/librustc/lint/levels.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,13 @@ impl<'a> LintLevelsBuilder<'a> {
231231
// FIXME (#55112): issue unused-attributes lint if we thereby
232232
// don't have any lint names (`#[level(reason = "foo")]`)
233233
if let ast::LitKind::Str(rationale, _) = name_value.kind {
234-
if !self.sess.features_untracked().lint_reasons {
235-
feature_gate::feature_err(
236-
&self.sess.parse_sess,
237-
sym::lint_reasons,
238-
item.span,
239-
"lint reasons are experimental"
240-
)
241-
.emit();
242-
}
234+
feature_gate::gate_feature(
235+
&self.sess.parse_sess,
236+
self.sess.features_untracked(),
237+
item.span,
238+
sym::lint_reasons,
239+
"lint reasons are experimental"
240+
);
243241
reason = Some(rationale);
244242
} else {
245243
bad_attr(name_value.span)

src/librustc/middle/stability.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
116116
item_sp: Span, kind: AnnotationKind, visit_children: F)
117117
where F: FnOnce(&mut Self)
118118
{
119-
if self.tcx.features().staged_api {
119+
if self.tcx.features().on(sym::staged_api) {
120120
// This crate explicitly wants staged API.
121121
debug!("annotate(id = {:?}, attrs = {:?})", hir_id, attrs);
122122
if let Some(..) = attr::find_deprecation(&self.tcx.sess.parse_sess, attrs, item_sp) {
@@ -393,7 +393,7 @@ impl<'tcx> Index<'tcx> {
393393
pub fn new(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
394394
let is_staged_api =
395395
tcx.sess.opts.debugging_opts.force_unstable_if_unmarked ||
396-
tcx.features().staged_api;
396+
tcx.features().on(sym::staged_api);
397397
let mut staged_api = FxHashMap::default();
398398
staged_api.insert(LOCAL_CRATE, is_staged_api);
399399
let mut index = Index {
@@ -836,7 +836,7 @@ impl Visitor<'tcx> for Checker<'tcx> {
836836

837837
// There's no good place to insert stability check for non-Copy unions,
838838
// so semi-randomly perform it here in stability.rs
839-
hir::ItemKind::Union(..) if !self.tcx.features().untagged_unions => {
839+
hir::ItemKind::Union(..) if !self.tcx.features().on(sym::untagged_unions) => {
840840
let def_id = self.tcx.hir().local_def_id(item.hir_id);
841841
let adt_def = self.tcx.adt_def(def_id);
842842
let ty = self.tcx.type_of(def_id);

src/librustc/traits/error_reporting.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,13 +2353,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
23532353
}
23542354
ObligationCauseCode::VariableType(_) => {
23552355
err.note("all local variables must have a statically known size");
2356-
if !self.tcx.features().unsized_locals {
2356+
if !self.tcx.features().on(sym::unsized_locals) {
23572357
err.help("unsized locals are gated as an unstable feature");
23582358
}
23592359
}
23602360
ObligationCauseCode::SizedArgumentType => {
23612361
err.note("all function arguments must have a statically known size");
2362-
if !self.tcx.features().unsized_locals {
2362+
if !self.tcx.features().on(sym::unsized_locals) {
23632363
err.help("unsized locals are gated as an unstable feature");
23642364
}
23652365
}

src/librustc/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
22152215
}
22162216

22172217
if let Some(principal) = data.principal() {
2218-
if !self.infcx.tcx.features().object_safe_for_dispatch {
2218+
if !self.infcx.tcx.features().on(sym::object_safe_for_dispatch) {
22192219
principal.with_self_ty(self.tcx(), self_ty)
22202220
} else if self.tcx().is_object_safe(principal.def_id()) {
22212221
principal.with_self_ty(self.tcx(), self_ty)

src/librustc/traits/specialize/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::infer::{InferCtxt, InferOk};
1616
use crate::lint;
1717
use crate::traits::{self, coherence, FutureCompatOverlapErrorKind, ObligationCause, TraitEngine};
1818
use rustc_data_structures::fx::FxHashSet;
19-
use syntax_pos::DUMMY_SP;
19+
use syntax_pos::{DUMMY_SP, symbol::sym};
2020
use crate::traits::select::IntercrateAmbiguityCause;
2121
use crate::ty::{self, TyCtxt, TypeFoldable};
2222
use crate::ty::subst::{Subst, InternalSubsts, SubstsRef};
@@ -155,7 +155,7 @@ pub(super) fn specializes(
155155

156156
// The feature gate should prevent introducing new specializations, but not
157157
// taking advantage of upstream ones.
158-
if !tcx.features().specialization &&
158+
if !tcx.features().on(sym::specialization) &&
159159
(impl1_def_id.is_local() || impl2_def_id.is_local()) {
160160
return false;
161161
}

src/librustc/ty/constness.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::ty::query::Providers;
22
use crate::hir::def_id::DefId;
33
use crate::hir;
44
use crate::ty::TyCtxt;
5-
use syntax_pos::symbol::Symbol;
5+
use syntax_pos::symbol::{sym, Symbol};
66
use crate::hir::map::blocks::FnLikeNode;
77
use syntax::attr;
88

@@ -42,7 +42,7 @@ impl<'tcx> TyCtxt<'tcx> {
4242
return false;
4343
}
4444

45-
if self.features().staged_api {
45+
if self.features().on(sym::staged_api) {
4646
// in order for a libstd function to be considered min_const_fn
4747
// it needs to be stable and have no `rustc_const_unstable` attribute
4848
match self.lookup_stability(def_id) {
@@ -56,7 +56,7 @@ impl<'tcx> TyCtxt<'tcx> {
5656
}
5757
} else {
5858
// users enabling the `const_fn` feature gate can do what they want
59-
!self.features().const_fn
59+
!self.features().on(sym::const_fn)
6060
}
6161
}
6262
}

0 commit comments

Comments
 (0)