summary refs log tree commit diff
diff options
context:
space:
mode:
authorEzra Shaw <ezrasure@outlook.com>2023-01-09 23:21:31 +1300
committerEzra Shaw <ezrasure@outlook.com>2023-01-14 22:04:42 +1300
commitbe1a6db9f8978113021e3f1214ea66700a22fe9a (patch)
tree6b35d538b73ed2ba7dd6c2eecd2893541396a8a8
parente9e09083674a58d361cd805877be55b5856d2806 (diff)
downloadrust-be1a6db9f8978113021e3f1214ea66700a22fe9a.tar.gz
rust-be1a6db9f8978113021e3f1214ea66700a22fe9a.zip
fix: don't emit `E0711` if `staged_api` not enabled
-rw-r--r--compiler/rustc_passes/src/lib_features.rs6
-rw-r--r--tests/ui/stability-attribute/issue-106589.rs10
-rw-r--r--tests/ui/stability-attribute/issue-106589.stderr15
3 files changed, 31 insertions, 0 deletions
diff --git a/compiler/rustc_passes/src/lib_features.rs b/compiler/rustc_passes/src/lib_features.rs
index b5843c0ae48..4c6a9b23fdf 100644
--- a/compiler/rustc_passes/src/lib_features.rs
+++ b/compiler/rustc_passes/src/lib_features.rs
@@ -137,6 +137,12 @@ impl<'tcx> Visitor<'tcx> for LibFeatureCollector<'tcx> {
 }
 
 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
index 00000000000..3cad9a3d283
--- /dev/null
+++ b/tests/ui/stability-attribute/issue-106589.rs
@@ -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
index 00000000000..ccf3f7164e3
--- /dev/null
+++ b/tests/ui/stability-attribute/issue-106589.stderr
@@ -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`.