Skip to content

Commit 3542995

Browse files
committed
syntax: Keep full Stability in SyntaxExtension
1 parent 73dec4a commit 3542995

File tree

4 files changed

+18
-26
lines changed

4 files changed

+18
-26
lines changed

src/librustc_resolve/macros.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc::hir::def::{self, DefKind, NonMacroAttrKind};
1111
use rustc::hir::map::{self, DefCollector};
1212
use rustc::{ty, lint, span_bug};
1313
use syntax::ast::{self, Ident};
14-
use syntax::attr;
14+
use syntax::attr::{self, StabilityLevel};
1515
use syntax::errors::DiagnosticBuilder;
1616
use syntax::ext::base::{self, Determinacy};
1717
use syntax::ext::base::{MacroKind, SyntaxExtension};
@@ -236,13 +236,15 @@ impl<'a> base::Resolver for Resolver<'a> {
236236
};
237237
invoc.expansion_data.mark.set_expn_info(ext.expn_info(span, &format));
238238

239-
if let Some((feature, issue)) = ext.unstable_feature {
240-
let features = self.session.features_untracked();
241-
if !span.allows_unstable(feature) &&
242-
features.declared_lib_features.iter().all(|(feat, _)| *feat != feature) {
243-
let msg = format!("macro {}! is unstable", path);
244-
emit_feature_err(&self.session.parse_sess, feature, span,
245-
GateIssue::Library(Some(issue)), &msg);
239+
if let Some(stability) = ext.stability {
240+
if let StabilityLevel::Unstable { issue, .. } = stability.level {
241+
let features = self.session.features_untracked();
242+
if !span.allows_unstable(stability.feature) &&
243+
features.declared_lib_features.iter().all(|(feat, _)| *feat != stability.feature) {
244+
let msg = format!("macro {}! is unstable", path);
245+
emit_feature_err(&self.session.parse_sess, stability.feature, span,
246+
GateIssue::Library(Some(issue)), &msg);
247+
}
246248
}
247249
}
248250

src/libsyntax/attr/builtin.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ pub fn contains_feature_attr(attrs: &[Attribute], feature_name: Symbol) -> bool
171171
})
172172
}
173173

174-
/// Finds the first stability attribute. `None` if none exists.
174+
/// Collects stability info from all stability attributes in `attrs`.
175+
/// Returns `None` if no stability attributes are found.
175176
pub fn find_stability(sess: &ParseSess, attrs: &[Attribute],
176177
item_sp: Span) -> Option<Stability> {
177178
find_stability_generic(sess, attrs.iter(), item_sp)

src/libsyntax/ext/base.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ast::{self, Attribute, Name, PatKind};
2-
use crate::attr::HasAttrs;
2+
use crate::attr::{HasAttrs, Stability};
33
use crate::source_map::{SourceMap, Spanned, respan};
44
use crate::edition::Edition;
55
use crate::ext::expand::{self, AstFragment, Invocation};
@@ -616,8 +616,8 @@ pub struct SyntaxExtension {
616616
pub allow_internal_unsafe: bool,
617617
/// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`) for this macro.
618618
pub local_inner_macros: bool,
619-
/// The macro's feature name and tracking issue number if it is unstable.
620-
pub unstable_feature: Option<(Symbol, u32)>,
619+
/// The macro's stability and deprecation info.
620+
pub stability: Option<Stability>,
621621
/// Names of helper attributes registered by this macro.
622622
pub helper_attrs: Vec<Symbol>,
623623
/// Edition of the crate in which this macro is defined.
@@ -662,7 +662,7 @@ impl SyntaxExtension {
662662
allow_internal_unstable: None,
663663
allow_internal_unsafe: false,
664664
local_inner_macros: false,
665-
unstable_feature: None,
665+
stability: None,
666666
helper_attrs: Vec::new(),
667667
edition,
668668
kind,

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -422,32 +422,21 @@ pub fn compile(
422422
})
423423
});
424424

425-
let allow_internal_unsafe = attr::contains_name(&def.attrs, sym::allow_internal_unsafe);
426-
427425
let mut local_inner_macros = false;
428426
if let Some(macro_export) = attr::find_by_name(&def.attrs, sym::macro_export) {
429427
if let Some(l) = macro_export.meta_item_list() {
430428
local_inner_macros = attr::list_contains_name(&l, sym::local_inner_macros);
431429
}
432430
}
433431

434-
let unstable_feature =
435-
attr::find_stability(&sess, &def.attrs, def.span).and_then(|stability| {
436-
if let attr::StabilityLevel::Unstable { issue, .. } = stability.level {
437-
Some((stability.feature, issue))
438-
} else {
439-
None
440-
}
441-
});
442-
443432
SyntaxExtension {
444433
kind: SyntaxExtensionKind::LegacyBang(expander),
445434
span: def.span,
446435
default_transparency,
447436
allow_internal_unstable,
448-
allow_internal_unsafe,
437+
allow_internal_unsafe: attr::contains_name(&def.attrs, sym::allow_internal_unsafe),
449438
local_inner_macros,
450-
unstable_feature,
439+
stability: attr::find_stability(&sess, &def.attrs, def.span),
451440
helper_attrs: Vec::new(),
452441
edition,
453442
}

0 commit comments

Comments
 (0)