Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require a list of features in #[allow_internal_unstable] #58098

Merged
merged 13 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/liballoc/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
#[cfg(not(test))]
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow_internal_unstable]
#[cfg_attr(not(stage0), allow_internal_unstable(box_syntax))]
#[cfg_attr(stage0, allow_internal_unstable)]
macro_rules! vec {
($elem:expr; $n:expr) => (
$crate::vec::from_elem($elem, $n)
Expand Down
6 changes: 4 additions & 2 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// Entry point of thread panic, for details, see std::macros
#[macro_export]
#[allow_internal_unstable]
#[cfg_attr(not(stage0), allow_internal_unstable(core_panic, __rust_unstable_column))]
#[cfg_attr(stage0, allow_internal_unstable)]
#[stable(feature = "core", since = "1.6.0")]
macro_rules! panic {
() => (
Expand Down Expand Up @@ -409,7 +410,8 @@ macro_rules! write {
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow_internal_unstable]
#[cfg_attr(stage0, allow_internal_unstable)]
#[cfg_attr(not(stage0), allow_internal_unstable(format_args_nl))]
macro_rules! writeln {
($dst:expr) => (
write!($dst, "\n")
Expand Down
44 changes: 35 additions & 9 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use crate::middle::cstore::CrateStore;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::thin_vec::ThinVec;
use rustc_data_structures::sync::Lrc;
use crate::session::Session;
use crate::session::config::nightly_options;
use crate::util::common::FN_OUTPUT_NAME;
Expand Down Expand Up @@ -681,13 +682,20 @@ impl<'a> LoweringContext<'a> {
Ident::with_empty_ctxt(Symbol::gensym(s))
}

fn allow_internal_unstable(&self, reason: CompilerDesugaringKind, span: Span) -> Span {
/// Reuses the span but adds information like the kind of the desugaring and features that are
/// allowed inside this span.
fn mark_span_with_reason(
&self,
reason: CompilerDesugaringKind,
span: Span,
allow_internal_unstable: Option<Lrc<[Symbol]>>,
) -> Span {
let mark = Mark::fresh(Mark::root());
mark.set_expn_info(source_map::ExpnInfo {
call_site: span,
def_site: Some(span),
format: source_map::CompilerDesugaring(reason),
allow_internal_unstable: true,
allow_internal_unstable,
allow_internal_unsafe: false,
local_inner_macros: false,
edition: source_map::hygiene::default_edition(),
Expand Down Expand Up @@ -964,7 +972,13 @@ impl<'a> LoweringContext<'a> {
attrs: ThinVec::new(),
};

let unstable_span = self.allow_internal_unstable(CompilerDesugaringKind::Async, span);
let unstable_span = self.mark_span_with_reason(
CompilerDesugaringKind::Async,
span,
Some(vec![
Symbol::intern("gen_future"),
].into()),
);
let gen_future = self.expr_std_path(
unstable_span, &["future", "from_generator"], None, ThinVec::new());
hir::ExprKind::Call(P(gen_future), hir_vec![generator])
Expand Down Expand Up @@ -1360,9 +1374,10 @@ impl<'a> LoweringContext<'a> {
// desugaring that explicitly states that we don't want to track that.
// Not tracking it makes lints in rustc and clippy very fragile as
// frequently opened issues show.
let exist_ty_span = self.allow_internal_unstable(
let exist_ty_span = self.mark_span_with_reason(
CompilerDesugaringKind::ExistentialReturnType,
span,
None,
);

let exist_ty_def_index = self
Expand Down Expand Up @@ -3927,8 +3942,13 @@ impl<'a> LoweringContext<'a> {
}),
ExprKind::TryBlock(ref body) => {
self.with_catch_scope(body.id, |this| {
let unstable_span =
this.allow_internal_unstable(CompilerDesugaringKind::TryBlock, body.span);
let unstable_span = this.mark_span_with_reason(
CompilerDesugaringKind::TryBlock,
body.span,
Some(vec![
Symbol::intern("try_trait"),
].into()),
);
let mut block = this.lower_block(body, true).into_inner();
let tail = block.expr.take().map_or_else(
|| {
Expand Down Expand Up @@ -4360,9 +4380,10 @@ impl<'a> LoweringContext<'a> {
// expand <head>
let head = self.lower_expr(head);
let head_sp = head.span;
let desugared_span = self.allow_internal_unstable(
let desugared_span = self.mark_span_with_reason(
CompilerDesugaringKind::ForLoop,
head_sp,
None,
);

let iter = self.str_to_ident("iter");
Expand Down Expand Up @@ -4525,8 +4546,13 @@ impl<'a> LoweringContext<'a> {
// return Try::from_error(From::from(err)),
// }

let unstable_span =
self.allow_internal_unstable(CompilerDesugaringKind::QuestionMark, e.span);
let unstable_span = self.mark_span_with_reason(
CompilerDesugaringKind::QuestionMark,
e.span,
Some(vec![
Symbol::intern("try_trait")
].into()),
);

// `Try::into_result(<expr>)`
let discr = {
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
/// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to
/// `id`.
pub fn eval_stability(self, def_id: DefId, id: Option<NodeId>, span: Span) -> EvalResult {
if span.allows_unstable() {
debug!("stability: skipping span={:?} since it is internal", span);
return EvalResult::Allow;
}

let lint_deprecated = |def_id: DefId,
id: NodeId,
note: Option<Symbol>,
Expand Down Expand Up @@ -694,6 +689,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

match stability {
Some(&Stability { level: attr::Unstable { reason, issue }, feature, .. }) => {
if span.allows_unstable(&feature.as_str()) {
debug!("stability: skipping span={:?} since it is internal", span);
return EvalResult::Allow;
}
if self.stability().active_features.contains(&feature) {
return EvalResult::Allow;
}
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_allocator/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
call_site: item.span, // use the call site of the static
def_site: None,
format: MacroAttribute(Symbol::intern(name)),
allow_internal_unstable: true,
allow_internal_unstable: Some(vec![
Symbol::intern("rustc_attrs"),
].into()),
allow_internal_unsafe: false,
local_inner_macros: false,
edition: hygiene::default_edition(),
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_data_structures/macros.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/// A simple static assertion macro. The first argument should be a unique
/// ALL_CAPS identifier that describes the condition.
#[macro_export]
#[allow_internal_unstable]
#[cfg_attr(stage0, allow_internal_unstable)]
#[cfg_attr(not(stage0), allow_internal_unstable(type_ascription))]
macro_rules! static_assert {
($name:ident: $test:expr) => {
// Use the bool to access an array such that if the bool is false, the access
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ impl<'a> CrateLoader<'a> {
ProcMacro::Bang { name, client } => {
(name, SyntaxExtension::ProcMacro {
expander: Box::new(BangProcMacro { client }),
allow_internal_unstable: false,
allow_internal_unstable: None,
edition: root.edition,
})
}
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_metadata/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,9 @@ impl cstore::CStore {
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
let ext = SyntaxExtension::ProcMacro {
expander: Box::new(BangProcMacro { client }),
allow_internal_unstable: true,
allow_internal_unstable: Some(vec![
Symbol::intern("proc_macro_def_site"),
].into()),
edition: data.root.edition,
};
return LoadedMacro::ProcMacro(Lrc::new(ext));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
// Check `#[unstable]` const fns or `#[rustc_const_unstable]`
// functions without the feature gate active in this crate in
// order to report a better error message than the one below.
if self.span.allows_unstable() {
if self.span.allows_unstable(&feature.as_str()) {
// `allow_internal_unstable` can make such calls stable.
is_const_fn = true;
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_plugin/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ impl<'a> Registry<'a> {
edition,
}
}
IdentTT(ext, _, allow_internal_unstable) => {
IdentTT(ext, Some(self.krate_span), allow_internal_unstable)
IdentTT { expander, span: _, allow_internal_unstable } => {
IdentTT { expander, span: Some(self.krate_span), allow_internal_unstable }
}
_ => extension,
}));
Expand All @@ -126,7 +126,7 @@ impl<'a> Registry<'a> {
self.register_syntax_extension(Symbol::intern(name), NormalTT {
expander: Box::new(expander),
def_info: None,
allow_internal_unstable: false,
allow_internal_unstable: None,
allow_internal_unsafe: false,
local_inner_macros: false,
unstable_feature: None,
Expand Down
18 changes: 12 additions & 6 deletions src/libstd/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow_internal_unstable]
#[cfg_attr(stage0, allow_internal_unstable)]
#[cfg_attr(not(stage0), allow_internal_unstable(__rust_unstable_column, libstd_sys_internals))]
macro_rules! panic {
() => ({
panic!("explicit panic")
Expand Down Expand Up @@ -111,7 +112,8 @@ macro_rules! panic {
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow_internal_unstable]
#[cfg_attr(stage0, allow_internal_unstable)]
#[cfg_attr(not(stage0), allow_internal_unstable(print_internals))]
macro_rules! print {
($($arg:tt)*) => ($crate::io::_print(format_args!($($arg)*)));
}
Expand Down Expand Up @@ -143,7 +145,8 @@ macro_rules! print {
/// ```
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[allow_internal_unstable]
#[cfg_attr(stage0, allow_internal_unstable)]
#[cfg_attr(not(stage0), allow_internal_unstable(print_internals, format_args_nl))]
macro_rules! println {
() => (print!("\n"));
($($arg:tt)*) => ({
Expand Down Expand Up @@ -174,7 +177,8 @@ macro_rules! println {
/// ```
#[macro_export]
#[stable(feature = "eprint", since = "1.19.0")]
#[allow_internal_unstable]
#[cfg_attr(stage0, allow_internal_unstable)]
#[cfg_attr(not(stage0), allow_internal_unstable(print_internals))]
macro_rules! eprint {
($($arg:tt)*) => ($crate::io::_eprint(format_args!($($arg)*)));
}
Expand Down Expand Up @@ -202,7 +206,8 @@ macro_rules! eprint {
/// ```
#[macro_export]
#[stable(feature = "eprint", since = "1.19.0")]
#[allow_internal_unstable]
#[cfg_attr(stage0, allow_internal_unstable)]
#[cfg_attr(not(stage0), allow_internal_unstable(print_internals, format_args_nl))]
macro_rules! eprintln {
() => (eprint!("\n"));
($($arg:tt)*) => ({
Expand Down Expand Up @@ -325,7 +330,8 @@ macro_rules! dbg {
/// A macro to await on an async call.
#[macro_export]
#[unstable(feature = "await_macro", issue = "50547")]
#[allow_internal_unstable]
#[cfg_attr(stage0, allow_internal_unstable)]
#[cfg_attr(not(stage0), allow_internal_unstable(gen_future, generators))]
#[allow_internal_unsafe]
macro_rules! await {
($e:expr) => { {
Expand Down
3 changes: 3 additions & 0 deletions src/libstd/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ use self::select::StartResult;
use self::select::StartResult::*;
use self::blocking::SignalToken;

#[cfg(all(test, not(target_os = "emscripten")))]
mod select_tests;

mod blocking;
mod oneshot;
mod select;
Expand Down
Loading