Skip to content

Commit

Permalink
Auto merge of #106627 - Ezrashaw:no-e0711-without-staged-api, r=Mark-…
Browse files Browse the repository at this point in the history
…Simulacrum

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.
  • Loading branch information
bors committed Jan 17, 2023
2 parents 85357e3 + be1a6db commit 159ba8a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/rustc_passes/src/lib_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/stability-attribute/issue-106589.rs
Original file line number Diff line number Diff line change
@@ -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() {}
15 changes: 15 additions & 0 deletions tests/ui/stability-attribute/issue-106589.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 159ba8a

Please sign in to comment.