Skip to content

Commit d3e24bd

Browse files
authored
Rollup merge of rust-lang#71350 - GuillaumeGomez:error-code-explanation-extra-check, r=oli-obk
Error code explanation extra check r? @Mark-Simulacrum
2 parents 10e47f5 + 5cdea2d commit d3e24bd

25 files changed

+231
-84
lines changed

src/librustc_error_codes/error_codes/E0060.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ External C functions are allowed to be variadic. However, a variadic function
22
takes a minimum number of arguments. For example, consider C's variadic `printf`
33
function:
44

5-
```
5+
```compile_fail,E0060
66
use std::os::raw::{c_char, c_int};
77
88
extern "C" {
99
fn printf(_: *const c_char, ...) -> c_int;
1010
}
11+
12+
unsafe { printf(); } // error!
1113
```
1214

1315
Using this declaration, it must be called with at least one argument, so

src/librustc_error_codes/error_codes/E0130.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ A pattern was declared as an argument in a foreign function declaration.
22

33
Erroneous code example:
44

5-
```compile_fail
5+
```compile_fail,E0130
66
extern {
77
fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
88
// function declarations

src/librustc_error_codes/error_codes/E0198.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ A negative implementation was marked as unsafe.
22

33
Erroneous code example:
44

5-
```compile_fail
5+
```compile_fail,E0198
66
struct Foo;
77
88
unsafe impl !Clone for Foo { } // error!
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
Inherent associated types were part of [RFC 195] but are not yet implemented.
22
See [the tracking issue][iss8995] for the status of this implementation.
33

4+
Erroneous code example:
5+
6+
```compile_fail,E0202
7+
struct Foo;
8+
9+
impl Foo {
10+
type Bar = isize; // error!
11+
}
12+
```
13+
414
[RFC 195]: https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md
515
[iss8995]: https://github.com/rust-lang/rust/issues/8995

src/librustc_error_codes/error_codes/E0230.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ message for when a particular trait isn't implemented on a type placed in a
33
position that needs that trait. For example, when the following code is
44
compiled:
55

6-
```compile_fail
6+
```compile_fail,E0230
77
#![feature(rustc_attrs)]
88
9-
fn foo<T: Index<u8>>(x: T){}
10-
11-
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
12-
trait Index<Idx> { /* ... */ }
13-
14-
foo(true); // `bool` does not implement `Index<u8>`
9+
#[rustc_on_unimplemented = "error on `{Self}` with params `<{A},{B}>`"] // error
10+
trait BadAnnotation<A> {}
1511
```
1612

1713
There will be an error about `bool` not implementing `Index<u8>`, followed by a

src/librustc_error_codes/error_codes/E0231.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ message for when a particular trait isn't implemented on a type placed in a
33
position that needs that trait. For example, when the following code is
44
compiled:
55

6-
```compile_fail
6+
```compile_fail,E0231
77
#![feature(rustc_attrs)]
88
9-
fn foo<T: Index<u8>>(x: T){}
10-
11-
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
12-
trait Index<Idx> { /* ... */ }
13-
14-
foo(true); // `bool` does not implement `Index<u8>`
9+
#[rustc_on_unimplemented = "error on `{Self}` with params `<{A},{}>`"] // error!
10+
trait BadAnnotation<A> {}
1511
```
1612

1713
there will be an error about `bool` not implementing `Index<u8>`, followed by a

src/librustc_error_codes/error_codes/E0232.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ message for when a particular trait isn't implemented on a type placed in a
33
position that needs that trait. For example, when the following code is
44
compiled:
55

6-
```compile_fail
6+
```compile_fail,E0232
77
#![feature(rustc_attrs)]
88
9-
fn foo<T: Index<u8>>(x: T){}
10-
11-
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
12-
trait Index<Idx> { /* ... */ }
13-
14-
foo(true); // `bool` does not implement `Index<u8>`
9+
#[rustc_on_unimplemented(lorem="")] // error!
10+
trait BadAnnotation {}
1511
```
1612

1713
there will be an error about `bool` not implementing `Index<u8>`, followed by a

src/librustc_error_codes/error_codes/E0281.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You tried to supply a type which doesn't implement some trait in a location
44
which expected that trait. This error typically occurs when working with
55
`Fn`-based types. Erroneous code example:
66

7-
```compile-fail
7+
```compile_fail
88
fn foo<F: Fn(usize)>(x: F) { }
99
1010
fn main() {

src/librustc_error_codes/error_codes/E0364.md

+13-13
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ attempted to `pub use` a type or value that was not itself public.
33

44
Erroneous code example:
55

6-
```compile_fail
7-
mod foo {
8-
const X: u32 = 1;
9-
}
10-
11-
pub use foo::X;
6+
```compile_fail,E0364
7+
mod a {
8+
fn foo() {}
129
13-
fn main() {}
10+
mod a {
11+
pub use super::foo; // error!
12+
}
13+
}
1414
```
1515

1616
The solution to this problem is to ensure that the items that you are
1717
re-exporting are themselves marked with `pub`:
1818

1919
```
20-
mod foo {
21-
pub const X: u32 = 1;
22-
}
23-
24-
pub use foo::X;
20+
mod a {
21+
pub fn foo() {} // ok!
2522
26-
fn main() {}
23+
mod a {
24+
pub use super::foo;
25+
}
26+
}
2727
```
2828

2929
See the [Use Declarations][use-declarations] section of the reference for

src/librustc_error_codes/error_codes/E0378.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ or a newtype wrapper around a pointer.
33

44
Erroneous code example:
55

6-
```compile-fail,E0378
6+
```compile_fail,E0378
77
#![feature(dispatch_from_dyn)]
88
use std::ops::DispatchFromDyn;
99

src/librustc_error_codes/error_codes/E0590.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
Example of erroneous code:
55

6-
```compile_fail
6+
```compile_fail,E0590
77
while break {}
88
```
99

src/librustc_error_codes/error_codes/E0639.md

+12
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,17 @@ instantiated from outside of the defining crate as it has been marked
33
as `non_exhaustive` and as such more fields/variants may be added in
44
future that could cause adverse side effects for this code.
55

6+
Erroneous code example:
7+
8+
```ignore (it only works cross-crate)
9+
#[non_exhaustive]
10+
pub struct NormalStruct {
11+
pub first_field: u16,
12+
pub second_field: u16,
13+
}
14+
15+
let ns = NormalStruct { first_field: 640, second_field: 480 }; // error!
16+
```
17+
618
It is recommended that you look for a `new` function or equivalent in the
719
crate's documentation.

src/librustc_error_codes/error_codes/E0644.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ A closure or generator was constructed that references its own type.
22

33
Erroneous example:
44

5-
```compile-fail,E0644
5+
```compile_fail,E0644
66
fn fix<F>(f: &F)
77
where F: Fn(&F)
88
{
9-
f(&f);
9+
f(&f);
1010
}
1111
1212
fn main() {
13-
fix(&|y| {
14-
// Here, when `x` is called, the parameter `y` is equal to `x`.
15-
});
13+
fix(&|y| {
14+
// Here, when `x` is called, the parameter `y` is equal to `x`.
15+
});
1616
}
1717
```
1818

src/librustc_error_codes/error_codes/E0658.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ An unstable feature was used.
22

33
Erroneous code example:
44

5-
```compile_fail,E658
5+
```compile_fail,E0658
66
#[repr(u128)] // error: use of unstable library feature 'repr128'
77
enum Foo {
88
Bar(u64),

src/librustc_error_codes/error_codes/E0669.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
Cannot convert inline assembly operand to a single LLVM value.
22

3+
Erroneous code example:
4+
5+
```compile_fail,E0669
6+
#![feature(llvm_asm)]
7+
8+
fn main() {
9+
unsafe {
10+
llvm_asm!("" :: "r"("")); // error!
11+
}
12+
}
13+
```
14+
315
This error usually happens when trying to pass in a value to an input inline
416
assembly operand that is actually a pair of values. In particular, this can
517
happen when trying to pass in a slice, for instance a `&str`. In Rust, these

src/librustc_error_codes/error_codes/E0698.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ generator can be constructed.
33

44
Erroneous code example:
55

6-
```edition2018,compile-fail,E0698
6+
```edition2018,compile_fail,E0698
77
async fn bar<T>() -> () {}
88
99
async fn foo() {

src/librustc_error_codes/error_codes/E0700.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ appear within the `impl Trait` itself.
33

44
Erroneous code example:
55

6-
```compile-fail,E0700
6+
```compile_fail,E0700
77
use std::cell::Cell;
88
99
trait Trait<'a> { }

src/librustc_error_codes/error_codes/E0708.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Erroneous code example:
44

5-
```compile_fail,edition2018
5+
```compile_fail,edition2018,E0708
66
#![feature(async_closure)]
77
88
fn main() {
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
A `#[marker]` trait contained an associated item.
22

3+
Erroneous code example:
4+
5+
```compile_fail,E0714
6+
#![feature(marker_trait_attr)]
7+
#![feature(associated_type_defaults)]
8+
9+
#[marker]
10+
trait MarkerConst {
11+
const N: usize; // error!
12+
}
13+
14+
fn main() {}
15+
```
16+
317
The items of marker traits cannot be overridden, so there's no need to have them
418
when they cannot be changed per-type anyway. If you wanted them for ergonomic
519
reasons, consider making an extension trait instead.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
An `impl` for a `#[marker]` trait tried to override an associated item.
22

3+
Erroneous code example:
4+
5+
```compile_fail,E0715
6+
#![feature(marker_trait_attr)]
7+
8+
#[marker]
9+
trait Marker {
10+
const N: usize = 0;
11+
fn do_something() {}
12+
}
13+
14+
struct OverrideConst;
15+
impl Marker for OverrideConst { // error!
16+
const N: usize = 1;
17+
}
18+
19+
fn main() {}
20+
```
21+
322
Because marker traits are allowed to have multiple implementations for the same
423
type, it's not allowed to override anything in those implementations, as it
524
would be ambiguous which override should actually be used.

src/librustc_error_codes/error_codes/E0727.md

+14-10
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,29 @@ A `yield` clause was used in an `async` context.
22

33
Example of erroneous code:
44

5-
```compile_fail
5+
```compile_fail,E0727,edition2018
66
#![feature(generators)]
77
8-
let generator = || {
9-
async {
10-
yield;
11-
}
12-
};
8+
fn main() {
9+
let generator = || {
10+
async {
11+
yield;
12+
}
13+
};
14+
}
1315
```
1416

1517
Here, the `yield` keyword is used in an `async` block,
1618
which is not yet supported.
1719

1820
To fix this error, you have to move `yield` out of the `async` block:
1921

20-
```
22+
```edition2018
2123
#![feature(generators)]
2224
23-
let generator = || {
24-
yield;
25-
};
25+
fn main() {
26+
let generator = || {
27+
yield;
28+
};
29+
}
2630
```

src/librustc_error_codes/error_codes/E0732.md

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
An `enum` with a discriminant must specify a `#[repr(inttype)]`.
22

3+
Erroneous code example:
4+
5+
```compile_fail,E0732
6+
#![feature(arbitrary_enum_discriminant)]
7+
8+
enum Enum { // error!
9+
Unit = 1,
10+
Tuple() = 2,
11+
Struct{} = 3,
12+
}
13+
# fn main() {}
14+
```
15+
316
A `#[repr(inttype)]` must be provided on an `enum` if it has a non-unit
417
variant with a discriminant, or where there are both unit variants with
518
discriminants and non-unit variants. This restriction ensures that there
@@ -23,7 +36,9 @@ fn discriminant(v : &Enum) -> u8 {
2336
unsafe { *(v as *const Enum as *const u8) }
2437
}
2538
26-
assert_eq!(3, discriminant(&Enum::Unit));
27-
assert_eq!(2, discriminant(&Enum::Tuple(5)));
28-
assert_eq!(1, discriminant(&Enum::Struct{a: 7, b: 11}));
39+
fn main() {
40+
assert_eq!(3, discriminant(&Enum::Unit));
41+
assert_eq!(2, discriminant(&Enum::Tuple(5)));
42+
assert_eq!(1, discriminant(&Enum::Struct{a: 7, b: 11}));
43+
}
2944
```

0 commit comments

Comments
 (0)