diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-12-16 09:24:08 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-12-21 22:05:37 -0800 |
| commit | 617a7af70400c7a3f82fafcb50daf01f01db95a0 (patch) | |
| tree | 7d6e3b7b770d47e2eb670d1e050c347852b310d7 /src/libsyntax | |
| parent | b67b5a8d0149096712e75336f6aa32daffcaa42d (diff) | |
| download | rust-617a7af70400c7a3f82fafcb50daf01f01db95a0.tar.gz rust-617a7af70400c7a3f82fafcb50daf01f01db95a0.zip | |
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).
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 14 |
1 files changed, 10 insertions, 4 deletions
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); } |
