Skip to content

Commit 6b29f18

Browse files
authored
Rollup merge of #149903 - JonathanBrouwer:cfg_old_cleanup, r=jdonszelmann
Remove unused code in `cfg_old` r? ```@jdonszelmann``` Fixes one of the todos from #149865
2 parents bcde603 + 0ab4b8b commit 6b29f18

File tree

8 files changed

+25
-299
lines changed

8 files changed

+25
-299
lines changed

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 0 additions & 12 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,12 +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
248-
attr_parsing_unsupported_literal_generic =
249-
unsupported literal
250238
attr_parsing_unsupported_literal_suggestion =
251239
consider removing the prefix
252240

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: 3 additions & 13 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) => {
@@ -302,12 +302,7 @@ pub(crate) fn parse_stability<S: Stage>(
302302
for param in list.mixed() {
303303
let param_span = param.span();
304304
let Some(param) = param.meta_item() else {
305-
cx.emit_err(session_diagnostics::UnsupportedLiteral {
306-
span: param_span,
307-
reason: UnsupportedLiteralReason::Generic,
308-
is_bytestr: false,
309-
start_point_span: cx.sess().source_map().start_point(param_span),
310-
});
305+
cx.unexpected_literal(param.span());
311306
return None;
312307
};
313308

@@ -382,12 +377,7 @@ pub(crate) fn parse_unstability<S: Stage>(
382377

383378
for param in list.mixed() {
384379
let Some(param) = param.meta_item() else {
385-
cx.emit_err(session_diagnostics::UnsupportedLiteral {
386-
span: param.span(),
387-
reason: UnsupportedLiteralReason::Generic,
388-
is_bytestr: false,
389-
start_point_span: cx.sess().source_map().start_point(param.span()),
390-
});
380+
cx.unexpected_literal(param.span());
391381
return None;
392382
};
393383

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};

0 commit comments

Comments
 (0)