Skip to content

Commit 66e78d8

Browse files
authored
Unrolled build for rust-lang#118123
Rollup merge of rust-lang#118123 - RalfJung:internal-lib-features, r=compiler-errors Add support for making lib features internal We have the notion of an "internal" lang feature: a feature that is never intended to be stabilized, and using which can cause ICEs and other issues without that being considered a bug. This extends that idea to lib features as well. It is an alternative to rust-lang#115623: instead of using an attribute to declare lib features internal, we simply do this based on the name. Everything ending in `_internals` or `_internal` is considered internal. Then we rename `core_intrinsics` to `core_intrinsics_internal`, which fixes rust-lang#115597.
2 parents 84a554c + 74834a9 commit 66e78d8

File tree

8 files changed

+59
-8
lines changed

8 files changed

+59
-8
lines changed

compiler/rustc_feature/src/unstable.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ macro_rules! declare_features {
5656
#[derive(Clone, Default, Debug)]
5757
pub struct Features {
5858
/// `#![feature]` attrs for language features, for error reporting.
59+
/// "declared" here means that the feature is actually enabled in the current crate.
5960
pub declared_lang_features: Vec<(Symbol, Span, Option<Symbol>)>,
6061
/// `#![feature]` attrs for non-language (library) features.
62+
/// "declared" here means that the feature is actually enabled in the current crate.
6163
pub declared_lib_features: Vec<(Symbol, Span)>,
6264
/// `declared_lang_features` + `declared_lib_features`.
6365
pub declared_features: FxHashSet<Symbol>,
@@ -133,9 +135,18 @@ macro_rules! declare_features {
133135
$(
134136
sym::$feature => status_to_enum!($status) == FeatureStatus::Internal,
135137
)*
136-
// Accepted/removed features aren't in this file but are never internal
137-
// (a removed feature might have been internal, but that's now irrelevant).
138-
_ if self.declared_features.contains(&feature) => false,
138+
_ if self.declared_features.contains(&feature) => {
139+
// This could be accepted/removed, or a libs feature.
140+
// Accepted/removed features aren't in this file but are never internal
141+
// (a removed feature might have been internal, but that's now irrelevant).
142+
// Libs features are internal if they end in `_internal` or `_internals`.
143+
// As a special exception we also consider `core_intrinsics` internal;
144+
// renaming that age-old feature is just not worth the hassle.
145+
// We just always test the name; it's not a big deal if we accidentally hit
146+
// an accepted/removed lang feature that way.
147+
let name = feature.as_str();
148+
name == "core_intrinsics" || name.ends_with("_internal") || name.ends_with("_internals")
149+
}
139150
_ => panic!("`{}` was not listed in `declare_features`", feature),
140151
}
141152
}
@@ -215,9 +226,6 @@ declare_features! (
215226
(internal, test_2018_feature, "1.31.0", None, Some(Edition::Edition2018)),
216227
/// Added for testing unstable lints; perma-unstable.
217228
(internal, test_unstable_lint, "1.60.0", None, None),
218-
/// Allows non-`unsafe` —and thus, unsound— access to `Pin` constructions.
219-
/// Marked `internal` since perma-unstable and unsound.
220-
(internal, unsafe_pin_internals, "1.60.0", None, None),
221229
/// Use for stable + negative coherence and strict coherence depending on trait's
222230
/// rustc_strict_coherence value.
223231
(unstable, with_negative_coherence, "1.60.0", None, None),

compiler/rustc_query_system/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![feature(hash_raw_entry)]
44
#![feature(min_specialization)]
55
#![feature(let_chains)]
6-
#![allow(rustc::potential_query_instability)]
6+
#![allow(rustc::potential_query_instability, internal_features)]
77
#![deny(rustc::untranslatable_diagnostic)]
88
#![deny(rustc::diagnostic_outside_of_impl)]
99

library/alloc/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#![feature(thin_box)]
4242
#![feature(strict_provenance)]
4343
#![feature(drain_keep_rest)]
44+
#![allow(internal_features)]
4445
#![deny(fuzzy_provenance_casts)]
4546
#![deny(unsafe_op_in_unsafe_fn)]
4647

library/core/src/intrinsics.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,7 @@ extern "rust-intrinsic" {
19061906
///
19071907
/// ```
19081908
/// #![feature(core_intrinsics)]
1909+
/// # #![allow(internal_features)]
19091910
///
19101911
/// use std::intrinsics::ctlz;
19111912
///
@@ -1918,6 +1919,7 @@ extern "rust-intrinsic" {
19181919
///
19191920
/// ```
19201921
/// #![feature(core_intrinsics)]
1922+
/// # #![allow(internal_features)]
19211923
///
19221924
/// use std::intrinsics::ctlz;
19231925
///
@@ -1939,6 +1941,7 @@ extern "rust-intrinsic" {
19391941
///
19401942
/// ```
19411943
/// #![feature(core_intrinsics)]
1944+
/// # #![allow(internal_features)]
19421945
///
19431946
/// use std::intrinsics::ctlz_nonzero;
19441947
///
@@ -1965,6 +1968,7 @@ extern "rust-intrinsic" {
19651968
///
19661969
/// ```
19671970
/// #![feature(core_intrinsics)]
1971+
/// # #![allow(internal_features)]
19681972
///
19691973
/// use std::intrinsics::cttz;
19701974
///
@@ -1977,6 +1981,7 @@ extern "rust-intrinsic" {
19771981
///
19781982
/// ```
19791983
/// #![feature(core_intrinsics)]
1984+
/// # #![allow(internal_features)]
19801985
///
19811986
/// use std::intrinsics::cttz;
19821987
///
@@ -1998,6 +2003,7 @@ extern "rust-intrinsic" {
19982003
///
19992004
/// ```
20002005
/// #![feature(core_intrinsics)]
2006+
/// # #![allow(internal_features)]
20012007
///
20022008
/// use std::intrinsics::cttz_nonzero;
20032009
///
@@ -2463,6 +2469,7 @@ extern "rust-intrinsic" {
24632469
/// ```no_run
24642470
/// #![feature(const_eval_select)]
24652471
/// #![feature(core_intrinsics)]
2472+
/// # #![allow(internal_features)]
24662473
/// use std::hint::unreachable_unchecked;
24672474
/// use std::intrinsics::const_eval_select;
24682475
///

library/core/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
#![feature(get_many_mut)]
118118
#![feature(offset_of)]
119119
#![feature(iter_map_windows)]
120+
#![allow(internal_features)]
120121
#![deny(unsafe_op_in_unsafe_fn)]
121122
#![deny(fuzzy_provenance_casts)]
122123

src/tools/rust-analyzer/crates/proc-macro-srv/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#![cfg(feature = "sysroot-abi")]
1414
#![feature(proc_macro_internals, proc_macro_diagnostic, proc_macro_span)]
1515
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
16-
#![allow(unreachable_pub)]
16+
#![allow(unreachable_pub, internal_features)]
1717

1818
extern crate proc_macro;
1919

tests/ui/lint/internal_features.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![forbid(internal_features)]
2+
// A lang feature and a lib feature.
3+
#![feature(intrinsics, panic_internals)]
4+
//~^ ERROR: internal
5+
//~| ERROR: internal
6+
7+
extern "rust-intrinsic" {
8+
fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
9+
}
10+
11+
fn main() {}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error: the feature `intrinsics` is internal to the compiler or standard library
2+
--> $DIR/internal_features.rs:3:12
3+
|
4+
LL | #![feature(intrinsics, panic_internals)]
5+
| ^^^^^^^^^^
6+
|
7+
= note: using it is strongly discouraged
8+
note: the lint level is defined here
9+
--> $DIR/internal_features.rs:1:11
10+
|
11+
LL | #![forbid(internal_features)]
12+
| ^^^^^^^^^^^^^^^^^
13+
14+
error: the feature `panic_internals` is internal to the compiler or standard library
15+
--> $DIR/internal_features.rs:3:24
16+
|
17+
LL | #![feature(intrinsics, panic_internals)]
18+
| ^^^^^^^^^^^^^^^
19+
|
20+
= note: using it is strongly discouraged
21+
22+
error: aborting due to 2 previous errors
23+

0 commit comments

Comments
 (0)