Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit be01dab

Browse files
committed
Auto merge of #132027 - RalfJung:lang-feature-bool-fields, r=nnethercote
nightly feature tracking: get rid of the per-feature bool fields The `struct Features` that tracks which features are enabled has a ton of public `bool`-typed fields that are basically caching the result of looking up the corresponding feature in `enabled_lang_features`. Having public fields with an invariant is not great, so at least they should be made private. However, it turns out caching these lookups is actually [not worth it](#131321 (comment)), so this PR just entirely gets rid of these fields. (The alternative would be to make them private and have a method for each of them to expose them in a read-only way. Most of the diff of this PR would be the same in that case.) r? `@nnethercote`
2 parents ffd978b + 4463885 commit be01dab

File tree

111 files changed

+324
-385
lines changed

Some content is hidden

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

111 files changed

+324
-385
lines changed

‎compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
4949
| asm::InlineAsmArch::RiscV64
5050
| asm::InlineAsmArch::LoongArch64
5151
);
52-
if !is_stable && !self.tcx.features().asm_experimental_arch {
52+
if !is_stable && !self.tcx.features().asm_experimental_arch() {
5353
feature_err(
5454
&self.tcx.sess,
5555
sym::asm_experimental_arch,
@@ -65,7 +65,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
6565
{
6666
self.dcx().emit_err(AttSyntaxOnlyX86 { span: sp });
6767
}
68-
if asm.options.contains(InlineAsmOptions::MAY_UNWIND) && !self.tcx.features().asm_unwind {
68+
if asm.options.contains(InlineAsmOptions::MAY_UNWIND) && !self.tcx.features().asm_unwind() {
6969
feature_err(
7070
&self.tcx.sess,
7171
sym::asm_unwind,
@@ -237,7 +237,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
237237
}
238238
}
239239
InlineAsmOperand::Label { block } => {
240-
if !self.tcx.features().asm_goto {
240+
if !self.tcx.features().asm_goto() {
241241
feature_err(
242242
sess,
243243
sym::asm_goto,

‎compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
575575
} else {
576576
// Either `body.is_none()` or `is_never_pattern` here.
577577
if !is_never_pattern {
578-
if self.tcx.features().never_patterns {
578+
if self.tcx.features().never_patterns() {
579579
// If the feature is off we already emitted the error after parsing.
580580
let suggestion = span.shrink_to_hi();
581581
self.dcx().emit_err(MatchArmWithNoBody { span, suggestion });
@@ -717,7 +717,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
717717
outer_hir_id: HirId,
718718
inner_hir_id: HirId,
719719
) {
720-
if self.tcx.features().async_fn_track_caller
720+
if self.tcx.features().async_fn_track_caller()
721721
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
722722
&& attrs.into_iter().any(|attr| attr.has_name(sym::track_caller))
723723
{
@@ -1572,7 +1572,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15721572
);
15731573
}
15741574
Some(hir::CoroutineKind::Coroutine(_)) => {
1575-
if !self.tcx.features().coroutines {
1575+
if !self.tcx.features().coroutines() {
15761576
rustc_session::parse::feature_err(
15771577
&self.tcx.sess,
15781578
sym::coroutines,
@@ -1584,7 +1584,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15841584
false
15851585
}
15861586
None => {
1587-
if !self.tcx.features().coroutines {
1587+
if !self.tcx.features().coroutines() {
15881588
rustc_session::parse::feature_err(
15891589
&self.tcx.sess,
15901590
sym::coroutines,

‎compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15121512
continue;
15131513
}
15141514
let is_param = *is_param.get_or_insert_with(compute_is_param);
1515-
if !is_param && !self.tcx.features().more_maybe_bounds {
1515+
if !is_param && !self.tcx.features().more_maybe_bounds() {
15161516
self.tcx
15171517
.sess
15181518
.create_feature_err(
@@ -1530,7 +1530,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15301530
let host_param_parts = if let Const::Yes(span) = constness
15311531
// if this comes from implementing a `const` trait, we must force constness to be appended
15321532
// to the impl item, no matter whether effects is enabled.
1533-
&& (self.tcx.features().effects || force_append_constness)
1533+
&& (self.tcx.features().effects() || force_append_constness)
15341534
{
15351535
let span = self.lower_span(span);
15361536
let param_node_id = self.next_node_id();

‎compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
193193
impl_trait_defs: Vec::new(),
194194
impl_trait_bounds: Vec::new(),
195195
allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].into(),
196-
allow_gen_future: if tcx.features().async_fn_track_caller {
196+
allow_gen_future: if tcx.features().async_fn_track_caller() {
197197
[sym::gen_future, sym::closure_track_caller].into()
198198
} else {
199199
[sym::gen_future].into()
@@ -1035,7 +1035,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10351035
span: data.inputs_span,
10361036
})
10371037
};
1038-
if !self.tcx.features().return_type_notation
1038+
if !self.tcx.features().return_type_notation()
10391039
&& self.tcx.sess.is_nightly_build()
10401040
{
10411041
add_feature_diagnostics(
@@ -1160,7 +1160,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11601160
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(lt)),
11611161
ast::GenericArg::Type(ty) => {
11621162
match &ty.kind {
1163-
TyKind::Infer if self.tcx.features().generic_arg_infer => {
1163+
TyKind::Infer if self.tcx.features().generic_arg_infer() => {
11641164
return GenericArg::Infer(hir::InferArg {
11651165
hir_id: self.lower_node_id(ty.id),
11661166
span: self.lower_span(ty.span),
@@ -1500,7 +1500,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15001500
// is enabled. We don't check the span of the edition, since this is done
15011501
// on a per-opaque basis to account for nested opaques.
15021502
let always_capture_in_scope = match origin {
1503-
_ if self.tcx.features().lifetime_capture_rules_2024 => true,
1503+
_ if self.tcx.features().lifetime_capture_rules_2024() => true,
15041504
hir::OpaqueTyOrigin::TyAlias { .. } => true,
15051505
hir::OpaqueTyOrigin::FnReturn { in_trait_or_impl, .. } => in_trait_or_impl.is_some(),
15061506
hir::OpaqueTyOrigin::AsyncFn { .. } => {
@@ -1519,7 +1519,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
15191519
// Feature gate for RPITIT + use<..>
15201520
match origin {
15211521
rustc_hir::OpaqueTyOrigin::FnReturn { in_trait_or_impl: Some(_), .. } => {
1522-
if !self.tcx.features().precise_capturing_in_traits
1522+
if !self.tcx.features().precise_capturing_in_traits()
15231523
&& let Some(span) = bounds.iter().find_map(|bound| match *bound {
15241524
ast::GenericBound::Use(_, span) => Some(span),
15251525
_ => None,
@@ -2270,7 +2270,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22702270
fn lower_array_length(&mut self, c: &AnonConst) -> hir::ArrayLen<'hir> {
22712271
match c.value.kind {
22722272
ExprKind::Underscore => {
2273-
if self.tcx.features().generic_arg_infer {
2273+
if self.tcx.features().generic_arg_infer() {
22742274
hir::ArrayLen::Infer(hir::InferArg {
22752275
hir_id: self.lower_node_id(c.id),
22762276
span: self.lower_span(c.value.span),

‎compiler/rustc_ast_lowering/src/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
268268
span: data.inputs_span,
269269
})
270270
};
271-
if !self.tcx.features().return_type_notation
271+
if !self.tcx.features().return_type_notation()
272272
&& self.tcx.sess.is_nightly_build()
273273
{
274274
add_feature_diagnostics(
@@ -496,7 +496,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
496496
// // disallowed --^^^^^^^^^^ allowed --^^^^^^^^^^
497497
// ```
498498
FnRetTy::Ty(ty) if matches!(itctx, ImplTraitContext::OpaqueTy { .. }) => {
499-
if self.tcx.features().impl_trait_in_fn_trait_return {
499+
if self.tcx.features().impl_trait_in_fn_trait_return() {
500500
self.lower_ty(ty, itctx)
501501
} else {
502502
self.lower_ty(

‎compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ impl<'a> AstValidator<'a> {
295295
return;
296296
};
297297

298-
let make_impl_const_sugg = if self.features.const_trait_impl
298+
let const_trait_impl = self.features.const_trait_impl();
299+
let make_impl_const_sugg = if const_trait_impl
299300
&& let TraitOrTraitImpl::TraitImpl {
300301
constness: Const::No,
301302
polarity: ImplPolarity::Positive,
@@ -308,13 +309,12 @@ impl<'a> AstValidator<'a> {
308309
None
309310
};
310311

311-
let make_trait_const_sugg = if self.features.const_trait_impl
312-
&& let TraitOrTraitImpl::Trait { span, constness: None } = parent
313-
{
314-
Some(span.shrink_to_lo())
315-
} else {
316-
None
317-
};
312+
let make_trait_const_sugg =
313+
if const_trait_impl && let TraitOrTraitImpl::Trait { span, constness: None } = parent {
314+
Some(span.shrink_to_lo())
315+
} else {
316+
None
317+
};
318318

319319
let parent_constness = parent.constness();
320320
self.dcx().emit_err(errors::TraitFnConst {
@@ -1145,7 +1145,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11451145
}
11461146
self.check_type_no_bounds(bounds, "this context");
11471147

1148-
if self.features.lazy_type_alias {
1148+
if self.features.lazy_type_alias() {
11491149
if let Err(err) = self.check_type_alias_where_clause_location(ty_alias) {
11501150
self.dcx().emit_err(err);
11511151
}
@@ -1286,7 +1286,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12861286
GenericBound::Trait(trait_ref) => {
12871287
match (ctxt, trait_ref.modifiers.constness, trait_ref.modifiers.polarity) {
12881288
(BoundKind::SuperTraits, BoundConstness::Never, BoundPolarity::Maybe(_))
1289-
if !self.features.more_maybe_bounds =>
1289+
if !self.features.more_maybe_bounds() =>
12901290
{
12911291
self.sess
12921292
.create_feature_err(
@@ -1299,7 +1299,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12991299
.emit();
13001300
}
13011301
(BoundKind::TraitObject, BoundConstness::Never, BoundPolarity::Maybe(_))
1302-
if !self.features.more_maybe_bounds =>
1302+
if !self.features.more_maybe_bounds() =>
13031303
{
13041304
self.sess
13051305
.create_feature_err(

‎compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ use crate::errors;
1515
/// The common case.
1616
macro_rules! gate {
1717
($visitor:expr, $feature:ident, $span:expr, $explain:expr) => {{
18-
if !$visitor.features.$feature && !$span.allows_unstable(sym::$feature) {
18+
if !$visitor.features.$feature() && !$span.allows_unstable(sym::$feature) {
1919
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
2020
feature_err(&$visitor.sess, sym::$feature, $span, $explain).emit();
2121
}
2222
}};
2323
($visitor:expr, $feature:ident, $span:expr, $explain:expr, $help:expr) => {{
24-
if !$visitor.features.$feature && !$span.allows_unstable(sym::$feature) {
24+
if !$visitor.features.$feature() && !$span.allows_unstable(sym::$feature) {
2525
// FIXME: make this translatable
2626
#[allow(rustc::diagnostic_outside_of_impl)]
2727
#[allow(rustc::untranslatable_diagnostic)]
@@ -43,7 +43,7 @@ macro_rules! gate_alt {
4343
/// The case involving a multispan.
4444
macro_rules! gate_multi {
4545
($visitor:expr, $feature:ident, $spans:expr, $explain:expr) => {{
46-
if !$visitor.features.$feature {
46+
if !$visitor.features.$feature() {
4747
let spans: Vec<_> =
4848
$spans.filter(|span| !span.allows_unstable(sym::$feature)).collect();
4949
if !spans.is_empty() {
@@ -56,7 +56,7 @@ macro_rules! gate_multi {
5656
/// The legacy case.
5757
macro_rules! gate_legacy {
5858
($visitor:expr, $feature:ident, $span:expr, $explain:expr) => {{
59-
if !$visitor.features.$feature && !$span.allows_unstable(sym::$feature) {
59+
if !$visitor.features.$feature() && !$span.allows_unstable(sym::$feature) {
6060
feature_warn(&$visitor.sess, sym::$feature, $span, $explain);
6161
}
6262
}};
@@ -150,7 +150,7 @@ impl<'a> PostExpansionVisitor<'a> {
150150

151151
// FIXME(non_lifetime_binders): Const bound params are pretty broken.
152152
// Let's keep users from using this feature accidentally.
153-
if self.features.non_lifetime_binders {
153+
if self.features.non_lifetime_binders() {
154154
let const_param_spans: Vec<_> = params
155155
.iter()
156156
.filter_map(|param| match param.kind {
@@ -210,7 +210,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
210210
}
211211

212212
// Emit errors for non-staged-api crates.
213-
if !self.features.staged_api {
213+
if !self.features.staged_api() {
214214
if attr.has_name(sym::unstable)
215215
|| attr.has_name(sym::stable)
216216
|| attr.has_name(sym::rustc_const_unstable)
@@ -470,7 +470,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
470470
// Limit `min_specialization` to only specializing functions.
471471
gate_alt!(
472472
&self,
473-
self.features.specialization || (is_fn && self.features.min_specialization),
473+
self.features.specialization() || (is_fn && self.features.min_specialization()),
474474
sym::specialization,
475475
i.span,
476476
"specialization is unstable"
@@ -548,7 +548,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
548548
gate_all!(return_type_notation, "return type notation is experimental");
549549
gate_all!(pin_ergonomics, "pinned reference syntax is experimental");
550550

551-
if !visitor.features.never_patterns {
551+
if !visitor.features.never_patterns() {
552552
if let Some(spans) = spans.get(&sym::never_patterns) {
553553
for &span in spans {
554554
if span.allows_unstable(sym::never_patterns) {
@@ -572,7 +572,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
572572
}
573573
}
574574

575-
if !visitor.features.negative_bounds {
575+
if !visitor.features.negative_bounds() {
576576
for &span in spans.get(&sym::negative_bounds).iter().copied().flatten() {
577577
sess.dcx().emit_err(errors::NegativeBoundUnsupported { span });
578578
}

‎compiler/rustc_attr/src/builtin.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ pub fn eval_condition(
622622
&((
623623
if *b { kw::True } else { kw::False },
624624
sym::cfg_boolean_literals,
625-
|features: &Features| features.cfg_boolean_literals,
625+
|features: &Features| features.cfg_boolean_literals(),
626626
)),
627627
cfg.span(),
628628
sess,
@@ -711,7 +711,7 @@ pub fn eval_condition(
711711
}
712712
sym::target => {
713713
if let Some(features) = features
714-
&& !features.cfg_target_compact
714+
&& !features.cfg_target_compact()
715715
{
716716
feature_err(
717717
sess,
@@ -831,7 +831,7 @@ pub fn find_deprecation(
831831
attrs: &[Attribute],
832832
) -> Option<(Deprecation, Span)> {
833833
let mut depr: Option<(Deprecation, Span)> = None;
834-
let is_rustc = features.staged_api;
834+
let is_rustc = features.staged_api();
835835

836836
'outer: for attr in attrs {
837837
if !attr.has_name(sym::deprecated) {
@@ -891,7 +891,7 @@ pub fn find_deprecation(
891891
}
892892
}
893893
sym::suggestion => {
894-
if !features.deprecated_suggestion {
894+
if !features.deprecated_suggestion() {
895895
sess.dcx().emit_err(
896896
session_diagnostics::DeprecatedItemSuggestion {
897897
span: mi.span,
@@ -909,7 +909,7 @@ pub fn find_deprecation(
909909
sess.dcx().emit_err(session_diagnostics::UnknownMetaItem {
910910
span: meta.span(),
911911
item: pprust::path_to_string(&mi.path),
912-
expected: if features.deprecated_suggestion {
912+
expected: if features.deprecated_suggestion() {
913913
&["since", "note", "suggestion"]
914914
} else {
915915
&["since", "note"]

‎compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1035,7 +1035,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10351035

10361036
fn unsized_feature_enabled(&self) -> bool {
10371037
let features = self.tcx().features();
1038-
features.unsized_locals || features.unsized_fn_params
1038+
features.unsized_locals() || features.unsized_fn_params()
10391039
}
10401040

10411041
/// Equate the inferred type and the annotated type for user type annotations

‎compiler/rustc_builtin_macros/src/assert.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub(crate) fn expand_assert<'cx>(
6969
// If `generic_assert` is enabled, generates rich captured outputs
7070
//
7171
// FIXME(c410-f3r) See https://github.com/rust-lang/rust/issues/96949
72-
else if cx.ecfg.features.generic_assert {
72+
else if cx.ecfg.features.generic_assert() {
7373
context::Context::new(cx, call_site_span).build(cond_expr, panic_path())
7474
}
7575
// If `generic_assert` is not enabled, only outputs a literal "assertion failed: ..."

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /