about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-11-21 08:00:26 +0100
committerRalf Jung <post@ralfj.de>2023-11-21 08:00:26 +0100
commitd1583eba66bf1ccb65c3aeaa5de30bcc90ae208c (patch)
tree59aa27a10315f23f3f14a614543188d8f0cb9a1d
parent9a66e4471f71283fd54d80ef8147630d34756332 (diff)
downloadrust-d1583eba66bf1ccb65c3aeaa5de30bcc90ae208c.tar.gz
rust-d1583eba66bf1ccb65c3aeaa5de30bcc90ae208c.zip
lib features ending in '_internals?' are internal
-rw-r--r--compiler/rustc_feature/src/unstable.rs18
-rw-r--r--tests/ui/lint/internal_features.rs11
-rw-r--r--tests/ui/lint/internal_features.stderr23
3 files changed, 46 insertions, 6 deletions
diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs
index b11b190bded..40611102250 100644
--- a/compiler/rustc_feature/src/unstable.rs
+++ b/compiler/rustc_feature/src/unstable.rs
@@ -54,8 +54,10 @@ macro_rules! declare_features {
         #[derive(Clone, Default, Debug)]
         pub struct Features {
             /// `#![feature]` attrs for language features, for error reporting.
+            /// "declared" here means that the feature is actually enabled in the current crate.
             pub declared_lang_features: Vec<(Symbol, Span, Option<Symbol>)>,
             /// `#![feature]` attrs for non-language (library) features.
+            /// "declared" here means that the feature is actually enabled in the current crate.
             pub declared_lib_features: Vec<(Symbol, Span)>,
             /// `declared_lang_features` + `declared_lib_features`.
             pub declared_features: FxHashSet<Symbol>,
@@ -125,9 +127,16 @@ macro_rules! declare_features {
                     $(
                         sym::$feature => status_to_enum!($status) == FeatureStatus::Internal,
                     )*
-                    // Accepted/removed features aren't in this file but are never internal
-                    // (a removed feature might have been internal, but that's now irrelevant).
-                    _ if self.declared_features.contains(&feature) => false,
+                    _ if self.declared_features.contains(&feature) => {
+                        // This could be accepted/removed, or a libs feature.
+                        // Accepted/removed features aren't in this file but are never internal
+                        // (a removed feature might have been internal, but that's now irrelevant).
+                        // Libs features are internal if they end in `_internal` or `_internals`.
+                        // We just always test the name; it's not a big deal if we accidentally hit
+                        // an accepted/removed lang feature that way.
+                        let name = feature.as_str();
+                        name.ends_with("_internal") || name.ends_with("_internals")
+                    }
                     _ => panic!("`{}` was not listed in `declare_features`", feature),
                 }
             }
@@ -207,9 +216,6 @@ declare_features! (
     (internal, test_2018_feature, "1.31.0", None, Some(Edition::Edition2018)),
     /// Added for testing unstable lints; perma-unstable.
     (internal, test_unstable_lint, "1.60.0", None, None),
-    /// Allows non-`unsafe` —and thus, unsound— access to `Pin` constructions.
-    /// 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.
     (unstable, with_negative_coherence, "1.60.0", None, None),
diff --git a/tests/ui/lint/internal_features.rs b/tests/ui/lint/internal_features.rs
new file mode 100644
index 00000000000..32ce9540cb3
--- /dev/null
+++ b/tests/ui/lint/internal_features.rs
@@ -0,0 +1,11 @@
+#![forbid(internal_features)]
+// A lang feature and a lib feature.
+#![feature(intrinsics, panic_internals)]
+//~^ ERROR: internal
+//~| ERROR: internal
+
+extern "rust-intrinsic" {
+    fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
+}
+
+fn main() {}
diff --git a/tests/ui/lint/internal_features.stderr b/tests/ui/lint/internal_features.stderr
new file mode 100644
index 00000000000..8b52bef8f03
--- /dev/null
+++ b/tests/ui/lint/internal_features.stderr
@@ -0,0 +1,23 @@
+error: the feature `intrinsics` is internal to the compiler or standard library
+  --> $DIR/internal_features.rs:3:12
+   |
+LL | #![feature(intrinsics, panic_internals)]
+   |            ^^^^^^^^^^
+   |
+   = note: using it is strongly discouraged
+note: the lint level is defined here
+  --> $DIR/internal_features.rs:1:11
+   |
+LL | #![forbid(internal_features)]
+   |           ^^^^^^^^^^^^^^^^^
+
+error: the feature `panic_internals` is internal to the compiler or standard library
+  --> $DIR/internal_features.rs:3:24
+   |
+LL | #![feature(intrinsics, panic_internals)]
+   |                        ^^^^^^^^^^^^^^^
+   |
+   = note: using it is strongly discouraged
+
+error: aborting due to 2 previous errors
+