]> git.lizzy.rs Git - rust.git/commitdiff
syntax: Respect allow_internal_unstable in macros
authorAlex Crichton <alex@alexcrichton.com>
Wed, 16 Dec 2015 17:24:08 +0000 (09:24 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 22 Dec 2015 06:05:37 +0000 (22:05 -0800)
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/librustc_driver/driver.rs
src/libsyntax/feature_gate.rs

index 5f2548a550467c6e77fe4636aed92bac369375e9..89299c01199756ca5e7c6578f1806e6ee7b5d56e 100644 (file)
@@ -606,7 +606,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
         feature_gated_cfgs.sort();
         feature_gated_cfgs.dedup();
         for cfg in &feature_gated_cfgs {
-            cfg.check_and_emit(sess.diagnostic(), &features);
+            cfg.check_and_emit(sess.diagnostic(), &features, sess.codemap());
         }
     });
 
index 390e8253dcf403eb96fa0416857da0ab48278227..caad7c6e7f54243d83a5b8bc4cafa85815f23ceb 100644 (file)
@@ -454,10 +454,13 @@ fn partial_cmp(&self, other: &GatedCfgAttr) -> Option<cmp::Ordering> {
 }
 
 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 @@ pub fn gate(cfg: &ast::MetaItem) -> Option<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);
         }