Skip to content

Commit 00ff718

Browse files
committed
add UI test + docs for E0789
1 parent 94a300b commit 00ff718

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ E0785: include_str!("./error_codes/E0785.md"),
506506
E0786: include_str!("./error_codes/E0786.md"),
507507
E0787: include_str!("./error_codes/E0787.md"),
508508
E0788: include_str!("./error_codes/E0788.md"),
509+
E0789: include_str!("./error_codes/E0789.md"),
509510
E0790: include_str!("./error_codes/E0790.md"),
510511
E0791: include_str!("./error_codes/E0791.md"),
511512
E0792: include_str!("./error_codes/E0792.md"),
@@ -645,5 +646,4 @@ E0792: include_str!("./error_codes/E0792.md"),
645646
// E0721, // `await` keyword
646647
// E0723, // unstable feature in `const` context
647648
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
648-
E0789, // rustc_allowed_through_unstable_modules without stability attribute
649649
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#### This error code is internal to the compiler and will not be emitted with normal Rust code.
2+
3+
The internal `rustc_allowed_through_unstable_modules` attribute must be used
4+
on an item with a `stable` attribute.
5+
6+
Erroneous code example:
7+
8+
```compile_fail,E0789
9+
// NOTE: both of these attributes are perma-unstable and should *never* be
10+
// used outside of the compiler and standard library.
11+
#![feature(rustc_attrs)]
12+
#![feature(staged_api)]
13+
14+
#![unstable(feature = "foo_module", reason = "...", issue = "123")]
15+
16+
#[rustc_allowed_through_unstable_modules]
17+
// #[stable(feature = "foo", since = "1.0")]
18+
struct Foo;
19+
// ^^^ error: `rustc_allowed_through_unstable_modules` attribute must be
20+
// paired with a `stable` attribute
21+
```
22+
23+
Typically when an item is marked with a `stable` attribute, the modules that
24+
enclose the item must also be marked with `stable` attributes, otherwise the
25+
item becomes *de facto* unstable. `#[rustc_allowed_through_unstable_modules]`
26+
is a workaround which allows an item to "escape" its unstable parent modules.
27+
This error occurs when an item is marked with
28+
`#[rustc_allowed_through_unstable_modules]` but no supplementary `stable`
29+
attribute exists. See [#99288](https://github.com/rust-lang/rust/pull/99288)
30+
for an example of `#[rustc_allowed_through_unstable_modules]` in use.

src/tools/tidy/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const IGNORE_DOCTEST_CHECK: &[&str] = &["E0464", "E0570", "E0601", "E0602", "E06
3131

3232
// Error codes that don't yet have a UI test. This list will eventually be removed.
3333
const IGNORE_UI_TEST_CHECK: &[&str] =
34-
&["E0461", "E0465", "E0476", "E0514", "E0523", "E0554", "E0640", "E0717", "E0729", "E0789"];
34+
&["E0461", "E0465", "E0476", "E0514", "E0523", "E0554", "E0640", "E0717", "E0729"];
3535

3636
macro_rules! verbose_print {
3737
($verbose:expr, $($fmt:tt)*) => {

tests/ui/error-codes/E0789.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// compile-flags: --crate-type lib
2+
3+
#![feature(rustc_attrs)]
4+
#![feature(staged_api)]
5+
#![unstable(feature = "foo_module", reason = "...", issue = "123")]
6+
7+
#[rustc_allowed_through_unstable_modules]
8+
// #[stable(feature = "foo", since = "1.0")]
9+
struct Foo;
10+
//~^ ERROR `rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute
11+
//~^^ ERROR `rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute
12+
// FIXME: we shouldn't have two errors here, only occurs when using `-Zdeduplicate-diagnostics=no`

tests/ui/error-codes/E0789.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0789]: `rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute
2+
--> $DIR/E0789.rs:9:1
3+
|
4+
LL | struct Foo;
5+
| ^^^^^^^^^^^
6+
7+
error[E0789]: `rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute
8+
--> $DIR/E0789.rs:9:1
9+
|
10+
LL | struct Foo;
11+
| ^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0789`.

0 commit comments

Comments
 (0)