Skip to content

Commit f8bbb60

Browse files
committed
syntax: Respect allow_internal_unstable in macros
This change modifies the feature gating of special `#[cfg]` attributes to not require a `#![feature]` directive in the crate-of-use if the source of the macro was declared with `#[allow_internal_unstable]`. This enables the standard library's macro for `thread_local!` to make use of the `#[cfg(target_thread_local)]` attribute despite it being feature gated (e.g. it's a hidden implementation detail).
1 parent 8d1e3bb commit f8bbb60

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/librustc_driver/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
606606
feature_gated_cfgs.sort();
607607
feature_gated_cfgs.dedup();
608608
for cfg in &feature_gated_cfgs {
609-
cfg.check_and_emit(sess.diagnostic(), &features);
609+
cfg.check_and_emit(sess.diagnostic(), &features, sess.codemap());
610610
}
611611
});
612612

src/libsyntax/feature_gate.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,13 @@ impl PartialOrd for GatedCfgAttr {
454454
}
455455

456456
impl GatedCfgAttr {
457-
pub fn check_and_emit(&self, diagnostic: &Handler, features: &Features) {
457+
pub fn check_and_emit(&self,
458+
diagnostic: &Handler,
459+
features: &Features,
460+
codemap: &CodeMap) {
458461
match *self {
459462
GatedCfgAttr::GatedCfg(ref cfg) => {
460-
cfg.check_and_emit(diagnostic, features);
463+
cfg.check_and_emit(diagnostic, features, codemap);
461464
}
462465
GatedCfgAttr::GatedAttr(span) => {
463466
if !features.stmt_expr_attributes {
@@ -484,9 +487,12 @@ impl GatedCfg {
484487
}
485488
})
486489
}
487-
fn check_and_emit(&self, diagnostic: &Handler, features: &Features) {
490+
fn check_and_emit(&self,
491+
diagnostic: &Handler,
492+
features: &Features,
493+
codemap: &CodeMap) {
488494
let (cfg, feature, has_feature) = GATED_CFGS[self.index];
489-
if !has_feature(features) {
495+
if !has_feature(features) && !codemap.span_allows_unstable(self.span) {
490496
let explain = format!("`cfg({})` is experimental and subject to change", cfg);
491497
emit_feature_err(diagnostic, feature, self.span, GateIssue::Language, &explain);
492498
}

0 commit comments

Comments
 (0)