Skip to content

Commit

Permalink
Add internal_features lint
Browse files Browse the repository at this point in the history
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^^
  • Loading branch information
Nilstrieb committed Aug 3, 2023
1 parent c115ec1 commit 5830ca2
Show file tree
Hide file tree
Showing 68 changed files with 209 additions and 49 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_abi/src/lib.rs
@@ -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")]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_arena/src/lib.rs
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_borrowck/src/lib.rs
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/src/lib.rs
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0092.md
Expand Up @@ -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
Expand All @@ -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!
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0093.md
Expand Up @@ -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`
Expand All @@ -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!
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0094.md
Expand Up @@ -4,6 +4,7 @@ Erroneous code example:

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

```
#![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" {
#[rustc_safe_intrinsic]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/error_codes/E0208.md
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0211.md
Expand Up @@ -5,6 +5,7 @@ used. Erroneous code examples:

```compile_fail
#![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" {
#[rustc_safe_intrinsic]
Expand Down Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/error_codes/E0230.md
Expand Up @@ -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> {}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/error_codes/E0231.md
Expand Up @@ -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> {}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/error_codes/E0232.md
Expand Up @@ -5,6 +5,7 @@ compiled:

```compile_fail,E0232
#![feature(rustc_attrs)]
#![allow(internal_features)]
#[rustc_on_unimplemented(lorem="")] // error!
trait BadAnnotation {}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0264.md
Expand Up @@ -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`
Expand All @@ -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!
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0539.md
Expand Up @@ -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!
Expand All @@ -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!
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0542.md
Expand Up @@ -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
Expand All @@ -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!
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0543.md
Expand Up @@ -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")]
Expand All @@ -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")]
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0544.md
Expand Up @@ -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")]
Expand All @@ -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!
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0545.md
Expand Up @@ -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
Expand All @@ -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!
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0546.md
Expand Up @@ -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
Expand All @@ -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!
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0547.md
Expand Up @@ -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
Expand All @@ -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!
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0549.md
Expand Up @@ -5,6 +5,7 @@ Erroneous code example:

```compile_fail,E0549
#![feature(staged_api)]
#![allow(internal_features)]
#![stable(since = "1.0.0", feature = "test")]
#[deprecated(
Expand All @@ -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")]
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0622.md
Expand Up @@ -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
}
Expand All @@ -17,6 +19,8 @@ error, just declare a function. Example:

```no_run
#![feature(intrinsics)]
#![allow(internal_features)]
extern "rust-intrinsic" {
pub fn breakpoint(); // ok!
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0773.md
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_error_codes/src/error_codes/E0789.md
Expand Up @@ -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")]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_error_messages/src/lib.rs
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_errors/src/lib.rs
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_expand/src/lib.rs
Expand Up @@ -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;
Expand Down

0 comments on commit 5830ca2

Please sign in to comment.