From 617a7af70400c7a3f82fafcb50daf01f01db95a0 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 16 Dec 2015 09:24:08 -0800 Subject: 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). --- src/libsyntax/feature_gate.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 390e8253dcf..caad7c6e7f5 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -454,10 +454,13 @@ impl PartialOrd for GatedCfgAttr { } impl GatedCfgAttr { - pub fn check_and_emit(&self, diagnostic: &Handler, features: &Features) { + pub fn check_and_emit(&self, + diagnostic: &Handler, + features: &Features, + codemap: &CodeMap) { match *self { GatedCfgAttr::GatedCfg(ref cfg) => { - cfg.check_and_emit(diagnostic, features); + cfg.check_and_emit(diagnostic, features, codemap); } GatedCfgAttr::GatedAttr(span) => { if !features.stmt_expr_attributes { @@ -484,9 +487,12 @@ impl GatedCfg { } }) } - fn check_and_emit(&self, diagnostic: &Handler, features: &Features) { + fn check_and_emit(&self, + diagnostic: &Handler, + features: &Features, + codemap: &CodeMap) { let (cfg, feature, has_feature) = GATED_CFGS[self.index]; - if !has_feature(features) { + if !has_feature(features) && !codemap.span_allows_unstable(self.span) { let explain = format!("`cfg({})` is experimental and subject to change", cfg); emit_feature_err(diagnostic, feature, self.span, GateIssue::Language, &explain); } -- cgit 1.4.1-3-g733a5