Skip to content

Commit d3c212c

Browse files
committed
Require a list of features to allow in allow_internal_unstable
1 parent 57d7cfc commit d3c212c

35 files changed

+182
-93
lines changed

src/liballoc/macros.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
#[cfg(not(test))]
3535
#[macro_export]
3636
#[stable(feature = "rust1", since = "1.0.0")]
37-
#[allow_internal_unstable]
37+
#[cfg_attr(not(stage0), allow_internal_unstable(box_syntax))]
38+
#[cfg_attr(stage0, allow_internal_unstable)]
3839
macro_rules! vec {
3940
($elem:expr; $n:expr) => (
4041
$crate::vec::from_elem($elem, $n)

src/libcore/macros.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// Entry point of thread panic, for details, see std::macros
22
#[macro_export]
3-
#[allow_internal_unstable]
3+
#[cfg_attr(not(stage0), allow_internal_unstable(core_panic, __rust_unstable_column))]
4+
#[cfg_attr(stage0, allow_internal_unstable)]
45
#[stable(feature = "core", since = "1.6.0")]
56
macro_rules! panic {
67
() => (
@@ -409,7 +410,8 @@ macro_rules! write {
409410
/// ```
410411
#[macro_export]
411412
#[stable(feature = "rust1", since = "1.0.0")]
412-
#[allow_internal_unstable]
413+
#[cfg_attr(stage0, allow_internal_unstable)]
414+
#[cfg_attr(not(stage0), allow_internal_unstable(format_args_nl))]
413415
macro_rules! writeln {
414416
($dst:expr) => (
415417
write!($dst, "\n")

src/librustc/hir/lowering.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -681,13 +681,18 @@ impl<'a> LoweringContext<'a> {
681681
Ident::with_empty_ctxt(Symbol::gensym(s))
682682
}
683683

684-
fn allow_internal_unstable(&self, reason: CompilerDesugaringKind, span: Span) -> Span {
684+
fn allow_internal_unstable(
685+
&self,
686+
reason: CompilerDesugaringKind,
687+
span: Span,
688+
allow_internal_unstable: Vec<Symbol>,
689+
) -> Span {
685690
let mark = Mark::fresh(Mark::root());
686691
mark.set_expn_info(source_map::ExpnInfo {
687692
call_site: span,
688693
def_site: Some(span),
689694
format: source_map::CompilerDesugaring(reason),
690-
allow_internal_unstable: true,
695+
allow_internal_unstable,
691696
allow_internal_unsafe: false,
692697
local_inner_macros: false,
693698
edition: source_map::hygiene::default_edition(),
@@ -964,7 +969,13 @@ impl<'a> LoweringContext<'a> {
964969
attrs: ThinVec::new(),
965970
};
966971

967-
let unstable_span = self.allow_internal_unstable(CompilerDesugaringKind::Async, span);
972+
let unstable_span = self.allow_internal_unstable(
973+
CompilerDesugaringKind::Async,
974+
span,
975+
vec![
976+
Symbol::intern("gen_future"),
977+
],
978+
);
968979
let gen_future = self.expr_std_path(
969980
unstable_span, &["future", "from_generator"], None, ThinVec::new());
970981
hir::ExprKind::Call(P(gen_future), hir_vec![generator])
@@ -1363,6 +1374,7 @@ impl<'a> LoweringContext<'a> {
13631374
let exist_ty_span = self.allow_internal_unstable(
13641375
CompilerDesugaringKind::ExistentialReturnType,
13651376
span,
1377+
Vec::new(), // doesn'c actually allow anything unstable
13661378
);
13671379

13681380
let exist_ty_def_index = self
@@ -3927,8 +3939,13 @@ impl<'a> LoweringContext<'a> {
39273939
}),
39283940
ExprKind::TryBlock(ref body) => {
39293941
self.with_catch_scope(body.id, |this| {
3930-
let unstable_span =
3931-
this.allow_internal_unstable(CompilerDesugaringKind::TryBlock, body.span);
3942+
let unstable_span = this.allow_internal_unstable(
3943+
CompilerDesugaringKind::TryBlock,
3944+
body.span,
3945+
vec![
3946+
Symbol::intern("try_trait"),
3947+
],
3948+
);
39323949
let mut block = this.lower_block(body, true).into_inner();
39333950
let tail = block.expr.take().map_or_else(
39343951
|| {
@@ -4363,6 +4380,7 @@ impl<'a> LoweringContext<'a> {
43634380
let desugared_span = self.allow_internal_unstable(
43644381
CompilerDesugaringKind::ForLoop,
43654382
head_sp,
4383+
Vec::new(),
43664384
);
43674385

43684386
let iter = self.str_to_ident("iter");
@@ -4525,8 +4543,13 @@ impl<'a> LoweringContext<'a> {
45254543
// return Try::from_error(From::from(err)),
45264544
// }
45274545

4528-
let unstable_span =
4529-
self.allow_internal_unstable(CompilerDesugaringKind::QuestionMark, e.span);
4546+
let unstable_span = self.allow_internal_unstable(
4547+
CompilerDesugaringKind::QuestionMark,
4548+
e.span,
4549+
vec![
4550+
Symbol::intern("try_trait")
4551+
],
4552+
);
45304553

45314554
// `Try::into_result(<expr>)`
45324555
let discr = {

src/librustc/middle/stability.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
561561
/// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to
562562
/// `id`.
563563
pub fn eval_stability(self, def_id: DefId, id: Option<NodeId>, span: Span) -> EvalResult {
564-
if span.allows_unstable() {
565-
debug!("stability: skipping span={:?} since it is internal", span);
566-
return EvalResult::Allow;
567-
}
568-
569564
let lint_deprecated = |def_id: DefId,
570565
id: NodeId,
571566
note: Option<Symbol>,
@@ -694,6 +689,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
694689

695690
match stability {
696691
Some(&Stability { level: attr::Unstable { reason, issue }, feature, .. }) => {
692+
if span.allows_unstable(&feature.as_str()) {
693+
debug!("stability: skipping span={:?} since it is internal", span);
694+
return EvalResult::Allow;
695+
}
697696
if self.stability().active_features.contains(&feature) {
698697
return EvalResult::Allow;
699698
}

src/librustc_allocator/expand.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ impl MutVisitor for ExpandAllocatorDirectives<'_> {
9191
call_site: item.span, // use the call site of the static
9292
def_site: None,
9393
format: MacroAttribute(Symbol::intern(name)),
94-
allow_internal_unstable: true,
94+
allow_internal_unstable: vec![
95+
Symbol::intern("rustc_attrs"),
96+
],
9597
allow_internal_unsafe: false,
9698
local_inner_macros: false,
9799
edition: hygiene::default_edition(),

src/librustc_metadata/creader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ impl<'a> CrateLoader<'a> {
570570
ProcMacro::Bang { name, client } => {
571571
(name, SyntaxExtension::ProcMacro {
572572
expander: Box::new(BangProcMacro { client }),
573-
allow_internal_unstable: false,
573+
allow_internal_unstable: Vec::new(),
574574
edition: root.edition,
575575
})
576576
}

src/librustc_metadata/cstore_impl.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,9 @@ impl cstore::CStore {
425425
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
426426
let ext = SyntaxExtension::ProcMacro {
427427
expander: Box::new(BangProcMacro { client }),
428-
allow_internal_unstable: true,
428+
allow_internal_unstable: vec![
429+
Symbol::intern("proc_macro_def_site"),
430+
],
429431
edition: data.root.edition,
430432
};
431433
return LoadedMacro::ProcMacro(Lrc::new(ext));

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
907907
// Check `#[unstable]` const fns or `#[rustc_const_unstable]`
908908
// functions without the feature gate active in this crate in
909909
// order to report a better error message than the one below.
910-
if self.span.allows_unstable() {
910+
if self.span.allows_unstable(&feature.as_str()) {
911911
// `allow_internal_unstable` can make such calls stable.
912912
is_const_fn = true;
913913
} else {

src/librustc_plugin/registry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ impl<'a> Registry<'a> {
110110
edition,
111111
}
112112
}
113-
IdentTT(ext, _, allow_internal_unstable) => {
114-
IdentTT(ext, Some(self.krate_span), allow_internal_unstable)
113+
IdentTT { ext, span: _, allow_internal_unstable } => {
114+
IdentTT { ext, span: Some(self.krate_span), allow_internal_unstable }
115115
}
116116
_ => extension,
117117
}));
@@ -126,7 +126,7 @@ impl<'a> Registry<'a> {
126126
self.register_syntax_extension(Symbol::intern(name), NormalTT {
127127
expander: Box::new(expander),
128128
def_info: None,
129-
allow_internal_unstable: false,
129+
allow_internal_unstable: Vec::new(),
130130
allow_internal_unsafe: false,
131131
local_inner_macros: false,
132132
unstable_feature: None,

src/libstd/macros.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
/// ```
5454
#[macro_export]
5555
#[stable(feature = "rust1", since = "1.0.0")]
56-
#[allow_internal_unstable]
56+
#[cfg_attr(stage0, allow_internal_unstable)]
57+
#[cfg_attr(not(stage0), allow_internal_unstable(__rust_unstable_column, libstd_sys_internals))]
5758
macro_rules! panic {
5859
() => ({
5960
panic!("explicit panic")
@@ -111,7 +112,8 @@ macro_rules! panic {
111112
/// ```
112113
#[macro_export]
113114
#[stable(feature = "rust1", since = "1.0.0")]
114-
#[allow_internal_unstable]
115+
#[cfg_attr(stage0, allow_internal_unstable)]
116+
#[cfg_attr(not(stage0), allow_internal_unstable(print_internals))]
115117
macro_rules! print {
116118
($($arg:tt)*) => ($crate::io::_print(format_args!($($arg)*)));
117119
}
@@ -143,7 +145,8 @@ macro_rules! print {
143145
/// ```
144146
#[macro_export]
145147
#[stable(feature = "rust1", since = "1.0.0")]
146-
#[allow_internal_unstable]
148+
#[cfg_attr(stage0, allow_internal_unstable)]
149+
#[cfg_attr(not(stage0), allow_internal_unstable(print_internals, format_args_nl))]
147150
macro_rules! println {
148151
() => (print!("\n"));
149152
($($arg:tt)*) => ({
@@ -174,7 +177,8 @@ macro_rules! println {
174177
/// ```
175178
#[macro_export]
176179
#[stable(feature = "eprint", since = "1.19.0")]
177-
#[allow_internal_unstable]
180+
#[cfg_attr(stage0, allow_internal_unstable)]
181+
#[cfg_attr(not(stage0), allow_internal_unstable(print_internals))]
178182
macro_rules! eprint {
179183
($($arg:tt)*) => ($crate::io::_eprint(format_args!($($arg)*)));
180184
}
@@ -202,7 +206,8 @@ macro_rules! eprint {
202206
/// ```
203207
#[macro_export]
204208
#[stable(feature = "eprint", since = "1.19.0")]
205-
#[allow_internal_unstable]
209+
#[cfg_attr(stage0, allow_internal_unstable)]
210+
#[cfg_attr(not(stage0), allow_internal_unstable(print_internals, format_args_nl))]
206211
macro_rules! eprintln {
207212
() => (eprint!("\n"));
208213
($($arg:tt)*) => ({
@@ -325,7 +330,8 @@ macro_rules! dbg {
325330
/// A macro to await on an async call.
326331
#[macro_export]
327332
#[unstable(feature = "await_macro", issue = "50547")]
328-
#[allow_internal_unstable]
333+
#[cfg_attr(stage0, allow_internal_unstable)]
334+
#[cfg_attr(not(stage0), allow_internal_unstable(gen_future, generators))]
329335
#[allow_internal_unsafe]
330336
macro_rules! await {
331337
($e:expr) => { {

0 commit comments

Comments
 (0)