Skip to content

Commit

Permalink
introduce crate rustc_feature and move active, accepted, and removed …
Browse files Browse the repository at this point in the history
…to it
  • Loading branch information
Centril committed Nov 29, 2019
1 parent c4375c9 commit 3d080a4
Show file tree
Hide file tree
Showing 31 changed files with 87 additions and 52 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3199,6 +3199,7 @@ dependencies = [
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_fs_util",
"rustc_index",
"rustc_macros",
Expand Down Expand Up @@ -3607,6 +3608,13 @@ dependencies = [
"unicode-width",
]

[[package]]
name = "rustc_feature"
version = "0.0.0"
dependencies = [
"syntax_pos",
]

[[package]]
name = "rustc_fs_util"
version = "0.0.0"
Expand Down Expand Up @@ -3682,6 +3690,7 @@ dependencies = [
"rustc",
"rustc_data_structures",
"rustc_error_codes",
"rustc_feature",
"rustc_index",
"rustc_target",
"syntax",
Expand Down Expand Up @@ -3786,6 +3795,7 @@ dependencies = [
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_lexer",
"rustc_target",
"smallvec 1.0.0",
Expand All @@ -3802,6 +3812,7 @@ dependencies = [
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_index",
"rustc_parse",
"rustc_target",
Expand Down Expand Up @@ -4442,6 +4453,7 @@ dependencies = [
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_index",
"rustc_lexer",
"rustc_macros",
Expand All @@ -4458,6 +4470,7 @@ dependencies = [
"log",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
"rustc_lexer",
"rustc_parse",
"serialize",
Expand All @@ -4475,6 +4488,7 @@ dependencies = [
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_parse",
"rustc_target",
"smallvec 1.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rustc-rayon = "0.3.0"
rustc-rayon-core = "0.3.0"
polonius-engine = "0.10.0"
rustc_apfloat = { path = "../librustc_apfloat" }
rustc_feature = { path = "../librustc_feature" }
rustc_target = { path = "../librustc_target" }
rustc_macros = { path = "../librustc_macros" }
rustc_data_structures = { path = "../librustc_data_structures" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ macro_rules! arena_types {
[few] resolve_lifetimes: rustc::middle::resolve_lifetime::ResolveLifetimes,
[few] lint_levels: rustc::lint::LintLevelMap,
[few] stability_index: rustc::middle::stability::Index<'tcx>,
[few] features: syntax::feature_gate::Features,
[few] features: rustc_feature::Features,
[few] all_traits: Vec<rustc::hir::def_id::DefId>,
[few] privacy_access_levels: rustc::middle::privacy::AccessLevels,
[few] target_features_whitelist: rustc_data_structures::fx::FxHashMap<
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use crate::ich::StableHashingContext;

use syntax::ast;
use syntax::feature_gate;
use syntax_pos::SourceFile;

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


impl<'tcx> HashStable<StableHashingContext<'tcx>> for feature_gate::Features {
impl<'tcx> HashStable<StableHashingContext<'tcx>> for rustc_feature::Features {
fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
// Unfortunately we cannot exhaustively list fields here, since the
// struct is macro generated.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ rustc_queries! {
desc { |tcx| "estimating size for `{}`", tcx.def_path_str(def.def_id()) }
}

query features_query(_: CrateNum) -> &'tcx feature_gate::Features {
query features_query(_: CrateNum) -> &'tcx rustc_feature::Features {
eval_always
desc { "looking up enabled feature gates" }
}
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use errors::emitter::{Emitter, EmitterWriter};
use errors::emitter::HumanReadableErrorType;
use errors::annotate_snippet_emitter_writer::{AnnotateSnippetEmitterWriter};
use syntax::edition::Edition;
use syntax::feature_gate;
use errors::json::JsonEmitter;
use syntax::source_map;
use syntax::sess::ParseSess;
Expand Down Expand Up @@ -86,7 +85,7 @@ pub struct Session {
/// `rustc_codegen_llvm::back::symbol_names` module for more information.
pub crate_disambiguator: Once<CrateDisambiguator>,

features: Once<feature_gate::Features>,
features: Once<rustc_feature::Features>,

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

pub fn init_features(&self, features: feature_gate::Features) {
pub fn init_features(&self, features: rustc_feature::Features) {
self.features.set(features);
}

Expand Down
3 changes: 1 addition & 2 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ use rustc_macros::HashStable;
use syntax::ast;
use syntax::attr;
use syntax::source_map::MultiSpan;
use syntax::feature_gate;
use syntax::symbol::{Symbol, kw, sym};
use syntax_pos::Span;
use syntax::expand::allocator::AllocatorKind;
Expand Down Expand Up @@ -1315,7 +1314,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.cstore.allocator_kind()
}

pub fn features(self) -> &'tcx feature_gate::Features {
pub fn features(self) -> &'tcx rustc_feature::Features {
self.features_query(LOCAL_CRATE)
}

Expand Down
1 change: 0 additions & 1 deletion src/librustc/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ use std::any::type_name;
use syntax_pos::{Span, DUMMY_SP};
use syntax::attr;
use syntax::ast;
use syntax::feature_gate;
use syntax::symbol::Symbol;

#[macro_use]
Expand Down
13 changes: 13 additions & 0 deletions src/librustc_feature/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
authors = ["The Rust Project Developers"]
name = "rustc_feature"
version = "0.0.0"
edition = "2018"

[lib]
name = "rustc_feature"
path = "lib.rs"
doctest = false

[dependencies]
syntax_pos = { path = "../libsyntax_pos" }
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! List of the accepted feature gates.

use crate::symbol::sym;
use super::{State, Feature};
use syntax_pos::symbol::sym;

macro_rules! declare_features {
($(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

use super::{State, Feature};

use crate::edition::Edition;
use crate::symbol::{Symbol, sym};

use syntax_pos::edition::Edition;
use syntax_pos::Span;
use syntax_pos::symbol::{Symbol, sym};

macro_rules! set {
($field: ident) => {{
Expand Down
30 changes: 10 additions & 20 deletions src/libsyntax/feature_gate/mod.rs → src/librustc_feature/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
mod accepted;
mod removed;
mod active;
mod builtin_attrs;
mod check;

use crate::{edition::Edition, symbol::Symbol};
use std::fmt;
use std::num::NonZeroU32;
use syntax_pos::Span;
use syntax_pos::{Span, edition::Edition, symbol::Symbol};

#[derive(Clone, Copy)]
pub enum State {
Expand All @@ -44,28 +41,21 @@ impl fmt::Debug for State {

#[derive(Debug, Clone)]
pub struct Feature {
state: State,
name: Symbol,
since: &'static str,
pub state: State,
pub name: Symbol,
pub since: &'static str,
issue: Option<u32>, // FIXME: once #58732 is done make this an Option<NonZeroU32>
edition: Option<Edition>,
pub edition: Option<Edition>,
description: &'static str,
}

impl Feature {
fn issue(&self) -> Option<NonZeroU32> {
// FIXME(Centril): privatize again.
pub fn issue(&self) -> Option<NonZeroU32> {
self.issue.and_then(|i| NonZeroU32::new(i))
}
}

pub use active::{Features, INCOMPLETE_FEATURES};
pub use builtin_attrs::{
AttributeGate, AttributeType, GatedCfg,
BuiltinAttribute, BUILTIN_ATTRIBUTES, BUILTIN_ATTRIBUTE_MAP,
deprecated_attributes, is_builtin_attr, is_builtin_attr_name,
};
pub use check::{
check_crate, check_attribute, get_features, feature_err, emit_feature_err,
Stability, GateIssue, UnstableFeatures,
EXPLAIN_STMT_ATTR_SYNTAX, EXPLAIN_UNSIZED_TUPLE_COERCION,
};
pub use accepted::ACCEPTED_FEATURES;
pub use active::{ACTIVE_FEATURES, Features, INCOMPLETE_FEATURES};
pub use removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! List of the removed feature gates.

use crate::symbol::sym;
use super::{State, Feature};
use syntax_pos::symbol::sym;

macro_rules! declare_features {
($(
Expand Down
1 change: 1 addition & 0 deletions src/librustc_lint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ rustc_target = { path = "../librustc_target" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_feature = { path = "../librustc_feature" }
rustc_index = { path = "../librustc_index" }
rustc_error_codes = { path = "../librustc_error_codes" }
4 changes: 2 additions & 2 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use syntax::ptr::P;
use syntax::attr::{self, HasAttrs, AttributeTemplate};
use syntax::source_map::Spanned;
use syntax::edition::Edition;
use syntax::feature_gate::{self, AttributeGate, AttributeType};
use syntax::feature_gate::{AttributeGate, AttributeType};
use syntax::feature_gate::{Stability, deprecated_attributes};
use syntax_pos::{BytePos, Span};
use syntax::symbol::{Symbol, kw, sym};
Expand Down Expand Up @@ -1850,7 +1850,7 @@ impl EarlyLintPass for IncompleteFeatures {
features.declared_lang_features
.iter().map(|(name, span, _)| (name, span))
.chain(features.declared_lib_features.iter().map(|(name, span)| (name, span)))
.filter(|(name, _)| feature_gate::INCOMPLETE_FEATURES.iter().any(|f| name == &f))
.filter(|(name, _)| rustc_feature::INCOMPLETE_FEATURES.iter().any(|f| name == &f))
.for_each(|(name, &span)| {
cx.struct_span_lint(
INCOMPLETE_FEATURES,
Expand Down
1 change: 1 addition & 0 deletions src/librustc_parse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ syntax_pos = { path = "../libsyntax_pos" }
syntax = { path = "../libsyntax" }
errors = { path = "../librustc_errors", package = "rustc_errors" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_feature = { path = "../librustc_feature" }
rustc_lexer = { path = "../librustc_lexer" }
rustc_target = { path = "../librustc_target" }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_parse/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
//! [#64197]: https://github.com/rust-lang/rust/issues/64197

use crate::validate_attr;
use rustc_feature::Features;
use syntax::attr::HasAttrs;
use syntax::feature_gate::{
feature_err,
EXPLAIN_STMT_ATTR_SYNTAX,
Features,
get_features,
GateIssue,
};
Expand Down
1 change: 1 addition & 0 deletions src/librustc_passes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ path = "lib.rs"
log = "0.4"
rustc = { path = "../librustc" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_feature = { path = "../librustc_feature" }
rustc_index = { path = "../librustc_index" }
rustc_parse = { path = "../librustc_parse" }
rustc_target = { path = "../librustc_target" }
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_passes/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ use rustc::hir::map::Map;
use rustc::hir;
use rustc::ty::TyCtxt;
use rustc::ty::query::Providers;
use rustc_feature::Features;
use syntax::ast::Mutability;
use syntax::feature_gate::{emit_feature_err, Features, GateIssue};
use syntax::feature_gate::{emit_feature_err, GateIssue};
use syntax::span_err;
use syntax_pos::{sym, Span};
use rustc_error_codes::*;
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use std::mem;
use std::fmt::{self, Write};
use std::ops;

use rustc_feature::Features;
use syntax::symbol::{Symbol, sym};
use syntax::ast::{MetaItem, MetaItemKind, NestedMetaItem, LitKind};
use syntax::sess::ParseSess;
use syntax::feature_gate::Features;

use syntax_pos::Span;

Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern crate env_logger;
extern crate rustc;
extern crate rustc_data_structures;
extern crate rustc_driver;
extern crate rustc_feature;
extern crate rustc_error_codes;
extern crate rustc_index;
extern crate rustc_resolve;
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ lazy_static = "1.0.0"
syntax_pos = { path = "../libsyntax_pos" }
errors = { path = "../librustc_errors", package = "rustc_errors" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_feature = { path = "../librustc_feature" }
rustc_index = { path = "../librustc_index" }
rustc_lexer = { path = "../librustc_lexer" }
rustc_macros = { path = "../librustc_macros" }
Expand Down
3 changes: 2 additions & 1 deletion src/libsyntax/attr/builtin.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//! Parsing and validation of builtin attributes

use crate::ast::{self, Attribute, MetaItem, NestedMetaItem};
use crate::feature_gate::{Features, GatedCfg};
use crate::print::pprust;
use crate::feature_gate::GatedCfg;
use crate::sess::ParseSess;

use errors::{Applicability, Handler};
use std::num::NonZeroU32;
use syntax_pos::hygiene::Transparency;
use syntax_pos::{symbol::Symbol, symbol::sym, Span};
use rustc_feature::Features;
use rustc_macros::HashStable_Generic;

use super::{mark_used, MetaItemKind};
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/feature_gate/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use AttributeGate::*;

use super::check::{emit_feature_err, GateIssue};
use super::check::{Stability, EXPLAIN_ALLOW_INTERNAL_UNSAFE, EXPLAIN_ALLOW_INTERNAL_UNSTABLE};
use super::active::Features;
use rustc_feature::Features;

use crate::ast;
use crate::attr::AttributeTemplate;
use crate::sess::ParseSess;
use crate::symbol::{Symbol, sym};

use syntax_pos::symbol::{Symbol, sym};
use syntax_pos::Span;
use rustc_data_structures::fx::FxHashMap;
use lazy_static::lazy_static;
Expand Down
Loading

0 comments on commit 3d080a4

Please sign in to comment.