Auto merge of #108955 - Nilstrieb:dont-use-me-pls, r=oli-obk

Add `internal_features` lint

Implements https://github.com/rust-lang/compiler-team/issues/596

Also requires some more test blessing for codegen tests etc

`@jyn514` had the idea of just `allow`ing the lint by default in the test suite. I'm not sure whether this is a good idea, but it's definitely one worth considering. Additional input encouraged.
This commit is contained in:
bors 2023-08-03 22:58:02 +00:00
commit 1fe384649a
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(all(not(bootstrap), feature = "nightly"), allow(internal_features))]
use std::fmt;
#[cfg(feature = "nightly")]

View File

@ -23,6 +23,7 @@
#![deny(unsafe_op_in_unsafe_fn)]
#![deny(rustc::untranslatable_diagnostic)]
#![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.
use smallvec::SmallVec;

View File

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

View File

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

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0092
#![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" {
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)]
#![allow(internal_features)]
extern "rust-intrinsic" {
fn atomic_fence_seqcst(); // ok!

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0093
#![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" {
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)]
#![allow(internal_features)]
extern "rust-intrinsic" {
fn atomic_fence_seqcst(); // ok!

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0264
#![feature(lang_items)]
#![allow(internal_features)]
extern "C" {
#[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)]
#![allow(internal_features)]
extern "C" {
#[lang = "panic_impl"] // ok!

View File

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

View File

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

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0543
#![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")]
#[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)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")]
#[stable(since = "0.1.0", feature = "_deprecated_fn")]

View File

@ -4,6 +4,7 @@ Erroneous code example:
```compile_fail,E0544
#![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "rust1")]
#[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)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "rust1")]
#[stable(feature = "test", since = "2.0.0")] // ok!

View File

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

View File

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

View File

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

View File

@ -5,6 +5,7 @@ Erroneous code example:
```compile_fail,E0549
#![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")]
#[deprecated(
@ -19,6 +20,7 @@ Example:
```
#![feature(staged_api)]
#![allow(internal_features)]
#![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
#![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" {
pub static breakpoint: fn(); // error: intrinsic must be a function
}
@ -17,6 +19,8 @@ error, just declare a function. Example:
```no_run
#![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" {
pub fn breakpoint(); // ok!
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,12 +16,22 @@ fn f(features: &mut Features, _: Span) {
}};
}
#[derive(PartialEq)]
enum FeatureStatus {
Default,
Incomplete,
Internal,
}
macro_rules! declare_features {
(__status_to_bool active) => {
false
(__status_to_enum active) => {
FeatureStatus::Default
};
(__status_to_bool incomplete) => {
true
(__status_to_enum incomplete) => {
FeatureStatus::Incomplete
};
(__status_to_enum internal) => {
FeatureStatus::Internal
};
($(
$(#[doc = $doc:tt])* ($status:ident, $feature:ident, $ver:expr, $issue:expr, $edition:expr),
@ -83,7 +93,7 @@ pub fn enabled(&self, feature: Symbol) -> bool {
pub fn incomplete(&self, feature: Symbol) -> bool {
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
_ if self.declared_lang_features.iter().any(|f| f.0 == feature) => false,
@ -91,6 +101,22 @@ pub fn incomplete(&self, feature: Symbol) -> bool {
_ => 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 @@ pub fn set(&self, features: &mut Features, span: Span) {
/// Allows using the `vectorcall` ABI.
(active, abi_vectorcall, "1.7.0", None, None),
/// 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
/// attribute on `macro_rules!` and can't use the attribute handling
/// below (it has to be checked before expansion possibly makes
/// 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
/// attribute on `macro_rules!` and can't use the attribute handling
/// below (it has to be checked before expansion possibly makes
/// 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.
(active, anonymous_lifetime_in_impl_trait, "1.63.0", None, None),
/// 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
(active, custom_mir, "1.65.0", None, None),
(internal, custom_mir, "1.65.0", None, None),
/// Outputs useful `assert!` messages
(active, generic_assert, "1.63.0", None, None),
/// 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.
(active, lang_items, "1.0.0", None, None),
(internal, lang_items, "1.0.0", None, None),
/// Allows `#[link(..., cfg(..))]`; perma-unstable per #37406
(active, link_cfg, "1.14.0", None, None),
/// Allows the `multiple_supertrait_upcastable` lint.
@ -167,22 +193,22 @@ pub fn set(&self, features: &mut Features, span: Span) {
/// Allow negative trait bounds. This is an internal-only feature for testing the trait solver!
(incomplete, negative_bounds, "1.71.0", None, None),
/// 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.
(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.
(active, profiler_runtime, "1.18.0", None, None),
(internal, profiler_runtime, "1.18.0", None, None),
/// 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.
(active, staged_api, "1.0.0", None, None),
(internal, staged_api, "1.0.0", None, None),
/// 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.
(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.
/// Marked `incomplete` since perma-unstable and unsound.
(incomplete, unsafe_pin_internals, "1.60.0", None, None),
/// Marked `internal` since perma-unstable and unsound.
(internal, unsafe_pin_internals, "1.60.0", None, None),
/// Use for stable + negative coherence and strict coherence depending on trait's
/// rustc_strict_coherence value.
(active, with_negative_coherence, "1.60.0", None, None),
@ -216,19 +242,19 @@ pub fn set(&self, features: &mut Features, span: Span) {
/// Allows using the `#[linkage = ".."]` attribute.
(active, linkage, "1.0.0", Some(29603), None),
/// 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.
(active, packed_bundled_libs, "1.69.0", Some(108081), None),
/// 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]`.
/// This is an attribute on `const fn` for the same
/// 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.
(active, rustc_private, "1.0.0", Some(27812), None),
/// 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
(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.

View File

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

View File

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

View File

@ -12,6 +12,7 @@
test
)
)]
#![cfg_attr(all(not(bootstrap), feature = "nightly"), allow(internal_features))]
#[cfg(feature = "nightly")]
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
.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
.suggestion = you can use a raw identifier to stay compatible

View File

@ -28,8 +28,8 @@
BuiltinClashingExternSub, BuiltinConstNoMangle, BuiltinDeprecatedAttrLink,
BuiltinDeprecatedAttrLinkSuggestion, BuiltinDeprecatedAttrUsed, BuiltinDerefNullptr,
BuiltinEllipsisInclusiveRangePatternsLint, BuiltinExplicitOutlives,
BuiltinExplicitOutlivesSuggestion, BuiltinIncompleteFeatures,
BuiltinIncompleteFeaturesHelp, BuiltinIncompleteFeaturesNote, BuiltinKeywordIdents,
BuiltinExplicitOutlivesSuggestion, BuiltinFeatureIssueNote, BuiltinIncompleteFeatures,
BuiltinIncompleteFeaturesHelp, BuiltinInternalFeatures, BuiltinKeywordIdents,
BuiltinMissingCopyImpl, BuiltinMissingDebugImpl, BuiltinMissingDoc,
BuiltinMutablesTransmutes, BuiltinNoMangleGeneric, BuiltinNonShorthandFieldPatterns,
BuiltinSpecialModuleNameUsed, BuiltinTrivialBounds, BuiltinTypeAliasGenericBounds,
@ -2301,12 +2301,36 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
"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!(
/// 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) {
let features = cx.sess().features_untracked();
features
@ -2314,17 +2338,26 @@ fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
.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)| {
let note = rustc_feature::find_feature_issue(name, GateIssue::Language)
.map(|n| BuiltinIncompleteFeaturesNote { n });
let help =
HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp);
cx.emit_spanned_lint(
INCOMPLETE_FEATURES,
span,
BuiltinIncompleteFeatures { name, note, help },
);
.map(|n| BuiltinFeatureIssueNote { n });
if features.incomplete(name) {
let help =
HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp);
cx.emit_spanned_lint(
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"]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use]
extern crate rustc_middle;
@ -173,7 +174,7 @@ fn lint_mod(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
WhileTrue: WhileTrue,
NonAsciiIdents: NonAsciiIdents,
HiddenUnicodeCodepoints: HiddenUnicodeCodepoints,
IncompleteFeatures: IncompleteFeatures,
IncompleteInternalFeatures: IncompleteInternalFeatures,
RedundantSemicolons: RedundantSemicolons,
UnusedDocComment: UnusedDocComment,
UnexpectedCfgs: UnexpectedCfgs,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -14,6 +14,7 @@
//!
//! ```rust
//! #![feature(core_intrinsics, custom_mir)]
#![cfg_attr(not(bootstrap), doc = "#![allow(internal_features)]")]
//!
//! use core::intrinsics::mir::*;
//!
@ -63,6 +64,7 @@
//!
//! ```rust
//! #![feature(core_intrinsics, custom_mir)]
#![cfg_attr(not(bootstrap), doc = "#![allow(internal_features)]")]
//!
//! use core::intrinsics::mir::*;
//!
@ -315,6 +317,7 @@ fn Discriminant<T>(place: T) -> <T as ::core::marker::DiscriminantKind>::Discrim
/// # Examples
///
/// ```rust
#[cfg_attr(not(bootstrap), doc = "#![allow(internal_features)]")]
/// #![feature(custom_mir, core_intrinsics)]
///
/// use core::intrinsics::mir::*;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -220,6 +220,7 @@
#![warn(missing_debug_implementations)]
#![allow(explicit_outlives_requirements)]
#![allow(unused_lifetimes)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
#![deny(rustc::existing_doc_keyword)]
#![deny(fuzzy_provenance_casts)]
// 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(panic_can_unwind)]
#![feature(test)]
#![cfg_attr(not(bootstrap), allow(internal_features))]
// Public reexports
pub use self::bench::{black_box, Bencher};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -868,6 +868,8 @@ fn print_source(&self, read_from: ReadFrom, pretty_type: &str) -> ProcRes {
.args(&["--target", &self.config.target])
.arg("-L")
.arg(&aux_dir)
.arg("-A")
.arg("internal_features")
.args(&self.props.compile_flags)
.envs(self.props.rustc_env.clone());
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
@ -936,7 +938,9 @@ fn typecheck_source(&self, src: String) -> ProcRes {
.arg("-L")
.arg(&self.config.build_base)
.arg("-L")
.arg(aux_dir);
.arg(aux_dir)
.arg("-A")
.arg("internal_features");
self.set_revision_flags(&mut rustc);
self.maybe_add_external_args(&mut rustc, &self.config.target_rustcflags);
rustc.args(&self.props.compile_flags);
@ -1867,6 +1871,8 @@ fn document(&self, out_dir: &Path) -> ProcRes {
.arg("--deny")
.arg("warnings")
.arg(&self.testpaths.file)
.arg("-A")
.arg("internal_features")
.args(&self.props.compile_flags);
if self.config.mode == RustdocJson {
@ -2459,6 +2465,9 @@ fn make_compile_args(
rustc.args(&["-A", "unused"]);
}
// Allow tests to use internal features.
rustc.args(&["-A", "internal_features"]);
if self.props.force_host {
self.maybe_add_external_args(&mut rustc, &self.config.host_rustcflags);
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.
program.args.push("-Dwarnings".into());
program.args.push("-Dunused".into());
program.args.push("-Ainternal_features".into());
if let Ok(extra_flags) = env::var("MIRIFLAGS") {
for flag in extra_flags.split_whitespace() {
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('(')) {
Some("active") => Status::Unstable,
Some("incomplete") => Status::Unstable,
Some("internal") => Status::Unstable,
Some("removed") => Status::Removed,
Some("accepted") => Status::Stable,
_ => continue,

View File

@ -8,7 +8,7 @@ TARGET_RPATH_ENV = \
RUSTC_ORIGINAL := $(RUSTC)
BARE_RUSTC := $(HOST_RPATH_ENV) '$(RUSTC)'
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)
ifdef RUSTC_LINKER
RUSTC := $(RUSTC) -Clinker='$(RUSTC_LINKER)'

View File

@ -1,4 +1,5 @@
#![feature(staged_api)]
#![allow(internal_features)]
#![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/")]
#![crate_name = "test_docs"]
#![allow(internal_features)]
#![feature(rustdoc_internals)]
#![feature(doc_cfg)]
#![feature(associated_type_defaults)]

View File

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

View File

@ -1,7 +1,7 @@
// edition:2018
#![forbid(incomplete_features, unsafe_code)]
#![forbid(internal_features, unsafe_code)]
#![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};

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
|
LL | #![feature(unsafe_pin_internals)]
| ^^^^^^^^^^^^^^^^^^^^
|
= note: using it is strongly discouraged
note: the lint level is defined here
--> $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