Skip to content

Commit b772b5b

Browse files
authored
Rollup merge of #66895 - Centril:rustc_feature, r=oli-obk
Feature gating *declarations* => new crate `rustc_feature` This PR moves the data-oriented parts of feature gating into its own crate, `rustc_feature`. The parts consist of some data types as well as `accepted`, `active`, `removed`, and `builtin_attrs`. Feature gate checking itself remains in `syntax::feature_gate::check`. The parts which define how to emit feature gate errors could probably be moved to `rustc_errors` or to the new `rustc_session` crate introduced in #66878. The visitor itself could probably be moved as a pass in `rustc_passes` depending on how the dependency edges work out. The PR also contains some drive-by cleanup of feature gate checking. As such, the PR probably best read commit-by-commit. r? @oli-obk cc @petrochenkov cc @Mark-Simulacrum
2 parents b4bffce + ded177a commit b772b5b

Some content is hidden

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

62 files changed

+444
-460
lines changed

Cargo.lock

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3199,6 +3199,7 @@ dependencies = [
31993199
"rustc_data_structures",
32003200
"rustc_error_codes",
32013201
"rustc_errors",
3202+
"rustc_feature",
32023203
"rustc_fs_util",
32033204
"rustc_index",
32043205
"rustc_macros",
@@ -3574,6 +3575,7 @@ dependencies = [
35743575
"rustc_data_structures",
35753576
"rustc_error_codes",
35763577
"rustc_errors",
3578+
"rustc_feature",
35773579
"rustc_interface",
35783580
"rustc_lint",
35793581
"rustc_metadata",
@@ -3607,6 +3609,15 @@ dependencies = [
36073609
"unicode-width",
36083610
]
36093611

3612+
[[package]]
3613+
name = "rustc_feature"
3614+
version = "0.0.0"
3615+
dependencies = [
3616+
"lazy_static 1.3.0",
3617+
"rustc_data_structures",
3618+
"syntax_pos",
3619+
]
3620+
36103621
[[package]]
36113622
name = "rustc_fs_util"
36123623
version = "0.0.0"
@@ -3682,6 +3693,7 @@ dependencies = [
36823693
"rustc",
36833694
"rustc_data_structures",
36843695
"rustc_error_codes",
3696+
"rustc_feature",
36853697
"rustc_index",
36863698
"rustc_target",
36873699
"syntax",
@@ -3786,6 +3798,7 @@ dependencies = [
37863798
"rustc_data_structures",
37873799
"rustc_error_codes",
37883800
"rustc_errors",
3801+
"rustc_feature",
37893802
"rustc_lexer",
37903803
"rustc_target",
37913804
"smallvec 1.0.0",
@@ -3802,6 +3815,7 @@ dependencies = [
38023815
"rustc_data_structures",
38033816
"rustc_error_codes",
38043817
"rustc_errors",
3818+
"rustc_feature",
38053819
"rustc_index",
38063820
"rustc_parse",
38073821
"rustc_target",
@@ -3844,6 +3858,7 @@ dependencies = [
38443858
"rustc_data_structures",
38453859
"rustc_error_codes",
38463860
"rustc_errors",
3861+
"rustc_feature",
38473862
"rustc_metadata",
38483863
"smallvec 1.0.0",
38493864
"syntax",
@@ -4442,6 +4457,7 @@ dependencies = [
44424457
"rustc_data_structures",
44434458
"rustc_error_codes",
44444459
"rustc_errors",
4460+
"rustc_feature",
44454461
"rustc_index",
44464462
"rustc_lexer",
44474463
"rustc_macros",
@@ -4458,6 +4474,7 @@ dependencies = [
44584474
"log",
44594475
"rustc_data_structures",
44604476
"rustc_errors",
4477+
"rustc_feature",
44614478
"rustc_lexer",
44624479
"rustc_parse",
44634480
"serialize",
@@ -4475,6 +4492,7 @@ dependencies = [
44754492
"rustc_data_structures",
44764493
"rustc_error_codes",
44774494
"rustc_errors",
4495+
"rustc_feature",
44784496
"rustc_parse",
44794497
"rustc_target",
44804498
"smallvec 1.0.0",

src/librustc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ rustc-rayon = "0.3.0"
2222
rustc-rayon-core = "0.3.0"
2323
polonius-engine = "0.10.0"
2424
rustc_apfloat = { path = "../librustc_apfloat" }
25+
rustc_feature = { path = "../librustc_feature" }
2526
rustc_target = { path = "../librustc_target" }
2627
rustc_macros = { path = "../librustc_macros" }
2728
rustc_data_structures = { path = "../librustc_data_structures" }

src/librustc/arena.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ macro_rules! arena_types {
101101
[few] resolve_lifetimes: rustc::middle::resolve_lifetime::ResolveLifetimes,
102102
[few] lint_levels: rustc::lint::LintLevelMap,
103103
[few] stability_index: rustc::middle::stability::Index<'tcx>,
104-
[few] features: syntax::feature_gate::Features,
104+
[few] features: rustc_feature::Features,
105105
[few] all_traits: Vec<rustc::hir::def_id::DefId>,
106106
[few] privacy_access_levels: rustc::middle::privacy::AccessLevels,
107107
[few] target_features_whitelist: rustc_data_structures::fx::FxHashMap<

src/librustc/ich/impls_syntax.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use crate::ich::StableHashingContext;
55

66
use syntax::ast;
7-
use syntax::feature_gate;
87
use syntax_pos::SourceFile;
98

109
use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX};
@@ -156,7 +155,7 @@ fn stable_normalized_pos(np: ::syntax_pos::NormalizedPos,
156155
}
157156

158157

159-
impl<'tcx> HashStable<StableHashingContext<'tcx>> for feature_gate::Features {
158+
impl<'tcx> HashStable<StableHashingContext<'tcx>> for rustc_feature::Features {
160159
fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
161160
// Unfortunately we cannot exhaustively list fields here, since the
162161
// struct is macro generated.

src/librustc/lint/levels.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,13 @@ impl<'a> LintLevelsBuilder<'a> {
232232
// don't have any lint names (`#[level(reason = "foo")]`)
233233
if let ast::LitKind::Str(rationale, _) = name_value.kind {
234234
if !self.sess.features_untracked().lint_reasons {
235-
feature_gate::emit_feature_err(
235+
feature_gate::feature_err(
236236
&self.sess.parse_sess,
237237
sym::lint_reasons,
238238
item.span,
239-
feature_gate::GateIssue::Language,
240239
"lint reasons are experimental"
241-
);
240+
)
241+
.emit();
242242
}
243243
reason = Some(rationale);
244244
} else {

src/librustc/middle/stability.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ use crate::ty::query::Providers;
1313
use crate::middle::privacy::AccessLevels;
1414
use crate::session::{DiagnosticMessageId, Session};
1515
use errors::DiagnosticBuilder;
16+
use rustc_feature::GateIssue;
1617
use syntax::symbol::{Symbol, sym};
1718
use syntax_pos::{Span, MultiSpan};
1819
use syntax::ast::{Attribute, CRATE_NODE_ID};
1920
use syntax::errors::Applicability;
20-
use syntax::feature_gate::{GateIssue, emit_feature_err};
21+
use syntax::feature_gate::{feature_err, feature_err_issue};
2122
use syntax::attr::{self, Stability, Deprecation, RustcDeprecation};
2223
use crate::ty::{self, TyCtxt};
2324
use crate::util::nodemap::{FxHashSet, FxHashMap};
@@ -512,9 +513,8 @@ pub fn report_unstable(
512513
if is_soft {
513514
soft_handler(lint::builtin::SOFT_UNSTABLE, span, &msg)
514515
} else {
515-
emit_feature_err(
516-
&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg
517-
);
516+
feature_err_issue(&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg)
517+
.emit();
518518
}
519519
}
520520
}
@@ -842,15 +842,19 @@ impl Visitor<'tcx> for Checker<'tcx> {
842842
let ty = self.tcx.type_of(def_id);
843843

844844
if adt_def.has_dtor(self.tcx) {
845-
emit_feature_err(&self.tcx.sess.parse_sess,
846-
sym::untagged_unions, item.span, GateIssue::Language,
847-
"unions with `Drop` implementations are unstable");
845+
feature_err(
846+
&self.tcx.sess.parse_sess, sym::untagged_unions, item.span,
847+
"unions with `Drop` implementations are unstable"
848+
)
849+
.emit();
848850
} else {
849851
let param_env = self.tcx.param_env(def_id);
850852
if !param_env.can_type_implement_copy(self.tcx, ty).is_ok() {
851-
emit_feature_err(&self.tcx.sess.parse_sess,
852-
sym::untagged_unions, item.span, GateIssue::Language,
853-
"unions with non-`Copy` fields are unstable");
853+
feature_err(
854+
&self.tcx.sess.parse_sess, sym::untagged_unions, item.span,
855+
"unions with non-`Copy` fields are unstable"
856+
)
857+
.emit();
854858
}
855859
}
856860
}

src/librustc/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ rustc_queries! {
11301130
desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
11311131
}
11321132

1133-
query features_query(_: CrateNum) -> &'tcx feature_gate::Features {
1133+
query features_query(_: CrateNum) -> &'tcx rustc_feature::Features {
11341134
eval_always
11351135
desc { "looking up enabled feature gates" }
11361136
}

src/librustc/session/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::session::{early_error, early_warn, Session};
77
use crate::session::search_paths::SearchPath;
88

99
use rustc_data_structures::fx::FxHashSet;
10+
use rustc_feature::UnstableFeatures;
1011

1112
use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel};
1213
use rustc_target::spec::{Target, TargetTriple};
@@ -16,7 +17,6 @@ use syntax::ast;
1617
use syntax::source_map::{FileName, FilePathMapping};
1718
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
1819
use syntax::symbol::{sym, Symbol};
19-
use syntax::feature_gate::UnstableFeatures;
2020

2121
use errors::emitter::HumanReadableErrorType;
2222
use errors::{ColorConfig, FatalError, Handler};
@@ -2701,7 +2701,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
27012701

27022702
pub mod nightly_options {
27032703
use getopts;
2704-
use syntax::feature_gate::UnstableFeatures;
2704+
use rustc_feature::UnstableFeatures;
27052705
use super::{ErrorOutputType, OptionStability, RustcOptGroup};
27062706
use crate::session::early_error;
27072707

@@ -2850,9 +2850,9 @@ mod dep_tracking {
28502850
use super::{CrateType, DebugInfo, ErrorOutputType, OptLevel, OutputTypes,
28512851
Passes, Sanitizer, LtoCli, LinkerPluginLto, SwitchWithOptPath,
28522852
SymbolManglingVersion};
2853+
use rustc_feature::UnstableFeatures;
28532854
use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel, TargetTriple};
28542855
use syntax::edition::Edition;
2855-
use syntax::feature_gate::UnstableFeatures;
28562856

28572857
pub trait DepTrackingHash {
28582858
fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType);

src/librustc/session/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use errors::emitter::{Emitter, EmitterWriter};
2121
use errors::emitter::HumanReadableErrorType;
2222
use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
2323
use syntax::edition::Edition;
24-
use syntax::feature_gate;
2524
use errors::json::JsonEmitter;
2625
use syntax::source_map;
2726
use syntax::sess::ParseSess;
@@ -86,7 +85,7 @@ pub struct Session {
8685
/// `rustc_codegen_llvm::back::symbol_names` module for more information.
8786
pub crate_disambiguator: Once<CrateDisambiguator>,
8887

89-
features: Once<feature_gate::Features>,
88+
features: Once<rustc_feature::Features>,
9089

9190
/// The maximum recursion limit for potentially infinitely recursive
9291
/// operations such as auto-dereference and monomorphization.
@@ -470,11 +469,11 @@ impl Session {
470469
/// DO NOT USE THIS METHOD if there is a TyCtxt available, as it circumvents
471470
/// dependency tracking. Use tcx.features() instead.
472471
#[inline]
473-
pub fn features_untracked(&self) -> &feature_gate::Features {
472+
pub fn features_untracked(&self) -> &rustc_feature::Features {
474473
self.features.get()
475474
}
476475

477-
pub fn init_features(&self, features: feature_gate::Features) {
476+
pub fn init_features(&self, features: rustc_feature::Features) {
478477
self.features.set(features);
479478
}
480479

src/librustc/ty/context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ use rustc_macros::HashStable;
7272
use syntax::ast;
7373
use syntax::attr;
7474
use syntax::source_map::MultiSpan;
75-
use syntax::feature_gate;
7675
use syntax::symbol::{Symbol, kw, sym};
7776
use syntax_pos::Span;
7877
use syntax::expand::allocator::AllocatorKind;
@@ -1312,7 +1311,7 @@ impl<'tcx> TyCtxt<'tcx> {
13121311
self.cstore.allocator_kind()
13131312
}
13141313

1315-
pub fn features(self) -> &'tcx feature_gate::Features {
1314+
pub fn features(self) -> &'tcx rustc_feature::Features {
13161315
self.features_query(LOCAL_CRATE)
13171316
}
13181317

0 commit comments

Comments
 (0)