Skip to content

Commit 04fedf7

Browse files
Remove unused code in cfg_old
1 parent 5b150d2 commit 04fedf7

File tree

7 files changed

+22
-263
lines changed

7 files changed

+22
-263
lines changed

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ attr_parsing_bundle_needs_static =
66
77
attr_parsing_cfg_attr_bad_delim = wrong `cfg_attr` delimiters
88
9-
attr_parsing_cfg_predicate_identifier =
10-
`cfg` predicate key must be an identifier
11-
129
attr_parsing_deprecated_item_suggestion =
1310
suggestions on deprecated items are unstable
1411
.help = add `#![feature(deprecated_suggestion)]` to the crate root
@@ -41,9 +38,6 @@ attr_parsing_empty_link_name =
4138
link name must not be empty
4239
.label = empty link name
4340
44-
attr_parsing_expected_one_cfg_pattern =
45-
expected 1 cfg-pattern
46-
4741
attr_parsing_expected_single_version_literal =
4842
expected single version literal
4943
@@ -241,10 +235,6 @@ attr_parsing_unstable_cfg_target_compact =
241235
attr_parsing_unstable_feature_bound_incompatible_stability = item annotated with `#[unstable_feature_bound]` should not be stable
242236
.help = If this item is meant to be stable, do not use any functions annotated with `#[unstable_feature_bound]`. Otherwise, mark this item as unstable with `#[unstable]`
243237
244-
attr_parsing_unsupported_literal_cfg_boolean =
245-
literal in `cfg` predicate value must be a boolean
246-
attr_parsing_unsupported_literal_cfg_string =
247-
literal in `cfg` predicate value must be a string
248238
attr_parsing_unsupported_literal_generic =
249239
unsupported literal
250240
attr_parsing_unsupported_literal_suggestion =

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use rustc_ast::token::Delimiter;
44
use rustc_ast::tokenstream::DelimSpan;
55
use rustc_ast::{AttrItem, Attribute, CRATE_NODE_ID, LitKind, ast, token};
66
use rustc_errors::{Applicability, PResult};
7-
use rustc_feature::{AttrSuggestionStyle, AttributeTemplate, Features, template};
7+
use rustc_feature::{
8+
AttrSuggestionStyle, AttributeTemplate, Features, GatedCfg, find_gated_cfg, template,
9+
};
810
use rustc_hir::attrs::CfgEntry;
911
use rustc_hir::lints::AttributeLintKind;
1012
use rustc_hir::{AttrPath, RustcVersion};
@@ -23,7 +25,7 @@ use crate::session_diagnostics::{
2325
AttributeParseError, AttributeParseErrorReason, CfgAttrBadDelim, MetaBadDelimSugg,
2426
ParsedDescription,
2527
};
26-
use crate::{AttributeParser, fluent_generated, parse_version, session_diagnostics, try_gate_cfg};
28+
use crate::{AttributeParser, fluent_generated, parse_version, session_diagnostics};
2729

2830
pub const CFG_TEMPLATE: AttributeTemplate = template!(
2931
List: &["predicate"],
@@ -410,3 +412,19 @@ fn parse_cfg_attr_internal<'a>(
410412

411413
Ok((cfg_predicate, expanded_attrs))
412414
}
415+
416+
fn try_gate_cfg(name: Symbol, span: Span, sess: &Session, features: Option<&Features>) {
417+
let gate = find_gated_cfg(|sym| sym == name);
418+
if let (Some(feats), Some(gated_cfg)) = (features, gate) {
419+
gate_cfg(gated_cfg, span, sess, feats);
420+
}
421+
}
422+
423+
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
424+
fn gate_cfg(gated_cfg: &GatedCfg, cfg_span: Span, sess: &Session, features: &Features) {
425+
let (cfg, feature, has_feature) = gated_cfg;
426+
if !has_feature(features) && !cfg_span.allows_unstable(*feature) {
427+
let explain = format!("`cfg({cfg})` is experimental and subject to change");
428+
feature_err(sess, *feature, cfg_span, explain).emit();
429+
}
430+
}

compiler/rustc_attr_parsing/src/attributes/cfg_old.rs

Lines changed: 0 additions & 210 deletions
This file was deleted.

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ mod prelude;
3232
pub(crate) mod allow_unstable;
3333
pub(crate) mod body;
3434
pub(crate) mod cfg;
35-
pub(crate) mod cfg_old;
3635
pub(crate) mod cfg_select;
3736
pub(crate) mod codegen_attrs;
3837
pub(crate) mod confusables;

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::{
88

99
use super::prelude::*;
1010
use super::util::parse_version;
11-
use crate::session_diagnostics::{self, UnsupportedLiteralReason};
11+
use crate::session_diagnostics::{self};
1212

1313
macro_rules! reject_outside_std {
1414
($cx: ident) => {
@@ -304,7 +304,6 @@ pub(crate) fn parse_stability<S: Stage>(
304304
let Some(param) = param.meta_item() else {
305305
cx.emit_err(session_diagnostics::UnsupportedLiteral {
306306
span: param_span,
307-
reason: UnsupportedLiteralReason::Generic,
308307
is_bytestr: false,
309308
start_point_span: cx.sess().source_map().start_point(param_span),
310309
});
@@ -384,7 +383,6 @@ pub(crate) fn parse_unstability<S: Stage>(
384383
let Some(param) = param.meta_item() else {
385384
cx.emit_err(session_diagnostics::UnsupportedLiteral {
386385
span: param.span(),
387-
reason: UnsupportedLiteralReason::Generic,
388386
is_bytestr: false,
389387
start_point_span: cx.sess().source_map().start_point(param.span()),
390388
});

compiler/rustc_attr_parsing/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ pub mod validate_attr;
107107
pub use attributes::cfg::{
108108
CFG_TEMPLATE, EvalConfigResult, eval_config_entry, parse_cfg, parse_cfg_attr, parse_cfg_entry,
109109
};
110-
pub use attributes::cfg_old::*;
111110
pub use attributes::cfg_select::*;
112111
pub use attributes::util::{is_builtin_attr, parse_version};
113112
pub use context::{Early, Late, OmitDoc, ShouldEmit};

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,6 @@ use rustc_span::{Span, Symbol};
1212

1313
use crate::fluent_generated as fluent;
1414

15-
pub(crate) enum UnsupportedLiteralReason {
16-
Generic,
17-
CfgString,
18-
CfgBoolean,
19-
}
20-
21-
#[derive(Diagnostic)]
22-
#[diag(attr_parsing_expected_one_cfg_pattern, code = E0536)]
23-
pub(crate) struct ExpectedOneCfgPattern {
24-
#[primary_span]
25-
pub span: Span,
26-
}
27-
2815
#[derive(Diagnostic)]
2916
#[diag(attr_parsing_invalid_predicate, code = E0537)]
3017
pub(crate) struct InvalidPredicate {
@@ -234,28 +221,13 @@ pub(crate) struct InvalidReprHintNoValue {
234221
// FIXME(jdonszelmann): slowly phased out
235222
pub(crate) struct UnsupportedLiteral {
236223
pub span: Span,
237-
pub reason: UnsupportedLiteralReason,
238224
pub is_bytestr: bool,
239225
pub start_point_span: Span,
240226
}
241227

242228
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for UnsupportedLiteral {
243229
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
244-
let mut diag = Diag::new(
245-
dcx,
246-
level,
247-
match self.reason {
248-
UnsupportedLiteralReason::Generic => {
249-
fluent::attr_parsing_unsupported_literal_generic
250-
}
251-
UnsupportedLiteralReason::CfgString => {
252-
fluent::attr_parsing_unsupported_literal_cfg_string
253-
}
254-
UnsupportedLiteralReason::CfgBoolean => {
255-
fluent::attr_parsing_unsupported_literal_cfg_boolean
256-
}
257-
},
258-
);
230+
let mut diag = Diag::new(dcx, level, fluent::attr_parsing_unsupported_literal_generic);
259231
diag.span(self.span);
260232
diag.code(E0565);
261233
if self.is_bytestr {
@@ -375,13 +347,6 @@ pub(crate) struct RustcAllowedUnstablePairing {
375347
pub span: Span,
376348
}
377349

378-
#[derive(Diagnostic)]
379-
#[diag(attr_parsing_cfg_predicate_identifier)]
380-
pub(crate) struct CfgPredicateIdentifier {
381-
#[primary_span]
382-
pub span: Span,
383-
}
384-
385350
#[derive(Diagnostic)]
386351
#[diag(attr_parsing_deprecated_item_suggestion)]
387352
pub(crate) struct DeprecatedItemSuggestion {

0 commit comments

Comments
 (0)