]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #106627 - Ezrashaw:no-e0711-without-staged-api, r=Mark-Simulacrum
authorbors <bors@rust-lang.org>
Tue, 17 Jan 2023 07:20:32 +0000 (07:20 +0000)
committerbors <bors@rust-lang.org>
Tue, 17 Jan 2023 07:20:32 +0000 (07:20 +0000)
fix: don't emit `E0711` if `staged_api` not enabled

Fixes #106589

Simple fix, added UI test.

As an aside, it seems a lot of features are susceptible to this, `E0711` stands out to me because it's perma-unstable and we are effectively exposing an implementation detail.

compiler/rustc_passes/src/lib_features.rs
tests/ui/stability-attribute/issue-106589.rs [new file with mode: 0644]
tests/ui/stability-attribute/issue-106589.stderr [new file with mode: 0644]

index b5843c0ae488b1f17c58d81c1ae91758baf4e8e7..4c6a9b23fdf12a9ed33c99f71337ce81c64364d0 100644 (file)
@@ -137,6 +137,12 @@ fn visit_attribute(&mut self, attr: &'tcx Attribute) {
 }
 
 fn lib_features(tcx: TyCtxt<'_>, (): ()) -> LibFeatures {
+    // If `staged_api` is not enabled then we aren't allowed to define lib
+    // features; there is no point collecting them.
+    if !tcx.features().staged_api {
+        return new_lib_features();
+    }
+
     let mut collector = LibFeatureCollector::new(tcx);
     tcx.hir().walk_attributes(&mut collector);
     collector.lib_features
diff --git a/tests/ui/stability-attribute/issue-106589.rs b/tests/ui/stability-attribute/issue-106589.rs
new file mode 100644 (file)
index 0000000..3cad9a3
--- /dev/null
@@ -0,0 +1,10 @@
+// #![feature(staged_api)] // note: `staged_api` not enabled
+
+#![stable(feature = "foo", since = "1.0.0")]
+//~^ ERROR stability attributes may not be used outside of the standard library
+
+#[unstable(feature = "foo", issue = "none")]
+//~^ ERROR stability attributes may not be used outside of the standard library
+fn foo_unstable() {}
+
+fn main() {}
diff --git a/tests/ui/stability-attribute/issue-106589.stderr b/tests/ui/stability-attribute/issue-106589.stderr
new file mode 100644 (file)
index 0000000..ccf3f71
--- /dev/null
@@ -0,0 +1,15 @@
+error[E0734]: stability attributes may not be used outside of the standard library
+  --> $DIR/issue-106589.rs:6:1
+   |
+LL | #[unstable(feature = "foo", issue = "none")]
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0734]: stability attributes may not be used outside of the standard library
+  --> $DIR/issue-106589.rs:3:1
+   |
+LL | #![stable(feature = "foo", since = "1.0.0")]
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0734`.