Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature gating *declarations* => new crate rustc_feature #66895

Merged
merged 14 commits into from
Dec 1, 2019
Merged
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
21 changes: 8 additions & 13 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ use std::time::Instant;

use syntax::ast;
use syntax::source_map::FileLoader;
use syntax::feature_gate::{GatedCfg, UnstableFeatures};
use syntax::symbol::sym;
use syntax_pos::{DUMMY_SP, FileName};
use syntax::feature_gate::{find_gated_cfg, UnstableFeatures};
use syntax_pos::symbol::sym;
use syntax_pos::FileName;

pub mod pretty;
mod args;
Expand Down Expand Up @@ -677,12 +677,6 @@ impl RustcDefaultCalls {
.is_nightly_build();

let mut cfgs = sess.parse_sess.config.iter().filter_map(|&(name, ref value)| {
let gated_cfg = GatedCfg::gate(&ast::MetaItem {
path: ast::Path::from_ident(ast::Ident::with_dummy_span(name)),
kind: ast::MetaItemKind::Word,
span: DUMMY_SP,
});

// Note that crt-static is a specially recognized cfg
// directive that's printed out here as part of
// rust-lang/rust#37406, but in general the
Expand All @@ -693,10 +687,11 @@ impl RustcDefaultCalls {
// through to build scripts.
let value = value.as_ref().map(|s| s.as_str());
let value = value.as_ref().map(|s| s.as_ref());
if name != sym::target_feature || value != Some("crt-static") {
if !allow_unstable_cfg && gated_cfg.is_some() {
return None
}
if (name != sym::target_feature || value != Some("crt-static"))
&& !allow_unstable_cfg
&& find_gated_cfg(|cfg_sym| cfg_sym == name).is_some()
{
return None;
}

if let Some(value) = value {
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
38 changes: 18 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,29 @@ 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,
};
#[derive(Copy, Clone, Debug)]
pub enum Stability {
Unstable,
// First argument is tracking issue link; second argument is an optional
// help message, which defaults to "remove this attribute".
Deprecated(&'static str, Option<&'static str>),
}

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" }
9 changes: 5 additions & 4 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ use lint::{LateContext, LintContext, LintArray};
use lint::{LintPass, LateLintPass, EarlyLintPass, EarlyContext};

use rustc::util::nodemap::FxHashSet;
use rustc_feature::Stability;

use syntax::tokenstream::{TokenTree, TokenStream};
use syntax::ast::{self, Expr};
use syntax::ptr::P;
use syntax::attr::{self, HasAttrs, AttributeTemplate};
use syntax::attr::{self, HasAttrs};
use syntax::source_map::Spanned;
use syntax::edition::Edition;
use syntax::feature_gate::{self, AttributeGate, AttributeType};
use syntax::feature_gate::{Stability, deprecated_attributes};
use syntax::feature_gate::{AttributeGate, AttributeTemplate, AttributeType};
use syntax::feature_gate::deprecated_attributes;
use syntax_pos::{BytePos, Span};
use syntax::symbol::{Symbol, kw, sym};
use syntax::errors::{Applicability, DiagnosticBuilder};
Expand Down Expand Up @@ -1850,7 +1851,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
Loading