Add internal_features lint

It lints against features that are inteded to be internal to the
compiler and standard library. Implements MCP #596.

We allow `internal_features` in the standard library and compiler as those
use many features and this _is_ the standard library from the "internal to the compiler and
standard library" after all.

Marking some features as internal wasn't exactly the most scientific approach, I just marked some
mostly obvious features. While there is a categorization in the macro,
it's not very well upheld (should probably be fixed in another PR).

We always pass `-Ainternal_features` in the testsuite
About 400 UI tests and several other tests use internal features.
Instead of throwing the attribute on each one, just always allow them.
There's nothing wrong with testing internal features^^
This commit is contained in:
Nilstrieb 2023-03-09 20:54:53 +00:00
parent c115ec11d2
commit 5830ca216d
68 changed files with 209 additions and 49 deletions

View File

@ -1,4 +1,5 @@
#![cfg_attr(feature = "nightly", feature(step_trait, rustc_attrs, min_specialization))] #![cfg_attr(feature = "nightly", feature(step_trait, rustc_attrs, min_specialization))]
#![cfg_attr(all(not(bootstrap), feature = "nightly"), allow(internal_features))]
use std::fmt; use std::fmt;
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]

View File

@ -23,6 +23,7 @@
#![deny(unsafe_op_in_unsafe_fn)] #![deny(unsafe_op_in_unsafe_fn)]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![allow(clippy::mut_from_ref)] // Arena allocators are one of the places where this pattern is fine. #![allow(clippy::mut_from_ref)] // Arena allocators are one of the places where this pattern is fine.
use smallvec::SmallVec; use smallvec::SmallVec;

View File

@ -11,6 +11,7 @@
#![feature(trusted_step)] #![feature(trusted_step)]
#![feature(try_blocks)] #![feature(try_blocks)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use] #[macro_use]
extern crate rustc_middle; extern crate rustc_middle;

View File

@ -37,6 +37,7 @@
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![deny(unsafe_op_in_unsafe_fn)] #![deny(unsafe_op_in_unsafe_fn)]
#[macro_use] #[macro_use]

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0092 ```compile_fail,E0092
#![feature(intrinsics)] #![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" { extern "rust-intrinsic" {
fn atomic_foo(); // error: unrecognized atomic operation fn atomic_foo(); // error: unrecognized atomic operation
@ -17,6 +18,7 @@ functions are defined in `compiler/rustc_codegen_llvm/src/intrinsic.rs` and in
``` ```
#![feature(intrinsics)] #![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" { extern "rust-intrinsic" {
fn atomic_fence_seqcst(); // ok! fn atomic_fence_seqcst(); // ok!

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0093 ```compile_fail,E0093
#![feature(intrinsics)] #![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" { extern "rust-intrinsic" {
fn foo(); // error: unrecognized intrinsic function: `foo` fn foo(); // error: unrecognized intrinsic function: `foo`
@ -22,6 +23,7 @@ functions are defined in `compiler/rustc_codegen_llvm/src/intrinsic.rs` and in
``` ```
#![feature(intrinsics)] #![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" { extern "rust-intrinsic" {
fn atomic_fence_seqcst(); // ok! fn atomic_fence_seqcst(); // ok!

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0094 ```compile_fail,E0094
#![feature(intrinsics)] #![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" { extern "rust-intrinsic" {
#[rustc_safe_intrinsic] #[rustc_safe_intrinsic]
@ -18,6 +19,7 @@ Example:
``` ```
#![feature(intrinsics)] #![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" { extern "rust-intrinsic" {
#[rustc_safe_intrinsic] #[rustc_safe_intrinsic]

View File

@ -8,6 +8,7 @@ Erroneous code example:
```compile_fail ```compile_fail
// NOTE: this feature is perma-unstable and should *only* be used for // NOTE: this feature is perma-unstable and should *only* be used for
// testing purposes. // testing purposes.
#![allow(internal_features)]
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#[rustc_variance] #[rustc_variance]

View File

@ -5,6 +5,7 @@ used. Erroneous code examples:
```compile_fail ```compile_fail
#![feature(intrinsics)] #![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" { extern "rust-intrinsic" {
#[rustc_safe_intrinsic] #[rustc_safe_intrinsic]
@ -41,6 +42,7 @@ For the first code example, please check the function definition. Example:
``` ```
#![feature(intrinsics)] #![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" { extern "rust-intrinsic" {
#[rustc_safe_intrinsic] #[rustc_safe_intrinsic]

View File

@ -5,6 +5,7 @@ compiled:
```compile_fail,E0230 ```compile_fail,E0230
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![allow(internal_features)]
#[rustc_on_unimplemented = "error on `{Self}` with params `<{A},{B}>`"] // error #[rustc_on_unimplemented = "error on `{Self}` with params `<{A},{B}>`"] // error
trait BadAnnotation<A> {} trait BadAnnotation<A> {}

View File

@ -5,6 +5,7 @@ compiled:
```compile_fail,E0231 ```compile_fail,E0231
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![allow(internal_features)]
#[rustc_on_unimplemented = "error on `{Self}` with params `<{A},{}>`"] // error! #[rustc_on_unimplemented = "error on `{Self}` with params `<{A},{}>`"] // error!
trait BadAnnotation<A> {} trait BadAnnotation<A> {}

View File

@ -5,6 +5,7 @@ compiled:
```compile_fail,E0232 ```compile_fail,E0232
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![allow(internal_features)]
#[rustc_on_unimplemented(lorem="")] // error! #[rustc_on_unimplemented(lorem="")] // error!
trait BadAnnotation {} trait BadAnnotation {}

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0264 ```compile_fail,E0264
#![feature(lang_items)] #![feature(lang_items)]
#![allow(internal_features)]
extern "C" { extern "C" {
#[lang = "cake"] // error: unknown external lang item: `cake` #[lang = "cake"] // error: unknown external lang item: `cake`
@ -16,6 +17,7 @@ A list of available external lang items is available in
``` ```
#![feature(lang_items)] #![feature(lang_items)]
#![allow(internal_features)]
extern "C" { extern "C" {
#[lang = "panic_impl"] // ok! #[lang = "panic_impl"] // ok!

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0539 ```compile_fail,E0539
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")] #![stable(since = "1.0.0", feature = "test")]
#[deprecated(note)] // error! #[deprecated(note)] // error!
@ -28,6 +29,7 @@ To fix these issues you need to give required key-value pairs.
``` ```
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")] #![stable(since = "1.0.0", feature = "test")]
#[deprecated(since = "1.39.0", note = "reason")] // ok! #[deprecated(since = "1.39.0", note = "reason")] // ok!

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0542 ```compile_fail,E0542
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")] #![stable(since = "1.0.0", feature = "test")]
#[stable(feature = "_stable_fn")] // invalid #[stable(feature = "_stable_fn")] // invalid
@ -23,6 +24,7 @@ To fix this issue, you need to provide the `since` field. Example:
``` ```
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")] #![stable(since = "1.0.0", feature = "test")]
#[stable(feature = "_stable_fn", since = "1.0.0")] // ok! #[stable(feature = "_stable_fn", since = "1.0.0")] // ok!

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0543 ```compile_fail,E0543
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")] #![stable(since = "1.0.0", feature = "test")]
#[stable(since = "0.1.0", feature = "_deprecated_fn")] #[stable(since = "0.1.0", feature = "_deprecated_fn")]
@ -17,6 +18,7 @@ To fix this issue, you need to provide the `note` field. Example:
``` ```
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")] #![stable(since = "1.0.0", feature = "test")]
#[stable(since = "0.1.0", feature = "_deprecated_fn")] #[stable(since = "0.1.0", feature = "_deprecated_fn")]

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0544 ```compile_fail,E0544
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "rust1")] #![stable(since = "1.0.0", feature = "rust1")]
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
@ -15,6 +16,7 @@ To fix this issue, ensure that each item has at most one stability attribute.
``` ```
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "rust1")] #![stable(since = "1.0.0", feature = "rust1")]
#[stable(feature = "test", since = "2.0.0")] // ok! #[stable(feature = "test", since = "2.0.0")] // ok!

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0545 ```compile_fail,E0545
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")] #![stable(since = "1.0.0", feature = "test")]
#[unstable(feature = "_unstable_fn", issue = "0")] // invalid #[unstable(feature = "_unstable_fn", issue = "0")] // invalid
@ -18,6 +19,7 @@ Example:
``` ```
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")] #![stable(since = "1.0.0", feature = "test")]
#[unstable(feature = "_unstable_fn", issue = "none")] // ok! #[unstable(feature = "_unstable_fn", issue = "none")] // ok!

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0546 ```compile_fail,E0546
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")] #![stable(since = "1.0.0", feature = "test")]
#[unstable(issue = "none")] // invalid #[unstable(issue = "none")] // invalid
@ -17,6 +18,7 @@ To fix this issue, you need to provide the `feature` field. Example:
``` ```
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")] #![stable(since = "1.0.0", feature = "test")]
#[unstable(feature = "unstable_fn", issue = "none")] // ok! #[unstable(feature = "unstable_fn", issue = "none")] // ok!

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0547 ```compile_fail,E0547
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")] #![stable(since = "1.0.0", feature = "test")]
#[unstable(feature = "_unstable_fn")] // invalid #[unstable(feature = "_unstable_fn")] // invalid
@ -17,6 +18,7 @@ To fix this issue, you need to provide the `issue` field. Example:
``` ```
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")] #![stable(since = "1.0.0", feature = "test")]
#[unstable(feature = "_unstable_fn", issue = "none")] // ok! #[unstable(feature = "_unstable_fn", issue = "none")] // ok!

View File

@ -5,6 +5,7 @@ Erroneous code example:
```compile_fail,E0549 ```compile_fail,E0549
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")] #![stable(since = "1.0.0", feature = "test")]
#[deprecated( #[deprecated(
@ -19,6 +20,7 @@ Example:
``` ```
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")] #![stable(since = "1.0.0", feature = "test")]
#[stable(since = "1.0.0", feature = "test")] #[stable(since = "1.0.0", feature = "test")]

View File

@ -4,6 +4,8 @@ Erroneous code example:
```compile_fail,E0622 ```compile_fail,E0622
#![feature(intrinsics)] #![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" { extern "rust-intrinsic" {
pub static breakpoint: fn(); // error: intrinsic must be a function pub static breakpoint: fn(); // error: intrinsic must be a function
} }
@ -17,6 +19,8 @@ error, just declare a function. Example:
```no_run ```no_run
#![feature(intrinsics)] #![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" { extern "rust-intrinsic" {
pub fn breakpoint(); // ok! pub fn breakpoint(); // ok!
} }

View File

@ -5,6 +5,7 @@ Erroneous code example:
```compile_fail,E0773 ```compile_fail,E0773
#![feature(decl_macro)] #![feature(decl_macro)]
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![allow(internal_features)]
#[rustc_builtin_macro] #[rustc_builtin_macro]
pub macro test($item:item) { pub macro test($item:item) {
@ -24,6 +25,7 @@ To fix the issue, remove the duplicate declaration:
``` ```
#![feature(decl_macro)] #![feature(decl_macro)]
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![allow(internal_features)]
#[rustc_builtin_macro] #[rustc_builtin_macro]
pub macro test($item:item) { pub macro test($item:item) {

View File

@ -10,6 +10,7 @@ Erroneous code example:
// used outside of the compiler and standard library. // used outside of the compiler and standard library.
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![unstable(feature = "foo_module", reason = "...", issue = "123")] #![unstable(feature = "foo_module", reason = "...", issue = "123")]

View File

@ -4,6 +4,7 @@
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use] #[macro_use]
extern crate tracing; extern crate tracing;

View File

@ -15,6 +15,7 @@
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(error_reporter)] #![feature(error_reporter)]
#![allow(incomplete_features)] #![allow(incomplete_features)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use] #[macro_use]
extern crate rustc_macros; extern crate rustc_macros;

View File

@ -11,6 +11,7 @@
#![feature(try_blocks)] #![feature(try_blocks)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use] #[macro_use]
extern crate rustc_macros; extern crate rustc_macros;

View File

@ -16,12 +16,22 @@ macro_rules! set {
}}; }};
} }
#[derive(PartialEq)]
enum FeatureStatus {
Default,
Incomplete,
Internal,
}
macro_rules! declare_features { macro_rules! declare_features {
(__status_to_bool active) => { (__status_to_enum active) => {
false FeatureStatus::Default
}; };
(__status_to_bool incomplete) => { (__status_to_enum incomplete) => {
true FeatureStatus::Incomplete
};
(__status_to_enum internal) => {
FeatureStatus::Internal
}; };
($( ($(
$(#[doc = $doc:tt])* ($status:ident, $feature:ident, $ver:expr, $issue:expr, $edition:expr), $(#[doc = $doc:tt])* ($status:ident, $feature:ident, $ver:expr, $issue:expr, $edition:expr),
@ -83,7 +93,7 @@ macro_rules! declare_features {
pub fn incomplete(&self, feature: Symbol) -> bool { pub fn incomplete(&self, feature: Symbol) -> bool {
match feature { match feature {
$( $(
sym::$feature => declare_features!(__status_to_bool $status), sym::$feature => declare_features!(__status_to_enum $status) == FeatureStatus::Incomplete,
)* )*
// accepted and removed features aren't in this file but are never incomplete // accepted and removed features aren't in this file but are never incomplete
_ if self.declared_lang_features.iter().any(|f| f.0 == feature) => false, _ if self.declared_lang_features.iter().any(|f| f.0 == feature) => false,
@ -91,6 +101,22 @@ macro_rules! declare_features {
_ => panic!("`{}` was not listed in `declare_features`", feature), _ => panic!("`{}` was not listed in `declare_features`", feature),
} }
} }
/// Some features are internal to the compiler and standard library and should not
/// be used in normal projects. We warn the user about these
/// to alert them.
pub fn internal(&self, feature: Symbol) -> bool {
match feature {
$(
sym::$feature => declare_features!(__status_to_enum $status) == FeatureStatus::Internal,
)*
// accepted and removed features aren't in this file but are never internal
// (a removed feature might have been internal, but it doesn't matter anymore)
_ if self.declared_lang_features.iter().any(|f| f.0 == feature) => false,
_ if self.declared_lib_features.iter().any(|f| f.0 == feature) => false,
_ => panic!("`{}` was not listed in `declare_features`", feature),
}
}
} }
}; };
} }
@ -137,29 +163,29 @@ declare_features! (
/// Allows using the `vectorcall` ABI. /// Allows using the `vectorcall` ABI.
(active, abi_vectorcall, "1.7.0", None, None), (active, abi_vectorcall, "1.7.0", None, None),
/// Allows using `#![needs_allocator]`, an implementation detail of `#[global_allocator]`. /// Allows using `#![needs_allocator]`, an implementation detail of `#[global_allocator]`.
(active, allocator_internals, "1.20.0", None, None), (internal, allocator_internals, "1.20.0", None, None),
/// Allows using `#[allow_internal_unsafe]`. This is an /// Allows using `#[allow_internal_unsafe]`. This is an
/// attribute on `macro_rules!` and can't use the attribute handling /// attribute on `macro_rules!` and can't use the attribute handling
/// below (it has to be checked before expansion possibly makes /// below (it has to be checked before expansion possibly makes
/// macros disappear). /// macros disappear).
(active, allow_internal_unsafe, "1.0.0", None, None), (internal, allow_internal_unsafe, "1.0.0", None, None),
/// Allows using `#[allow_internal_unstable]`. This is an /// Allows using `#[allow_internal_unstable]`. This is an
/// attribute on `macro_rules!` and can't use the attribute handling /// attribute on `macro_rules!` and can't use the attribute handling
/// below (it has to be checked before expansion possibly makes /// below (it has to be checked before expansion possibly makes
/// macros disappear). /// macros disappear).
(active, allow_internal_unstable, "1.0.0", None, None), (internal, allow_internal_unstable, "1.0.0", None, None),
/// Allows using anonymous lifetimes in argument-position impl-trait. /// Allows using anonymous lifetimes in argument-position impl-trait.
(active, anonymous_lifetime_in_impl_trait, "1.63.0", None, None), (active, anonymous_lifetime_in_impl_trait, "1.63.0", None, None),
/// Allows identifying the `compiler_builtins` crate. /// Allows identifying the `compiler_builtins` crate.
(active, compiler_builtins, "1.13.0", None, None), (internal, compiler_builtins, "1.13.0", None, None),
/// Allows writing custom MIR /// Allows writing custom MIR
(active, custom_mir, "1.65.0", None, None), (internal, custom_mir, "1.65.0", None, None),
/// Outputs useful `assert!` messages /// Outputs useful `assert!` messages
(active, generic_assert, "1.63.0", None, None), (active, generic_assert, "1.63.0", None, None),
/// Allows using the `rust-intrinsic`'s "ABI". /// Allows using the `rust-intrinsic`'s "ABI".
(active, intrinsics, "1.0.0", None, None), (internal, intrinsics, "1.0.0", None, None),
/// Allows using `#[lang = ".."]` attribute for linking items to special compiler logic. /// Allows using `#[lang = ".."]` attribute for linking items to special compiler logic.
(active, lang_items, "1.0.0", None, None), (internal, lang_items, "1.0.0", None, None),
/// Allows `#[link(..., cfg(..))]`; perma-unstable per #37406 /// Allows `#[link(..., cfg(..))]`; perma-unstable per #37406
(active, link_cfg, "1.14.0", None, None), (active, link_cfg, "1.14.0", None, None),
/// Allows the `multiple_supertrait_upcastable` lint. /// Allows the `multiple_supertrait_upcastable` lint.
@ -167,22 +193,22 @@ declare_features! (
/// Allow negative trait bounds. This is an internal-only feature for testing the trait solver! /// Allow negative trait bounds. This is an internal-only feature for testing the trait solver!
(incomplete, negative_bounds, "1.71.0", None, None), (incomplete, negative_bounds, "1.71.0", None, None),
/// Allows using `#[omit_gdb_pretty_printer_section]`. /// Allows using `#[omit_gdb_pretty_printer_section]`.
(active, omit_gdb_pretty_printer_section, "1.5.0", None, None), (internal, omit_gdb_pretty_printer_section, "1.5.0", None, None),
/// Allows using `#[prelude_import]` on glob `use` items. /// Allows using `#[prelude_import]` on glob `use` items.
(active, prelude_import, "1.2.0", None, None), (internal, prelude_import, "1.2.0", None, None),
/// Used to identify crates that contain the profiler runtime. /// Used to identify crates that contain the profiler runtime.
(active, profiler_runtime, "1.18.0", None, None), (internal, profiler_runtime, "1.18.0", None, None),
/// Allows using `rustc_*` attributes (RFC 572). /// Allows using `rustc_*` attributes (RFC 572).
(active, rustc_attrs, "1.0.0", None, None), (internal, rustc_attrs, "1.0.0", None, None),
/// Allows using the `#[stable]` and `#[unstable]` attributes. /// Allows using the `#[stable]` and `#[unstable]` attributes.
(active, staged_api, "1.0.0", None, None), (internal, staged_api, "1.0.0", None, None),
/// Added for testing E0705; perma-unstable. /// Added for testing E0705; perma-unstable.
(active, test_2018_feature, "1.31.0", None, Some(Edition::Edition2018)), (internal, test_2018_feature, "1.31.0", None, Some(Edition::Edition2018)),
/// Added for testing unstable lints; perma-unstable. /// Added for testing unstable lints; perma-unstable.
(active, test_unstable_lint, "1.60.0", None, None), (internal, test_unstable_lint, "1.60.0", None, None),
/// Allows non-`unsafe` —and thus, unsound— access to `Pin` constructions. /// Allows non-`unsafe` —and thus, unsound— access to `Pin` constructions.
/// Marked `incomplete` since perma-unstable and unsound. /// Marked `internal` since perma-unstable and unsound.
(incomplete, unsafe_pin_internals, "1.60.0", None, None), (internal, unsafe_pin_internals, "1.60.0", None, None),
/// Use for stable + negative coherence and strict coherence depending on trait's /// Use for stable + negative coherence and strict coherence depending on trait's
/// rustc_strict_coherence value. /// rustc_strict_coherence value.
(active, with_negative_coherence, "1.60.0", None, None), (active, with_negative_coherence, "1.60.0", None, None),
@ -216,19 +242,19 @@ declare_features! (
/// Allows using the `#[linkage = ".."]` attribute. /// Allows using the `#[linkage = ".."]` attribute.
(active, linkage, "1.0.0", Some(29603), None), (active, linkage, "1.0.0", Some(29603), None),
/// Allows declaring with `#![needs_panic_runtime]` that a panic runtime is needed. /// Allows declaring with `#![needs_panic_runtime]` that a panic runtime is needed.
(active, needs_panic_runtime, "1.10.0", Some(32837), None), (internal, needs_panic_runtime, "1.10.0", Some(32837), None),
/// Allows using `+bundled,+whole-archive` native libs. /// Allows using `+bundled,+whole-archive` native libs.
(active, packed_bundled_libs, "1.69.0", Some(108081), None), (active, packed_bundled_libs, "1.69.0", Some(108081), None),
/// Allows using the `#![panic_runtime]` attribute. /// Allows using the `#![panic_runtime]` attribute.
(active, panic_runtime, "1.10.0", Some(32837), None), (internal, panic_runtime, "1.10.0", Some(32837), None),
/// Allows using `#[rustc_allow_const_fn_unstable]`. /// Allows using `#[rustc_allow_const_fn_unstable]`.
/// This is an attribute on `const fn` for the same /// This is an attribute on `const fn` for the same
/// purpose as `#[allow_internal_unstable]`. /// purpose as `#[allow_internal_unstable]`.
(active, rustc_allow_const_fn_unstable, "1.49.0", Some(69399), None), (internal, rustc_allow_const_fn_unstable, "1.49.0", Some(69399), None),
/// Allows using compiler's own crates. /// Allows using compiler's own crates.
(active, rustc_private, "1.0.0", Some(27812), None), (active, rustc_private, "1.0.0", Some(27812), None),
/// Allows using internal rustdoc features like `doc(keyword)`. /// Allows using internal rustdoc features like `doc(keyword)`.
(active, rustdoc_internals, "1.58.0", Some(90418), None), (internal, rustdoc_internals, "1.58.0", Some(90418), None),
/// Allows using the `rustdoc::missing_doc_code_examples` lint /// Allows using the `rustdoc::missing_doc_code_examples` lint
(active, rustdoc_missing_doc_code_examples, "1.31.0", Some(101730), None), (active, rustdoc_missing_doc_code_examples, "1.31.0", Some(101730), None),
/// Allows using `#[start]` on a function indicating that it is the program entrypoint. /// Allows using `#[start]` on a function indicating that it is the program entrypoint.

View File

@ -13,6 +13,7 @@
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use] #[macro_use]
extern crate rustc_macros; extern crate rustc_macros;

View File

@ -6,6 +6,7 @@
//! //!
//! ``` //! ```
//! # #![feature(rustc_attrs)] //! # #![feature(rustc_attrs)]
//! # #![allow(internal_features)]
//! #![rustc_partition_reused(module="spike", cfg="rpass2")] //! #![rustc_partition_reused(module="spike", cfg="rpass2")]
//! #![rustc_partition_codegened(module="spike-x", cfg="rpass2")] //! #![rustc_partition_codegened(module="spike-x", cfg="rpass2")]
//! ``` //! ```

View File

@ -12,6 +12,7 @@
test test
) )
)] )]
#![cfg_attr(all(not(bootstrap), feature = "nightly"), allow(internal_features))]
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
pub mod bit_set; pub mod bit_set;

View File

@ -72,6 +72,9 @@ lint_builtin_incomplete_features = the feature `{$name}` is incomplete and may n
.note = see issue #{$n} <https://github.com/rust-lang/rust/issues/{$n}> for more information .note = see issue #{$n} <https://github.com/rust-lang/rust/issues/{$n}> for more information
.help = consider using `min_{$name}` instead, which is more stable and complete .help = consider using `min_{$name}` instead, which is more stable and complete
lint_builtin_internal_features = the feature `{$name}` is internal to the compiler or standard library
.note = using it is strongly discouraged
lint_builtin_keyword_idents = `{$kw}` is a keyword in the {$next} edition lint_builtin_keyword_idents = `{$kw}` is a keyword in the {$next} edition
.suggestion = you can use a raw identifier to stay compatible .suggestion = you can use a raw identifier to stay compatible

View File

@ -28,8 +28,8 @@ use crate::{
BuiltinClashingExternSub, BuiltinConstNoMangle, BuiltinDeprecatedAttrLink, BuiltinClashingExternSub, BuiltinConstNoMangle, BuiltinDeprecatedAttrLink,
BuiltinDeprecatedAttrLinkSuggestion, BuiltinDeprecatedAttrUsed, BuiltinDerefNullptr, BuiltinDeprecatedAttrLinkSuggestion, BuiltinDeprecatedAttrUsed, BuiltinDerefNullptr,
BuiltinEllipsisInclusiveRangePatternsLint, BuiltinExplicitOutlives, BuiltinEllipsisInclusiveRangePatternsLint, BuiltinExplicitOutlives,
BuiltinExplicitOutlivesSuggestion, BuiltinIncompleteFeatures, BuiltinExplicitOutlivesSuggestion, BuiltinFeatureIssueNote, BuiltinIncompleteFeatures,
BuiltinIncompleteFeaturesHelp, BuiltinIncompleteFeaturesNote, BuiltinKeywordIdents, BuiltinIncompleteFeaturesHelp, BuiltinInternalFeatures, BuiltinKeywordIdents,
BuiltinMissingCopyImpl, BuiltinMissingDebugImpl, BuiltinMissingDoc, BuiltinMissingCopyImpl, BuiltinMissingDebugImpl, BuiltinMissingDoc,
BuiltinMutablesTransmutes, BuiltinNoMangleGeneric, BuiltinNonShorthandFieldPatterns, BuiltinMutablesTransmutes, BuiltinNoMangleGeneric, BuiltinNonShorthandFieldPatterns,
BuiltinSpecialModuleNameUsed, BuiltinTrivialBounds, BuiltinTypeAliasGenericBounds, BuiltinSpecialModuleNameUsed, BuiltinTrivialBounds, BuiltinTypeAliasGenericBounds,
@ -2301,12 +2301,36 @@ declare_lint! {
"incomplete features that may function improperly in some or all cases" "incomplete features that may function improperly in some or all cases"
} }
declare_lint! {
/// The `internal_features` lint detects unstable features enabled with
/// the [`feature` attribute] that are internal to the compiler or standard
/// library.
///
/// [`feature` attribute]: https://doc.rust-lang.org/nightly/unstable-book/
///
/// ### Example
///
/// ```rust,compile_fail
/// #![feature(rustc_attrs)]
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// These features are an implementation detail of the compiler and standard
/// library and are not supposed to be used in user code.
pub INTERNAL_FEATURES,
Deny,
"internal features are not supposed to be used"
}
declare_lint_pass!( declare_lint_pass!(
/// Check for used feature gates in `INCOMPLETE_FEATURES` in `rustc_feature/src/active.rs`. /// Check for used feature gates in `INCOMPLETE_FEATURES` in `rustc_feature/src/active.rs`.
IncompleteFeatures => [INCOMPLETE_FEATURES] IncompleteInternalFeatures => [INCOMPLETE_FEATURES, INTERNAL_FEATURES]
); );
impl EarlyLintPass for IncompleteFeatures { impl EarlyLintPass for IncompleteInternalFeatures {
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) { fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
let features = cx.sess().features_untracked(); let features = cx.sess().features_untracked();
features features
@ -2314,17 +2338,26 @@ impl EarlyLintPass for IncompleteFeatures {
.iter() .iter()
.map(|(name, span, _)| (name, span)) .map(|(name, span, _)| (name, span))
.chain(features.declared_lib_features.iter().map(|(name, span)| (name, span))) .chain(features.declared_lib_features.iter().map(|(name, span)| (name, span)))
.filter(|(&name, _)| features.incomplete(name)) .filter(|(&name, _)| features.incomplete(name) || features.internal(name))
.for_each(|(&name, &span)| { .for_each(|(&name, &span)| {
let note = rustc_feature::find_feature_issue(name, GateIssue::Language) let note = rustc_feature::find_feature_issue(name, GateIssue::Language)
.map(|n| BuiltinIncompleteFeaturesNote { n }); .map(|n| BuiltinFeatureIssueNote { n });
let help =
HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp); if features.incomplete(name) {
cx.emit_spanned_lint( let help =
INCOMPLETE_FEATURES, HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp);
span, cx.emit_spanned_lint(
BuiltinIncompleteFeatures { name, note, help }, INCOMPLETE_FEATURES,
); span,
BuiltinIncompleteFeatures { name, note, help },
);
} else {
cx.emit_spanned_lint(
INTERNAL_FEATURES,
span,
BuiltinInternalFeatures { name, note },
);
}
}); });
} }
} }

View File

@ -40,6 +40,7 @@
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use] #[macro_use]
extern crate rustc_middle; extern crate rustc_middle;
@ -173,7 +174,7 @@ early_lint_methods!(
WhileTrue: WhileTrue, WhileTrue: WhileTrue,
NonAsciiIdents: NonAsciiIdents, NonAsciiIdents: NonAsciiIdents,
HiddenUnicodeCodepoints: HiddenUnicodeCodepoints, HiddenUnicodeCodepoints: HiddenUnicodeCodepoints,
IncompleteFeatures: IncompleteFeatures, IncompleteInternalFeatures: IncompleteInternalFeatures,
RedundantSemicolons: RedundantSemicolons, RedundantSemicolons: RedundantSemicolons,
UnusedDocComment: UnusedDocComment, UnusedDocComment: UnusedDocComment,
UnexpectedCfgs: UnexpectedCfgs, UnexpectedCfgs: UnexpectedCfgs,

View File

@ -405,18 +405,27 @@ pub struct BuiltinExplicitOutlivesSuggestion {
pub struct BuiltinIncompleteFeatures { pub struct BuiltinIncompleteFeatures {
pub name: Symbol, pub name: Symbol,
#[subdiagnostic] #[subdiagnostic]
pub note: Option<BuiltinIncompleteFeaturesNote>, pub note: Option<BuiltinFeatureIssueNote>,
#[subdiagnostic] #[subdiagnostic]
pub help: Option<BuiltinIncompleteFeaturesHelp>, pub help: Option<BuiltinIncompleteFeaturesHelp>,
} }
#[derive(LintDiagnostic)]
#[diag(lint_builtin_internal_features)]
#[note]
pub struct BuiltinInternalFeatures {
pub name: Symbol,
#[subdiagnostic]
pub note: Option<BuiltinFeatureIssueNote>,
}
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[help(lint_help)] #[help(lint_help)]
pub struct BuiltinIncompleteFeaturesHelp; pub struct BuiltinIncompleteFeaturesHelp;
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[note(lint_note)] #[note(lint_note)]
pub struct BuiltinIncompleteFeaturesNote { pub struct BuiltinFeatureIssueNote {
pub n: NonZeroU32, pub n: NonZeroU32,
} }

View File

@ -3925,7 +3925,6 @@ declare_lint! {
/// ///
/// // in crate B /// // in crate B
/// #![feature(non_exhaustive_omitted_patterns_lint)] /// #![feature(non_exhaustive_omitted_patterns_lint)]
///
/// match Bar::A { /// match Bar::A {
/// Bar::A => {}, /// Bar::A => {},
/// #[warn(non_exhaustive_omitted_patterns)] /// #[warn(non_exhaustive_omitted_patterns)]

View File

@ -7,6 +7,7 @@
#![allow(rustc::default_hash_types)] #![allow(rustc::default_hash_types)]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![recursion_limit = "128"] #![recursion_limit = "128"]
use synstructure::decl_derive; use synstructure::decl_derive;

View File

@ -64,6 +64,7 @@
#![feature(macro_metavar_expr)] #![feature(macro_metavar_expr)]
#![recursion_limit = "512"] #![recursion_limit = "512"]
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;

View File

@ -8,6 +8,7 @@
#![feature(never_type)] #![feature(never_type)]
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use] #[macro_use]
extern crate tracing; extern crate tracing;

View File

@ -11,6 +11,7 @@
#![allow(rustc::potential_query_instability, unused_parens)] #![allow(rustc::potential_query_instability, unused_parens)]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use] #[macro_use]
extern crate rustc_middle; extern crate rustc_middle;

View File

@ -18,6 +18,7 @@
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![allow(rustdoc::private_intra_doc_links)] #![allow(rustdoc::private_intra_doc_links)]
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use] #[macro_use]
extern crate tracing; extern crate tracing;

View File

@ -10,6 +10,7 @@
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use] #[macro_use]
extern crate rustc_macros; extern crate rustc_macros;

View File

@ -23,6 +23,7 @@
#![feature(round_char_boundary)] #![feature(round_char_boundary)]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use] #[macro_use]
extern crate rustc_macros; extern crate rustc_macros;

View File

@ -19,6 +19,7 @@
#![feature(step_trait)] #![feature(step_trait)]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};

View File

@ -6,6 +6,7 @@
#![feature(unwrap_infallible)] #![feature(unwrap_infallible)]
#![deny(rustc::untranslatable_diagnostic)] #![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)] #![deny(rustc::diagnostic_outside_of_impl)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use] #[macro_use]
extern crate bitflags; extern crate bitflags;

View File

@ -88,6 +88,7 @@
#![warn(missing_docs)] #![warn(missing_docs)]
#![allow(explicit_outlives_requirements)] #![allow(explicit_outlives_requirements)]
#![warn(multiple_supertrait_upcastable)] #![warn(multiple_supertrait_upcastable)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
// //
// Library features: // Library features:
// tidy-alphabetical-start // tidy-alphabetical-start

View File

@ -14,6 +14,7 @@
//! //!
//! ```rust //! ```rust
//! #![feature(core_intrinsics, custom_mir)] //! #![feature(core_intrinsics, custom_mir)]
#![cfg_attr(not(bootstrap), doc = "#![allow(internal_features)]")]
//! //!
//! use core::intrinsics::mir::*; //! use core::intrinsics::mir::*;
//! //!
@ -63,6 +64,7 @@
//! //!
//! ```rust //! ```rust
//! #![feature(core_intrinsics, custom_mir)] //! #![feature(core_intrinsics, custom_mir)]
#![cfg_attr(not(bootstrap), doc = "#![allow(internal_features)]")]
//! //!
//! use core::intrinsics::mir::*; //! use core::intrinsics::mir::*;
//! //!
@ -315,6 +317,7 @@ define!(
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
#[cfg_attr(not(bootstrap), doc = "#![allow(internal_features)]")]
/// #![feature(custom_mir, core_intrinsics)] /// #![feature(custom_mir, core_intrinsics)]
/// ///
/// use core::intrinsics::mir::*; /// use core::intrinsics::mir::*;

View File

@ -96,6 +96,7 @@
#![allow(explicit_outlives_requirements)] #![allow(explicit_outlives_requirements)]
#![allow(incomplete_features)] #![allow(incomplete_features)]
#![warn(multiple_supertrait_upcastable)] #![warn(multiple_supertrait_upcastable)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
// //
// Library features: // Library features:
// tidy-alphabetical-start // tidy-alphabetical-start

View File

@ -14,6 +14,7 @@
#![feature(staged_api)] #![feature(staged_api)]
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![feature(c_unwind)] #![feature(c_unwind)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[cfg(target_os = "android")] #[cfg(target_os = "android")]
mod android; mod android;

View File

@ -26,6 +26,7 @@
#![feature(c_unwind)] #![feature(c_unwind)]
// `real_imp` is unused with Miri, so silence warnings. // `real_imp` is unused with Miri, so silence warnings.
#![cfg_attr(miri, allow(dead_code))] #![cfg_attr(miri, allow(dead_code))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
use alloc::boxed::Box; use alloc::boxed::Box;
use core::any::Any; use core::any::Any;

View File

@ -33,6 +33,7 @@
#![feature(min_specialization)] #![feature(min_specialization)]
#![feature(strict_provenance)] #![feature(strict_provenance)]
#![recursion_limit = "256"] #![recursion_limit = "256"]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[unstable(feature = "proc_macro_internals", issue = "27812")] #[unstable(feature = "proc_macro_internals", issue = "27812")]
#[doc(hidden)] #[doc(hidden)]

View File

@ -7,4 +7,5 @@
issue = "none" issue = "none"
)] )]
#![allow(unused_features)] #![allow(unused_features)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![feature(staged_api)] #![feature(staged_api)]

View File

@ -220,6 +220,7 @@
#![warn(missing_debug_implementations)] #![warn(missing_debug_implementations)]
#![allow(explicit_outlives_requirements)] #![allow(explicit_outlives_requirements)]
#![allow(unused_lifetimes)] #![allow(unused_lifetimes)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![deny(rustc::existing_doc_keyword)] #![deny(rustc::existing_doc_keyword)]
#![deny(fuzzy_provenance_casts)] #![deny(fuzzy_provenance_casts)]
// Ensure that std can be linked against panic_abort despite compiled with `-C panic=unwind` // Ensure that std can be linked against panic_abort despite compiled with `-C panic=unwind`

View File

@ -21,6 +21,7 @@
#![feature(process_exitcode_internals)] #![feature(process_exitcode_internals)]
#![feature(panic_can_unwind)] #![feature(panic_can_unwind)]
#![feature(test)] #![feature(test)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
// Public reexports // Public reexports
pub use self::bench::{black_box, Bencher}; pub use self::bench::{black_box, Bencher};

View File

@ -5,6 +5,7 @@
#![feature(c_unwind)] #![feature(c_unwind)]
#![feature(cfg_target_abi)] #![feature(cfg_target_abi)]
#![cfg_attr(not(target_env = "msvc"), feature(libc))] #![cfg_attr(not(target_env = "msvc"), feature(libc))]
#![cfg_attr(not(bootstrap), allow(internal_features))]
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(target_env = "msvc")] { if #[cfg(target_env = "msvc")] {

View File

@ -200,6 +200,7 @@ To do so, the `#[doc(keyword = "...")]` attribute is used. Example:
```rust ```rust
#![feature(rustdoc_internals)] #![feature(rustdoc_internals)]
#![allow(internal_features)]
/// Some documentation about the keyword. /// Some documentation about the keyword.
#[doc(keyword = "keyword")] #[doc(keyword = "keyword")]

View File

@ -17,6 +17,7 @@ via a declaration like
```rust ```rust
#![feature(intrinsics)] #![feature(intrinsics)]
#![allow(internal_features)]
# fn main() {} # fn main() {}
extern "rust-intrinsic" { extern "rust-intrinsic" {

View File

@ -17,6 +17,7 @@ sugar for dynamic allocations via `malloc` and `free`:
```rust,ignore (libc-is-finicky) ```rust,ignore (libc-is-finicky)
#![feature(lang_items, start, libc, core_intrinsics, rustc_private, rustc_attrs)] #![feature(lang_items, start, libc, core_intrinsics, rustc_private, rustc_attrs)]
#![allow(internal_features)]
#![no_std] #![no_std]
use core::intrinsics; use core::intrinsics;
use core::panic::PanicInfo; use core::panic::PanicInfo;
@ -119,6 +120,7 @@ in the same format as C:
```rust,ignore (libc-is-finicky) ```rust,ignore (libc-is-finicky)
#![feature(lang_items, core_intrinsics, rustc_private)] #![feature(lang_items, core_intrinsics, rustc_private)]
#![feature(start)] #![feature(start)]
#![allow(internal_features)]
#![no_std] #![no_std]
use core::intrinsics; use core::intrinsics;
use core::panic::PanicInfo; use core::panic::PanicInfo;
@ -155,6 +157,7 @@ compiler's name mangling too:
```rust,ignore (libc-is-finicky) ```rust,ignore (libc-is-finicky)
#![feature(lang_items, core_intrinsics, rustc_private)] #![feature(lang_items, core_intrinsics, rustc_private)]
#![feature(start)] #![feature(start)]
#![allow(internal_features)]
#![no_std] #![no_std]
#![no_main] #![no_main]
use core::intrinsics; use core::intrinsics;

View File

@ -140,6 +140,7 @@ fn base_config(test_dir: &str) -> compiletest::Config {
[ [
"--emit=metadata", "--emit=metadata",
"-Aunused", "-Aunused",
"-Ainternal_features",
"-Zui-testing", "-Zui-testing",
"-Dwarnings", "-Dwarnings",
&format!("-Ldependency={}", deps_path.display()), &format!("-Ldependency={}", deps_path.display()),

View File

@ -868,6 +868,8 @@ impl<'test> TestCx<'test> {
.args(&["--target", &self.config.target]) .args(&["--target", &self.config.target])
.arg("-L") .arg("-L")
.arg(&aux_dir) .arg(&aux_dir)
.arg("-A")
.arg("internal_features")
.args(&self.props.compile_flags) .args(&self.props.compile_flags)
.envs(self.props.rustc_env.clone()); .envs(self.props.rustc_env.clone());
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags); self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
@ -936,7 +938,9 @@ impl<'test> TestCx<'test> {
.arg("-L") .arg("-L")
.arg(&self.config.build_base) .arg(&self.config.build_base)
.arg("-L") .arg("-L")
.arg(aux_dir); .arg(aux_dir)
.arg("-A")
.arg("internal_features");
self.set_revision_flags(&mut rustc); self.set_revision_flags(&mut rustc);
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags); self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
rustc.args(&self.props.compile_flags); rustc.args(&self.props.compile_flags);
@ -1867,6 +1871,8 @@ impl<'test> TestCx<'test> {
.arg("--deny") .arg("--deny")
.arg("warnings") .arg("warnings")
.arg(&self.testpaths.file) .arg(&self.testpaths.file)
.arg("-A")
.arg("internal_features")
.args(&self.props.compile_flags); .args(&self.props.compile_flags);
if self.config.mode == RustdocJson { if self.config.mode == RustdocJson {
@ -2459,6 +2465,9 @@ impl<'test> TestCx<'test> {
rustc.args(&["-A", "unused"]); rustc.args(&["-A", "unused"]);
} }
// Allow tests to use internal features.
rustc.args(&["-A", "internal_features"]);
if self.props.force_host { if self.props.force_host {
self.maybe_add_external_args(&mut rustc, &self.config.host_rustcflags); self.maybe_add_external_args(&mut rustc, &self.config.host_rustcflags);
if !is_rustdoc { if !is_rustdoc {

View File

@ -53,6 +53,7 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
// Add some flags we always want. // Add some flags we always want.
program.args.push("-Dwarnings".into()); program.args.push("-Dwarnings".into());
program.args.push("-Dunused".into()); program.args.push("-Dunused".into());
program.args.push("-Ainternal_features".into());
if let Ok(extra_flags) = env::var("MIRIFLAGS") { if let Ok(extra_flags) = env::var("MIRIFLAGS") {
for flag in extra_flags.split_whitespace() { for flag in extra_flags.split_whitespace() {
program.args.push(flag.into()); program.args.push(flag.into());

View File

@ -338,6 +338,7 @@ fn collect_lang_features_in(features: &mut Features, base: &Path, file: &str, ba
let level = match parts.next().map(|l| l.trim().trim_start_matches('(')) { let level = match parts.next().map(|l| l.trim().trim_start_matches('(')) {
Some("active") => Status::Unstable, Some("active") => Status::Unstable,
Some("incomplete") => Status::Unstable, Some("incomplete") => Status::Unstable,
Some("internal") => Status::Unstable,
Some("removed") => Status::Removed, Some("removed") => Status::Removed,
Some("accepted") => Status::Stable, Some("accepted") => Status::Stable,
_ => continue, _ => continue,

View File

@ -8,7 +8,7 @@ TARGET_RPATH_ENV = \
RUSTC_ORIGINAL := $(RUSTC) RUSTC_ORIGINAL := $(RUSTC)
BARE_RUSTC := $(HOST_RPATH_ENV) '$(RUSTC)' BARE_RUSTC := $(HOST_RPATH_ENV) '$(RUSTC)'
BARE_RUSTDOC := $(HOST_RPATH_ENV) '$(RUSTDOC)' BARE_RUSTDOC := $(HOST_RPATH_ENV) '$(RUSTDOC)'
RUSTC := $(BARE_RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR) $(RUSTFLAGS) RUSTC := $(BARE_RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR) $(RUSTFLAGS) -Ainternal_features
RUSTDOC := $(BARE_RUSTDOC) -L $(TARGET_RPATH_DIR) RUSTDOC := $(BARE_RUSTDOC) -L $(TARGET_RPATH_DIR)
ifdef RUSTC_LINKER ifdef RUSTC_LINKER
RUSTC := $(RUSTC) -Clinker='$(RUSTC_LINKER)' RUSTC := $(RUSTC) -Clinker='$(RUSTC_LINKER)'

View File

@ -1,4 +1,5 @@
#![feature(staged_api)] #![feature(staged_api)]
#![allow(internal_features)]
#![stable(feature = "some_feature", since = "1.3.5")] #![stable(feature = "some_feature", since = "1.3.5")]
#[stable(feature = "some_feature", since = "1.3.5")] #[stable(feature = "some_feature", since = "1.3.5")]

View File

@ -3,6 +3,7 @@
#![doc(html_playground_url="https://play.rust-lang.org/")] #![doc(html_playground_url="https://play.rust-lang.org/")]
#![crate_name = "test_docs"] #![crate_name = "test_docs"]
#![allow(internal_features)]
#![feature(rustdoc_internals)] #![feature(rustdoc_internals)]
#![feature(doc_cfg)] #![feature(doc_cfg)]
#![feature(associated_type_defaults)] #![feature(associated_type_defaults)]

View File

@ -3,6 +3,7 @@
#![doc(test(attr(feature(staged_api))))] #![doc(test(attr(feature(staged_api))))]
/// ``` /// ```
/// #![allow(internal_features)]
/// #![unstable(feature="test", issue="18199")] /// #![unstable(feature="test", issue="18199")]
/// fn main() {} /// fn main() {}
/// ``` /// ```

View File

@ -1,7 +1,7 @@
// edition:2018 // edition:2018
#![forbid(incomplete_features, unsafe_code)] #![forbid(internal_features, unsafe_code)]
#![feature(unsafe_pin_internals)] #![feature(unsafe_pin_internals)]
//~^ ERROR the feature `unsafe_pin_internals` is incomplete and may not be safe to use //~^ ERROR the feature `unsafe_pin_internals` is internal to the compiler or standard library
use core::{marker::PhantomPinned, pin::Pin}; use core::{marker::PhantomPinned, pin::Pin};

View File

@ -1,14 +1,15 @@
error: the feature `unsafe_pin_internals` is incomplete and may not be safe to use and/or cause compiler crashes error: the feature `unsafe_pin_internals` is internal to the compiler or standard library
--> $DIR/feature-gate-unsafe_pin_internals.rs:3:12 --> $DIR/feature-gate-unsafe_pin_internals.rs:3:12
| |
LL | #![feature(unsafe_pin_internals)] LL | #![feature(unsafe_pin_internals)]
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
| |
= note: using it is strongly discouraged
note: the lint level is defined here note: the lint level is defined here
--> $DIR/feature-gate-unsafe_pin_internals.rs:2:11 --> $DIR/feature-gate-unsafe_pin_internals.rs:2:11
| |
LL | #![forbid(incomplete_features, unsafe_code)] LL | #![forbid(internal_features, unsafe_code)]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^
error: aborting due to previous error error: aborting due to previous error