Skip to content

Commit 24ce65c

Browse files
committed
docs/test: add error-docs and UI test for E0711
1 parent ecc0507 commit 24ce65c

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ E0713: include_str!("./error_codes/E0713.md"),
436436
E0714: include_str!("./error_codes/E0714.md"),
437437
E0715: include_str!("./error_codes/E0715.md"),
438438
E0716: include_str!("./error_codes/E0716.md"),
439+
E0711: include_str!("./error_codes/E0711.md"),
439440
E0717: include_str!("./error_codes/E0717.md"),
440441
E0718: include_str!("./error_codes/E0718.md"),
441442
E0719: include_str!("./error_codes/E0719.md"),
@@ -640,7 +641,6 @@ E0791: include_str!("./error_codes/E0791.md"),
640641
// E0702, // replaced with a generic attribute input check
641642
// E0707, // multiple elided lifetimes used in arguments of `async fn`
642643
// E0709, // multiple different lifetimes used in arguments of `async fn`
643-
E0711, // a feature has been declared with conflicting stability attributes, internal error code
644644
// E0721, // `await` keyword
645645
// E0723, // unstable feature in `const` context
646646
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
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+
Feature declared with conflicting stability requirements.
4+
5+
```compile_fail,E0711
6+
// NOTE: this attribute is perma-unstable and should *never* be used outside of
7+
// stdlib and the compiler.
8+
#![feature(staged_api)]
9+
10+
#![stable(feature = "...", since = "1.0.0")]
11+
12+
#[stable(feature = "foo", since = "1.0.0")]
13+
fn foo_stable_1_0_0() {}
14+
15+
// error: feature `foo` is declared stable since 1.29.0
16+
#[stable(feature = "foo", since = "1.29.0")]
17+
fn foo_stable_1_29_0() {}
18+
19+
// error: feature `foo` is declared unstable
20+
#[unstable(feature = "foo", issue = "none")]
21+
fn foo_unstable() {}
22+
```
23+
24+
In the above example, the `foo` feature is first defined to be stable since
25+
1.0.0, but is then re-declared stable since 1.29.0. This discrepancy in
26+
versions causes an error. Furthermore, `foo` is then re-declared as unstable,
27+
again the conflict causes an error.
28+
29+
This error can be fixed by splitting the feature, this allows any
30+
stability requirements and removes any possibility of conflict.

src/test/ui/error-codes/E0711.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// copied from: src/test/ui/feature-gates/stability-attribute-consistency.rs
2+
3+
#![feature(staged_api)]
4+
5+
#![stable(feature = "stable_test_feature", since = "1.0.0")]
6+
7+
#[stable(feature = "foo", since = "1.0.0")]
8+
fn foo_stable_1_0_0() {}
9+
10+
#[stable(feature = "foo", since = "1.29.0")]
11+
//~^ ERROR feature `foo` is declared stable since 1.29.0
12+
fn foo_stable_1_29_0() {}
13+
14+
#[unstable(feature = "foo", issue = "none")]
15+
//~^ ERROR feature `foo` is declared unstable
16+
fn foo_unstable() {}
17+
18+
fn main() {}

src/test/ui/error-codes/E0711.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0711]: feature `foo` is declared stable since 1.29.0, but was previously declared stable since 1.0.0
2+
--> $DIR/E0711.rs:10:1
3+
|
4+
LL | #[stable(feature = "foo", since = "1.29.0")]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error[E0711]: feature `foo` is declared unstable, but was previously declared stable
8+
--> $DIR/E0711.rs:14:1
9+
|
10+
LL | #[unstable(feature = "foo", issue = "none")]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0711`.

0 commit comments

Comments
 (0)