Skip to content

Commit c84e797

Browse files
committed
Auto merge of #58098 - oli-obk:maybe_allow_internal_unstable, r=petrochenkov
Require a list of features in `#[allow_internal_unstable]` The blanket-permission slip is not great and will likely give us trouble some point down the road.
2 parents a54b5c7 + bbe524d commit c84e797

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+622
-512
lines changed

src/liballoc/macros.rs

+2-1
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

+4-2
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

+35-9
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ use crate::middle::cstore::CrateStore;
4444
use rustc_data_structures::fx::FxHashSet;
4545
use rustc_data_structures::indexed_vec::IndexVec;
4646
use rustc_data_structures::thin_vec::ThinVec;
47+
use rustc_data_structures::sync::Lrc;
4748
use crate::session::Session;
4849
use crate::session::config::nightly_options;
4950
use crate::util::common::FN_OUTPUT_NAME;
@@ -681,13 +682,20 @@ impl<'a> LoweringContext<'a> {
681682
Ident::with_empty_ctxt(Symbol::gensym(s))
682683
}
683684

684-
fn allow_internal_unstable(&self, reason: CompilerDesugaringKind, span: Span) -> Span {
685+
/// Reuses the span but adds information like the kind of the desugaring and features that are
686+
/// allowed inside this span.
687+
fn mark_span_with_reason(
688+
&self,
689+
reason: CompilerDesugaringKind,
690+
span: Span,
691+
allow_internal_unstable: Option<Lrc<[Symbol]>>,
692+
) -> Span {
685693
let mark = Mark::fresh(Mark::root());
686694
mark.set_expn_info(source_map::ExpnInfo {
687695
call_site: span,
688696
def_site: Some(span),
689697
format: source_map::CompilerDesugaring(reason),
690-
allow_internal_unstable: true,
698+
allow_internal_unstable,
691699
allow_internal_unsafe: false,
692700
local_inner_macros: false,
693701
edition: source_map::hygiene::default_edition(),
@@ -964,7 +972,13 @@ impl<'a> LoweringContext<'a> {
964972
attrs: ThinVec::new(),
965973
};
966974

967-
let unstable_span = self.allow_internal_unstable(CompilerDesugaringKind::Async, span);
975+
let unstable_span = self.mark_span_with_reason(
976+
CompilerDesugaringKind::Async,
977+
span,
978+
Some(vec![
979+
Symbol::intern("gen_future"),
980+
].into()),
981+
);
968982
let gen_future = self.expr_std_path(
969983
unstable_span, &["future", "from_generator"], None, ThinVec::new());
970984
hir::ExprKind::Call(P(gen_future), hir_vec![generator])
@@ -1360,9 +1374,10 @@ impl<'a> LoweringContext<'a> {
13601374
// desugaring that explicitly states that we don't want to track that.
13611375
// Not tracking it makes lints in rustc and clippy very fragile as
13621376
// frequently opened issues show.
1363-
let exist_ty_span = self.allow_internal_unstable(
1377+
let exist_ty_span = self.mark_span_with_reason(
13641378
CompilerDesugaringKind::ExistentialReturnType,
13651379
span,
1380+
None,
13661381
);
13671382

13681383
let exist_ty_def_index = self
@@ -3927,8 +3942,13 @@ impl<'a> LoweringContext<'a> {
39273942
}),
39283943
ExprKind::TryBlock(ref body) => {
39293944
self.with_catch_scope(body.id, |this| {
3930-
let unstable_span =
3931-
this.allow_internal_unstable(CompilerDesugaringKind::TryBlock, body.span);
3945+
let unstable_span = this.mark_span_with_reason(
3946+
CompilerDesugaringKind::TryBlock,
3947+
body.span,
3948+
Some(vec![
3949+
Symbol::intern("try_trait"),
3950+
].into()),
3951+
);
39323952
let mut block = this.lower_block(body, true).into_inner();
39333953
let tail = block.expr.take().map_or_else(
39343954
|| {
@@ -4360,9 +4380,10 @@ impl<'a> LoweringContext<'a> {
43604380
// expand <head>
43614381
let head = self.lower_expr(head);
43624382
let head_sp = head.span;
4363-
let desugared_span = self.allow_internal_unstable(
4383+
let desugared_span = self.mark_span_with_reason(
43644384
CompilerDesugaringKind::ForLoop,
43654385
head_sp,
4386+
None,
43664387
);
43674388

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

4528-
let unstable_span =
4529-
self.allow_internal_unstable(CompilerDesugaringKind::QuestionMark, e.span);
4549+
let unstable_span = self.mark_span_with_reason(
4550+
CompilerDesugaringKind::QuestionMark,
4551+
e.span,
4552+
Some(vec![
4553+
Symbol::intern("try_trait")
4554+
].into()),
4555+
);
45304556

45314557
// `Try::into_result(<expr>)`
45324558
let discr = {

src/librustc/middle/stability.rs

+4-5
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

+3-1
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: Some(vec![
95+
Symbol::intern("rustc_attrs"),
96+
].into()),
9597
allow_internal_unsafe: false,
9698
local_inner_macros: false,
9799
edition: hygiene::default_edition(),

src/librustc_data_structures/macros.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/// A simple static assertion macro. The first argument should be a unique
22
/// ALL_CAPS identifier that describes the condition.
33
#[macro_export]
4-
#[allow_internal_unstable]
4+
#[cfg_attr(stage0, allow_internal_unstable)]
5+
#[cfg_attr(not(stage0), allow_internal_unstable(type_ascription))]
56
macro_rules! static_assert {
67
($name:ident: $test:expr) => {
78
// Use the bool to access an array such that if the bool is false, the access

src/librustc_metadata/creader.rs

+1-1
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: None,
574574
edition: root.edition,
575575
})
576576
}

src/librustc_metadata/cstore_impl.rs

+3-1
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: Some(vec![
429+
Symbol::intern("proc_macro_def_site"),
430+
].into()),
429431
edition: data.root.edition,
430432
};
431433
return LoadedMacro::ProcMacro(Lrc::new(ext));

src/librustc_mir/transform/qualify_consts.rs

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

src/librustc_plugin/registry.rs

+3-3
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 { expander, span: _, allow_internal_unstable } => {
114+
IdentTT { expander, 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: None,
130130
allow_internal_unsafe: false,
131131
local_inner_macros: false,
132132
unstable_feature: None,

src/libstd/macros.rs

+12-6
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) => { {

src/libstd/sync/mpsc/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ use self::select::StartResult;
279279
use self::select::StartResult::*;
280280
use self::blocking::SignalToken;
281281

282+
#[cfg(all(test, not(target_os = "emscripten")))]
283+
mod select_tests;
284+
282285
mod blocking;
283286
mod oneshot;
284287
mod select;

0 commit comments

Comments
 (0)