提交 617a7af7 编写于 作者: A Alex Crichton

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).
上级 b67b5a8d
...@@ -606,7 +606,7 @@ pub fn phase_2_configure_and_expand(sess: &Session, ...@@ -606,7 +606,7 @@ pub fn phase_2_configure_and_expand(sess: &Session,
feature_gated_cfgs.sort(); feature_gated_cfgs.sort();
feature_gated_cfgs.dedup(); feature_gated_cfgs.dedup();
for cfg in &feature_gated_cfgs { for cfg in &feature_gated_cfgs {
cfg.check_and_emit(sess.diagnostic(), &features); cfg.check_and_emit(sess.diagnostic(), &features, sess.codemap());
} }
}); });
......
...@@ -454,10 +454,13 @@ fn partial_cmp(&self, other: &GatedCfgAttr) -> Option<cmp::Ordering> { ...@@ -454,10 +454,13 @@ fn partial_cmp(&self, other: &GatedCfgAttr) -> Option<cmp::Ordering> {
} }
impl 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 { match *self {
GatedCfgAttr::GatedCfg(ref cfg) => { GatedCfgAttr::GatedCfg(ref cfg) => {
cfg.check_and_emit(diagnostic, features); cfg.check_and_emit(diagnostic, features, codemap);
} }
GatedCfgAttr::GatedAttr(span) => { GatedCfgAttr::GatedAttr(span) => {
if !features.stmt_expr_attributes { if !features.stmt_expr_attributes {
...@@ -484,9 +487,12 @@ pub fn gate(cfg: &ast::MetaItem) -> Option<GatedCfg> { ...@@ -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]; 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); let explain = format!("`cfg({})` is experimental and subject to change", cfg);
emit_feature_err(diagnostic, feature, self.span, GateIssue::Language, &explain); emit_feature_err(diagnostic, feature, self.span, GateIssue::Language, &explain);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册