Skip to content

Commit 31d7ffa

Browse files
authored
Rollup merge of rust-lang#68018 - petrochenkov:nosoft, r=Centril
feature_gate: Remove `GateStrength` The "soft feature gating" from `feature_gate/check.rs` is unused, and even if it were used, hardcoded warning is not a good solution and [deny-by-default lint](rust-lang#64266) would be a better way to do this. cc rust-lang#67806 (comment) r? @Centril
2 parents 29a1cf2 + 8e35c4f commit 31d7ffa

File tree

2 files changed

+11
-74
lines changed

2 files changed

+11
-74
lines changed

src/librustc_ast_passes/feature_gate.rs

+10-37
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,25 @@ use rustc_span::Span;
88
use syntax::ast::{self, AssocTyConstraint, AssocTyConstraintKind, NodeId};
99
use syntax::ast::{GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData};
1010
use syntax::attr;
11-
use syntax::sess::{feature_err, leveled_feature_err, GateStrength, ParseSess};
11+
use syntax::sess::{feature_err, feature_err_issue, ParseSess};
1212
use syntax::visit::{self, FnKind, Visitor};
1313

1414
use log::debug;
1515

1616
macro_rules! gate_feature_fn {
17-
($cx: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr, $level: expr) => {{
18-
let (cx, has_feature, span, name, explain, level) =
19-
(&*$cx, $has_feature, $span, $name, $explain, $level);
17+
($cx: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr) => {{
18+
let (cx, has_feature, span, name, explain) = (&*$cx, $has_feature, $span, $name, $explain);
2019
let has_feature: bool = has_feature(&$cx.features);
2120
debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", name, span, has_feature);
2221
if !has_feature && !span.allows_unstable($name) {
23-
leveled_feature_err(cx.parse_sess, name, span, GateIssue::Language, explain, level)
24-
.emit();
22+
feature_err_issue(cx.parse_sess, name, span, GateIssue::Language, explain).emit();
2523
}
2624
}};
2725
}
2826

29-
macro_rules! gate_feature {
27+
macro_rules! gate_feature_post {
3028
($cx: expr, $feature: ident, $span: expr, $explain: expr) => {
31-
gate_feature_fn!(
32-
$cx,
33-
|x: &Features| x.$feature,
34-
$span,
35-
sym::$feature,
36-
$explain,
37-
GateStrength::Hard
38-
)
39-
};
40-
($cx: expr, $feature: ident, $span: expr, $explain: expr, $level: expr) => {
41-
gate_feature_fn!($cx, |x: &Features| x.$feature, $span, sym::$feature, $explain, $level)
29+
gate_feature_fn!($cx, |x: &Features| x.$feature, $span, sym::$feature, $explain)
4230
};
4331
}
4432

@@ -51,21 +39,6 @@ struct PostExpansionVisitor<'a> {
5139
features: &'a Features,
5240
}
5341

54-
macro_rules! gate_feature_post {
55-
($cx: expr, $feature: ident, $span: expr, $explain: expr) => {{
56-
let (cx, span) = ($cx, $span);
57-
if !span.allows_unstable(sym::$feature) {
58-
gate_feature!(cx, $feature, span, $explain)
59-
}
60-
}};
61-
($cx: expr, $feature: ident, $span: expr, $explain: expr, $level: expr) => {{
62-
let (cx, span) = ($cx, $span);
63-
if !span.allows_unstable(sym::$feature) {
64-
gate_feature!(cx, $feature, span, $explain, $level)
65-
}
66-
}};
67-
}
68-
6942
impl<'a> PostExpansionVisitor<'a> {
7043
fn check_abi(&self, abi: ast::StrLit) {
7144
let ast::StrLit { symbol_unescaped, span, .. } = abi;
@@ -257,15 +230,15 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
257230
attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)).map(|a| **a);
258231
// Check feature gates for built-in attributes.
259232
if let Some((.., AttributeGate::Gated(_, name, descr, has_feature))) = attr_info {
260-
gate_feature_fn!(self, has_feature, attr.span, name, descr, GateStrength::Hard);
233+
gate_feature_fn!(self, has_feature, attr.span, name, descr);
261234
}
262235
// Check unstable flavors of the `#[doc]` attribute.
263236
if attr.check_name(sym::doc) {
264237
for nested_meta in attr.meta_item_list().unwrap_or_default() {
265238
macro_rules! gate_doc { ($($name:ident => $feature:ident)*) => {
266239
$(if nested_meta.check_name(sym::$name) {
267240
let msg = concat!("`#[doc(", stringify!($name), ")]` is experimental");
268-
gate_feature!(self, $feature, attr.span, msg);
241+
gate_feature_post!(self, $feature, attr.span, msg);
269242
})*
270243
}}
271244

@@ -666,7 +639,7 @@ pub fn check_crate(
666639
macro_rules! gate_all {
667640
($gate:ident, $msg:literal) => {
668641
for span in spans.get(&sym::$gate).unwrap_or(&vec![]) {
669-
gate_feature!(&visitor, $gate, *span, $msg);
642+
gate_feature_post!(&visitor, $gate, *span, $msg);
670643
}
671644
};
672645
}
@@ -688,7 +661,7 @@ pub fn check_crate(
688661
// disabling these uses of early feature-gatings.
689662
if false {
690663
for span in spans.get(&sym::$gate).unwrap_or(&vec![]) {
691-
gate_feature!(&visitor, $gate, *span, $msg);
664+
gate_feature_post!(&visitor, $gate, *span, $msg);
692665
}
693666
}
694667
};

src/librustc_session/parse.rs

+1-37
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@ impl GatedSpans {
6262
}
6363
}
6464

65-
/// The strenght of a feature gate.
66-
/// Either it is a `Hard` error, or only a `Soft` warning.
67-
#[derive(Debug, Copy, Clone, PartialEq)]
68-
pub enum GateStrength {
69-
/// A hard error. (Most feature gates should use this.)
70-
Hard,
71-
/// Only a warning. (Use this only as backwards-compatibility demands.)
72-
Soft,
73-
}
74-
7565
/// Construct a diagnostic for a language feature error due to the given `span`.
7666
/// The `feature`'s `Symbol` is the one you used in `active.rs` and `rustc_span::symbols`.
7767
pub fn feature_err<'a>(
@@ -94,26 +84,7 @@ pub fn feature_err_issue<'a>(
9484
issue: GateIssue,
9585
explain: &str,
9686
) -> DiagnosticBuilder<'a> {
97-
leveled_feature_err(sess, feature, span, issue, explain, GateStrength::Hard)
98-
}
99-
100-
/// Construct a diagnostic for a feature gate error / warning.
101-
///
102-
/// You should typically just use `feature_err` instead.
103-
pub fn leveled_feature_err<'a>(
104-
sess: &'a ParseSess,
105-
feature: Symbol,
106-
span: impl Into<MultiSpan>,
107-
issue: GateIssue,
108-
explain: &str,
109-
level: GateStrength,
110-
) -> DiagnosticBuilder<'a> {
111-
let diag = &sess.span_diagnostic;
112-
113-
let mut err = match level {
114-
GateStrength::Hard => diag.struct_span_err_with_code(span, explain, error_code!(E0658)),
115-
GateStrength::Soft => diag.struct_span_warn(span, explain),
116-
};
87+
let mut err = sess.span_diagnostic.struct_span_err_with_code(span, explain, error_code!(E0658));
11788

11889
if let Some(n) = find_feature_issue(feature, issue) {
11990
err.note(&format!(
@@ -127,13 +98,6 @@ pub fn leveled_feature_err<'a>(
12798
err.help(&format!("add `#![feature({})]` to the crate attributes to enable", feature));
12899
}
129100

130-
// If we're on stable and only emitting a "soft" warning, add a note to
131-
// clarify that the feature isn't "on" (rather than being on but
132-
// warning-worthy).
133-
if !sess.unstable_features.is_nightly_build() && level == GateStrength::Soft {
134-
err.help("a nightly build of the compiler is required to enable this feature");
135-
}
136-
137101
err
138102
}
139103

0 commit comments

Comments
 (0)