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
18 changes: 18 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 @@ -3574,6 +3575,7 @@ dependencies = [
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_interface",
"rustc_lint",
"rustc_metadata",
Expand Down Expand Up @@ -3607,6 +3609,15 @@ dependencies = [
"unicode-width",
]

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

[[package]]
name = "rustc_fs_util"
version = "0.0.0"
Expand Down Expand Up @@ -3682,6 +3693,7 @@ dependencies = [
"rustc",
"rustc_data_structures",
"rustc_error_codes",
"rustc_feature",
"rustc_index",
"rustc_target",
"syntax",
Expand Down Expand Up @@ -3786,6 +3798,7 @@ dependencies = [
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_lexer",
"rustc_target",
"smallvec 1.0.0",
Expand All @@ -3802,6 +3815,7 @@ dependencies = [
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_index",
"rustc_parse",
"rustc_target",
Expand Down Expand Up @@ -3844,6 +3858,7 @@ dependencies = [
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_metadata",
"smallvec 1.0.0",
"syntax",
Expand Down Expand Up @@ -4442,6 +4457,7 @@ dependencies = [
"rustc_data_structures",
"rustc_error_codes",
"rustc_errors",
"rustc_feature",
"rustc_index",
"rustc_lexer",
"rustc_macros",
Expand All @@ -4458,6 +4474,7 @@ dependencies = [
"log",
"rustc_data_structures",
"rustc_errors",
"rustc_feature",
"rustc_lexer",
"rustc_parse",
"serialize",
Expand All @@ -4475,6 +4492,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
6 changes: 3 additions & 3 deletions src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ impl<'a> LintLevelsBuilder<'a> {
// don't have any lint names (`#[level(reason = "foo")]`)
if let ast::LitKind::Str(rationale, _) = name_value.kind {
if !self.sess.features_untracked().lint_reasons {
feature_gate::emit_feature_err(
feature_gate::feature_err(
&self.sess.parse_sess,
sym::lint_reasons,
item.span,
feature_gate::GateIssue::Language,
"lint reasons are experimental"
);
)
.emit();
}
reason = Some(rationale);
} else {
Expand Down
24 changes: 14 additions & 10 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ use crate::ty::query::Providers;
use crate::middle::privacy::AccessLevels;
use crate::session::{DiagnosticMessageId, Session};
use errors::DiagnosticBuilder;
use rustc_feature::GateIssue;
use syntax::symbol::{Symbol, sym};
use syntax_pos::{Span, MultiSpan};
use syntax::ast::{Attribute, CRATE_NODE_ID};
use syntax::errors::Applicability;
use syntax::feature_gate::{GateIssue, emit_feature_err};
use syntax::feature_gate::{feature_err, feature_err_issue};
use syntax::attr::{self, Stability, Deprecation, RustcDeprecation};
use crate::ty::{self, TyCtxt};
use crate::util::nodemap::{FxHashSet, FxHashMap};
Expand Down Expand Up @@ -512,9 +513,8 @@ pub fn report_unstable(
if is_soft {
soft_handler(lint::builtin::SOFT_UNSTABLE, span, &msg)
} else {
emit_feature_err(
&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg
);
feature_err_issue(&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg)
.emit();
}
}
}
Expand Down Expand Up @@ -842,15 +842,19 @@ impl Visitor<'tcx> for Checker<'tcx> {
let ty = self.tcx.type_of(def_id);

if adt_def.has_dtor(self.tcx) {
emit_feature_err(&self.tcx.sess.parse_sess,
sym::untagged_unions, item.span, GateIssue::Language,
"unions with `Drop` implementations are unstable");
feature_err(
&self.tcx.sess.parse_sess, sym::untagged_unions, item.span,
"unions with `Drop` implementations are unstable"
)
.emit();
} else {
let param_env = self.tcx.param_env(def_id);
if !param_env.can_type_implement_copy(self.tcx, ty).is_ok() {
emit_feature_err(&self.tcx.sess.parse_sess,
sym::untagged_unions, item.span, GateIssue::Language,
"unions with non-`Copy` fields are unstable");
feature_err(
&self.tcx.sess.parse_sess, sym::untagged_unions, item.span,
"unions with non-`Copy` fields are unstable"
)
.emit();
}
}
}
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
6 changes: 3 additions & 3 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::session::{early_error, early_warn, Session};
use crate::session::search_paths::SearchPath;

use rustc_data_structures::fx::FxHashSet;
use rustc_feature::UnstableFeatures;

use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel};
use rustc_target::spec::{Target, TargetTriple};
Expand All @@ -16,7 +17,6 @@ use syntax::ast;
use syntax::source_map::{FileName, FilePathMapping};
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
use syntax::symbol::{sym, Symbol};
use syntax::feature_gate::UnstableFeatures;

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

pub mod nightly_options {
use getopts;
use syntax::feature_gate::UnstableFeatures;
use rustc_feature::UnstableFeatures;
use super::{ErrorOutputType, OptionStability, RustcOptGroup};
use crate::session::early_error;

Expand Down Expand Up @@ -2850,9 +2850,9 @@ mod dep_tracking {
use super::{CrateType, DebugInfo, ErrorOutputType, OptLevel, OutputTypes,
Passes, Sanitizer, LtoCli, LinkerPluginLto, SwitchWithOptPath,
SymbolManglingVersion};
use rustc_feature::UnstableFeatures;
use rustc_target::spec::{MergeFunctions, PanicStrategy, RelroLevel, TargetTriple};
use syntax::edition::Edition;
use syntax::feature_gate::UnstableFeatures;

pub trait DepTrackingHash {
fn hash(&self, hasher: &mut DefaultHasher, error_format: ErrorOutputType);
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
1 change: 1 addition & 0 deletions src/librustc_codegen_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern crate libc;
#[macro_use] extern crate rustc;
extern crate rustc_target;
#[macro_use] extern crate rustc_data_structures;
extern crate rustc_feature;
extern crate rustc_index;
extern crate rustc_incremental;
extern crate rustc_codegen_utils;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc::session::config::PrintRequest;
use rustc_target::spec::{MergeFunctions, PanicStrategy};
use libc::c_int;
use std::ffi::CString;
use syntax::feature_gate::UnstableFeatures;
use rustc_feature::UnstableFeatures;
use syntax::symbol::sym;

use std::str;
Expand Down
1 change: 1 addition & 0 deletions src/librustc_driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ rustc_target = { path = "../librustc_target" }
rustc_lint = { path = "../librustc_lint" }
rustc_data_structures = { path = "../librustc_data_structures" }
errors = { path = "../librustc_errors", package = "rustc_errors" }
rustc_feature = { path = "../librustc_feature" }
rustc_metadata = { path = "../librustc_metadata" }
rustc_mir = { path = "../librustc_mir" }
rustc_parse = { path = "../librustc_parse" }
Expand Down
24 changes: 9 additions & 15 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use errors::{PResult, registry::Registry};
use rustc_interface::interface;
use rustc_interface::util::get_codegen_sysroot;
use rustc_data_structures::sync::SeqCst;

use rustc_feature::{find_gated_cfg, UnstableFeatures};
use rustc_serialize::json::ToJson;

use std::borrow::Cow;
Expand All @@ -61,10 +61,9 @@ use std::str;
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_pos::source_map::FileLoader;
use syntax_pos::symbol::sym;
use syntax_pos::FileName;

pub mod pretty;
mod args;
Expand Down Expand Up @@ -677,12 +676,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 +686,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
15 changes: 15 additions & 0 deletions src/librustc_feature/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[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]
rustc_data_structures = { path = "../librustc_data_structures" }
lazy_static = "1.0.0"
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
Loading