Skip to content

Commit

Permalink
move GateIssue to rustc_feature & simplify emit_feature_err
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Nov 30, 2019
1 parent 91fcd40 commit 79077f1
Show file tree
Hide file tree
Showing 17 changed files with 159 additions and 165 deletions.
6 changes: 3 additions & 3 deletions src/librustc/lint/levels.rs
Expand Up @@ -232,13 +232,13 @@ impl<'a> LintLevelsBuilder<'a> {
// don't have any lint names (`#[level(reason = "foo")]`) // don't have any lint names (`#[level(reason = "foo")]`)
if let ast::LitKind::Str(rationale, _) = name_value.kind { if let ast::LitKind::Str(rationale, _) = name_value.kind {
if !self.sess.features_untracked().lint_reasons { if !self.sess.features_untracked().lint_reasons {
feature_gate::emit_feature_err( feature_gate::feature_err(
&self.sess.parse_sess, &self.sess.parse_sess,
sym::lint_reasons, sym::lint_reasons,
item.span, item.span,
feature_gate::GateIssue::Language,
"lint reasons are experimental" "lint reasons are experimental"
); )
.emit();
} }
reason = Some(rationale); reason = Some(rationale);
} else { } else {
Expand Down
24 changes: 14 additions & 10 deletions src/librustc/middle/stability.rs
Expand Up @@ -13,11 +13,12 @@ use crate::ty::query::Providers;
use crate::middle::privacy::AccessLevels; use crate::middle::privacy::AccessLevels;
use crate::session::{DiagnosticMessageId, Session}; use crate::session::{DiagnosticMessageId, Session};
use errors::DiagnosticBuilder; use errors::DiagnosticBuilder;
use rustc_feature::GateIssue;
use syntax::symbol::{Symbol, sym}; use syntax::symbol::{Symbol, sym};
use syntax_pos::{Span, MultiSpan}; use syntax_pos::{Span, MultiSpan};
use syntax::ast::{Attribute, CRATE_NODE_ID}; use syntax::ast::{Attribute, CRATE_NODE_ID};
use syntax::errors::Applicability; 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 syntax::attr::{self, Stability, Deprecation, RustcDeprecation};
use crate::ty::{self, TyCtxt}; use crate::ty::{self, TyCtxt};
use crate::util::nodemap::{FxHashSet, FxHashMap}; use crate::util::nodemap::{FxHashSet, FxHashMap};
Expand Down Expand Up @@ -512,9 +513,8 @@ pub fn report_unstable(
if is_soft { if is_soft {
soft_handler(lint::builtin::SOFT_UNSTABLE, span, &msg) soft_handler(lint::builtin::SOFT_UNSTABLE, span, &msg)
} else { } else {
emit_feature_err( feature_err_issue(&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg)
&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); let ty = self.tcx.type_of(def_id);


if adt_def.has_dtor(self.tcx) { if adt_def.has_dtor(self.tcx) {
emit_feature_err(&self.tcx.sess.parse_sess, feature_err(
sym::untagged_unions, item.span, GateIssue::Language, &self.tcx.sess.parse_sess, sym::untagged_unions, item.span,
"unions with `Drop` implementations are unstable"); "unions with `Drop` implementations are unstable"
)
.emit();
} else { } else {
let param_env = self.tcx.param_env(def_id); let param_env = self.tcx.param_env(def_id);
if !param_env.can_type_implement_copy(self.tcx, ty).is_ok() { if !param_env.can_type_implement_copy(self.tcx, ty).is_ok() {
emit_feature_err(&self.tcx.sess.parse_sess, feature_err(
sym::untagged_unions, item.span, GateIssue::Language, &self.tcx.sess.parse_sess, sym::untagged_unions, item.span,
"unions with non-`Copy` fields are unstable"); "unions with non-`Copy` fields are unstable"
)
.emit();
} }
} }
} }
Expand Down
34 changes: 32 additions & 2 deletions src/librustc_feature/lib.rs
Expand Up @@ -49,8 +49,7 @@ pub struct Feature {
} }


impl Feature { impl Feature {
// FIXME(Centril): privatize again. fn issue(&self) -> Option<NonZeroU32> {
pub fn issue(&self) -> Option<NonZeroU32> {
self.issue.and_then(|i| NonZeroU32::new(i)) self.issue.and_then(|i| NonZeroU32::new(i))
} }
} }
Expand Down Expand Up @@ -97,6 +96,37 @@ impl UnstableFeatures {
} }
} }


fn find_lang_feature_issue(feature: Symbol) -> Option<NonZeroU32> {
if let Some(info) = ACTIVE_FEATURES.iter().find(|t| t.name == feature) {
// FIXME (#28244): enforce that active features have issue numbers
// assert!(info.issue().is_some())
info.issue()
} else {
// search in Accepted, Removed, or Stable Removed features
let found = ACCEPTED_FEATURES
.iter()
.chain(REMOVED_FEATURES)
.chain(STABLE_REMOVED_FEATURES)
.find(|t| t.name == feature);
match found {
Some(found) => found.issue(),
None => panic!("feature `{}` is not declared anywhere", feature),
}
}
}

pub enum GateIssue {
Language,
Library(Option<NonZeroU32>)
}

pub fn find_feature_issue(feature: Symbol, issue: GateIssue) -> Option<NonZeroU32> {
match issue {
GateIssue::Language => find_lang_feature_issue(feature),
GateIssue::Library(lib) => lib,
}
}

pub use accepted::ACCEPTED_FEATURES; pub use accepted::ACCEPTED_FEATURES;
pub use active::{ACTIVE_FEATURES, Features, INCOMPLETE_FEATURES}; pub use active::{ACTIVE_FEATURES, Features, INCOMPLETE_FEATURES};
pub use removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES}; pub use removed::{REMOVED_FEATURES, STABLE_REMOVED_FEATURES};
Expand Down
36 changes: 19 additions & 17 deletions src/librustc_metadata/native_libs.rs
Expand Up @@ -7,7 +7,7 @@ use rustc::util::nodemap::FxHashSet;
use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;
use syntax::attr; use syntax::attr;
use syntax::source_map::Span; use syntax::source_map::Span;
use syntax::feature_gate::{self, GateIssue}; use syntax::feature_gate::feature_err;
use syntax::symbol::{kw, sym, Symbol}; use syntax::symbol::{kw, sym, Symbol};
use syntax::{span_err, struct_span_err}; use syntax::{span_err, struct_span_err};


Expand Down Expand Up @@ -158,27 +158,29 @@ impl Collector<'tcx> {
} }
} }
if lib.cfg.is_some() && !self.tcx.features().link_cfg { if lib.cfg.is_some() && !self.tcx.features().link_cfg {
feature_gate::emit_feature_err(&self.tcx.sess.parse_sess, feature_err(&self.tcx.sess.parse_sess, sym::link_cfg, span.unwrap(), "is unstable")
sym::link_cfg, .emit();
span.unwrap(),
GateIssue::Language,
"is unstable");
} }
if lib.kind == cstore::NativeStaticNobundle && if lib.kind == cstore::NativeStaticNobundle &&
!self.tcx.features().static_nobundle { !self.tcx.features().static_nobundle
feature_gate::emit_feature_err(&self.tcx.sess.parse_sess, {
sym::static_nobundle, feature_err(
span.unwrap_or_else(|| syntax_pos::DUMMY_SP), &self.tcx.sess.parse_sess,
GateIssue::Language, sym::static_nobundle,
"kind=\"static-nobundle\" is unstable"); span.unwrap_or_else(|| syntax_pos::DUMMY_SP),
"kind=\"static-nobundle\" is unstable"
)
.emit();
} }
if lib.kind == cstore::NativeRawDylib && if lib.kind == cstore::NativeRawDylib &&
!self.tcx.features().raw_dylib { !self.tcx.features().raw_dylib {
feature_gate::emit_feature_err(&self.tcx.sess.parse_sess, feature_err(
sym::raw_dylib, &self.tcx.sess.parse_sess,
span.unwrap_or_else(|| syntax_pos::DUMMY_SP), sym::raw_dylib,
GateIssue::Language, span.unwrap_or_else(|| syntax_pos::DUMMY_SP),
"kind=\"raw-dylib\" is unstable"); "kind=\"raw-dylib\" is unstable"
)
.emit();
} }
self.libs.push(lib); self.libs.push(lib);
} }
Expand Down
48 changes: 24 additions & 24 deletions src/librustc_mir/transform/check_consts/ops.rs
Expand Up @@ -4,7 +4,7 @@ use rustc::hir::def_id::DefId;
use rustc::mir::BorrowKind; use rustc::mir::BorrowKind;
use rustc::session::config::nightly_options; use rustc::session::config::nightly_options;
use rustc::ty::TyCtxt; use rustc::ty::TyCtxt;
use syntax::feature_gate::{emit_feature_err, GateIssue}; use syntax::feature_gate::feature_err;
use syntax::symbol::sym; use syntax::symbol::sym;
use syntax_pos::{Span, Symbol}; use syntax_pos::{Span, Symbol};


Expand Down Expand Up @@ -222,13 +222,13 @@ impl NonConstOp for Panic {
} }


fn emit_error(&self, item: &Item<'_, '_>, span: Span) { fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
emit_feature_err( feature_err(
&item.tcx.sess.parse_sess, &item.tcx.sess.parse_sess,
sym::const_panic, sym::const_panic,
span, span,
GateIssue::Language,
&format!("panicking in {}s is unstable", item.const_kind()), &format!("panicking in {}s is unstable", item.const_kind()),
); )
.emit();
} }
} }


Expand All @@ -240,13 +240,13 @@ impl NonConstOp for RawPtrComparison {
} }


fn emit_error(&self, item: &Item<'_, '_>, span: Span) { fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
emit_feature_err( feature_err(
&item.tcx.sess.parse_sess, &item.tcx.sess.parse_sess,
sym::const_compare_raw_pointers, sym::const_compare_raw_pointers,
span, span,
GateIssue::Language,
&format!("comparing raw pointers inside {}", item.const_kind()), &format!("comparing raw pointers inside {}", item.const_kind()),
); )
.emit();
} }
} }


Expand All @@ -258,14 +258,14 @@ impl NonConstOp for RawPtrDeref {
} }


fn emit_error(&self, item: &Item<'_, '_>, span: Span) { fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
emit_feature_err( feature_err(
&item.tcx.sess.parse_sess, sym::const_raw_ptr_deref, &item.tcx.sess.parse_sess, sym::const_raw_ptr_deref, span,
span, GateIssue::Language,
&format!( &format!(
"dereferencing raw pointers in {}s is unstable", "dereferencing raw pointers in {}s is unstable",
item.const_kind(), item.const_kind(),
), ),
); )
.emit();
} }
} }


Expand All @@ -277,14 +277,14 @@ impl NonConstOp for RawPtrToIntCast {
} }


fn emit_error(&self, item: &Item<'_, '_>, span: Span) { fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
emit_feature_err( feature_err(
&item.tcx.sess.parse_sess, sym::const_raw_ptr_to_usize_cast, &item.tcx.sess.parse_sess, sym::const_raw_ptr_to_usize_cast, span,
span, GateIssue::Language,
&format!( &format!(
"casting pointers to integers in {}s is unstable", "casting pointers to integers in {}s is unstable",
item.const_kind(), item.const_kind(),
), ),
); )
.emit();
} }
} }


Expand Down Expand Up @@ -334,11 +334,11 @@ impl NonConstOp for Transmute {
} }


fn emit_error(&self, item: &Item<'_, '_>, span: Span) { fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
emit_feature_err( feature_err(
&item.tcx.sess.parse_sess, sym::const_transmute, &item.tcx.sess.parse_sess, sym::const_transmute, span,
span, GateIssue::Language, &format!("The use of std::mem::transmute() is gated in {}s", item.const_kind())
&format!("The use of std::mem::transmute() \ )
is gated in {}s", item.const_kind())); .emit();
} }
} }


Expand All @@ -355,10 +355,10 @@ impl NonConstOp for UnionAccess {
} }


fn emit_error(&self, item: &Item<'_, '_>, span: Span) { fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
emit_feature_err( feature_err(
&item.tcx.sess.parse_sess, sym::const_fn_union, &item.tcx.sess.parse_sess, sym::const_fn_union, span,
span, GateIssue::Language,
"unions in const fn are unstable", "unions in const fn are unstable",
); )
.emit();
} }
} }
3 changes: 1 addition & 2 deletions src/librustc_parse/config.rs
Expand Up @@ -11,7 +11,7 @@
use crate::validate_attr; use crate::validate_attr;
use rustc_feature::Features; use rustc_feature::Features;
use syntax::attr::HasAttrs; use syntax::attr::HasAttrs;
use syntax::feature_gate::{feature_err, get_features, GateIssue}; use syntax::feature_gate::{feature_err, get_features};
use syntax::attr; use syntax::attr;
use syntax::ast; use syntax::ast;
use syntax::edition::Edition; use syntax::edition::Edition;
Expand Down Expand Up @@ -212,7 +212,6 @@ impl<'a> StripUnconfigured<'a> {
let mut err = feature_err(self.sess, let mut err = feature_err(self.sess,
sym::stmt_expr_attributes, sym::stmt_expr_attributes,
attr.span, attr.span,
GateIssue::Language,
"attributes on expressions are experimental"); "attributes on expressions are experimental");


if attr.is_doc_comment() { if attr.is_doc_comment() {
Expand Down
10 changes: 2 additions & 8 deletions src/librustc_passes/check_const.rs
Expand Up @@ -15,7 +15,7 @@ use rustc::ty::TyCtxt;
use rustc::ty::query::Providers; use rustc::ty::query::Providers;
use rustc_feature::Features; use rustc_feature::Features;
use syntax::ast::Mutability; use syntax::ast::Mutability;
use syntax::feature_gate::{emit_feature_err, GateIssue}; use syntax::feature_gate::feature_err;
use syntax::span_err; use syntax::span_err;
use syntax_pos::{sym, Span}; use syntax_pos::{sym, Span};
use rustc_error_codes::*; use rustc_error_codes::*;
Expand Down Expand Up @@ -141,13 +141,7 @@ impl<'tcx> CheckConstVisitor<'tcx> {
| NonConstExpr::Match(hir::MatchSource::Normal) | NonConstExpr::Match(hir::MatchSource::Normal)
| NonConstExpr::Match(hir::MatchSource::IfDesugar { .. }) | NonConstExpr::Match(hir::MatchSource::IfDesugar { .. })
| NonConstExpr::Match(hir::MatchSource::IfLetDesugar { .. }) | NonConstExpr::Match(hir::MatchSource::IfLetDesugar { .. })
=> emit_feature_err( => feature_err(&self.tcx.sess.parse_sess, sym::const_if_match, span, &msg).emit(),
&self.tcx.sess.parse_sess,
sym::const_if_match,
span,
GateIssue::Language,
&msg
),


_ => span_err!(self.tcx.sess, span, E0744, "{}", msg), _ => span_err!(self.tcx.sess, span, E0744, "{}", msg),
} }
Expand Down
11 changes: 3 additions & 8 deletions src/librustc_resolve/macros.rs
Expand Up @@ -16,7 +16,7 @@ use rustc_feature::is_builtin_attr_name;
use syntax::ast::{self, NodeId, Ident}; use syntax::ast::{self, NodeId, Ident};
use syntax::attr::{self, StabilityLevel}; use syntax::attr::{self, StabilityLevel};
use syntax::edition::Edition; use syntax::edition::Edition;
use syntax::feature_gate::{emit_feature_err, GateIssue}; use syntax::feature_gate::feature_err;
use syntax::print::pprust; use syntax::print::pprust;
use syntax_expand::base::{self, InvocationRes, Indeterminate}; use syntax_expand::base::{self, InvocationRes, Indeterminate};
use syntax_expand::base::SyntaxExtension; use syntax_expand::base::SyntaxExtension;
Expand Down Expand Up @@ -346,13 +346,8 @@ impl<'a> Resolver<'a> {
segment.ident.as_str().starts_with("rustc") { segment.ident.as_str().starts_with("rustc") {
let msg = let msg =
"attributes starting with `rustc` are reserved for use by the `rustc` compiler"; "attributes starting with `rustc` are reserved for use by the `rustc` compiler";
emit_feature_err( feature_err(&self.session.parse_sess, sym::rustc_attrs, segment.ident.span, msg)
&self.session.parse_sess, .emit();
sym::rustc_attrs,
segment.ident.span,
GateIssue::Language,
msg,
);
} }
} }


Expand Down
5 changes: 2 additions & 3 deletions src/librustc_typeck/astconv.rs
Expand Up @@ -23,7 +23,7 @@ use crate::require_c_abi_if_c_variadic;
use smallvec::SmallVec; use smallvec::SmallVec;
use syntax::ast; use syntax::ast;
use syntax::errors::pluralize; use syntax::errors::pluralize;
use syntax::feature_gate::{GateIssue, emit_feature_err}; use syntax::feature_gate::feature_err;
use syntax::util::lev_distance::find_best_match_for_name; use syntax::util::lev_distance::find_best_match_for_name;
use syntax::symbol::sym; use syntax::symbol::sym;
use syntax_pos::{DUMMY_SP, Span, MultiSpan}; use syntax_pos::{DUMMY_SP, Span, MultiSpan};
Expand Down Expand Up @@ -914,8 +914,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
} else { } else {
"parenthetical notation is only stable when used with `Fn`-family traits" "parenthetical notation is only stable when used with `Fn`-family traits"
}; };
emit_feature_err(&self.tcx().sess.parse_sess, sym::unboxed_closures, feature_err(&self.tcx().sess.parse_sess, sym::unboxed_closures, span, msg).emit();
span, GateIssue::Language, msg);
} }


self.create_substs_for_ast_path(span, self.create_substs_for_ast_path(span,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/coercion.rs
Expand Up @@ -644,13 +644,13 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
} }


if has_unsized_tuple_coercion && !self.tcx.features().unsized_tuple_coercion { if has_unsized_tuple_coercion && !self.tcx.features().unsized_tuple_coercion {
feature_gate::emit_feature_err( feature_gate::feature_err(
&self.tcx.sess.parse_sess, &self.tcx.sess.parse_sess,
sym::unsized_tuple_coercion, sym::unsized_tuple_coercion,
self.cause.span, self.cause.span,
feature_gate::GateIssue::Language,
"unsized tuple coercion is not stable enough for use and is subject to change", "unsized tuple coercion is not stable enough for use and is subject to change",
); )
.emit();
} }


Ok(coercion) Ok(coercion)
Expand Down

0 comments on commit 79077f1

Please sign in to comment.