syntax: Keep full Stability
in SyntaxExtension
This commit is contained in:
parent
73dec4a804
commit
3542995ff9
4 changed files with 18 additions and 26 deletions
|
@ -11,7 +11,7 @@ use rustc::hir::def::{self, DefKind, NonMacroAttrKind};
|
|||
use rustc::hir::map::{self, DefCollector};
|
||||
use rustc::{ty, lint, span_bug};
|
||||
use syntax::ast::{self, Ident};
|
||||
use syntax::attr;
|
||||
use syntax::attr::{self, StabilityLevel};
|
||||
use syntax::errors::DiagnosticBuilder;
|
||||
use syntax::ext::base::{self, Determinacy};
|
||||
use syntax::ext::base::{MacroKind, SyntaxExtension};
|
||||
|
@ -236,13 +236,15 @@ impl<'a> base::Resolver for Resolver<'a> {
|
|||
};
|
||||
invoc.expansion_data.mark.set_expn_info(ext.expn_info(span, &format));
|
||||
|
||||
if let Some((feature, issue)) = ext.unstable_feature {
|
||||
let features = self.session.features_untracked();
|
||||
if !span.allows_unstable(feature) &&
|
||||
features.declared_lib_features.iter().all(|(feat, _)| *feat != feature) {
|
||||
let msg = format!("macro {}! is unstable", path);
|
||||
emit_feature_err(&self.session.parse_sess, feature, span,
|
||||
GateIssue::Library(Some(issue)), &msg);
|
||||
if let Some(stability) = ext.stability {
|
||||
if let StabilityLevel::Unstable { issue, .. } = stability.level {
|
||||
let features = self.session.features_untracked();
|
||||
if !span.allows_unstable(stability.feature) &&
|
||||
features.declared_lib_features.iter().all(|(feat, _)| *feat != stability.feature) {
|
||||
let msg = format!("macro {}! is unstable", path);
|
||||
emit_feature_err(&self.session.parse_sess, stability.feature, span,
|
||||
GateIssue::Library(Some(issue)), &msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -171,7 +171,8 @@ pub fn contains_feature_attr(attrs: &[Attribute], feature_name: Symbol) -> bool
|
|||
})
|
||||
}
|
||||
|
||||
/// Finds the first stability attribute. `None` if none exists.
|
||||
/// Collects stability info from all stability attributes in `attrs`.
|
||||
/// Returns `None` if no stability attributes are found.
|
||||
pub fn find_stability(sess: &ParseSess, attrs: &[Attribute],
|
||||
item_sp: Span) -> Option<Stability> {
|
||||
find_stability_generic(sess, attrs.iter(), item_sp)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::ast::{self, Attribute, Name, PatKind};
|
||||
use crate::attr::HasAttrs;
|
||||
use crate::attr::{HasAttrs, Stability};
|
||||
use crate::source_map::{SourceMap, Spanned, respan};
|
||||
use crate::edition::Edition;
|
||||
use crate::ext::expand::{self, AstFragment, Invocation};
|
||||
|
@ -616,8 +616,8 @@ pub struct SyntaxExtension {
|
|||
pub allow_internal_unsafe: bool,
|
||||
/// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`) for this macro.
|
||||
pub local_inner_macros: bool,
|
||||
/// The macro's feature name and tracking issue number if it is unstable.
|
||||
pub unstable_feature: Option<(Symbol, u32)>,
|
||||
/// The macro's stability and deprecation info.
|
||||
pub stability: Option<Stability>,
|
||||
/// Names of helper attributes registered by this macro.
|
||||
pub helper_attrs: Vec<Symbol>,
|
||||
/// Edition of the crate in which this macro is defined.
|
||||
|
@ -662,7 +662,7 @@ impl SyntaxExtension {
|
|||
allow_internal_unstable: None,
|
||||
allow_internal_unsafe: false,
|
||||
local_inner_macros: false,
|
||||
unstable_feature: None,
|
||||
stability: None,
|
||||
helper_attrs: Vec::new(),
|
||||
edition,
|
||||
kind,
|
||||
|
|
|
@ -422,8 +422,6 @@ pub fn compile(
|
|||
})
|
||||
});
|
||||
|
||||
let allow_internal_unsafe = attr::contains_name(&def.attrs, sym::allow_internal_unsafe);
|
||||
|
||||
let mut local_inner_macros = false;
|
||||
if let Some(macro_export) = attr::find_by_name(&def.attrs, sym::macro_export) {
|
||||
if let Some(l) = macro_export.meta_item_list() {
|
||||
|
@ -431,23 +429,14 @@ pub fn compile(
|
|||
}
|
||||
}
|
||||
|
||||
let unstable_feature =
|
||||
attr::find_stability(&sess, &def.attrs, def.span).and_then(|stability| {
|
||||
if let attr::StabilityLevel::Unstable { issue, .. } = stability.level {
|
||||
Some((stability.feature, issue))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
});
|
||||
|
||||
SyntaxExtension {
|
||||
kind: SyntaxExtensionKind::LegacyBang(expander),
|
||||
span: def.span,
|
||||
default_transparency,
|
||||
allow_internal_unstable,
|
||||
allow_internal_unsafe,
|
||||
allow_internal_unsafe: attr::contains_name(&def.attrs, sym::allow_internal_unsafe),
|
||||
local_inner_macros,
|
||||
unstable_feature,
|
||||
stability: attr::find_stability(&sess, &def.attrs, def.span),
|
||||
helper_attrs: Vec::new(),
|
||||
edition,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue