1
Fork 0

syntax: Migrate built-in macros to the regular stability checking

This commit is contained in:
Vadim Petrochenkov 2019-06-22 16:18:05 +03:00
parent 0817fc6c6c
commit 1ee0ce82cb
32 changed files with 161 additions and 209 deletions

View file

@ -1684,6 +1684,9 @@ pub struct Resolver<'a> {
current_type_ascription: Vec<Span>, current_type_ascription: Vec<Span>,
injected_crate: Option<Module<'a>>, injected_crate: Option<Module<'a>>,
/// Features enabled for this crate.
active_features: FxHashSet<Symbol>,
} }
/// Nothing really interesting here; it just provides memory for the rest of the crate. /// Nothing really interesting here; it just provides memory for the rest of the crate.
@ -1922,6 +1925,7 @@ impl<'a> Resolver<'a> {
let mut macro_defs = FxHashMap::default(); let mut macro_defs = FxHashMap::default();
macro_defs.insert(Mark::root(), root_def_id); macro_defs.insert(Mark::root(), root_def_id);
let features = session.features_untracked();
let non_macro_attr = |mark_used| Lrc::new(SyntaxExtension::default( let non_macro_attr = |mark_used| Lrc::new(SyntaxExtension::default(
SyntaxExtensionKind::NonMacroAttr { mark_used }, session.edition() SyntaxExtensionKind::NonMacroAttr { mark_used }, session.edition()
)); ));
@ -2009,6 +2013,10 @@ impl<'a> Resolver<'a> {
unused_macros: Default::default(), unused_macros: Default::default(),
current_type_ascription: Vec::new(), current_type_ascription: Vec::new(),
injected_crate: None, injected_crate: None,
active_features:
features.declared_lib_features.iter().map(|(feat, ..)| *feat)
.chain(features.declared_lang_features.iter().map(|(feat, ..)| *feat))
.collect(),
} }
} }

View file

@ -1013,9 +1013,8 @@ impl<'a> Resolver<'a> {
fn check_stability_and_deprecation(&self, ext: &SyntaxExtension, path: &str, span: Span) { fn check_stability_and_deprecation(&self, ext: &SyntaxExtension, path: &str, span: Span) {
if let Some(stability) = &ext.stability { if let Some(stability) = &ext.stability {
if let StabilityLevel::Unstable { reason, issue } = stability.level { if let StabilityLevel::Unstable { reason, issue } = stability.level {
let (feature, features) = (stability.feature, self.session.features_untracked()); let feature = stability.feature;
if !span.allows_unstable(feature) && if !self.active_features.contains(&feature) && !span.allows_unstable(feature) {
features.declared_lib_features.iter().all(|(feat, _)| *feat != feature) {
stability::report_unstable(self.session, feature, reason, issue, span); stability::report_unstable(self.session, feature, reason, issue, span);
} }
} }

View file

@ -103,6 +103,7 @@
//! //!
//! ```rust //! ```rust
//! # #![feature(rustc_private)] //! # #![feature(rustc_private)]
//! # #![allow(deprecated)]
//! extern crate serialize; //! extern crate serialize;
//! use serialize::json::{self, ToJson, Json}; //! use serialize::json::{self, ToJson, Json};
//! //!
@ -143,6 +144,7 @@
//! //!
//! ```rust //! ```rust
//! # #![feature(rustc_private)] //! # #![feature(rustc_private)]
//! # #![allow(deprecated)]
//! extern crate serialize; //! extern crate serialize;
//! use std::collections::BTreeMap; //! use std::collections::BTreeMap;
//! use serialize::json::{self, Json, ToJson}; //! use serialize::json::{self, Json, ToJson};

View file

@ -135,6 +135,19 @@ pub enum StabilityLevel {
Stable { since: Symbol }, Stable { since: Symbol },
} }
impl Stability {
pub fn unstable(feature: Symbol, reason: Option<Symbol>, issue: u32) -> Stability {
Stability {
level: StabilityLevel::Unstable { reason, issue },
feature,
rustc_depr: None,
const_stability: None,
promotable: false,
allow_const_fn_ptr: false,
}
}
}
impl StabilityLevel { impl StabilityLevel {
pub fn is_unstable(&self) -> bool { pub fn is_unstable(&self) -> bool {
if let StabilityLevel::Unstable {..} = *self { if let StabilityLevel::Unstable {..} = *self {

View file

@ -487,7 +487,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
fn expand_invoc(&mut self, invoc: Invocation, ext: &SyntaxExtension) -> Option<AstFragment> { fn expand_invoc(&mut self, invoc: Invocation, ext: &SyntaxExtension) -> Option<AstFragment> {
if invoc.fragment_kind == AstFragmentKind::ForeignItems && if invoc.fragment_kind == AstFragmentKind::ForeignItems &&
!self.cx.ecfg.macros_in_extern_enabled() { !self.cx.ecfg.macros_in_extern() {
if let SyntaxExtensionKind::NonMacroAttr { .. } = ext.kind {} else { if let SyntaxExtensionKind::NonMacroAttr { .. } = ext.kind {} else {
emit_feature_err(&self.cx.parse_sess, sym::macros_in_extern, emit_feature_err(&self.cx.parse_sess, sym::macros_in_extern,
invoc.span(), GateIssue::Language, invoc.span(), GateIssue::Language,
@ -919,7 +919,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
}) })
.map(|i| attrs.remove(i)); .map(|i| attrs.remove(i));
if let Some(attr) = &attr { if let Some(attr) = &attr {
if !self.cx.ecfg.enable_custom_inner_attributes() && if !self.cx.ecfg.custom_inner_attributes() &&
attr.style == ast::AttrStyle::Inner && attr.path != sym::test { attr.style == ast::AttrStyle::Inner && attr.path != sym::test {
emit_feature_err(&self.cx.parse_sess, sym::custom_inner_attributes, emit_feature_err(&self.cx.parse_sess, sym::custom_inner_attributes,
attr.span, GateIssue::Language, attr.span, GateIssue::Language,
@ -1432,19 +1432,6 @@ pub struct ExpansionConfig<'feat> {
pub keep_macs: bool, pub keep_macs: bool,
} }
macro_rules! feature_tests {
($( fn $getter:ident = $field:ident, )*) => {
$(
pub fn $getter(&self) -> bool {
match self.features {
Some(&Features { $field: true, .. }) => true,
_ => false,
}
}
)*
}
}
impl<'feat> ExpansionConfig<'feat> { impl<'feat> ExpansionConfig<'feat> {
pub fn default(crate_name: String) -> ExpansionConfig<'static> { pub fn default(crate_name: String) -> ExpansionConfig<'static> {
ExpansionConfig { ExpansionConfig {
@ -1458,20 +1445,13 @@ impl<'feat> ExpansionConfig<'feat> {
} }
} }
feature_tests! { fn macros_in_extern(&self) -> bool {
fn enable_asm = asm, self.features.map_or(false, |features| features.macros_in_extern)
fn enable_custom_test_frameworks = custom_test_frameworks,
fn enable_global_asm = global_asm,
fn enable_log_syntax = log_syntax,
fn enable_concat_idents = concat_idents,
fn enable_trace_macros = trace_macros,
fn enable_allow_internal_unstable = allow_internal_unstable,
fn enable_format_args_nl = format_args_nl,
fn macros_in_extern_enabled = macros_in_extern,
fn proc_macro_hygiene = proc_macro_hygiene,
} }
fn proc_macro_hygiene(&self) -> bool {
fn enable_custom_inner_attributes(&self) -> bool { self.features.map_or(false, |features| features.proc_macro_hygiene)
}
fn custom_inner_attributes(&self) -> bool {
self.features.map_or(false, |features| features.custom_inner_attributes) self.features.map_or(false, |features| features.custom_inner_attributes)
} }
} }

View file

@ -4,7 +4,7 @@ use crate::ext::build::AstBuilder;
use crate::parse::{self, token, DirectoryOwnership}; use crate::parse::{self, token, DirectoryOwnership};
use crate::print::pprust; use crate::print::pprust;
use crate::ptr::P; use crate::ptr::P;
use crate::symbol::{Symbol, sym}; use crate::symbol::Symbol;
use crate::tokenstream; use crate::tokenstream;
use smallvec::SmallVec; use smallvec::SmallVec;
@ -41,16 +41,6 @@ pub fn expand_column(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::TokenTr
base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32 + 1)) base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32 + 1))
} }
/* __rust_unstable_column!(): expands to the current column number */
pub fn expand_column_gated(cx: &mut ExtCtxt<'_>, sp: Span, tts: &[tokenstream::TokenTree])
-> Box<dyn base::MacResult+'static> {
if sp.allows_unstable(sym::__rust_unstable_column) {
expand_column(cx, sp, tts)
} else {
cx.span_fatal(sp, "the __rust_unstable_column macro is unstable");
}
}
/// file!(): expands to the current filename */ /// file!(): expands to the current filename */
/// The source_file (`loc.file`) contains a bunch more information we could spit /// The source_file (`loc.file`) contains a bunch more information we could spit
/// out if we wanted. /// out if we wanted.

View file

@ -1568,7 +1568,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
(sym::type_length_limit, CrateLevel, template!(NameValueStr: "N"), Ungated), (sym::type_length_limit, CrateLevel, template!(NameValueStr: "N"), Ungated),
(sym::test_runner, CrateLevel, template!(List: "path"), Gated(Stability::Unstable, (sym::test_runner, CrateLevel, template!(List: "path"), Gated(Stability::Unstable,
sym::custom_test_frameworks, sym::custom_test_frameworks,
EXPLAIN_CUSTOM_TEST_FRAMEWORKS, "custom test frameworks are an unstable feature",
cfg_fn!(custom_test_frameworks))), cfg_fn!(custom_test_frameworks))),
]; ];
@ -1819,26 +1819,6 @@ const EXPLAIN_BOX_SYNTAX: &str =
pub const EXPLAIN_STMT_ATTR_SYNTAX: &str = pub const EXPLAIN_STMT_ATTR_SYNTAX: &str =
"attributes on expressions are experimental"; "attributes on expressions are experimental";
pub const EXPLAIN_ASM: &str =
"inline assembly is not stable enough for use and is subject to change";
pub const EXPLAIN_GLOBAL_ASM: &str =
"`global_asm!` is not stable enough for use and is subject to change";
pub const EXPLAIN_CUSTOM_TEST_FRAMEWORKS: &str =
"custom test frameworks are an unstable feature";
pub const EXPLAIN_LOG_SYNTAX: &str =
"`log_syntax!` is not stable enough for use and is subject to change";
pub const EXPLAIN_CONCAT_IDENTS: &str =
"`concat_idents` is not stable enough for use and is subject to change";
pub const EXPLAIN_FORMAT_ARGS_NL: &str =
"`format_args_nl` is only for internal language use and is subject to change";
pub const EXPLAIN_TRACE_MACROS: &str =
"`trace_macros` is not stable enough for use and is subject to change";
pub const EXPLAIN_ALLOW_INTERNAL_UNSTABLE: &str = pub const EXPLAIN_ALLOW_INTERNAL_UNSTABLE: &str =
"allow_internal_unstable side-steps feature gating and stability checks"; "allow_internal_unstable side-steps feature gating and stability checks";
pub const EXPLAIN_ALLOW_INTERNAL_UNSAFE: &str = pub const EXPLAIN_ALLOW_INTERNAL_UNSAFE: &str =

View file

@ -8,7 +8,6 @@ use errors::DiagnosticBuilder;
use syntax::ast; use syntax::ast;
use syntax::ext::base::{self, *}; use syntax::ext::base::{self, *};
use syntax::feature_gate;
use syntax::parse; use syntax::parse;
use syntax::parse::token::{self, Token}; use syntax::parse::token::{self, Token};
use syntax::ptr::P; use syntax::ptr::P;
@ -46,14 +45,6 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
sp: Span, sp: Span,
tts: &[tokenstream::TokenTree]) tts: &[tokenstream::TokenTree])
-> Box<dyn base::MacResult + 'cx> { -> Box<dyn base::MacResult + 'cx> {
if !cx.ecfg.enable_asm() {
feature_gate::emit_feature_err(&cx.parse_sess,
sym::asm,
sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_ASM);
}
let mut inline_asm = match parse_inline_asm(cx, sp, tts) { let mut inline_asm = match parse_inline_asm(cx, sp, tts) {
Ok(Some(inline_asm)) => inline_asm, Ok(Some(inline_asm)) => inline_asm,
Ok(None) => return DummyResult::expr(sp), Ok(None) => return DummyResult::expr(sp),

View file

@ -2,25 +2,16 @@ use rustc_data_structures::thin_vec::ThinVec;
use syntax::ast; use syntax::ast;
use syntax::ext::base::{self, *}; use syntax::ext::base::{self, *};
use syntax::feature_gate;
use syntax::parse::token::{self, Token}; use syntax::parse::token::{self, Token};
use syntax::ptr::P; use syntax::ptr::P;
use syntax_pos::Span; use syntax_pos::Span;
use syntax_pos::symbol::{Symbol, sym}; use syntax_pos::symbol::Symbol;
use syntax::tokenstream::TokenTree; use syntax::tokenstream::TokenTree;
pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt<'_>, pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt<'_>,
sp: Span, sp: Span,
tts: &[TokenTree]) tts: &[TokenTree])
-> Box<dyn base::MacResult + 'cx> { -> Box<dyn base::MacResult + 'cx> {
if !cx.ecfg.enable_concat_idents() {
feature_gate::emit_feature_err(&cx.parse_sess,
sym::concat_idents,
sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_CONCAT_IDENTS);
}
if tts.is_empty() { if tts.is_empty() {
cx.span_err(sp, "concat_idents! takes 1 or more arguments."); cx.span_err(sp, "concat_idents! takes 1 or more arguments.");
return DummyResult::any(sp); return DummyResult::any(sp);

View file

@ -3,7 +3,6 @@
use crate::deriving::{self, pathvec_std}; use crate::deriving::{self, pathvec_std};
use crate::deriving::generic::*; use crate::deriving::generic::*;
use crate::deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use crate::deriving::warn_if_deprecated;
use syntax::ast; use syntax::ast;
use syntax::ast::{Expr, MetaItem, Mutability}; use syntax::ast::{Expr, MetaItem, Mutability};
@ -26,7 +25,6 @@ pub fn expand_deriving_decodable(cx: &mut ExtCtxt<'_>,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
push: &mut dyn FnMut(Annotatable)) { push: &mut dyn FnMut(Annotatable)) {
warn_if_deprecated(cx, span, "Decodable");
expand_deriving_decodable_imp(cx, span, mitem, item, push, "serialize") expand_deriving_decodable_imp(cx, span, mitem, item, push, "serialize")
} }

View file

@ -85,7 +85,6 @@
use crate::deriving::{self, pathvec_std}; use crate::deriving::{self, pathvec_std};
use crate::deriving::generic::*; use crate::deriving::generic::*;
use crate::deriving::generic::ty::*; use crate::deriving::generic::ty::*;
use crate::deriving::warn_if_deprecated;
use syntax::ast::{Expr, ExprKind, MetaItem, Mutability}; use syntax::ast::{Expr, ExprKind, MetaItem, Mutability};
use syntax::ext::base::{Annotatable, ExtCtxt}; use syntax::ext::base::{Annotatable, ExtCtxt};
@ -107,7 +106,6 @@ pub fn expand_deriving_encodable(cx: &mut ExtCtxt<'_>,
mitem: &MetaItem, mitem: &MetaItem,
item: &Annotatable, item: &Annotatable,
push: &mut dyn FnMut(Annotatable)) { push: &mut dyn FnMut(Annotatable)) {
warn_if_deprecated(cx, span, "Encodable");
expand_deriving_encodable_imp(cx, span, mitem, item, push, "serialize") expand_deriving_encodable_imp(cx, span, mitem, item, push, "serialize")
} }

View file

@ -2,6 +2,7 @@
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use syntax::ast::{self, MetaItem}; use syntax::ast::{self, MetaItem};
use syntax::attr::Deprecation;
use syntax::edition::Edition; use syntax::edition::Edition;
use syntax::ext::base::{Annotatable, ExtCtxt, Resolver, MultiItemModifier}; use syntax::ext::base::{Annotatable, ExtCtxt, Resolver, MultiItemModifier};
use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind}; use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind};
@ -60,7 +61,7 @@ impl MultiItemModifier for BuiltinDerive {
} }
macro_rules! derive_traits { macro_rules! derive_traits {
($( $name:expr => $func:path, )+) => { ($( [$deprecation:expr] $name:expr => $func:path, )+) => {
pub fn is_builtin_trait(name: ast::Name) -> bool { pub fn is_builtin_trait(name: ast::Name) -> bool {
match &*name.as_str() { match &*name.as_str() {
$( $name )|+ => true, $( $name )|+ => true,
@ -81,6 +82,10 @@ macro_rules! derive_traits {
resolver.add_builtin( resolver.add_builtin(
ast::Ident::with_empty_ctxt(Symbol::intern($name)), ast::Ident::with_empty_ctxt(Symbol::intern($name)),
Lrc::new(SyntaxExtension { Lrc::new(SyntaxExtension {
deprecation: $deprecation.map(|msg| Deprecation {
since: Some(Symbol::intern("1.0.0")),
note: Some(Symbol::intern(msg)),
}),
allow_internal_unstable: allow_internal_unstable.clone(), allow_internal_unstable: allow_internal_unstable.clone(),
..SyntaxExtension::default( ..SyntaxExtension::default(
SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($func))), SyntaxExtensionKind::LegacyDerive(Box::new(BuiltinDerive($func))),
@ -94,44 +99,43 @@ macro_rules! derive_traits {
} }
derive_traits! { derive_traits! {
[None]
"Clone" => clone::expand_deriving_clone, "Clone" => clone::expand_deriving_clone,
[None]
"Hash" => hash::expand_deriving_hash, "Hash" => hash::expand_deriving_hash,
[None]
"RustcEncodable" => encodable::expand_deriving_rustc_encodable, "RustcEncodable" => encodable::expand_deriving_rustc_encodable,
[None]
"RustcDecodable" => decodable::expand_deriving_rustc_decodable, "RustcDecodable" => decodable::expand_deriving_rustc_decodable,
[None]
"PartialEq" => partial_eq::expand_deriving_partial_eq, "PartialEq" => partial_eq::expand_deriving_partial_eq,
[None]
"Eq" => eq::expand_deriving_eq, "Eq" => eq::expand_deriving_eq,
[None]
"PartialOrd" => partial_ord::expand_deriving_partial_ord, "PartialOrd" => partial_ord::expand_deriving_partial_ord,
[None]
"Ord" => ord::expand_deriving_ord, "Ord" => ord::expand_deriving_ord,
[None]
"Debug" => debug::expand_deriving_debug, "Debug" => debug::expand_deriving_debug,
[None]
"Default" => default::expand_deriving_default, "Default" => default::expand_deriving_default,
[None]
"Copy" => bounds::expand_deriving_copy, "Copy" => bounds::expand_deriving_copy,
// deprecated // deprecated
[Some("derive(Encodable) is deprecated in favor of derive(RustcEncodable)")]
"Encodable" => encodable::expand_deriving_encodable, "Encodable" => encodable::expand_deriving_encodable,
[Some("derive(Decodable) is deprecated in favor of derive(RustcDecodable)")]
"Decodable" => decodable::expand_deriving_decodable, "Decodable" => decodable::expand_deriving_decodable,
} }
#[inline] // because `name` is a compile-time constant
fn warn_if_deprecated(ecx: &mut ExtCtxt<'_>, sp: Span, name: &str) {
if let Some(replacement) = match name {
"Encodable" => Some("RustcEncodable"),
"Decodable" => Some("RustcDecodable"),
_ => None,
} {
ecx.span_warn(sp,
&format!("derive({}) is deprecated in favor of derive({})",
name,
replacement));
}
}
/// Construct a name for the inner type parameter that can't collide with any type parameters of /// Construct a name for the inner type parameter that can't collide with any type parameters of
/// the item. This is achieved by starting with a base and then concatenating the names of all /// the item. This is achieved by starting with a base and then concatenating the names of all
/// other type parameters. /// other type parameters.

View file

@ -9,7 +9,6 @@ use errors::Applicability;
use syntax::ast; use syntax::ast;
use syntax::ext::base::{self, *}; use syntax::ext::base::{self, *};
use syntax::ext::build::AstBuilder; use syntax::ext::build::AstBuilder;
use syntax::feature_gate;
use syntax::parse::token; use syntax::parse::token;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::{Symbol, sym}; use syntax::symbol::{Symbol, sym};
@ -686,14 +685,16 @@ impl<'a, 'b> Context<'a, 'b> {
} }
} }
pub fn expand_format_args<'cx>(ecx: &'cx mut ExtCtxt<'_>, fn expand_format_args_impl<'cx>(
mut sp: Span, ecx: &'cx mut ExtCtxt<'_>,
tts: &[tokenstream::TokenTree]) mut sp: Span,
-> Box<dyn base::MacResult + 'cx> { tts: &[tokenstream::TokenTree],
nl: bool,
) -> Box<dyn base::MacResult + 'cx> {
sp = sp.apply_mark(ecx.current_expansion.mark); sp = sp.apply_mark(ecx.current_expansion.mark);
match parse_args(ecx, sp, tts) { match parse_args(ecx, sp, tts) {
Ok((efmt, args, names)) => { Ok((efmt, args, names)) => {
MacEager::expr(expand_preparsed_format_args(ecx, sp, efmt, args, names, false)) MacEager::expr(expand_preparsed_format_args(ecx, sp, efmt, args, names, nl))
} }
Err(mut err) => { Err(mut err) => {
err.emit(); err.emit();
@ -702,34 +703,20 @@ pub fn expand_format_args<'cx>(ecx: &'cx mut ExtCtxt<'_>,
} }
} }
pub fn expand_format_args_nl<'cx>( pub fn expand_format_args<'cx>(
ecx: &'cx mut ExtCtxt<'_>, ecx: &'cx mut ExtCtxt<'_>,
mut sp: Span, sp: Span,
tts: &[tokenstream::TokenTree], tts: &[tokenstream::TokenTree],
) -> Box<dyn base::MacResult + 'cx> { ) -> Box<dyn base::MacResult + 'cx> {
//if !ecx.ecfg.enable_allow_internal_unstable() { expand_format_args_impl(ecx, sp, tts, false)
}
// For some reason, the only one that actually works for `println` is the first check pub fn expand_format_args_nl<'cx>(
if !sp.allows_unstable(sym::format_args_nl) // the span is marked `#[allow_insternal_unsable]` ecx: &'cx mut ExtCtxt<'_>,
&& !ecx.ecfg.enable_allow_internal_unstable() // NOTE: when is this enabled? sp: Span,
&& !ecx.ecfg.enable_format_args_nl() // enabled using `#[feature(format_args_nl]` tts: &[tokenstream::TokenTree],
{ ) -> Box<dyn base::MacResult + 'cx> {
feature_gate::emit_feature_err(&ecx.parse_sess, expand_format_args_impl(ecx, sp, tts, true)
sym::format_args_nl,
sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_FORMAT_ARGS_NL);
}
sp = sp.apply_mark(ecx.current_expansion.mark);
match parse_args(ecx, sp, tts) {
Ok((efmt, args, names)) => {
MacEager::expr(expand_preparsed_format_args(ecx, sp, efmt, args, names, true))
}
Err(mut err) => {
err.emit();
DummyResult::expr(sp)
}
}
} }
/// Take the various parts of `format_args!(efmt, args..., name=names...)` /// Take the various parts of `format_args!(efmt, args..., name=names...)`

View file

@ -13,27 +13,15 @@ use errors::DiagnosticBuilder;
use syntax::ast; use syntax::ast;
use syntax::source_map::respan; use syntax::source_map::respan;
use syntax::ext::base::{self, *}; use syntax::ext::base::{self, *};
use syntax::feature_gate;
use syntax::parse::token; use syntax::parse::token;
use syntax::ptr::P; use syntax::ptr::P;
use syntax::symbol::{Symbol, sym};
use syntax_pos::Span; use syntax_pos::Span;
use syntax::tokenstream; use syntax::tokenstream;
use smallvec::smallvec; use smallvec::smallvec;
pub const MACRO: Symbol = sym::global_asm;
pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt<'_>, pub fn expand_global_asm<'cx>(cx: &'cx mut ExtCtxt<'_>,
sp: Span, sp: Span,
tts: &[tokenstream::TokenTree]) -> Box<dyn base::MacResult + 'cx> { tts: &[tokenstream::TokenTree]) -> Box<dyn base::MacResult + 'cx> {
if !cx.ecfg.enable_global_asm() {
feature_gate::emit_feature_err(&cx.parse_sess,
MACRO,
sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_GLOBAL_ASM);
}
match parse_global_asm(cx, sp, tts) { match parse_global_asm(cx, sp, tts) {
Ok(Some(global_asm)) => { Ok(Some(global_asm)) => {
MacEager::items(smallvec![P(ast::Item { MacEager::items(smallvec![P(ast::Item {

View file

@ -41,12 +41,29 @@ pub mod proc_macro_impl;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use syntax::ast; use syntax::ast;
use syntax::attr::Stability;
use syntax::ext::base::MacroExpanderFn; use syntax::ext::base::MacroExpanderFn;
use syntax::ext::base::{NamedSyntaxExtension, SyntaxExtension, SyntaxExtensionKind}; use syntax::ext::base::{NamedSyntaxExtension, SyntaxExtension, SyntaxExtensionKind};
use syntax::edition::Edition; use syntax::edition::Edition;
use syntax::symbol::{sym, Symbol}; use syntax::symbol::{sym, Symbol};
const EXPLAIN_ASM: &str =
"inline assembly is not stable enough for use and is subject to change";
const EXPLAIN_GLOBAL_ASM: &str =
"`global_asm!` is not stable enough for use and is subject to change";
const EXPLAIN_CUSTOM_TEST_FRAMEWORKS: &str =
"custom test frameworks are an unstable feature";
const EXPLAIN_LOG_SYNTAX: &str =
"`log_syntax!` is not stable enough for use and is subject to change";
const EXPLAIN_CONCAT_IDENTS: &str =
"`concat_idents` is not stable enough for use and is subject to change";
const EXPLAIN_FORMAT_ARGS_NL: &str =
"`format_args_nl` is only for internal language use and is subject to change";
const EXPLAIN_TRACE_MACROS: &str =
"`trace_macros` is not stable enough for use and is subject to change";
const EXPLAIN_UNSTABLE_COLUMN: &str =
"internal implementation detail of the `column` macro";
pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver, pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
user_exts: Vec<NamedSyntaxExtension>, user_exts: Vec<NamedSyntaxExtension>,
edition: Edition) { edition: Edition) {
@ -62,18 +79,22 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
)); ));
)* } )* }
} }
macro_rules! register_attr { macro_rules! register_unstable {
($( $name:ident: $f:expr, )*) => { $( ($( [$feature:expr, $reason:expr, $issue:expr] $name:ident: $f:expr, )*) => { $(
register(Symbol::intern(stringify!($name)), SyntaxExtension::default( register(Symbol::intern(stringify!($name)), SyntaxExtension {
SyntaxExtensionKind::LegacyAttr(Box::new($f)), edition stability: Some(Stability::unstable(
)); $feature, Some(Symbol::intern($reason)), $issue
)),
..SyntaxExtension::default(
SyntaxExtensionKind::LegacyBang(Box::new($f as MacroExpanderFn)), edition
)
});
)* } )* }
} }
use syntax::ext::source_util::*; use syntax::ext::source_util::*;
register! { register! {
line: expand_line, line: expand_line,
__rust_unstable_column: expand_column_gated,
column: expand_column, column: expand_column,
file: expand_file, file: expand_file,
stringify: expand_stringify, stringify: expand_stringify,
@ -81,26 +102,46 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
include_str: expand_include_str, include_str: expand_include_str,
include_bytes: expand_include_bytes, include_bytes: expand_include_bytes,
module_path: expand_mod, module_path: expand_mod,
asm: asm::expand_asm,
global_asm: global_asm::expand_global_asm,
cfg: cfg::expand_cfg, cfg: cfg::expand_cfg,
concat: concat::expand_syntax_ext, concat: concat::expand_syntax_ext,
concat_idents: concat_idents::expand_syntax_ext,
env: env::expand_env, env: env::expand_env,
option_env: env::expand_option_env, option_env: env::expand_option_env,
log_syntax: log_syntax::expand_syntax_ext,
trace_macros: trace_macros::expand_trace_macros,
compile_error: compile_error::expand_compile_error, compile_error: compile_error::expand_compile_error,
assert: assert::expand_assert, assert: assert::expand_assert,
} }
register_attr! { register_unstable! {
test_case: test_case::expand, [sym::__rust_unstable_column, EXPLAIN_UNSTABLE_COLUMN, 0]
test: test::expand_test, __rust_unstable_column: expand_column,
bench: test::expand_bench, [sym::asm, EXPLAIN_ASM, 29722]
asm: asm::expand_asm,
[sym::global_asm, EXPLAIN_GLOBAL_ASM, 35119]
global_asm: global_asm::expand_global_asm,
[sym::concat_idents, EXPLAIN_CONCAT_IDENTS, 29599]
concat_idents: concat_idents::expand_syntax_ext,
[sym::log_syntax, EXPLAIN_LOG_SYNTAX, 29598]
log_syntax: log_syntax::expand_syntax_ext,
[sym::trace_macros, EXPLAIN_TRACE_MACROS, 29598]
trace_macros: trace_macros::expand_trace_macros,
} }
register(sym::test_case, SyntaxExtension {
stability: Some(Stability::unstable(
sym::custom_test_frameworks,
Some(Symbol::intern(EXPLAIN_CUSTOM_TEST_FRAMEWORKS)),
50297,
)),
..SyntaxExtension::default(
SyntaxExtensionKind::LegacyAttr(Box::new(test_case::expand)), edition
)
});
register(sym::test, SyntaxExtension::default(
SyntaxExtensionKind::LegacyAttr(Box::new(test::expand_test)), edition
));
register(sym::bench, SyntaxExtension::default(
SyntaxExtensionKind::LegacyAttr(Box::new(test::expand_bench)), edition
));
// format_args uses `unstable` things internally. // format_args uses `unstable` things internally.
let allow_internal_unstable = Some([sym::fmt_internals][..].into()); let allow_internal_unstable = Some([sym::fmt_internals][..].into());
register(Symbol::intern("format_args"), SyntaxExtension { register(Symbol::intern("format_args"), SyntaxExtension {
@ -110,6 +151,11 @@ pub fn register_builtins(resolver: &mut dyn syntax::ext::base::Resolver,
) )
}); });
register(sym::format_args_nl, SyntaxExtension { register(sym::format_args_nl, SyntaxExtension {
stability: Some(Stability::unstable(
sym::format_args_nl,
Some(Symbol::intern(EXPLAIN_FORMAT_ARGS_NL)),
0,
)),
allow_internal_unstable, allow_internal_unstable,
..SyntaxExtension::default( ..SyntaxExtension::default(
SyntaxExtensionKind::LegacyBang(Box::new(format::expand_format_args_nl)), edition SyntaxExtensionKind::LegacyBang(Box::new(format::expand_format_args_nl)), edition

View file

@ -1,22 +1,12 @@
use syntax::ext::base; use syntax::ext::base;
use syntax::feature_gate;
use syntax::print; use syntax::print;
use syntax::tokenstream; use syntax::tokenstream;
use syntax::symbol::sym;
use syntax_pos; use syntax_pos;
pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt<'_>, pub fn expand_syntax_ext<'cx>(_cx: &'cx mut base::ExtCtxt<'_>,
sp: syntax_pos::Span, sp: syntax_pos::Span,
tts: &[tokenstream::TokenTree]) tts: &[tokenstream::TokenTree])
-> Box<dyn base::MacResult + 'cx> { -> Box<dyn base::MacResult + 'cx> {
if !cx.ecfg.enable_log_syntax() {
feature_gate::emit_feature_err(&cx.parse_sess,
sym::log_syntax,
sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_LOG_SYNTAX);
}
println!("{}", print::pprust::tts_to_string(tts)); println!("{}", print::pprust::tts_to_string(tts));
// any so that `log_syntax` can be invoked as an expression and item. // any so that `log_syntax` can be invoked as an expression and item.

View file

@ -17,7 +17,6 @@ use syntax::source_map::respan;
use syntax::symbol::sym; use syntax::symbol::sym;
use syntax_pos::Span; use syntax_pos::Span;
use syntax::source_map::{ExpnInfo, MacroAttribute}; use syntax::source_map::{ExpnInfo, MacroAttribute};
use syntax::feature_gate;
pub fn expand( pub fn expand(
ecx: &mut ExtCtxt<'_>, ecx: &mut ExtCtxt<'_>,
@ -25,14 +24,6 @@ pub fn expand(
_meta_item: &ast::MetaItem, _meta_item: &ast::MetaItem,
anno_item: Annotatable anno_item: Annotatable
) -> Vec<Annotatable> { ) -> Vec<Annotatable> {
if !ecx.ecfg.enable_custom_test_frameworks() {
feature_gate::emit_feature_err(&ecx.parse_sess,
sym::custom_test_frameworks,
attr_sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_CUSTOM_TEST_FRAMEWORKS);
}
if !ecx.ecfg.should_test { return vec![]; } if !ecx.ecfg.should_test { return vec![]; }
let sp = { let sp = {

View file

@ -1,6 +1,5 @@
use syntax::ext::base::{self, ExtCtxt}; use syntax::ext::base::{self, ExtCtxt};
use syntax::feature_gate; use syntax::symbol::kw;
use syntax::symbol::{kw, sym};
use syntax_pos::Span; use syntax_pos::Span;
use syntax::tokenstream::TokenTree; use syntax::tokenstream::TokenTree;
@ -8,14 +7,6 @@ pub fn expand_trace_macros(cx: &mut ExtCtxt<'_>,
sp: Span, sp: Span,
tt: &[TokenTree]) tt: &[TokenTree])
-> Box<dyn base::MacResult + 'static> { -> Box<dyn base::MacResult + 'static> {
if !cx.ecfg.enable_trace_macros() {
feature_gate::emit_feature_err(&cx.parse_sess,
sym::trace_macros,
sp,
feature_gate::GateIssue::Language,
feature_gate::EXPLAIN_TRACE_MACROS);
}
match tt { match tt {
[TokenTree::Token(token)] if token.is_keyword(kw::True) => { [TokenTree::Token(token)] if token.is_keyword(kw::True) => {
cx.set_trace_macros(true); cx.set_trace_macros(true);

View file

@ -1,6 +1,8 @@
warning: derive(Encodable) is deprecated in favor of derive(RustcEncodable) warning: use of deprecated item 'Encodable': derive(Encodable) is deprecated in favor of derive(RustcEncodable)
--> $DIR/deprecated-derive.rs:8:10 --> $DIR/deprecated-derive.rs:8:10
| |
LL | #[derive(Encodable)] LL | #[derive(Encodable)]
| ^^^^^^^^^ | ^^^^^^^^^
|
= note: #[warn(deprecated)] on by default

View file

@ -1,4 +1,4 @@
error[E0658]: inline assembly is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'asm': inline assembly is not stable enough for use and is subject to change
--> $DIR/feature-gate-asm.rs:3:9 --> $DIR/feature-gate-asm.rs:3:9
| |
LL | asm!(""); LL | asm!("");

View file

@ -1,4 +1,4 @@
error[E0658]: inline assembly is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'asm': inline assembly is not stable enough for use and is subject to change
--> $DIR/feature-gate-asm2.rs:5:26 --> $DIR/feature-gate-asm2.rs:5:26
| |
LL | println!("{:?}", asm!("")); LL | println!("{:?}", asm!(""));

View file

@ -1,4 +1,4 @@
error[E0658]: `concat_idents` is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'concat_idents': `concat_idents` is not stable enough for use and is subject to change
--> $DIR/feature-gate-concat_idents.rs:5:13 --> $DIR/feature-gate-concat_idents.rs:5:13
| |
LL | let a = concat_idents!(X, Y_1); LL | let a = concat_idents!(X, Y_1);
@ -7,7 +7,7 @@ LL | let a = concat_idents!(X, Y_1);
= note: for more information, see https://github.com/rust-lang/rust/issues/29599 = note: for more information, see https://github.com/rust-lang/rust/issues/29599
= help: add #![feature(concat_idents)] to the crate attributes to enable = help: add #![feature(concat_idents)] to the crate attributes to enable
error[E0658]: `concat_idents` is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'concat_idents': `concat_idents` is not stable enough for use and is subject to change
--> $DIR/feature-gate-concat_idents.rs:6:13 --> $DIR/feature-gate-concat_idents.rs:6:13
| |
LL | let b = concat_idents!(X, Y_2); LL | let b = concat_idents!(X, Y_2);

View file

@ -1,4 +1,4 @@
error[E0658]: `concat_idents` is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'concat_idents': `concat_idents` is not stable enough for use and is subject to change
--> $DIR/feature-gate-concat_idents2.rs:4:5 --> $DIR/feature-gate-concat_idents2.rs:4:5
| |
LL | concat_idents!(a, b); LL | concat_idents!(a, b);

View file

@ -1,4 +1,4 @@
error[E0658]: `concat_idents` is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'concat_idents': `concat_idents` is not stable enough for use and is subject to change
--> $DIR/feature-gate-concat_idents3.rs:7:20 --> $DIR/feature-gate-concat_idents3.rs:7:20
| |
LL | assert_eq!(10, concat_idents!(X, Y_1)); LL | assert_eq!(10, concat_idents!(X, Y_1));
@ -7,7 +7,7 @@ LL | assert_eq!(10, concat_idents!(X, Y_1));
= note: for more information, see https://github.com/rust-lang/rust/issues/29599 = note: for more information, see https://github.com/rust-lang/rust/issues/29599
= help: add #![feature(concat_idents)] to the crate attributes to enable = help: add #![feature(concat_idents)] to the crate attributes to enable
error[E0658]: `concat_idents` is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'concat_idents': `concat_idents` is not stable enough for use and is subject to change
--> $DIR/feature-gate-concat_idents3.rs:8:20 --> $DIR/feature-gate-concat_idents3.rs:8:20
| |
LL | assert_eq!(20, concat_idents!(X, Y_2)); LL | assert_eq!(20, concat_idents!(X, Y_2));

View file

@ -1,4 +1,4 @@
error[E0658]: `format_args_nl` is only for internal language use and is subject to change error[E0658]: use of unstable library feature 'format_args_nl': `format_args_nl` is only for internal language use and is subject to change
--> $DIR/feature-gate-format_args_nl.rs:2:5 --> $DIR/feature-gate-format_args_nl.rs:2:5
| |
LL | format_args_nl!(""); LL | format_args_nl!("");

View file

@ -1,4 +1,4 @@
error[E0658]: `global_asm!` is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'global_asm': `global_asm!` is not stable enough for use and is subject to change
--> $DIR/feature-gate-global_asm.rs:1:1 --> $DIR/feature-gate-global_asm.rs:1:1
| |
LL | global_asm!(""); LL | global_asm!("");

View file

@ -1,4 +1,4 @@
error[E0658]: `log_syntax!` is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'log_syntax': `log_syntax!` is not stable enough for use and is subject to change
--> $DIR/feature-gate-log_syntax.rs:2:5 --> $DIR/feature-gate-log_syntax.rs:2:5
| |
LL | log_syntax!() LL | log_syntax!()

View file

@ -1,4 +1,4 @@
error[E0658]: `log_syntax!` is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'log_syntax': `log_syntax!` is not stable enough for use and is subject to change
--> $DIR/feature-gate-log_syntax2.rs:4:22 --> $DIR/feature-gate-log_syntax2.rs:4:22
| |
LL | println!("{:?}", log_syntax!()); LL | println!("{:?}", log_syntax!());

View file

@ -1,4 +1,4 @@
error[E0658]: `trace_macros` is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'trace_macros': `trace_macros` is not stable enough for use and is subject to change
--> $DIR/feature-gate-trace_macros.rs:2:5 --> $DIR/feature-gate-trace_macros.rs:2:5
| |
LL | trace_macros!(true); LL | trace_macros!(true);

View file

@ -1,4 +1,4 @@
fn main() { fn main() {
println!("{}", __rust_unstable_column!()); println!("{}", __rust_unstable_column!());
//~^ERROR the __rust_unstable_column macro is unstable //~^ ERROR use of unstable library feature '__rust_unstable_column'
} }

View file

@ -1,8 +1,11 @@
error: the __rust_unstable_column macro is unstable error[E0658]: use of unstable library feature '__rust_unstable_column': internal implementation detail of the `column` macro
--> $DIR/rust-unstable-column-gated.rs:2:20 --> $DIR/rust-unstable-column-gated.rs:2:20
| |
LL | println!("{}", __rust_unstable_column!()); LL | println!("{}", __rust_unstable_column!());
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(__rust_unstable_column)] to the crate attributes to enable
error: aborting due to previous error error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View file

@ -1,4 +1,4 @@
error[E0658]: `trace_macros` is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'trace_macros': `trace_macros` is not stable enough for use and is subject to change
--> $DIR/trace_macros-gate.rs:4:5 --> $DIR/trace_macros-gate.rs:4:5
| |
LL | trace_macros!(); LL | trace_macros!();
@ -13,7 +13,7 @@ error: trace_macros! accepts only `true` or `false`
LL | trace_macros!(); LL | trace_macros!();
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
error[E0658]: `trace_macros` is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'trace_macros': `trace_macros` is not stable enough for use and is subject to change
--> $DIR/trace_macros-gate.rs:6:5 --> $DIR/trace_macros-gate.rs:6:5
| |
LL | trace_macros!(true); LL | trace_macros!(true);
@ -22,7 +22,7 @@ LL | trace_macros!(true);
= note: for more information, see https://github.com/rust-lang/rust/issues/29598 = note: for more information, see https://github.com/rust-lang/rust/issues/29598
= help: add #![feature(trace_macros)] to the crate attributes to enable = help: add #![feature(trace_macros)] to the crate attributes to enable
error[E0658]: `trace_macros` is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'trace_macros': `trace_macros` is not stable enough for use and is subject to change
--> $DIR/trace_macros-gate.rs:7:5 --> $DIR/trace_macros-gate.rs:7:5
| |
LL | trace_macros!(false); LL | trace_macros!(false);
@ -31,7 +31,7 @@ LL | trace_macros!(false);
= note: for more information, see https://github.com/rust-lang/rust/issues/29598 = note: for more information, see https://github.com/rust-lang/rust/issues/29598
= help: add #![feature(trace_macros)] to the crate attributes to enable = help: add #![feature(trace_macros)] to the crate attributes to enable
error[E0658]: `trace_macros` is not stable enough for use and is subject to change error[E0658]: use of unstable library feature 'trace_macros': `trace_macros` is not stable enough for use and is subject to change
--> $DIR/trace_macros-gate.rs:10:26 --> $DIR/trace_macros-gate.rs:10:26
| |
LL | ($x: ident) => { trace_macros!($x) } LL | ($x: ident) => { trace_macros!($x) }